summaryrefslogtreecommitdiff
path: root/sleekxmpp/xmlstream/handler
diff options
context:
space:
mode:
Diffstat (limited to 'sleekxmpp/xmlstream/handler')
-rw-r--r--sleekxmpp/xmlstream/handler/__init__.py0
-rw-r--r--sleekxmpp/xmlstream/handler/base.py18
-rw-r--r--sleekxmpp/xmlstream/handler/callback.py20
-rw-r--r--sleekxmpp/xmlstream/handler/waiter.py21
-rw-r--r--sleekxmpp/xmlstream/handler/xmlcallback.py7
-rw-r--r--sleekxmpp/xmlstream/handler/xmlwaiter.py6
6 files changed, 72 insertions, 0 deletions
diff --git a/sleekxmpp/xmlstream/handler/__init__.py b/sleekxmpp/xmlstream/handler/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/sleekxmpp/xmlstream/handler/__init__.py
diff --git a/sleekxmpp/xmlstream/handler/base.py b/sleekxmpp/xmlstream/handler/base.py
new file mode 100644
index 00000000..810aac91
--- /dev/null
+++ b/sleekxmpp/xmlstream/handler/base.py
@@ -0,0 +1,18 @@
+
+class BaseHandler(object):
+
+
+ def __init__(self, name, matcher):
+ self.name = name
+ self._destroy = False
+ self._payload = None
+ self._matcher = matcher
+
+ def match(self, xml):
+ return self._matcher.match(xml)
+
+ def run(self, payload):
+ self._payload = payload
+
+ def checkDelete(self):
+ return self._destroy
diff --git a/sleekxmpp/xmlstream/handler/callback.py b/sleekxmpp/xmlstream/handler/callback.py
new file mode 100644
index 00000000..e3ef8ccc
--- /dev/null
+++ b/sleekxmpp/xmlstream/handler/callback.py
@@ -0,0 +1,20 @@
+from . import base
+import threading
+
+class Callback(base.BaseHandler):
+
+ def __init__(self, name, matcher, pointer, thread=False, once=False):
+ base.BaseHandler.__init__(self, name, matcher)
+ self._pointer = pointer
+ self._thread = thread
+ self._once = once
+
+ 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:
+ self._pointer(payload)
+ if self._once:
+ self._destroy = True
diff --git a/sleekxmpp/xmlstream/handler/waiter.py b/sleekxmpp/xmlstream/handler/waiter.py
new file mode 100644
index 00000000..7c06ddf1
--- /dev/null
+++ b/sleekxmpp/xmlstream/handler/waiter.py
@@ -0,0 +1,21 @@
+from . import base
+import Queue
+import logging
+
+class Waiter(base.BaseHandler):
+
+ def __init__(self, name, matcher):
+ base.BaseHandler.__init__(self, name, matcher)
+ self._payload = Queue.Queue()
+
+ def run(self, payload):
+ self._payload.put(payload)
+
+ def wait(self, timeout=60):
+ try:
+ return self._payload.get(True, timeout)
+ except Queue.Empty:
+ return False
+
+ def checkDelete(self):
+ return True
diff --git a/sleekxmpp/xmlstream/handler/xmlcallback.py b/sleekxmpp/xmlstream/handler/xmlcallback.py
new file mode 100644
index 00000000..50d3d5fa
--- /dev/null
+++ b/sleekxmpp/xmlstream/handler/xmlcallback.py
@@ -0,0 +1,7 @@
+import threading
+from . callback import Callback
+
+class XMLCallback(Callback):
+
+ def run(self, payload):
+ Callback.run(self, payload.xml)
diff --git a/sleekxmpp/xmlstream/handler/xmlwaiter.py b/sleekxmpp/xmlstream/handler/xmlwaiter.py
new file mode 100644
index 00000000..9b2b3394
--- /dev/null
+++ b/sleekxmpp/xmlstream/handler/xmlwaiter.py
@@ -0,0 +1,6 @@
+from . waiter import Waiter
+
+class XMLWaiter(Waiter):
+
+ def run(self, payload):
+ Waiter.run(self, payload.xml)