summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2012-07-24 02:39:54 -0700
committerLance Stout <lancestout@gmail.com>2012-07-24 02:39:54 -0700
commit3e43b36a9d70801d90a6b09046f93879f2e29b89 (patch)
tree758b0f60cb569605a91900fcbfd10d7bc364a243
parent352ee2f2fd6458a46e046ecaedb78addd5d6ac20 (diff)
downloadslixmpp-3e43b36a9d70801d90a6b09046f93879f2e29b89.tar.gz
slixmpp-3e43b36a9d70801d90a6b09046f93879f2e29b89.tar.bz2
slixmpp-3e43b36a9d70801d90a6b09046f93879f2e29b89.tar.xz
slixmpp-3e43b36a9d70801d90a6b09046f93879f2e29b89.zip
Standardize importing of queue class.
This will make it easier to enable gevent support.
-rw-r--r--sleekxmpp/plugins/xep_0047/stream.py7
-rw-r--r--sleekxmpp/test/livesocket.py10
-rw-r--r--sleekxmpp/test/mocksocket.py10
-rw-r--r--sleekxmpp/test/sleektest.py7
-rw-r--r--sleekxmpp/util/__init__.py23
-rw-r--r--sleekxmpp/xmlstream/handler/waiter.py9
-rw-r--r--sleekxmpp/xmlstream/scheduler.py10
-rw-r--r--sleekxmpp/xmlstream/xmlstream.py13
8 files changed, 47 insertions, 42 deletions
diff --git a/sleekxmpp/plugins/xep_0047/stream.py b/sleekxmpp/plugins/xep_0047/stream.py
index 49f56f36..b49a077b 100644
--- a/sleekxmpp/plugins/xep_0047/stream.py
+++ b/sleekxmpp/plugins/xep_0047/stream.py
@@ -1,11 +1,8 @@
import socket
import threading
import logging
-try:
- import queue
-except ImportError:
- import Queue as queue
+from sleekxmpp.util import Queue
from sleekxmpp.exceptions import XMPPError
@@ -33,7 +30,7 @@ class IBBytestream(object):
self.stream_in_closed = threading.Event()
self.stream_out_closed = threading.Event()
- self.recv_queue = queue.Queue()
+ self.recv_queue = Queue()
self.send_window = threading.BoundedSemaphore(value=self.window_size)
self.window_ids = set()
diff --git a/sleekxmpp/test/livesocket.py b/sleekxmpp/test/livesocket.py
index 80d63307..d70ee4eb 100644
--- a/sleekxmpp/test/livesocket.py
+++ b/sleekxmpp/test/livesocket.py
@@ -8,10 +8,8 @@
import socket
import threading
-try:
- import queue
-except ImportError:
- import Queue as queue
+
+from sleekxmpp.util import Queue
class TestLiveSocket(object):
@@ -39,8 +37,8 @@ class TestLiveSocket(object):
"""
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.recv_buffer = []
- self.recv_queue = queue.Queue()
- self.send_queue = queue.Queue()
+ self.recv_queue = Queue()
+ self.send_queue = Queue()
self.send_queue_lock = threading.Lock()
self.recv_queue_lock = threading.Lock()
self.is_live = True
diff --git a/sleekxmpp/test/mocksocket.py b/sleekxmpp/test/mocksocket.py
index 0920b7ea..4c9d1699 100644
--- a/sleekxmpp/test/mocksocket.py
+++ b/sleekxmpp/test/mocksocket.py
@@ -7,10 +7,8 @@
"""
import socket
-try:
- import queue
-except ImportError:
- import Queue as queue
+
+from sleekxmpp.util import Queue
class TestSocket(object):
@@ -36,8 +34,8 @@ class TestSocket(object):
Same as arguments for socket.socket
"""
self.socket = socket.socket(*args, **kwargs)
- self.recv_queue = queue.Queue()
- self.send_queue = queue.Queue()
+ self.recv_queue = Queue()
+ self.send_queue = Queue()
self.is_live = False
self.disconnected = False
diff --git a/sleekxmpp/test/sleektest.py b/sleekxmpp/test/sleektest.py
index cac99f77..47af86cf 100644
--- a/sleekxmpp/test/sleektest.py
+++ b/sleekxmpp/test/sleektest.py
@@ -8,13 +8,10 @@
import unittest
from xml.parsers.expat import ExpatError
-try:
- import Queue as queue
-except:
- import queue
import sleekxmpp
from sleekxmpp import ClientXMPP, ComponentXMPP
+from sleekxmpp.util import Queue
from sleekxmpp.stanza import Message, Iq, Presence
from sleekxmpp.test import TestSocket, TestLiveSocket
from sleekxmpp.exceptions import XMPPError, IqTimeout, IqError
@@ -338,7 +335,7 @@ class SleekTest(unittest.TestCase):
# We will use this to wait for the session_start event
# for live connections.
- skip_queue = queue.Queue()
+ skip_queue = Queue()
if socket == 'mock':
self.xmpp.set_socket(TestSocket())
diff --git a/sleekxmpp/util/__init__.py b/sleekxmpp/util/__init__.py
index e69de29b..86a87222 100644
--- a/sleekxmpp/util/__init__.py
+++ b/sleekxmpp/util/__init__.py
@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+"""
+ sleekxmpp.util
+ ~~~~~~~~~~~~~~
+
+ Part of SleekXMPP: The Sleek XMPP Library
+
+ :copyright: (c) 2012 Nathanael C. Fritz, Lance J.T. Stout
+ :license: MIT, see LICENSE for more details
+"""
+
+
+# =====================================================================
+# Standardize import of Queue class:
+
+try:
+ import queue
+except ImportError:
+ import Queue as queue
+
+
+Queue = queue.Queue
+QueueEmpty = queue.Empty
diff --git a/sleekxmpp/xmlstream/handler/waiter.py b/sleekxmpp/xmlstream/handler/waiter.py
index 899df17c..66e14496 100644
--- a/sleekxmpp/xmlstream/handler/waiter.py
+++ b/sleekxmpp/xmlstream/handler/waiter.py
@@ -10,11 +10,8 @@
"""
import logging
-try:
- import queue
-except ImportError:
- import Queue as queue
+from sleekxmpp.util import Queue, QueueEmpty
from sleekxmpp.xmlstream.handler.base import BaseHandler
@@ -37,7 +34,7 @@ class Waiter(BaseHandler):
def __init__(self, name, matcher, stream=None):
BaseHandler.__init__(self, name, matcher, stream=stream)
- self._payload = queue.Queue()
+ self._payload = Queue()
def prerun(self, payload):
"""Store the matched stanza when received during processing.
@@ -74,7 +71,7 @@ class Waiter(BaseHandler):
try:
stanza = self._payload.get(True, 1)
break
- except queue.Empty:
+ except QueueEmpty:
elapsed_time += 1
if elapsed_time >= timeout:
log.warning("Timed out waiting for %s", self.name)
diff --git a/sleekxmpp/xmlstream/scheduler.py b/sleekxmpp/xmlstream/scheduler.py
index f68af081..d98dc6c8 100644
--- a/sleekxmpp/xmlstream/scheduler.py
+++ b/sleekxmpp/xmlstream/scheduler.py
@@ -15,10 +15,8 @@
import time
import threading
import logging
-try:
- import queue
-except ImportError:
- import Queue as queue
+
+from sleekxmpp.util import Queue, QueueEmpty
log = logging.getLogger(__name__)
@@ -102,7 +100,7 @@ class Scheduler(object):
def __init__(self, parentstop=None):
#: A queue for storing tasks
- self.addq = queue.Queue()
+ self.addq = Queue()
#: A list of tasks in order of execution time.
self.schedule = []
@@ -157,7 +155,7 @@ class Scheduler(object):
elapsed < wait:
newtask = self.addq.get(True, 0.1)
elapsed += 0.1
- except queue.Empty:
+ except QueueEmpty:
cleanup = []
self.schedule_lock.acquire()
for task in self.schedule:
diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py
index 49f33933..81b9209f 100644
--- a/sleekxmpp/xmlstream/xmlstream.py
+++ b/sleekxmpp/xmlstream/xmlstream.py
@@ -26,14 +26,11 @@ import time
import random
import weakref
import uuid
-try:
- import queue
-except ImportError:
- import Queue as queue
from xml.parsers.expat import ExpatError
import sleekxmpp
+from sleekxmpp.util import Queue, QueueEmpty
from sleekxmpp.thirdparty.statemachine import StateMachine
from sleekxmpp.xmlstream import Scheduler, tostring, cert
from sleekxmpp.xmlstream.stanzabase import StanzaBase, ET, ElementBase
@@ -270,10 +267,10 @@ class XMLStream(object):
self.end_session_on_disconnect = True
#: A queue of stream, custom, and scheduled events to be processed.
- self.event_queue = queue.Queue()
+ self.event_queue = Queue()
#: A queue of string data to be sent over the stream.
- self.send_queue = queue.Queue()
+ self.send_queue = Queue()
self.send_queue_lock = threading.Lock()
self.send_lock = threading.RLock()
@@ -1586,7 +1583,7 @@ class XMLStream(object):
try:
wait = self.wait_timeout
event = self.event_queue.get(True, timeout=wait)
- except queue.Empty:
+ except QueueEmpty:
event = None
if event is None:
continue
@@ -1655,7 +1652,7 @@ class XMLStream(object):
else:
try:
data = self.send_queue.get(True, 1)
- except queue.Empty:
+ except QueueEmpty:
continue
log.debug("SEND: %s", data)
enc_data = data.encode('utf-8')