diff options
author | Lance Stout <lancestout@gmail.com> | 2010-11-18 00:44:51 -0500 |
---|---|---|
committer | Lance Stout <lancestout@gmail.com> | 2010-11-18 00:44:51 -0500 |
commit | 58b95e4ae45432ae97bd643c591f4f078f29f300 (patch) | |
tree | 0bf29e982c6f7a7d486d00f01188e021ab193aa1 /sleekxmpp/test/livesocket.py | |
parent | debf90935981622c7b23009b7edeb311fd57ee5c (diff) | |
parent | 60d3afe6b6814bb5d30c4d4d355451d3c15364ca (diff) | |
download | slixmpp-58b95e4ae45432ae97bd643c591f4f078f29f300.tar.gz slixmpp-58b95e4ae45432ae97bd643c591f4f078f29f300.tar.bz2 slixmpp-58b95e4ae45432ae97bd643c591f4f078f29f300.tar.xz slixmpp-58b95e4ae45432ae97bd643c591f4f078f29f300.zip |
Merge branch 'develop' of github.com:fritzy/SleekXMPP into roster
Diffstat (limited to 'sleekxmpp/test/livesocket.py')
-rw-r--r-- | sleekxmpp/test/livesocket.py | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/sleekxmpp/test/livesocket.py b/sleekxmpp/test/livesocket.py index 5e8c5471..3e0f2135 100644 --- a/sleekxmpp/test/livesocket.py +++ b/sleekxmpp/test/livesocket.py @@ -7,6 +7,7 @@ """ import socket +import threading try: import queue except ImportError: @@ -40,6 +41,8 @@ class TestLiveSocket(object): self.recv_buffer = [] self.recv_queue = queue.Queue() self.send_queue = queue.Queue() + self.send_queue_lock = threading.Lock() + self.recv_queue_lock = threading.Lock() self.is_live = True def __getattr__(self, name): @@ -108,7 +111,8 @@ class TestLiveSocket(object): Placeholders. Same as for socket.recv. """ data = self.socket.recv(*args, **kwargs) - self.recv_queue.put(data) + with self.recv_queue_lock: + self.recv_queue.put(data) return data def send(self, data): @@ -120,7 +124,8 @@ class TestLiveSocket(object): Arguments: data -- String value to write. """ - self.send_queue.put(data) + with self.send_queue_lock: + self.send_queue.put(data) self.socket.send(data) # ------------------------------------------------------------------ @@ -143,3 +148,15 @@ class TestLiveSocket(object): Placeholders, same as socket.recv() """ return self.recv(*args, **kwargs) + + def clear(self): + """ + Empty the send queue, typically done once the session has started to + remove the feature negotiation and log in stanzas. + """ + with self.send_queue_lock: + for i in range(0, self.send_queue.qsize()): + self.send_queue.get(block=False) + with self.recv_queue_lock: + for i in range(0, self.recv_queue.qsize()): + self.recv_queue.get(block=False) |