aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot2014-08-16 20:37:29 (GMT)
committerFlorent Le Coz2014-09-01 00:47:08 (GMT)
commit6175cbcd99f917b08646d130770a132458056249 (patch)
tree7aa51df981039fdfec06c141feb5b61888a4e8f9
parent476d76a53301f9da2ac7efa094e209b0607adfdc (diff)
downloadslixmpp-6175cbcd99f917b08646d130770a132458056249.tar.gz
slixmpp-6175cbcd99f917b08646d130770a132458056249.tar.xz
Reintroduce XMLStream.process, making it run the asyncio event loop.
-rwxr-xr-xexamples/adhoc_provider.py14
-rwxr-xr-xexamples/adhoc_user.py14
-rwxr-xr-xexamples/admin_commands.py14
-rwxr-xr-xexamples/custom_stanzas/custom_stanza_provider.py14
-rwxr-xr-xexamples/custom_stanzas/custom_stanza_user.py14
-rwxr-xr-xexamples/disco_browser.py13
-rwxr-xr-xexamples/download_avatars.py13
-rwxr-xr-xexamples/echo_client.py14
-rwxr-xr-xexamples/echo_component.py7
-rwxr-xr-xexamples/gtalk_custom_domain.py14
-rwxr-xr-xexamples/ibb_transfer/ibb_receiver.py14
-rwxr-xr-xexamples/ibb_transfer/ibb_sender.py14
-rwxr-xr-xexamples/muc.py14
-rwxr-xr-xexamples/ping.py14
-rwxr-xr-xexamples/proxy_echo_client.py14
-rwxr-xr-xexamples/pubsub_client.py13
-rwxr-xr-xexamples/pubsub_events.py14
-rwxr-xr-xexamples/register_account.py14
-rwxr-xr-xexamples/roster_browser.py14
-rwxr-xr-xexamples/send_client.py14
-rwxr-xr-xexamples/set_avatar.py13
-rwxr-xr-xexamples/thirdparty_auth.py14
-rwxr-xr-xexamples/user_location.py14
-rwxr-xr-xexamples/user_tune.py14
-rw-r--r--slixmpp/basexmpp.py4
-rw-r--r--slixmpp/xmlstream/xmlstream.py14
26 files changed, 66 insertions, 277 deletions
diff --git a/examples/adhoc_provider.py b/examples/adhoc_provider.py
index e0a7eff..e4a8fc0 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 646b41a..4aa2a23 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 e6415a4..97708cd 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 b1b6e0a..cfc8335 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 af6bf9b..891eb72 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 11ea2e3..2f92668 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 fc89317..61b07c5 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 733b541..de649eb 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 d56935f..0512f37 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 92d9fea..8c280ac 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 d24e500..02c899e 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 2d88d4c..f5e44fb 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 08a71a4..b609cef 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 25aaf98..8ecb8cf 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 b4b4dab..e1eab19 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 7fdd227..1e24dbd 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 f2384db..f4be2d6 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 17f672e..396b23c 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 6ca7ffe..0bdc7c1 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 beecfac..17dffca 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 12a79b3..452363b 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 fbe49f8..504048a 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 7fa77e6..3e484d7 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 9654851..4ecfdb7 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 b15354c..a3aa557 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 e3a8265..ff5a3d2 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