moved seesmic branch to trunk
This commit is contained in:
0
sleekxmpp/xmlstream/handler/__init__.py
Normal file
0
sleekxmpp/xmlstream/handler/__init__.py
Normal file
18
sleekxmpp/xmlstream/handler/base.py
Normal file
18
sleekxmpp/xmlstream/handler/base.py
Normal file
@@ -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
|
||||
20
sleekxmpp/xmlstream/handler/callback.py
Normal file
20
sleekxmpp/xmlstream/handler/callback.py
Normal file
@@ -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
|
||||
21
sleekxmpp/xmlstream/handler/waiter.py
Normal file
21
sleekxmpp/xmlstream/handler/waiter.py
Normal file
@@ -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
|
||||
7
sleekxmpp/xmlstream/handler/xmlcallback.py
Normal file
7
sleekxmpp/xmlstream/handler/xmlcallback.py
Normal file
@@ -0,0 +1,7 @@
|
||||
import threading
|
||||
from . callback import Callback
|
||||
|
||||
class XMLCallback(Callback):
|
||||
|
||||
def run(self, payload):
|
||||
Callback.run(self, payload.xml)
|
||||
6
sleekxmpp/xmlstream/handler/xmlwaiter.py
Normal file
6
sleekxmpp/xmlstream/handler/xmlwaiter.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from . waiter import Waiter
|
||||
|
||||
class XMLWaiter(Waiter):
|
||||
|
||||
def run(self, payload):
|
||||
Waiter.run(self, payload.xml)
|
||||
Reference in New Issue
Block a user