Skip to content

Commit 1cadada

Browse files
Expose the ignore_queue option in namespaces (Fixes miguelgrinberg#1103)
1 parent de4d5b5 commit 1cadada

File tree

8 files changed

+69
-26
lines changed

8 files changed

+69
-26
lines changed

src/socketio/asyncio_namespace.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async def trigger_event(self, event, *args):
4242
return ret
4343

4444
async def emit(self, event, data=None, to=None, room=None, skip_sid=None,
45-
namespace=None, callback=None):
45+
namespace=None, callback=None, ignore_queue=False):
4646
"""Emit a custom event to one or more connected clients.
4747
4848
The only difference with the :func:`socketio.Server.emit` method is
@@ -54,10 +54,11 @@ async def emit(self, event, data=None, to=None, room=None, skip_sid=None,
5454
return await self.server.emit(event, data=data, to=to, room=room,
5555
skip_sid=skip_sid,
5656
namespace=namespace or self.namespace,
57-
callback=callback)
57+
callback=callback,
58+
ignore_queue=ignore_queue)
5859

5960
async def send(self, data, to=None, room=None, skip_sid=None,
60-
namespace=None, callback=None):
61+
namespace=None, callback=None, ignore_queue=False):
6162
"""Send a message to one or more connected clients.
6263
6364
The only difference with the :func:`socketio.Server.send` method is
@@ -69,10 +70,11 @@ async def send(self, data, to=None, room=None, skip_sid=None,
6970
return await self.server.send(data, to=to, room=room,
7071
skip_sid=skip_sid,
7172
namespace=namespace or self.namespace,
72-
callback=callback)
73+
callback=callback,
74+
ignore_queue=ignore_queue)
7375

7476
async def call(self, event, data=None, to=None, sid=None, namespace=None,
75-
timeout=None):
77+
timeout=None, ignore_queue=False):
7678
"""Emit a custom event to a client and wait for the response.
7779
7880
The only difference with the :func:`socketio.Server.call` method is
@@ -81,7 +83,8 @@ async def call(self, event, data=None, to=None, sid=None, namespace=None,
8183
"""
8284
return await self.server.call(event, data=data, to=to, sid=sid,
8385
namespace=namespace or self.namespace,
84-
timeout=timeout)
86+
timeout=timeout,
87+
ignore_queue=ignore_queue)
8588

8689
async def close_room(self, room, namespace=None):
8790
"""Close a room.

src/socketio/asyncio_server.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def attach(self, app, socketio_path='socket.io'):
117117
self.eio.attach(app, socketio_path)
118118

119119
async def emit(self, event, data=None, to=None, room=None, skip_sid=None,
120-
namespace=None, callback=None, **kwargs):
120+
namespace=None, callback=None, ignore_queue=False):
121121
"""Emit a custom event to one or more connected clients.
122122
123123
:param event: The event name. It can be any string. The event names
@@ -167,10 +167,10 @@ async def emit(self, event, data=None, to=None, room=None, skip_sid=None,
167167
room or 'all', namespace)
168168
await self.manager.emit(event, data, namespace, room=room,
169169
skip_sid=skip_sid, callback=callback,
170-
**kwargs)
170+
ignore_queue=ignore_queue)
171171

172172
async def send(self, data, to=None, room=None, skip_sid=None,
173-
namespace=None, callback=None, **kwargs):
173+
namespace=None, callback=None, ignore_queue=False):
174174
"""Send a message to one or more connected clients.
175175
176176
This function emits an event with the name ``'message'``. Use
@@ -210,10 +210,10 @@ async def send(self, data, to=None, room=None, skip_sid=None,
210210
"""
211211
await self.emit('message', data=data, to=to, room=room,
212212
skip_sid=skip_sid, namespace=namespace,
213-
callback=callback, **kwargs)
213+
callback=callback, ignore_queue=ignore_queue)
214214

215215
async def call(self, event, data=None, to=None, sid=None, namespace=None,
216-
timeout=60, **kwargs):
216+
timeout=60, ignore_queue=False):
217217
"""Emit a custom event to a client and wait for the response.
218218
219219
This method issues an emit with a callback and waits for the callback
@@ -266,7 +266,7 @@ def event_callback(*args):
266266
callback_event.set()
267267

268268
await self.emit(event, data=data, room=to or sid, namespace=namespace,
269-
callback=event_callback, **kwargs)
269+
callback=event_callback, ignore_queue=ignore_queue)
270270
try:
271271
await asyncio.wait_for(callback_event.wait(), timeout)
272272
except asyncio.TimeoutError:

src/socketio/namespace.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def _set_server(self, server):
3838
self.server = server
3939

4040
def emit(self, event, data=None, to=None, room=None, skip_sid=None,
41-
namespace=None, callback=None):
41+
namespace=None, callback=None, ignore_queue=False):
4242
"""Emit a custom event to one or more connected clients.
4343
4444
The only difference with the :func:`socketio.Server.emit` method is
@@ -48,10 +48,10 @@ def emit(self, event, data=None, to=None, room=None, skip_sid=None,
4848
return self.server.emit(event, data=data, to=to, room=room,
4949
skip_sid=skip_sid,
5050
namespace=namespace or self.namespace,
51-
callback=callback)
51+
callback=callback, ignore_queue=ignore_queue)
5252

5353
def send(self, data, to=None, room=None, skip_sid=None, namespace=None,
54-
callback=None):
54+
callback=None, ignore_queue=False):
5555
"""Send a message to one or more connected clients.
5656
5757
The only difference with the :func:`socketio.Server.send` method is
@@ -60,10 +60,10 @@ def send(self, data, to=None, room=None, skip_sid=None, namespace=None,
6060
"""
6161
return self.server.send(data, to=to, room=room, skip_sid=skip_sid,
6262
namespace=namespace or self.namespace,
63-
callback=callback)
63+
callback=callback, ignore_queue=ignore_queue)
6464

6565
def call(self, event, data=None, to=None, sid=None, namespace=None,
66-
timeout=None):
66+
timeout=None, ignore_queue=False):
6767
"""Emit a custom event to a client and wait for the response.
6868
6969
The only difference with the :func:`socketio.Server.call` method is
@@ -72,7 +72,7 @@ def call(self, event, data=None, to=None, sid=None, namespace=None,
7272
"""
7373
return self.server.call(event, data=data, to=to, sid=sid,
7474
namespace=namespace or self.namespace,
75-
timeout=timeout)
75+
timeout=timeout, ignore_queue=ignore_queue)
7676

7777
def enter_room(self, sid, room, namespace=None):
7878
"""Enter a room.

src/socketio/server.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def register_namespace(self, namespace_handler):
269269
namespace_handler
270270

271271
def emit(self, event, data=None, to=None, room=None, skip_sid=None,
272-
namespace=None, callback=None, **kwargs):
272+
namespace=None, callback=None, ignore_queue=False):
273273
"""Emit a custom event to one or more connected clients.
274274
275275
:param event: The event name. It can be any string. The event names
@@ -317,10 +317,11 @@ def emit(self, event, data=None, to=None, room=None, skip_sid=None,
317317
self.logger.info('emitting event "%s" to %s [%s]', event,
318318
room or 'all', namespace)
319319
self.manager.emit(event, data, namespace, room=room,
320-
skip_sid=skip_sid, callback=callback, **kwargs)
320+
skip_sid=skip_sid, callback=callback,
321+
ignore_queue=ignore_queue)
321322

322323
def send(self, data, to=None, room=None, skip_sid=None, namespace=None,
323-
callback=None, **kwargs):
324+
callback=None, ignore_queue=False):
324325
"""Send a message to one or more connected clients.
325326
326327
This function emits an event with the name ``'message'``. Use
@@ -358,10 +359,11 @@ def send(self, data, to=None, room=None, skip_sid=None, namespace=None,
358359
value of ``False``.
359360
"""
360361
self.emit('message', data=data, to=to, room=room, skip_sid=skip_sid,
361-
namespace=namespace, callback=callback, **kwargs)
362+
namespace=namespace, callback=callback,
363+
ignore_queue=ignore_queue)
362364

363365
def call(self, event, data=None, to=None, sid=None, namespace=None,
364-
timeout=60, **kwargs):
366+
timeout=60, ignore_queue=False):
365367
"""Emit a custom event to a client and wait for the response.
366368
367369
This method issues an emit with a callback and waits for the callback
@@ -412,7 +414,7 @@ def event_callback(*args):
412414
callback_event.set()
413415

414416
self.emit(event, data=data, room=to or sid, namespace=namespace,
415-
callback=event_callback, **kwargs)
417+
callback=event_callback, ignore_queue=ignore_queue)
416418
if not callback_event.wait(timeout=timeout):
417419
raise exceptions.TimeoutError()
418420
return callback_args[0] if len(callback_args[0]) > 1 \

tests/asyncio/test_asyncio_namespace.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def test_emit(self):
104104
skip_sid='skip',
105105
namespace='/foo',
106106
callback='cb',
107+
ignore_queue=False,
107108
)
108109
_run(
109110
ns.emit(
@@ -113,6 +114,7 @@ def test_emit(self):
113114
skip_sid='skip',
114115
namespace='/bar',
115116
callback='cb',
117+
ignore_queue=True,
116118
)
117119
)
118120
ns.server.emit.mock.assert_called_with(
@@ -123,6 +125,7 @@ def test_emit(self):
123125
skip_sid='skip',
124126
namespace='/bar',
125127
callback='cb',
128+
ignore_queue=True,
126129
)
127130

128131
def test_send(self):
@@ -138,6 +141,7 @@ def test_send(self):
138141
skip_sid='skip',
139142
namespace='/foo',
140143
callback='cb',
144+
ignore_queue=False,
141145
)
142146
_run(
143147
ns.send(
@@ -146,6 +150,7 @@ def test_send(self):
146150
skip_sid='skip',
147151
namespace='/bar',
148152
callback='cb',
153+
ignore_queue=True,
149154
)
150155
)
151156
ns.server.send.mock.assert_called_with(
@@ -155,6 +160,7 @@ def test_send(self):
155160
skip_sid='skip',
156161
namespace='/bar',
157162
callback='cb',
163+
ignore_queue=True,
158164
)
159165

160166
def test_call(self):
@@ -170,16 +176,18 @@ def test_call(self):
170176
sid=None,
171177
namespace='/foo',
172178
timeout=None,
179+
ignore_queue=False,
173180
)
174181
_run(ns.call('ev', data='data', sid='sid', namespace='/bar',
175-
timeout=45))
182+
timeout=45, ignore_queue=True))
176183
ns.server.call.mock.assert_called_with(
177184
'ev',
178185
data='data',
179186
to=None,
180187
sid='sid',
181188
namespace='/bar',
182189
timeout=45,
190+
ignore_queue=True,
183191
)
184192

185193
def test_enter_room(self):

tests/asyncio/test_asyncio_server.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def test_emit(self, eio):
101101
room='room',
102102
skip_sid='123',
103103
callback='cb',
104+
ignore_queue=False,
104105
)
105106
_run(
106107
s.emit(
@@ -110,6 +111,7 @@ def test_emit(self, eio):
110111
skip_sid='123',
111112
namespace='/foo',
112113
callback='cb',
114+
ignore_queue=True,
113115
)
114116
)
115117
s.manager.emit.mock.assert_called_with(
@@ -119,6 +121,7 @@ def test_emit(self, eio):
119121
room='room',
120122
skip_sid='123',
121123
callback='cb',
124+
ignore_queue=True,
122125
)
123126

124127
def test_emit_default_namespace(self, eio):
@@ -140,6 +143,7 @@ def test_emit_default_namespace(self, eio):
140143
room='room',
141144
skip_sid='123',
142145
callback='cb',
146+
ignore_queue=False,
143147
)
144148
_run(
145149
s.emit(
@@ -148,6 +152,7 @@ def test_emit_default_namespace(self, eio):
148152
room='room',
149153
skip_sid='123',
150154
callback='cb',
155+
ignore_queue=True,
151156
)
152157
)
153158
s.manager.emit.mock.assert_called_with(
@@ -157,6 +162,7 @@ def test_emit_default_namespace(self, eio):
157162
room='room',
158163
skip_sid='123',
159164
callback='cb',
165+
ignore_queue=True,
160166
)
161167

162168
def test_send(self, eio):
@@ -178,6 +184,7 @@ def test_send(self, eio):
178184
room='room',
179185
skip_sid='123',
180186
callback='cb',
187+
ignore_queue=False,
181188
)
182189
_run(
183190
s.send(
@@ -186,6 +193,7 @@ def test_send(self, eio):
186193
skip_sid='123',
187194
namespace='/foo',
188195
callback='cb',
196+
ignore_queue=True,
189197
)
190198
)
191199
s.manager.emit.mock.assert_called_with(
@@ -195,6 +203,7 @@ def test_send(self, eio):
195203
room='room',
196204
skip_sid='123',
197205
callback='cb',
206+
ignore_queue=True,
198207
)
199208

200209
def test_call(self, eio):

tests/common/test_namespace.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def test_emit(self):
6565
skip_sid='skip',
6666
namespace='/foo',
6767
callback='cb',
68+
ignore_queue=False,
6869
)
6970
ns.emit(
7071
'ev',
@@ -73,6 +74,7 @@ def test_emit(self):
7374
skip_sid='skip',
7475
namespace='/bar',
7576
callback='cb',
77+
ignore_queue=True,
7678
)
7779
ns.server.emit.assert_called_with(
7880
'ev',
@@ -82,6 +84,7 @@ def test_emit(self):
8284
skip_sid='skip',
8385
namespace='/bar',
8486
callback='cb',
87+
ignore_queue=True,
8588
)
8689

8790
def test_send(self):
@@ -95,13 +98,15 @@ def test_send(self):
9598
skip_sid='skip',
9699
namespace='/foo',
97100
callback='cb',
101+
ignore_queue=False,
98102
)
99103
ns.send(
100104
data='data',
101105
room='room',
102106
skip_sid='skip',
103107
namespace='/bar',
104108
callback='cb',
109+
ignore_queue=True,
105110
)
106111
ns.server.send.assert_called_with(
107112
'data',
@@ -110,6 +115,7 @@ def test_send(self):
110115
skip_sid='skip',
111116
namespace='/bar',
112117
callback='cb',
118+
ignore_queue=True,
113119
)
114120

115121
def test_call(self):
@@ -123,13 +129,15 @@ def test_call(self):
123129
sid=None,
124130
namespace='/foo',
125131
timeout=None,
132+
ignore_queue=False,
126133
)
127134
ns.call(
128135
'ev',
129136
data='data',
130137
sid='sid',
131138
namespace='/bar',
132139
timeout=45,
140+
ignore_queue=True,
133141
)
134142
ns.server.call.assert_called_with(
135143
'ev',
@@ -138,6 +146,7 @@ def test_call(self):
138146
sid='sid',
139147
namespace='/bar',
140148
timeout=45,
149+
ignore_queue=True,
141150
)
142151

143152
def test_enter_room(self):

0 commit comments

Comments
 (0)