From 7f90de887a7e3ca53103babf5a9acf15a69ab959 Mon Sep 17 00:00:00 2001 From: Nathan Fritz Date: Thu, 4 Aug 2011 21:49:32 -0700 Subject: added block as process option and updated documentation. added typical use example to ClientXMPP. --- sleekxmpp/xmlstream/xmlstream.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'sleekxmpp/xmlstream') diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py index 15bbe655..41c53a3e 100644 --- a/sleekxmpp/xmlstream/xmlstream.py +++ b/sleekxmpp/xmlstream/xmlstream.py @@ -831,7 +831,7 @@ class XMLStream(object): self.send_queue.put(data) return True - def process(self, threaded=True): + def process(self, **kwargs): """ Initialize the XML streams and begin processing events. @@ -839,14 +839,28 @@ class XMLStream(object): by HANDLER_THREADS. Arguments: + block -- If block=False then event dispatcher will run + in a separate thread, allowing for the stream to be + used in the background for another application. + Otherwise, process(block=True) blocks the current thread. + Defaults to False. + + **threaded is deprecated and included for API compatibility** threaded -- If threaded=True then event dispatcher will run in a separate thread, allowing for the stream to be used in the background for another application. Defaults to True. - Event handlers and the send queue will be threaded - regardless of this parameter's value. + Event handlers and the send queue will be threaded + regardless of these parameters. """ + if kwargs.has_key('threaded') and kwargs.has_key('block'): + raise ValueError("process() called with both block and threaded arguments") + elif kwargs.has_key('block'): + threaded = not(kwargs.get('block', False)) + else: + threaded = kwargs.get('threaded', True) + self.scheduler.process(threaded=True) def start_thread(name, target): -- cgit v1.2.3 From 93a4a3f8a0f64eed846895365fa3da059bbf5ea1 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Thu, 4 Aug 2011 22:34:34 -0700 Subject: Fix Python3 issue with dict.has_key() --- sleekxmpp/xmlstream/xmlstream.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'sleekxmpp/xmlstream') diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py index 41c53a3e..5ba4269f 100644 --- a/sleekxmpp/xmlstream/xmlstream.py +++ b/sleekxmpp/xmlstream/xmlstream.py @@ -854,13 +854,14 @@ class XMLStream(object): Event handlers and the send queue will be threaded regardless of these parameters. """ - if kwargs.has_key('threaded') and kwargs.has_key('block'): - raise ValueError("process() called with both block and threaded arguments") - elif kwargs.has_key('block'): + if 'threaded' in kwargs and 'block' in kwargs: + raise ValueError("process() called with both " + \ + "block and threaded arguments") + elif 'block' in kwargs: threaded = not(kwargs.get('block', False)) else: threaded = kwargs.get('threaded', True) - + self.scheduler.process(threaded=True) def start_thread(name, target): -- cgit v1.2.3 From 47bc50d9fbbe8d72b589a6360aa8b5f32d6ba74b Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Thu, 4 Aug 2011 22:37:22 -0700 Subject: Cosmetic PEP8 fixes. --- sleekxmpp/xmlstream/stanzabase.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'sleekxmpp/xmlstream') diff --git a/sleekxmpp/xmlstream/stanzabase.py b/sleekxmpp/xmlstream/stanzabase.py index f1a9e1f5..a2826ead 100644 --- a/sleekxmpp/xmlstream/stanzabase.py +++ b/sleekxmpp/xmlstream/stanzabase.py @@ -482,7 +482,8 @@ class ElementBase(object): if plugin: if plugin not in self.plugins: self.init_plugin(plugin) - handler = getattr(self.plugins[plugin], set_method, None) + handler = getattr(self.plugins[plugin], + set_method, None) if handler: return handler(value) @@ -1066,7 +1067,7 @@ class ElementBase(object): stanza_ns = '' if top_level_ns else self.namespace return tostring(self.xml, xmlns='', stanza_ns=stanza_ns, - top_level = not top_level_ns) + top_level=not top_level_ns) def __repr__(self): """ @@ -1285,7 +1286,7 @@ class StanzaBase(ElementBase): return tostring(self.xml, xmlns='', stanza_ns=stanza_ns, stream=self.stream, - top_level = not top_level_ns) + top_level=not top_level_ns) # To comply with PEP8, method names now use underscores. -- cgit v1.2.3