Skip to content

Commit

Permalink
Stop using deprecated datetime functions
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Dec 29, 2024
1 parent b75fd31 commit 8fe012a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
18 changes: 9 additions & 9 deletions src/socketio/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timezone
import functools
import os
import socket
Expand Down Expand Up @@ -204,7 +204,7 @@ def _trigger_event(self, event, namespace, *args):
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]
Expand All @@ -213,14 +213,14 @@ def _trigger_event(self, event, namespace, *args):
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)

Expand All @@ -246,7 +246,7 @@ def _basic_enter_room(self, sid, namespace, room, eio_sid=None):
namespace,
room,
sid,
datetime.utcnow().isoformat() + 'Z',
datetime.now(timezone.utc).isoformat(),
), namespace=self.admin_namespace)
return ret

Expand All @@ -256,7 +256,7 @@ def _basic_leave_room(self, sid, namespace, room):
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)

Expand All @@ -276,7 +276,7 @@ def _emit(self, event, data, namespace, room=None, skip_sid=None,
namespace,
sid,
event_data,
datetime.utcnow().isoformat() + 'Z',
datetime.now(timezone.utc).isoformat(),
), namespace=self.admin_namespace)
return ret

Expand Down Expand Up @@ -335,7 +335,7 @@ def _eio_send_ping(socket, self): # pragma: no cover
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()

Expand Down Expand Up @@ -384,7 +384,7 @@ def serialize_socket(self, sid, namespace, eio_sid=None):
'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),
Expand Down
18 changes: 9 additions & 9 deletions src/socketio/async_admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import asyncio
from datetime import datetime
from datetime import datetime, timezone
import functools
import os
import socket
Expand Down Expand Up @@ -192,7 +192,7 @@ async def _trigger_event(self, event, namespace, *args):
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]
Expand All @@ -201,14 +201,14 @@ async def _trigger_event(self, event, namespace, *args):
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)

Expand All @@ -235,7 +235,7 @@ def _basic_enter_room(self, sid, namespace, room, eio_sid=None):
namespace,
room,
sid,
datetime.utcnow().isoformat() + 'Z',
datetime.now(timezone.utc).isoformat(),
)))
return ret

Expand All @@ -245,7 +245,7 @@ def _basic_leave_room(self, sid, namespace, room):
namespace,
room,
sid,
datetime.utcnow().isoformat() + 'Z',
datetime.now(timezone.utc).isoformat(),
)))
return self.sio.manager.__basic_leave_room(sid, namespace, room)

Expand All @@ -265,7 +265,7 @@ async def _emit(self, event, data, namespace, room=None, skip_sid=None,
namespace,
sid,
event_data,
datetime.utcnow().isoformat() + 'Z',
datetime.now(timezone.utc).isoformat(),
), namespace=self.admin_namespace)
return ret

Expand Down Expand Up @@ -324,7 +324,7 @@ async def _eio_send_ping(socket, self): # pragma: no cover
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()

Expand Down Expand Up @@ -377,7 +377,7 @@ def serialize_socket(self, sid, namespace, eio_sid=None):
'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),
Expand Down

0 comments on commit 8fe012a

Please sign in to comment.