python-engineio 4.9.0__tar.gz → 4.10.0__tar.gz

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.
Files changed (75) hide show
  1. {python-engineio-4.9.0/src/python_engineio.egg-info → python_engineio-4.10.0}/PKG-INFO +1 -1
  2. {python-engineio-4.9.0 → python_engineio-4.10.0}/pyproject.toml +1 -1
  3. {python-engineio-4.9.0 → python_engineio-4.10.0}/src/engineio/async_client.py +1 -1
  4. {python-engineio-4.9.0 → python_engineio-4.10.0}/src/engineio/async_drivers/asgi.py +23 -10
  5. {python-engineio-4.9.0 → python_engineio-4.10.0}/src/engineio/async_drivers/eventlet.py +1 -1
  6. {python-engineio-4.9.0 → python_engineio-4.10.0}/src/engineio/async_server.py +26 -15
  7. {python-engineio-4.9.0 → python_engineio-4.10.0}/src/engineio/client.py +2 -3
  8. {python-engineio-4.9.0 → python_engineio-4.10.0}/src/engineio/server.py +20 -14
  9. {python-engineio-4.9.0 → python_engineio-4.10.0/src/python_engineio.egg-info}/PKG-INFO +1 -1
  10. {python-engineio-4.9.0 → python_engineio-4.10.0}/src/python_engineio.egg-info/SOURCES.txt +0 -1
  11. {python-engineio-4.9.0 → python_engineio-4.10.0}/tests/async/test_asgi.py +70 -0
  12. {python-engineio-4.9.0 → python_engineio-4.10.0}/tests/async/test_server.py +26 -0
  13. {python-engineio-4.9.0 → python_engineio-4.10.0}/tests/common/test_server.py +39 -1
  14. {python-engineio-4.9.0 → python_engineio-4.10.0}/tox.ini +2 -2
  15. python-engineio-4.9.0/tests/common/test_async_eventlet.py +0 -29
  16. {python-engineio-4.9.0 → python_engineio-4.10.0}/LICENSE +0 -0
  17. {python-engineio-4.9.0 → python_engineio-4.10.0}/MANIFEST.in +0 -0
  18. {python-engineio-4.9.0 → python_engineio-4.10.0}/README.md +0 -0
  19. {python-engineio-4.9.0 → python_engineio-4.10.0}/docs/Makefile +0 -0
  20. {python-engineio-4.9.0 → python_engineio-4.10.0}/docs/_static/README.md +0 -0
  21. {python-engineio-4.9.0 → python_engineio-4.10.0}/docs/api.rst +0 -0
  22. {python-engineio-4.9.0 → python_engineio-4.10.0}/docs/client.rst +0 -0
  23. {python-engineio-4.9.0 → python_engineio-4.10.0}/docs/conf.py +0 -0
  24. {python-engineio-4.9.0 → python_engineio-4.10.0}/docs/index.rst +0 -0
  25. {python-engineio-4.9.0 → python_engineio-4.10.0}/docs/intro.rst +0 -0
  26. {python-engineio-4.9.0 → python_engineio-4.10.0}/docs/make.bat +0 -0
  27. {python-engineio-4.9.0 → python_engineio-4.10.0}/docs/server.rst +0 -0
  28. {python-engineio-4.9.0 → python_engineio-4.10.0}/setup.cfg +0 -0
  29. {python-engineio-4.9.0 → python_engineio-4.10.0}/src/engineio/__init__.py +0 -0
  30. {python-engineio-4.9.0 → python_engineio-4.10.0}/src/engineio/async_drivers/__init__.py +0 -0
  31. {python-engineio-4.9.0 → python_engineio-4.10.0}/src/engineio/async_drivers/_websocket_wsgi.py +0 -0
  32. {python-engineio-4.9.0 → python_engineio-4.10.0}/src/engineio/async_drivers/aiohttp.py +0 -0
  33. {python-engineio-4.9.0 → python_engineio-4.10.0}/src/engineio/async_drivers/gevent.py +0 -0
  34. {python-engineio-4.9.0 → python_engineio-4.10.0}/src/engineio/async_drivers/gevent_uwsgi.py +0 -0
  35. {python-engineio-4.9.0 → python_engineio-4.10.0}/src/engineio/async_drivers/sanic.py +0 -0
  36. {python-engineio-4.9.0 → python_engineio-4.10.0}/src/engineio/async_drivers/threading.py +0 -0
  37. {python-engineio-4.9.0 → python_engineio-4.10.0}/src/engineio/async_drivers/tornado.py +0 -0
  38. {python-engineio-4.9.0 → python_engineio-4.10.0}/src/engineio/async_socket.py +0 -0
  39. {python-engineio-4.9.0 → python_engineio-4.10.0}/src/engineio/base_client.py +0 -0
  40. {python-engineio-4.9.0 → python_engineio-4.10.0}/src/engineio/base_server.py +0 -0
  41. {python-engineio-4.9.0 → python_engineio-4.10.0}/src/engineio/base_socket.py +0 -0
  42. {python-engineio-4.9.0 → python_engineio-4.10.0}/src/engineio/exceptions.py +0 -0
  43. {python-engineio-4.9.0 → python_engineio-4.10.0}/src/engineio/json.py +0 -0
  44. {python-engineio-4.9.0 → python_engineio-4.10.0}/src/engineio/middleware.py +0 -0
  45. {python-engineio-4.9.0 → python_engineio-4.10.0}/src/engineio/packet.py +0 -0
  46. {python-engineio-4.9.0 → python_engineio-4.10.0}/src/engineio/payload.py +0 -0
  47. {python-engineio-4.9.0 → python_engineio-4.10.0}/src/engineio/socket.py +0 -0
  48. {python-engineio-4.9.0 → python_engineio-4.10.0}/src/engineio/static_files.py +0 -0
  49. {python-engineio-4.9.0 → python_engineio-4.10.0}/src/python_engineio.egg-info/dependency_links.txt +0 -0
  50. {python-engineio-4.9.0 → python_engineio-4.10.0}/src/python_engineio.egg-info/not-zip-safe +0 -0
  51. {python-engineio-4.9.0 → python_engineio-4.10.0}/src/python_engineio.egg-info/requires.txt +0 -0
  52. {python-engineio-4.9.0 → python_engineio-4.10.0}/src/python_engineio.egg-info/top_level.txt +0 -0
  53. {python-engineio-4.9.0 → python_engineio-4.10.0}/tests/__init__.py +0 -0
  54. {python-engineio-4.9.0 → python_engineio-4.10.0}/tests/async/__init__.py +0 -0
  55. {python-engineio-4.9.0 → python_engineio-4.10.0}/tests/async/index.html +0 -0
  56. {python-engineio-4.9.0 → python_engineio-4.10.0}/tests/async/test_aiohttp.py +0 -0
  57. {python-engineio-4.9.0 → python_engineio-4.10.0}/tests/async/test_client.py +0 -0
  58. {python-engineio-4.9.0 → python_engineio-4.10.0}/tests/async/test_sanic.py +0 -0
  59. {python-engineio-4.9.0 → python_engineio-4.10.0}/tests/async/test_socket.py +0 -0
  60. {python-engineio-4.9.0 → python_engineio-4.10.0}/tests/async/test_tornado.py +0 -0
  61. {python-engineio-4.9.0 → python_engineio-4.10.0}/tests/common/__init__.py +0 -0
  62. {python-engineio-4.9.0 → python_engineio-4.10.0}/tests/common/index.html +0 -0
  63. {python-engineio-4.9.0 → python_engineio-4.10.0}/tests/common/test_client.py +0 -0
  64. {python-engineio-4.9.0 → python_engineio-4.10.0}/tests/common/test_middleware.py +0 -0
  65. {python-engineio-4.9.0 → python_engineio-4.10.0}/tests/common/test_packet.py +0 -0
  66. {python-engineio-4.9.0 → python_engineio-4.10.0}/tests/common/test_payload.py +0 -0
  67. {python-engineio-4.9.0 → python_engineio-4.10.0}/tests/common/test_socket.py +0 -0
  68. {python-engineio-4.9.0 → python_engineio-4.10.0}/tests/performance/README.md +0 -0
  69. {python-engineio-4.9.0 → python_engineio-4.10.0}/tests/performance/binary_b64_packet.py +0 -0
  70. {python-engineio-4.9.0 → python_engineio-4.10.0}/tests/performance/binary_packet.py +0 -0
  71. {python-engineio-4.9.0 → python_engineio-4.10.0}/tests/performance/json_packet.py +0 -0
  72. {python-engineio-4.9.0 → python_engineio-4.10.0}/tests/performance/payload.py +0 -0
  73. {python-engineio-4.9.0 → python_engineio-4.10.0}/tests/performance/run.sh +0 -0
  74. {python-engineio-4.9.0 → python_engineio-4.10.0}/tests/performance/server_receive.py +0 -0
  75. {python-engineio-4.9.0 → python_engineio-4.10.0}/tests/performance/text_packet.py +0 -0
@@ -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,6 +1,6 @@
1
1
  [project]
2
2
  name = "python-engineio"
3
- version = "4.9.0"
3
+ version = "4.10.0"
4
4
  authors = [{name = "Miguel Grinberg", email = "miguel.grinberg@gmail.com"}]
5
5
  description = "Engine.IO server and client for Python"
6
6
  classifiers = [
@@ -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__(
@@ -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,
@@ -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',
@@ -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
@@ -56,7 +56,6 @@ tests/async/test_socket.py
56
56
  tests/async/test_tornado.py
57
57
  tests/common/__init__.py
58
58
  tests/common/index.html
59
- tests/common/test_async_eventlet.py
60
59
  tests/common/test_client.py
61
60
  tests/common/test_middleware.py
62
61
  tests/common/test_packet.py
@@ -38,12 +38,55 @@ class AsgiTests(unittest.TestCase):
38
38
  def test_engineio_routing(self):
39
39
  mock_server = mock.MagicMock()
40
40
  mock_server.handle_request = AsyncMock()
41
+
41
42
  app = async_asgi.ASGIApp(mock_server)
42
43
  scope = {'type': 'http', 'path': '/engine.io/'}
43
44
  _run(app(scope, 'receive', 'send'))
44
45
  mock_server.handle_request.mock.assert_called_once_with(
45
46
  scope, 'receive', 'send'
46
47
  )
48
+ mock_server.handle_request.mock.reset_mock()
49
+ scope = {'type': 'http', 'path': '/engine.io/'}
50
+ _run(app(scope, 'receive', 'send'))
51
+ mock_server.handle_request.mock.assert_called_once_with(
52
+ scope, 'receive', 'send'
53
+ )
54
+ mock_server.handle_request.mock.reset_mock()
55
+ scope = {'type': 'http', 'path': '/engine.iofoo/'}
56
+ _run(app(scope, 'receive', AsyncMock()))
57
+ mock_server.handle_request.mock.assert_not_called()
58
+
59
+ app = async_asgi.ASGIApp(mock_server, engineio_path=None)
60
+ mock_server.handle_request.mock.reset_mock()
61
+ scope = {'type': 'http', 'path': '/foo'}
62
+ _run(app(scope, 'receive', 'send'))
63
+ mock_server.handle_request.mock.assert_called_once_with(
64
+ scope, 'receive', 'send'
65
+ )
66
+
67
+ app = async_asgi.ASGIApp(mock_server, engineio_path='mysocket.io')
68
+ mock_server.handle_request.mock.reset_mock()
69
+ scope = {'type': 'http', 'path': '/mysocket.io'}
70
+ _run(app(scope, 'receive', 'send'))
71
+ mock_server.handle_request.mock.assert_called_once_with(
72
+ scope, 'receive', 'send'
73
+ )
74
+ mock_server.handle_request.mock.reset_mock()
75
+ scope = {'type': 'http', 'path': '/mysocket.io/'}
76
+ _run(app(scope, 'receive', 'send'))
77
+ mock_server.handle_request.mock.assert_called_once_with(
78
+ scope, 'receive', 'send'
79
+ )
80
+ mock_server.handle_request.mock.reset_mock()
81
+ scope = {'type': 'http', 'path': '/mysocket.io/foo'}
82
+ _run(app(scope, 'receive', 'send'))
83
+ mock_server.handle_request.mock.assert_called_once_with(
84
+ scope, 'receive', 'send'
85
+ )
86
+ mock_server.handle_request.mock.reset_mock()
87
+ scope = {'type': 'http', 'path': '/mysocket.iofoo'}
88
+ _run(app(scope, 'receive', AsyncMock()))
89
+ mock_server.handle_request.mock.assert_not_called()
47
90
 
48
91
  def test_other_app_routing(self):
49
92
  other_app = AsyncMock()
@@ -514,3 +557,30 @@ class AsgiTests(unittest.TestCase):
514
557
  environ['asgi.send'].mock.assert_called_with(
515
558
  {'type': 'websocket.close'}
516
559
  )
560
+
561
+ def test_sub_app_routing(self):
562
+
563
+ class ASGIDispatcher:
564
+ def __init__(self, routes):
565
+ self.routes = routes
566
+
567
+ async def __call__(self, scope, receive, send):
568
+ path = scope['path']
569
+ for prefix, app in self.routes.items():
570
+ if path.startswith(prefix):
571
+ await app(scope, receive, send)
572
+ return
573
+ assert False, 'No route found'
574
+
575
+ other_app = AsyncMock()
576
+ mock_server = mock.MagicMock()
577
+ mock_server.handle_request = AsyncMock()
578
+ eio_app = async_asgi.ASGIApp(mock_server, engineio_path=None)
579
+ root_app = ASGIDispatcher({'/foo': other_app, '/eio': eio_app})
580
+ scope = {'type': 'http', 'path': '/foo/bar'}
581
+ _run(root_app(scope, 'receive', 'send'))
582
+ other_app.mock.assert_called_once_with(scope, 'receive', 'send')
583
+ scope = {'type': 'http', 'path': '/eio/'}
584
+ _run(root_app(scope, 'receive', 'send'))
585
+ eio_app.engineio_server.handle_request.mock.assert_called_once_with(
586
+ scope, 'receive', 'send')
@@ -659,6 +659,32 @@ class TestAsyncServer(unittest.TestCase):
659
659
  assert len(s.sockets) == 0
660
660
  assert a._async['make_response'].call_args[0][0] == '400 BAD REQUEST'
661
661
 
662
+ @mock.patch('importlib.import_module')
663
+ def test_get_request_bad_websocket_transport(self, import_module):
664
+ a = self.get_async_mock(
665
+ {'REQUEST_METHOD': 'GET',
666
+ 'QUERY_STRING': 'EIO=4&transport=websocket&sid=foo'}
667
+ )
668
+ import_module.side_effect = [a]
669
+ s = async_server.AsyncServer()
670
+ s.sockets['foo'] = mock_socket = self._get_mock_socket()
671
+ mock_socket.upgraded = False
672
+ _run(s.handle_request('request'))
673
+ assert a._async['make_response'].call_args[0][0] == '400 BAD REQUEST'
674
+
675
+ @mock.patch('importlib.import_module')
676
+ def test_get_request_bad_polling_transport(self, import_module):
677
+ a = self.get_async_mock(
678
+ {'REQUEST_METHOD': 'GET',
679
+ 'QUERY_STRING': 'EIO=4&transport=polling&sid=foo'}
680
+ )
681
+ import_module.side_effect = [a]
682
+ s = async_server.AsyncServer()
683
+ s.sockets['foo'] = mock_socket = self._get_mock_socket()
684
+ mock_socket.upgraded = True
685
+ _run(s.handle_request('request'))
686
+ assert a._async['make_response'].call_args[0][0] == '400 BAD REQUEST'
687
+
662
688
  @mock.patch('importlib.import_module')
663
689
  def test_post_request_with_bad_sid(self, import_module):
664
690
  a = self.get_async_mock(
@@ -111,6 +111,14 @@ class TestServer(unittest.TestCase):
111
111
  del sys.modules['engineio.async_drivers.threading']
112
112
 
113
113
  def test_async_mode_eventlet(self):
114
+ sys.modules['eventlet'] = mock.MagicMock()
115
+ sys.modules['eventlet'].green = mock.MagicMock()
116
+ sys.modules['eventlet.green'] = sys.modules['eventlet'].green
117
+ sys.modules['eventlet.green'].threading = mock.MagicMock()
118
+ sys.modules['eventlet.green.threading'] = \
119
+ sys.modules['eventlet.green'].threading
120
+ sys.modules['eventlet'].websocket = mock.MagicMock()
121
+ sys.modules['eventlet.websocket'] = sys.modules['eventlet'].websocket
114
122
  s = server.Server(async_mode='eventlet')
115
123
  assert s.async_mode == 'eventlet'
116
124
 
@@ -120,6 +128,11 @@ class TestServer(unittest.TestCase):
120
128
  assert s._async['thread'] == async_eventlet.EventletThread
121
129
  assert s._async['queue'] == queue.Queue
122
130
  assert s._async['websocket'] == async_eventlet.WebSocketWSGI
131
+ del sys.modules['eventlet']
132
+ del sys.modules['eventlet.green']
133
+ del sys.modules['eventlet.green.threading']
134
+ del sys.modules['eventlet.websocket']
135
+ del sys.modules['engineio.async_drivers.eventlet']
123
136
 
124
137
  @mock.patch('importlib.import_module', side_effect=_mock_import)
125
138
  def test_async_mode_gevent_uwsgi(self, import_module):
@@ -228,7 +241,10 @@ class TestServer(unittest.TestCase):
228
241
  with pytest.raises(ValueError):
229
242
  server.Server(async_mode='foo')
230
243
 
231
- @mock.patch('importlib.import_module', side_effect=[_mock_async])
244
+ @mock.patch(
245
+ 'importlib.import_module',
246
+ side_effect=[_mock_async],
247
+ )
232
248
  def test_async_mode_auto_eventlet(self, import_module):
233
249
  s = server.Server()
234
250
  assert s.async_mode == 'eventlet'
@@ -867,6 +883,28 @@ class TestServer(unittest.TestCase):
867
883
  assert start_response.call_args[0][0] == '400 BAD REQUEST'
868
884
  assert len(s.sockets) == 0
869
885
 
886
+ def test_get_request_bad_websocket_transport(self):
887
+ s = server.Server()
888
+ mock_socket = self._get_mock_socket()
889
+ mock_socket.upgraded = False
890
+ s.sockets['foo'] = mock_socket
891
+ environ = {'REQUEST_METHOD': 'GET',
892
+ 'QUERY_STRING': 'EIO=4&transport=websocket&sid=foo'}
893
+ start_response = mock.MagicMock()
894
+ s.handle_request(environ, start_response)
895
+ assert start_response.call_args[0][0] == '400 BAD REQUEST'
896
+
897
+ def test_get_request_bad_polling_transport(self):
898
+ s = server.Server()
899
+ mock_socket = self._get_mock_socket()
900
+ mock_socket.upgraded = True
901
+ s.sockets['foo'] = mock_socket
902
+ environ = {'REQUEST_METHOD': 'GET',
903
+ 'QUERY_STRING': 'EIO=4&transport=polling&sid=foo'}
904
+ start_response = mock.MagicMock()
905
+ s.handle_request(environ, start_response)
906
+ assert start_response.call_args[0][0] == '400 BAD REQUEST'
907
+
870
908
  def test_post_request(self):
871
909
  s = server.Server()
872
910
  mock_socket = self._get_mock_socket()
@@ -1,5 +1,5 @@
1
1
  [tox]
2
- envlist=flake8,py38,py39,py310,py311,py312,pypy3,docs
2
+ envlist=flake8,py38,py39,py310,py311,py312,py313,pypy3,docs
3
3
  skip_missing_interpreters=True
4
4
 
5
5
  [gh-actions]
@@ -9,6 +9,7 @@ python =
9
9
  3.10: py310
10
10
  3.11: py311
11
11
  3.12: py312
12
+ 3.13: py313
12
13
  pypy-3: pypy3
13
14
 
14
15
  [testenv]
@@ -18,7 +19,6 @@ commands=
18
19
  deps=
19
20
  pytest
20
21
  pytest-cov
21
- eventlet
22
22
  aiohttp
23
23
  tornado
24
24
  requests
@@ -1,29 +0,0 @@
1
- import logging
2
- import unittest
3
- from unittest import mock
4
-
5
- from engineio.async_drivers import eventlet as async_eventlet
6
- import pytest
7
-
8
-
9
- class TestAsyncEventlet(unittest.TestCase):
10
- def setUp(self):
11
- logging.getLogger('engineio').setLevel(logging.NOTSET)
12
-
13
- def test_bad_environ(self):
14
- wsgi = async_eventlet.WebSocketWSGI(None, mock.MagicMock())
15
- environ = {'foo': 'bar'}
16
- start_response = 'bar'
17
- with pytest.raises(RuntimeError):
18
- wsgi(environ, start_response)
19
-
20
- @mock.patch(
21
- 'engineio.async_drivers.eventlet._WebSocketWSGI.__call__',
22
- return_value='data',
23
- )
24
- def test_wsgi_call(self, _WebSocketWSGI):
25
- _WebSocketWSGI.__call__ = lambda e, s: 'data'
26
- environ = {'eventlet.input': mock.MagicMock()}
27
- start_response = 'bar'
28
- wsgi = async_eventlet.WebSocketWSGI(None, mock.MagicMock())
29
- assert wsgi(environ, start_response) == 'data'