python-engineio 4.9.0__py3-none-any.whl → 4.10.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
engineio/async_client.py CHANGED
@@ -62,7 +62,7 @@ class AsyncClient(base_client.BaseClient):
62
62
  :param http_session: an initialized ``aiohttp.ClientSession`` object to be
63
63
  used when sending requests to the server. Use it if
64
64
  you need to add special client options such as proxy
65
- servers, SSL certificates, etc.
65
+ servers, SSL certificates, custom CA bundle, etc.
66
66
  :param ssl_verify: ``True`` to verify SSL certificates, or ``False`` to
67
67
  skip SSL certificate verification, allowing
68
68
  connections to servers with self signed certificates.
@@ -19,7 +19,12 @@ class ASGIApp:
19
19
  :param other_asgi_app: A separate ASGI app that receives all other traffic.
20
20
  :param engineio_path: The endpoint where the Engine.IO application should
21
21
  be installed. The default value is appropriate for
22
- most cases.
22
+ most cases. With a value of ``None``, all incoming
23
+ traffic is directed to the Engine.IO server, with the
24
+ assumption that routing, if necessary, is handled by
25
+ a different layer. When this option is set to
26
+ ``None``, ``static_files`` and ``other_asgi_app`` are
27
+ ignored.
23
28
  :param on_startup: function to be called on application startup; can be
24
29
  coroutine
25
30
  :param on_shutdown: function to be called on application shutdown; can be
@@ -44,24 +49,27 @@ class ASGIApp:
44
49
  self.engineio_server = engineio_server
45
50
  self.other_asgi_app = other_asgi_app
46
51
  self.engineio_path = engineio_path
47
- if not self.engineio_path.startswith('/'):
48
- self.engineio_path = '/' + self.engineio_path
49
- if not self.engineio_path.endswith('/'):
50
- self.engineio_path += '/'
52
+ if self.engineio_path is not None:
53
+ if not self.engineio_path.startswith('/'):
54
+ self.engineio_path = '/' + self.engineio_path
55
+ if not self.engineio_path.endswith('/'):
56
+ self.engineio_path += '/'
51
57
  self.static_files = static_files or {}
52
58
  self.on_startup = on_startup
53
59
  self.on_shutdown = on_shutdown
54
60
 
55
61
  async def __call__(self, scope, receive, send):
56
- if scope['type'] in ['http', 'websocket'] and \
57
- scope['path'].startswith(self.engineio_path):
62
+ if scope['type'] == 'lifespan':
63
+ await self.lifespan(scope, receive, send)
64
+ elif scope['type'] in ['http', 'websocket'] and (
65
+ self.engineio_path is None
66
+ or self._ensure_trailing_slash(scope['path']).startswith(
67
+ self.engineio_path)):
58
68
  await self.engineio_server.handle_request(scope, receive, send)
59
69
  else:
60
70
  static_file = get_static_file(scope['path'], self.static_files) \
61
71
  if scope['type'] == 'http' and self.static_files else None
62
- if scope['type'] == 'lifespan':
63
- await self.lifespan(scope, receive, send)
64
- elif static_file and os.path.exists(static_file['filename']):
72
+ if static_file and os.path.exists(static_file['filename']):
65
73
  await self.serve_static_file(static_file, receive, send)
66
74
  elif self.other_asgi_app is not None:
67
75
  await self.other_asgi_app(scope, receive, send)
@@ -120,6 +128,11 @@ class ASGIApp:
120
128
  await send({'type': 'http.response.body',
121
129
  'body': b'Not Found'})
122
130
 
131
+ def _ensure_trailing_slash(self, path):
132
+ if not path.endswith('/'):
133
+ path += '/'
134
+ return path
135
+
123
136
 
124
137
  async def translate_request(scope, receive, send):
125
138
  class AwaitablePayload(object): # pragma: no cover
@@ -25,7 +25,7 @@ class EventletThread: # pragma: no cover
25
25
  return self.g.wait()
26
26
 
27
27
 
28
- class WebSocketWSGI(_WebSocketWSGI):
28
+ class WebSocketWSGI(_WebSocketWSGI): # pragma: no cover
29
29
  def __init__(self, handler, server):
30
30
  try:
31
31
  super().__init__(
engineio/async_server.py CHANGED
@@ -70,6 +70,10 @@ class AsyncServer(base_server.BaseServer):
70
70
  :param async_handlers: If set to ``True``, run message event handlers in
71
71
  non-blocking threads. To run handlers synchronously,
72
72
  set to ``False``. The default is ``True``.
73
+ :param monitor_clients: If set to ``True``, a background task will ensure
74
+ inactive clients are closed. Set to ``False`` to
75
+ disable the monitoring task (not recommended). The
76
+ default is ``True``.
73
77
  :param transports: The list of allowed transports. Valid transports
74
78
  are ``'polling'`` and ``'websocket'``. Defaults to
75
79
  ``['polling', 'websocket']``.
@@ -284,18 +288,24 @@ class AsyncServer(base_server.BaseServer):
284
288
  r = self._bad_request('Invalid session ' + sid)
285
289
  else:
286
290
  socket = self._get_socket(sid)
287
- try:
288
- packets = await socket.handle_get_request(environ)
289
- if isinstance(packets, list):
290
- r = self._ok(packets, jsonp_index=jsonp_index)
291
- else:
292
- r = packets
293
- except exceptions.EngineIOError:
294
- if sid in self.sockets: # pragma: no cover
295
- await self.disconnect(sid)
296
- r = self._bad_request()
297
- if sid in self.sockets and self.sockets[sid].closed:
298
- del self.sockets[sid]
291
+ if self.transport(sid) != transport:
292
+ self._log_error_once(
293
+ 'Invalid transport for session ' + sid,
294
+ 'bad-transport')
295
+ r = self._bad_request('Invalid transport')
296
+ else:
297
+ try:
298
+ packets = await socket.handle_get_request(environ)
299
+ if isinstance(packets, list):
300
+ r = self._ok(packets, jsonp_index=jsonp_index)
301
+ else:
302
+ r = packets
303
+ except exceptions.EngineIOError:
304
+ if sid in self.sockets: # pragma: no cover
305
+ await self.disconnect(sid)
306
+ r = self._bad_request()
307
+ if sid in self.sockets and self.sockets[sid].closed:
308
+ del self.sockets[sid]
299
309
  elif method == 'POST':
300
310
  if sid is None or sid not in self.sockets:
301
311
  self._log_error_once('Invalid session ' + sid, 'bad-sid')
@@ -524,9 +534,9 @@ class AsyncServer(base_server.BaseServer):
524
534
  try:
525
535
  await asyncio.wait_for(self.service_task_event.wait(),
526
536
  timeout=self.ping_timeout)
527
- except asyncio.TimeoutError:
528
537
  break
529
- continue
538
+ except asyncio.TimeoutError:
539
+ continue
530
540
 
531
541
  # go through the entire client list in a ping interval cycle
532
542
  sleep_interval = self.ping_timeout / len(self.sockets)
@@ -546,8 +556,9 @@ class AsyncServer(base_server.BaseServer):
546
556
  try:
547
557
  await asyncio.wait_for(self.service_task_event.wait(),
548
558
  timeout=sleep_interval)
549
- except asyncio.TimeoutError:
550
559
  raise KeyboardInterrupt()
560
+ except asyncio.TimeoutError:
561
+ continue
551
562
  except (
552
563
  SystemExit,
553
564
  KeyboardInterrupt,
engineio/client.py CHANGED
@@ -494,7 +494,7 @@ class Client(base_client.BaseClient):
494
494
  p = None
495
495
  try:
496
496
  p = self.ws.recv()
497
- if len(p) == 0: # pragma: no cover
497
+ if len(p) == 0 and not self.ws.connected: # pragma: no cover
498
498
  # websocket client can return an empty string after close
499
499
  raise websocket.WebSocketConnectionClosedException()
500
500
  except websocket.WebSocketTimeoutException:
@@ -510,8 +510,7 @@ class Client(base_client.BaseClient):
510
510
  except Exception as e: # pragma: no cover
511
511
  if type(e) is OSError and e.errno == 9:
512
512
  self.logger.info(
513
- 'WebSocket connection is closing, aborting',
514
- str(e))
513
+ 'WebSocket connection is closing, aborting')
515
514
  else:
516
515
  self.logger.info(
517
516
  'Unexpected error receiving packet: "%s", aborting',
engineio/server.py CHANGED
@@ -180,7 +180,7 @@ class Server(base_server.BaseServer):
180
180
  if sid in self.sockets: # pragma: no cover
181
181
  del self.sockets[sid]
182
182
  else:
183
- for client in self.sockets.values():
183
+ for client in self.sockets.copy().values():
184
184
  client.close()
185
185
  self.sockets = {}
186
186
 
@@ -270,19 +270,25 @@ class Server(base_server.BaseServer):
270
270
  r = self._bad_request('Invalid session')
271
271
  else:
272
272
  socket = self._get_socket(sid)
273
- try:
274
- packets = socket.handle_get_request(
275
- environ, start_response)
276
- if isinstance(packets, list):
277
- r = self._ok(packets, jsonp_index=jsonp_index)
278
- else:
279
- r = packets
280
- except exceptions.EngineIOError:
281
- if sid in self.sockets: # pragma: no cover
282
- self.disconnect(sid)
283
- r = self._bad_request()
284
- if sid in self.sockets and self.sockets[sid].closed:
285
- del self.sockets[sid]
273
+ if self.transport(sid) != transport:
274
+ self._log_error_once(
275
+ 'Invalid transport for session ' + sid,
276
+ 'bad-transport')
277
+ r = self._bad_request('Invalid transport')
278
+ else:
279
+ try:
280
+ packets = socket.handle_get_request(
281
+ environ, start_response)
282
+ if isinstance(packets, list):
283
+ r = self._ok(packets, jsonp_index=jsonp_index)
284
+ else:
285
+ r = packets
286
+ except exceptions.EngineIOError:
287
+ if sid in self.sockets: # pragma: no cover
288
+ self.disconnect(sid)
289
+ r = self._bad_request()
290
+ if sid in self.sockets and self.sockets[sid].closed:
291
+ del self.sockets[sid]
286
292
  elif method == 'POST':
287
293
  if sid is None or sid not in self.sockets:
288
294
  self._log_error_once(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-engineio
3
- Version: 4.9.0
3
+ Version: 4.10.0
4
4
  Summary: Engine.IO server and client for Python
5
5
  Author-email: Miguel Grinberg <miguel.grinberg@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/miguelgrinberg/python-engineio
@@ -1,31 +1,31 @@
1
1
  engineio/__init__.py,sha256=0R2PY1EXu3sicP7mkA0_QxEVGRlFlgvsxfhByqREE1A,481
2
- engineio/async_client.py,sha256=QyHBWpLZxfBc4lK_eodkPM0xzsfVYpt7mzNaA9uG3cg,27932
3
- engineio/async_server.py,sha256=gO7Tq1i4c3rSnN2zQdRrbVZIrPCI9ynjFqsqyIVLP80,25061
2
+ engineio/async_client.py,sha256=jC7T6r_ya9LV46q4OdIQ041-3uLlRr6aUt__YmHNPEM,27950
3
+ engineio/async_server.py,sha256=q29JCvIpCriUXZoqHwjJUwV2bK2MRypMQptROGw6imI,25738
4
4
  engineio/async_socket.py,sha256=P8OZW1N5y7jr2hW1qLLK2y_Clt7aHdv2ucYW69mbU4Q,10305
5
5
  engineio/base_client.py,sha256=Q_w0Stvy89wPHwWk7411dRxpGjxNPypm4xy_4XMPZ9M,4872
6
6
  engineio/base_server.py,sha256=Em2RRpbohulKjmYTWHnf_lALKvTT_jHr442Rr2g_BEQ,14013
7
7
  engineio/base_socket.py,sha256=Bw6TWv1pnlXcDdqT59C5CyTaBi7l-_mkykIUuZLjz-g,400
8
- engineio/client.py,sha256=xz1KVYlxjynGUUn6hR_rga1sByYcVdYb5taMVsfXJkk,26291
8
+ engineio/client.py,sha256=m_eLSes3b-mE5MYajELquSktkAWceCNGZOtUU78as50,26285
9
9
  engineio/exceptions.py,sha256=FyuMb5qhX9CUYP3fEoe1m-faU96ApdQTSbblaaoo8LA,292
10
10
  engineio/json.py,sha256=SG5FTojqd1ix6u0dKXJsZVqqdYioZLO4S2GPL7BKl3U,405
11
11
  engineio/middleware.py,sha256=BF_qHAIZZnIbfiP256SD1CX3kzNWbSuto1cpih8oIFg,3766
12
12
  engineio/packet.py,sha256=ETMeLgdpZghXK9fth93IZO8pIft6Sg3d1QGpyTx4xBE,3189
13
13
  engineio/payload.py,sha256=2iLIFgIweTWkLok_UZ5zCgELmRSGyUUI5eeYcEerFSs,1547
14
- engineio/server.py,sha256=UegXydKobZaR1O0MxS_MENKNF7PBjpP_kPI0-OpI5EQ,21558
14
+ engineio/server.py,sha256=v0QnoLCD1ReVAhzQRn5keHmjZ61jEJXNQeikfXaELl0,21926
15
15
  engineio/socket.py,sha256=dasec3jXoV2eR1jmIrhEIfHzyUuuv8FwvxLB3DpyjeY,9996
16
16
  engineio/static_files.py,sha256=pwez9LQFaSQXMbtI0vLyD6UDiokQ4rNfmRYgVLKOthc,2064
17
17
  engineio/async_drivers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
18
  engineio/async_drivers/_websocket_wsgi.py,sha256=FGoRBGOUsEtlfklYNylR0o3oLOGmXIR8QzaCsGLgr3I,949
19
19
  engineio/async_drivers/aiohttp.py,sha256=zJdujjO6dSL_oKDDr4xfO4ID_Vd8faEp1AOIW4ogKME,3768
20
- engineio/async_drivers/asgi.py,sha256=AVEXVP4KLu0etH2kTiuJgVTUkstdNHh0srQSxXx3sBM,10354
21
- engineio/async_drivers/eventlet.py,sha256=IG6oLaWH663dw5CEnO-SRz6IsJb6lO55kRCYTdmqZE0,1755
20
+ engineio/async_drivers/asgi.py,sha256=mvCErNpYw1T7XE_1Ixb0YQN0YqJkKMpWqNV5_tZQYMg,11011
21
+ engineio/async_drivers/eventlet.py,sha256=_ZgPg0HTx_yhSm5iBcd3ez01yMg3KRFmb2ycKD8o8pY,1775
22
22
  engineio/async_drivers/gevent.py,sha256=hnJHeWdDQE2jfoLCP5DnwVPzsQlcTLJUMA5EVf1UL-k,2962
23
23
  engineio/async_drivers/gevent_uwsgi.py,sha256=cnjCsnDHTa6rKgwDKD6rLvIw1Yun-g4c1QbujOC_bMY,5962
24
24
  engineio/async_drivers/sanic.py,sha256=SY0HIp5DUHF7B55tJCBB_8qDjrRTD_FyNQ2cIwRIGR8,4538
25
25
  engineio/async_drivers/threading.py,sha256=ywmG59d4H6OHZjKarBN97-9BHEsRxFEz9YN-E9QAu_I,463
26
26
  engineio/async_drivers/tornado.py,sha256=9bB7FvY47Snx_h4rsNwRk5wIINf2ju7hXWTAqF3intA,5909
27
- python_engineio-4.9.0.dist-info/LICENSE,sha256=yel9Pbwfu82094CLKCzWRtuIev9PUxP-a76NTDFAWpw,1082
28
- python_engineio-4.9.0.dist-info/METADATA,sha256=Qb43yDoGFRx78nu3tWw4hLWtPAt3bU-44hLJV-4P8DA,2244
29
- python_engineio-4.9.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
30
- python_engineio-4.9.0.dist-info/top_level.txt,sha256=u8PmNisCZLwRYcWrNLe9wutQ2tt4zNi8IH362c-HWuA,9
31
- python_engineio-4.9.0.dist-info/RECORD,,
27
+ python_engineio-4.10.0.dist-info/LICENSE,sha256=yel9Pbwfu82094CLKCzWRtuIev9PUxP-a76NTDFAWpw,1082
28
+ python_engineio-4.10.0.dist-info/METADATA,sha256=SaBVFlF_cqRa2i_sQ3Fdiaz6GdxT1qASxZpSugLD57A,2245
29
+ python_engineio-4.10.0.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
30
+ python_engineio-4.10.0.dist-info/top_level.txt,sha256=u8PmNisCZLwRYcWrNLe9wutQ2tt4zNi8IH362c-HWuA,9
31
+ python_engineio-4.10.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.42.0)
2
+ Generator: setuptools (75.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5