diff --git a/src/socketio/admin.py b/src/socketio/admin.py index 8d6fbcf..12b905e 100644 --- a/src/socketio/admin.py +++ b/src/socketio/admin.py @@ -1,4 +1,4 @@ -from datetime import datetime +from datetime import datetime, timezone import functools import os import socket @@ -204,7 +204,7 @@ class InstrumentedServer: serialized_socket = self.serialize_socket(sid, namespace, eio_sid) self.sio.emit('socket_connected', ( serialized_socket, - datetime.utcfromtimestamp(t).isoformat() + 'Z', + datetime.fromtimestamp(t, timezone.utc).isoformat(), ), namespace=self.admin_namespace) elif event == 'disconnect': del self.sio.manager._timestamps[sid] @@ -213,14 +213,14 @@ class InstrumentedServer: namespace, sid, reason, - datetime.utcfromtimestamp(t).isoformat() + 'Z', + datetime.fromtimestamp(t, timezone.utc).isoformat(), ), namespace=self.admin_namespace) else: self.sio.emit('event_received', ( namespace, sid, (event, *args[1:]), - datetime.utcfromtimestamp(t).isoformat() + 'Z', + datetime.fromtimestamp(t, timezone.utc).isoformat(), ), namespace=self.admin_namespace) return self.sio.__trigger_event(event, namespace, *args) @@ -246,7 +246,7 @@ class InstrumentedServer: namespace, room, sid, - datetime.utcnow().isoformat() + 'Z', + datetime.now(timezone.utc).isoformat(), ), namespace=self.admin_namespace) return ret @@ -256,7 +256,7 @@ class InstrumentedServer: namespace, room, sid, - datetime.utcnow().isoformat() + 'Z', + datetime.now(timezone.utc).isoformat(), ), namespace=self.admin_namespace) return self.sio.manager.__basic_leave_room(sid, namespace, room) @@ -276,7 +276,7 @@ class InstrumentedServer: namespace, sid, event_data, - datetime.utcnow().isoformat() + 'Z', + datetime.now(timezone.utc).isoformat(), ), namespace=self.admin_namespace) return ret @@ -335,7 +335,7 @@ class InstrumentedServer: eio_sid) self.sio.emit('socket_connected', ( serialized_socket, - datetime.utcfromtimestamp(t).isoformat() + 'Z', + datetime.fromtimestamp(t, timezone.utc).isoformat(), ), namespace=self.admin_namespace) return socket.__send_ping() @@ -384,7 +384,7 @@ class InstrumentedServer: 'secure': environ.get('wsgi.url_scheme', '') == 'https', 'url': environ.get('PATH_INFO', ''), 'issued': tm * 1000, - 'time': datetime.utcfromtimestamp(tm).isoformat() + 'Z' + 'time': datetime.fromtimestamp(tm, timezone.utc).isoformat() if tm else '', }, 'rooms': self.sio.manager.get_rooms(sid, namespace), diff --git a/src/socketio/async_admin.py b/src/socketio/async_admin.py index 68ea289..b052d8f 100644 --- a/src/socketio/async_admin.py +++ b/src/socketio/async_admin.py @@ -1,5 +1,5 @@ import asyncio -from datetime import datetime +from datetime import datetime, timezone import functools import os import socket @@ -192,7 +192,7 @@ class InstrumentedAsyncServer: serialized_socket = self.serialize_socket(sid, namespace, eio_sid) await self.sio.emit('socket_connected', ( serialized_socket, - datetime.utcfromtimestamp(t).isoformat() + 'Z', + datetime.fromtimestamp(t, timezone.utc).isoformat(), ), namespace=self.admin_namespace) elif event == 'disconnect': del self.sio.manager._timestamps[sid] @@ -201,14 +201,14 @@ class InstrumentedAsyncServer: namespace, sid, reason, - datetime.utcfromtimestamp(t).isoformat() + 'Z', + datetime.fromtimestamp(t, timezone.utc).isoformat(), ), namespace=self.admin_namespace) else: await self.sio.emit('event_received', ( namespace, sid, (event, *args[1:]), - datetime.utcfromtimestamp(t).isoformat() + 'Z', + datetime.fromtimestamp(t, timezone.utc).isoformat(), ), namespace=self.admin_namespace) return await self.sio.__trigger_event(event, namespace, *args) @@ -235,7 +235,7 @@ class InstrumentedAsyncServer: namespace, room, sid, - datetime.utcnow().isoformat() + 'Z', + datetime.now(timezone.utc).isoformat(), ))) return ret @@ -245,7 +245,7 @@ class InstrumentedAsyncServer: namespace, room, sid, - datetime.utcnow().isoformat() + 'Z', + datetime.now(timezone.utc).isoformat(), ))) return self.sio.manager.__basic_leave_room(sid, namespace, room) @@ -265,7 +265,7 @@ class InstrumentedAsyncServer: namespace, sid, event_data, - datetime.utcnow().isoformat() + 'Z', + datetime.now(timezone.utc).isoformat(), ), namespace=self.admin_namespace) return ret @@ -324,7 +324,7 @@ class InstrumentedAsyncServer: eio_sid) await self.sio.emit('socket_connected', ( serialized_socket, - datetime.utcfromtimestamp(t).isoformat() + 'Z', + datetime.fromtimestamp(t, timezone.utc).isoformat(), ), namespace=self.admin_namespace) return await socket.__send_ping() @@ -377,7 +377,7 @@ class InstrumentedAsyncServer: 'secure': environ.get('wsgi.url_scheme', '') == 'https', 'url': environ.get('PATH_INFO', ''), 'issued': tm * 1000, - 'time': datetime.utcfromtimestamp(tm).isoformat() + 'Z' + 'time': datetime.fromtimestamp(tm, timezone.utc).isoformat() if tm else '', }, 'rooms': self.sio.manager.get_rooms(sid, namespace),