diff options
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2014-08-16 22:37:29 +0200 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2014-09-01 02:47:08 +0200 |
commit | 6175cbcd99f917b08646d130770a132458056249 (patch) | |
tree | 7aa51df981039fdfec06c141feb5b61888a4e8f9 | |
parent | 476d76a53301f9da2ac7efa094e209b0607adfdc (diff) | |
download | slixmpp-6175cbcd99f917b08646d130770a132458056249.tar.gz slixmpp-6175cbcd99f917b08646d130770a132458056249.tar.bz2 slixmpp-6175cbcd99f917b08646d130770a132458056249.tar.xz slixmpp-6175cbcd99f917b08646d130770a132458056249.zip |
Reintroduce XMLStream.process, making it run the asyncio event loop.
26 files changed, 66 insertions, 277 deletions
diff --git a/examples/adhoc_provider.py b/examples/adhoc_provider.py index e0a7effd..e4a8fc04 100755 --- a/examples/adhoc_provider.py +++ b/examples/adhoc_provider.py @@ -179,15 +179,5 @@ if __name__ == '__main__': # xmpp.ca_certs = "path/to/ca/cert" # Connect to the XMPP server and start processing XMPP stanzas. - if xmpp.connect(): - # If you do not have the dnspython library installed, you will need - # to manually specify the name of the server if it does not match - # the one in the JID. For example, to use Google Talk you would - # need to use: - # - # if xmpp.connect(('talk.google.com', 5222)): - # ... - xmpp.process(block=True) - print("Done") - else: - print("Unable to connect.") + xmpp.connect() + xmpp.process() diff --git a/examples/adhoc_user.py b/examples/adhoc_user.py index 646b41ac..4aa2a236 100755 --- a/examples/adhoc_user.py +++ b/examples/adhoc_user.py @@ -185,15 +185,5 @@ if __name__ == '__main__': # xmpp.ca_certs = "path/to/ca/cert" # Connect to the XMPP server and start processing XMPP stanzas. - if xmpp.connect(): - # If you do not have the dnspython library installed, you will need - # to manually specify the name of the server if it does not match - # the one in the JID. For example, to use Google Talk you would - # need to use: - # - # if xmpp.connect(('talk.google.com', 5222)): - # ... - xmpp.process(block=True) - print("Done") - else: - print("Unable to connect.") + xmpp.connect() + xmpp.process() diff --git a/examples/admin_commands.py b/examples/admin_commands.py index e6415a45..97708cd8 100755 --- a/examples/admin_commands.py +++ b/examples/admin_commands.py @@ -153,15 +153,5 @@ if __name__ == '__main__': # xmpp.ca_certs = "path/to/ca/cert" # Connect to the XMPP server and start processing XMPP stanzas. - if xmpp.connect(): - # If you do not have the dnspython library installed, you will need - # to manually specify the name of the server if it does not match - # the one in the JID. For example, to use Google Talk you would - # need to use: - # - # if xmpp.connect(('talk.google.com', 5222)): - # ... - xmpp.process(block=True) - print("Done") - else: - print("Unable to connect.") + xmpp.connect() + xmpp.process() diff --git a/examples/custom_stanzas/custom_stanza_provider.py b/examples/custom_stanzas/custom_stanza_provider.py index b1b6e0a9..cfc8335d 100755 --- a/examples/custom_stanzas/custom_stanza_provider.py +++ b/examples/custom_stanzas/custom_stanza_provider.py @@ -143,15 +143,5 @@ if __name__ == '__main__': # xmpp.ca_certs = "path/to/ca/cert" # Connect to the XMPP server and start processing XMPP stanzas. - if xmpp.connect(): - # If you do not have the dnspython library installed, you will need - # to manually specify the name of the server if it does not match - # the one in the JID. For example, to use Google Talk you would - # need to use: - # - # if xmpp.connect(('talk.google.com', 5222)): - # ... - xmpp.process(block=True) - print("Done") - else: - print("Unable to connect.") + xmpp.connect() + xmpp.process() diff --git a/examples/custom_stanzas/custom_stanza_user.py b/examples/custom_stanzas/custom_stanza_user.py index af6bf9b3..891eb72b 100755 --- a/examples/custom_stanzas/custom_stanza_user.py +++ b/examples/custom_stanzas/custom_stanza_user.py @@ -150,15 +150,5 @@ if __name__ == '__main__': # xmpp.ca_certs = "path/to/ca/cert" # Connect to the XMPP server and start processing XMPP stanzas. - if xmpp.connect(): - # If you do not have the dnspython library installed, you will need - # to manually specify the name of the server if it does not match - # the one in the JID. For example, to use Google Talk you would - # need to use: - # - # if xmpp.connect(('talk.google.com', 5222)): - # ... - xmpp.process(block=True) - print("Done") - else: - print("Unable to connect.") + xmpp.connect() + xmpp.process() diff --git a/examples/disco_browser.py b/examples/disco_browser.py index 11ea2e3c..2f926687 100755 --- a/examples/disco_browser.py +++ b/examples/disco_browser.py @@ -179,14 +179,5 @@ if __name__ == '__main__': # xmpp.ca_certs = "path/to/ca/cert" # Connect to the XMPP server and start processing XMPP stanzas. - if xmpp.connect(): - # If you do not have the dnspython library installed, you will need - # to manually specify the name of the server if it does not match - # the one in the JID. For example, to use Google Talk you would - # need to use: - # - # if xmpp.connect(('talk.google.com', 5222)): - # ... - xmpp.process(block=True) - else: - print("Unable to connect.") + xmpp.connect() + xmpp.process() diff --git a/examples/download_avatars.py b/examples/download_avatars.py index fc893177..61b07c58 100755 --- a/examples/download_avatars.py +++ b/examples/download_avatars.py @@ -159,14 +159,5 @@ if __name__ == '__main__': # xmpp.ca_certs = "path/to/ca/cert" # Connect to the XMPP server and start processing XMPP stanzas. - if xmpp.connect(): - # If you do not have the dnspython library installed, you will need - # to manually specify the name of the server if it does not match - # the one in the JID. For example, to use Google Talk you would - # need to use: - # - # if xmpp.connect(('talk.google.com', 5222)): - # ... - xmpp.process(block=True) - else: - print("Unable to connect.") + xmpp.connect() + xmpp.process() diff --git a/examples/echo_client.py b/examples/echo_client.py index 733b541d..de649eb6 100755 --- a/examples/echo_client.py +++ b/examples/echo_client.py @@ -132,15 +132,5 @@ if __name__ == '__main__': # xmpp.ca_certs = "path/to/ca/cert" # Connect to the XMPP server and start processing XMPP stanzas. - if xmpp.connect(): - # If you do not have the dnspython library installed, you will need - # to manually specify the name of the server if it does not match - # the one in the JID. For example, to use Google Talk you would - # need to use: - # - # if xmpp.connect(('talk.google.com', 5222)): - # ... - xmpp.process(block=True) - print("Done") - else: - print("Unable to connect.") + xmpp.connect() + xmpp.process() diff --git a/examples/echo_component.py b/examples/echo_component.py index d56935f8..0512f37c 100755 --- a/examples/echo_component.py +++ b/examples/echo_component.py @@ -104,8 +104,5 @@ if __name__ == '__main__': xmpp.registerPlugin('xep_0199') # XMPP Ping # Connect to the XMPP server and start processing XMPP stanzas. - if xmpp.connect(): - xmpp.process(block=True) - print("Done") - else: - print("Unable to connect.") + xmpp.connect() + xmpp.process() diff --git a/examples/gtalk_custom_domain.py b/examples/gtalk_custom_domain.py index 92d9fea3..8c280ac4 100755 --- a/examples/gtalk_custom_domain.py +++ b/examples/gtalk_custom_domain.py @@ -139,15 +139,5 @@ if __name__ == '__main__': # xmpp.ca_certs = "path/to/ca/cert" # Connect to the XMPP server and start processing XMPP stanzas. - if xmpp.connect(): - # If you do not have the dnspython library installed, you will need - # to manually specify the name of the server if it does not match - # the one in the JID. For example, to use Google Talk you would - # need to use: - # - # if xmpp.connect(('talk.google.com', 5222)): - # ... - xmpp.process(block=True) - print("Done") - else: - print("Unable to connect.") + xmpp.connect() + xmpp.process() diff --git a/examples/ibb_transfer/ibb_receiver.py b/examples/ibb_transfer/ibb_receiver.py index d24e5003..02c899eb 100755 --- a/examples/ibb_transfer/ibb_receiver.py +++ b/examples/ibb_transfer/ibb_receiver.py @@ -122,15 +122,5 @@ if __name__ == '__main__': # xmpp.ca_certs = "path/to/ca/cert" # Connect to the XMPP server and start processing XMPP stanzas. - if xmpp.connect(): - # If you do not have the dnspython library installed, you will need - # to manually specify the name of the server if it does not match - # the one in the JID. For example, to use Google Talk you would - # need to use: - # - # if xmpp.connect(('talk.google.com', 5222)): - # ... - xmpp.process(block=True) - print("Done") - else: - print("Unable to connect.") + xmpp.connect() + xmpp.process() diff --git a/examples/ibb_transfer/ibb_sender.py b/examples/ibb_transfer/ibb_sender.py index 2d88d4ce..f5e44fb7 100755 --- a/examples/ibb_transfer/ibb_sender.py +++ b/examples/ibb_transfer/ibb_sender.py @@ -120,15 +120,5 @@ if __name__ == '__main__': # xmpp.ca_certs = "path/to/ca/cert" # Connect to the XMPP server and start processing XMPP stanzas. - if xmpp.connect(): - # If you do not have the dnspython library installed, you will need - # to manually specify the name of the server if it does not match - # the one in the JID. For example, to use Google Talk you would - # need to use: - # - # if xmpp.connect(('talk.google.com', 5222)): - # ... - xmpp.process(block=True) - print("Done") - else: - print("Unable to connect.") + xmpp.connect() + xmpp.process() diff --git a/examples/muc.py b/examples/muc.py index 08a71a44..b609cefe 100755 --- a/examples/muc.py +++ b/examples/muc.py @@ -168,15 +168,5 @@ if __name__ == '__main__': xmpp.register_plugin('xep_0199') # XMPP Ping # Connect to the XMPP server and start processing XMPP stanzas. - if xmpp.connect(): - # If you do not have the dnspython library installed, you will need - # to manually specify the name of the server if it does not match - # the one in the JID. For example, to use Google Talk you would - # need to use: - # - # if xmpp.connect(('talk.google.com', 5222)): - # ... - xmpp.process(block=True) - print("Done") - else: - print("Unable to connect.") + xmpp.connect() + xmpp.process() diff --git a/examples/ping.py b/examples/ping.py index 25aaf989..8ecb8cff 100755 --- a/examples/ping.py +++ b/examples/ping.py @@ -118,15 +118,5 @@ if __name__ == '__main__': # xmpp.ca_certs = "path/to/ca/cert" # Connect to the XMPP server and start processing XMPP stanzas. - if xmpp.connect(): - # If you do not have the dnspython library installed, you will need - # to manually specify the name of the server if it does not match - # the one in the JID. For example, to use Google Talk you would - # need to use: - # - # if xmpp.connect(('talk.google.com', 5222)): - # ... - xmpp.process(block=True) - print("Done") - else: - print("Unable to connect.") + xmpp.connect() + xmpp.process() diff --git a/examples/proxy_echo_client.py b/examples/proxy_echo_client.py index b4b4dab4..e1eab19f 100755 --- a/examples/proxy_echo_client.py +++ b/examples/proxy_echo_client.py @@ -143,15 +143,5 @@ if __name__ == '__main__': 'password': opts.proxy_pass} # Connect to the XMPP server and start processing XMPP stanzas. - if xmpp.connect(): - # If you do not have the dnspython library installed, you will need - # to manually specify the name of the server if it does not match - # the one in the JID. For example, to use Google Talk you would - # need to use: - # - # if xmpp.connect(('talk.google.com', 5222)): - # ... - xmpp.process(block=True) - print("Done") - else: - print("Unable to connect.") + xmpp.connect() + xmpp.process() diff --git a/examples/pubsub_client.py b/examples/pubsub_client.py index 7fdd227b..1e24dbd8 100755 --- a/examples/pubsub_client.py +++ b/examples/pubsub_client.py @@ -176,14 +176,5 @@ if __name__ == '__main__': # xmpp.ca_certs = "path/to/ca/cert" # Connect to the XMPP server and start processing XMPP stanzas. - if xmpp.connect(): - # If you do not have the dnspython library installed, you will need - # to manually specify the name of the server if it does not match - # the one in the JID. For example, to use Google Talk you would - # need to use: - # - # if xmpp.connect(('talk.google.com', 5222)): - # ... - xmpp.process(block=True) - else: - print("Unable to connect.") + xmpp.connect() + xmpp.process() diff --git a/examples/pubsub_events.py b/examples/pubsub_events.py index f2384db8..f4be2d6c 100755 --- a/examples/pubsub_events.py +++ b/examples/pubsub_events.py @@ -128,15 +128,5 @@ if __name__ == '__main__': # xmpp.ca_certs = "path/to/ca/cert" # Connect to the XMPP server and start processing XMPP stanzas. - if xmpp.connect(): - # If you do not have the dnspython library installed, you will need - # to manually specify the name of the server if it does not match - # the one in the JID. For example, to use Google Talk you would - # need to use: - # - # if xmpp.connect(('talk.google.com', 5222)): - # ... - xmpp.process(block=True) - print("Done") - else: - print("Unable to connect.") + xmpp.connect() + xmpp.process() diff --git a/examples/register_account.py b/examples/register_account.py index 17f672ea..396b23c6 100755 --- a/examples/register_account.py +++ b/examples/register_account.py @@ -154,15 +154,5 @@ if __name__ == '__main__': # xmpp.ca_certs = "path/to/ca/cert" # Connect to the XMPP server and start processing XMPP stanzas. - if xmpp.connect(): - # If you do not have the dnspython library installed, you will need - # to manually specify the name of the server if it does not match - # the one in the JID. For example, to use Google Talk you would - # need to use: - # - # if xmpp.connect(('talk.google.com', 5222)): - # ... - xmpp.process(block=True) - print("Done") - else: - print("Unable to connect.") + xmpp.connect() + xmpp.process() diff --git a/examples/roster_browser.py b/examples/roster_browser.py index 6ca7ffe8..0bdc7c18 100755 --- a/examples/roster_browser.py +++ b/examples/roster_browser.py @@ -144,15 +144,5 @@ if __name__ == '__main__': # xmpp.ca_certs = "path/to/ca/cert" # Connect to the XMPP server and start processing XMPP stanzas. - if xmpp.connect(): - # If you do not have the dnspython library installed, you will need - # to manually specify the name of the server if it does not match - # the one in the JID. For example, to use Google Talk you would - # need to use: - # - # if xmpp.connect(('talk.google.com', 5222)): - # ... - xmpp.process(block=True) - else: - print("Unable to connect.") - + xmpp.connect() + xmpp.process() diff --git a/examples/send_client.py b/examples/send_client.py index beecfac0..17dffcaa 100755 --- a/examples/send_client.py +++ b/examples/send_client.py @@ -118,15 +118,5 @@ if __name__ == '__main__': # xmpp.ca_certs = "path/to/ca/cert" # Connect to the XMPP server and start processing XMPP stanzas. - if xmpp.connect(): - # If you do not have the dnspython library installed, you will need - # to manually specify the name of the server if it does not match - # the one in the JID. For example, to use Google Talk you would - # need to use: - # - # if xmpp.connect(('talk.google.com', 5222)): - # ... - xmpp.process(block=True) - print("Done") - else: - print("Unable to connect.") + xmpp.connect() + xmpp.process() diff --git a/examples/set_avatar.py b/examples/set_avatar.py index 12a79b3e..452363b7 100755 --- a/examples/set_avatar.py +++ b/examples/set_avatar.py @@ -149,14 +149,5 @@ if __name__ == '__main__': # xmpp.ca_certs = "path/to/ca/cert" # Connect to the XMPP server and start processing XMPP stanzas. - if xmpp.connect(): - # If you do not have the dnspython library installed, you will need - # to manually specify the name of the server if it does not match - # the one in the JID. For example, to use Google Talk you would - # need to use: - # - # if xmpp.connect(('talk.google.com', 5222)): - # ... - xmpp.process(block=True) - else: - print("Unable to connect.") + xmpp.connect() + xmpp.process() diff --git a/examples/thirdparty_auth.py b/examples/thirdparty_auth.py index fbe49f8b..504048a9 100755 --- a/examples/thirdparty_auth.py +++ b/examples/thirdparty_auth.py @@ -223,15 +223,5 @@ if __name__ == '__main__': # Connect to the XMPP server and start processing XMPP stanzas. # Google only allows one SASL attempt per connection, so in order to # enable the X-GOOGLE-TOKEN mechanism, we'll disable TLS. - if xmpp.connect(use_tls=False): - # If you do not have the dnspython library installed, you will need - # to manually specify the name of the server if it does not match - # the one in the JID. For example, to use Google Talk you would - # need to use: - # - # if xmpp.connect(('talk.google.com', 5222)): - # ... - xmpp.process(block=True) - print("Done") - else: - print("Unable to connect.") + xmpp.connect() + xmpp.process() diff --git a/examples/user_location.py b/examples/user_location.py index 7fa77e68..3e484d72 100755 --- a/examples/user_location.py +++ b/examples/user_location.py @@ -111,15 +111,5 @@ if __name__ == '__main__': # xmpp.ca_certs = "path/to/ca/cert" # Connect to the XMPP server and start processing XMPP stanzas. - if xmpp.connect(): - # If you do not have the dnspython library installed, you will need - # to manually specify the name of the server if it does not match - # the one in the JID. For example, to use Google Talk you would - # need to use: - # - # if xmpp.connect(('talk.google.com', 5222)): - # ... - xmpp.process(block=True) - print("Done") - else: - print("Unable to connect.") + xmpp.connect() + xmpp.process() diff --git a/examples/user_tune.py b/examples/user_tune.py index 96548514..4ecfdb7d 100755 --- a/examples/user_tune.py +++ b/examples/user_tune.py @@ -123,15 +123,5 @@ if __name__ == '__main__': # xmpp.ca_certs = "path/to/ca/cert" # Connect to the XMPP server and start processing XMPP stanzas. - if xmpp.connect(): - # If you do not have the dnspython library installed, you will need - # to manually specify the name of the server if it does not match - # the one in the JID. For example, to use Google Talk you would - # need to use: - # - # if xmpp.connect(('talk.google.com', 5222)): - # ... - xmpp.process(block=True) - print("Done") - else: - print("Unable to connect.") + xmpp.connect() + xmpp.process() diff --git a/slixmpp/basexmpp.py b/slixmpp/basexmpp.py index b15354c9..a3aa557a 100644 --- a/slixmpp/basexmpp.py +++ b/slixmpp/basexmpp.py @@ -203,6 +203,10 @@ class BaseXMPP(XMLStream): log.warning('Legacy XMPP 0.9 protocol detected.') self.event('legacy_protocol') + def process(self, timeout=None): + self.init_plugins() + XMLStream.process(self, timeout) + def init_plugins(self): for name in self.plugin: if not hasattr(self.plugin[name], 'post_inited'): diff --git a/slixmpp/xmlstream/xmlstream.py b/slixmpp/xmlstream/xmlstream.py index e3a8265a..ff5a3d26 100644 --- a/slixmpp/xmlstream/xmlstream.py +++ b/slixmpp/xmlstream/xmlstream.py @@ -302,6 +302,20 @@ class XMLStream(object): except OSError as e: self.event("connection_failed", e) + def process(self, timeout=None): + """Process all the available XMPP events (receiving or sending data on the + socket(s), calling various registered callbacks, calling expired + timers, handling signal events, etc). If timeout is None, this + function will run forever. If timeout is a number, this function + will return after the given time in seconds. + """ + loop = asyncio.get_event_loop() + if timeout is None: + loop.run_forever() + else: + future = asyncio.sleep(timeout) + loop.run_until_complete(future) + def init_parser(self): """init the XML parser. The parser must always be reset for each new connexion |