summaryrefslogtreecommitdiff
path: root/sleekxmpp/xmlstream/handler
diff options
context:
space:
mode:
authorNathan Fritz <fritzy@netflint.net>2009-08-31 22:46:31 +0000
committerNathan Fritz <fritzy@netflint.net>2009-08-31 22:46:31 +0000
commit05c9ea5c1d953637343c9fad07267e7f89b20561 (patch)
treed4b0d432870bb195a4f14ec07ce889fcd080a357 /sleekxmpp/xmlstream/handler
parent00d46ee2b0fe4c0d76525d284dcc7ed588e701af (diff)
downloadslixmpp-05c9ea5c1d953637343c9fad07267e7f89b20561.tar.gz
slixmpp-05c9ea5c1d953637343c9fad07267e7f89b20561.tar.bz2
slixmpp-05c9ea5c1d953637343c9fad07267e7f89b20561.tar.xz
slixmpp-05c9ea5c1d953637343c9fad07267e7f89b20561.zip
* converted sleekxmpp to Python 3.x
* sleekxmpp no longer spawns threads for callback handlers -- there are now two threads: one for handlers and one for reading. callback handlers can get results from the read queue directly with the "wait" handler which is used in .send() for the reply catching argument.
Diffstat (limited to 'sleekxmpp/xmlstream/handler')
-rw-r--r--sleekxmpp/xmlstream/handler/base.py3
-rw-r--r--sleekxmpp/xmlstream/handler/callback.py26
-rw-r--r--sleekxmpp/xmlstream/handler/waiter.py11
-rw-r--r--sleekxmpp/xmlstream/handler/xmlcallback.py4
-rw-r--r--sleekxmpp/xmlstream/handler/xmlwaiter.py4
5 files changed, 30 insertions, 18 deletions
diff --git a/sleekxmpp/xmlstream/handler/base.py b/sleekxmpp/xmlstream/handler/base.py
index 810aac91..9a951193 100644
--- a/sleekxmpp/xmlstream/handler/base.py
+++ b/sleekxmpp/xmlstream/handler/base.py
@@ -11,6 +11,9 @@ class BaseHandler(object):
def match(self, xml):
return self._matcher.match(xml)
+ def prerun(self, payload):
+ self._payload = payload
+
def run(self, payload):
self._payload = payload
diff --git a/sleekxmpp/xmlstream/handler/callback.py b/sleekxmpp/xmlstream/handler/callback.py
index e3ef8ccc..c618b718 100644
--- a/sleekxmpp/xmlstream/handler/callback.py
+++ b/sleekxmpp/xmlstream/handler/callback.py
@@ -1,20 +1,26 @@
from . import base
-import threading
class Callback(base.BaseHandler):
- def __init__(self, name, matcher, pointer, thread=False, once=False):
+ def __init__(self, name, matcher, pointer, thread=False, once=False, instream=False):
base.BaseHandler.__init__(self, name, matcher)
self._pointer = pointer
self._thread = thread
self._once = once
+ self._instream = instream
+
+ def prerun(self, payload):
+ base.BaseHandler.prerun(self, payload)
+ if self._instream:
+ self.run(payload, True)
- def run(self, payload):
- base.BaseHandler.run(self, payload)
- if self._thread:
- x = threading.Thread(name="Callback_%s" % self.name, target=self._pointer, args=(payload,))
- x.start()
- else:
+ def run(self, payload, instream=False):
+ if not self._instream or instream:
+ base.BaseHandler.run(self, payload)
+ #if self._thread:
+ # x = threading.Thread(name="Callback_%s" % self.name, target=self._pointer, args=(payload,))
+ # x.start()
+ #else:
self._pointer(payload)
- if self._once:
- self._destroy = True
+ if self._once:
+ self._destroy = True
diff --git a/sleekxmpp/xmlstream/handler/waiter.py b/sleekxmpp/xmlstream/handler/waiter.py
index 7c06ddf1..e62f330f 100644
--- a/sleekxmpp/xmlstream/handler/waiter.py
+++ b/sleekxmpp/xmlstream/handler/waiter.py
@@ -1,20 +1,23 @@
from . import base
-import Queue
+import queue
import logging
class Waiter(base.BaseHandler):
def __init__(self, name, matcher):
base.BaseHandler.__init__(self, name, matcher)
- self._payload = Queue.Queue()
+ self._payload = queue.Queue()
- def run(self, payload):
+ def prerun(self, payload):
self._payload.put(payload)
+
+ def run(self, payload):
+ pass
def wait(self, timeout=60):
try:
return self._payload.get(True, timeout)
- except Queue.Empty:
+ except queue.Empty:
return False
def checkDelete(self):
diff --git a/sleekxmpp/xmlstream/handler/xmlcallback.py b/sleekxmpp/xmlstream/handler/xmlcallback.py
index 50d3d5fa..ae288ff1 100644
--- a/sleekxmpp/xmlstream/handler/xmlcallback.py
+++ b/sleekxmpp/xmlstream/handler/xmlcallback.py
@@ -3,5 +3,5 @@ from . callback import Callback
class XMLCallback(Callback):
- def run(self, payload):
- Callback.run(self, payload.xml)
+ def run(self, payload, instream=False):
+ Callback.run(self, payload.xml, instream)
diff --git a/sleekxmpp/xmlstream/handler/xmlwaiter.py b/sleekxmpp/xmlstream/handler/xmlwaiter.py
index 9b2b3394..1e524b02 100644
--- a/sleekxmpp/xmlstream/handler/xmlwaiter.py
+++ b/sleekxmpp/xmlstream/handler/xmlwaiter.py
@@ -2,5 +2,5 @@ from . waiter import Waiter
class XMLWaiter(Waiter):
- def run(self, payload):
- Waiter.run(self, payload.xml)
+ def prerun(self, payload):
+ Waiter.prerun(self, payload.xml)