Rename to slixmpp
This commit is contained in:
@@ -8,17 +8,17 @@ Create and Run a Server Component
|
||||
|
||||
If you have any issues working through this quickstart guide
|
||||
or the other tutorials here, please either send a message to the
|
||||
`mailing list <http://groups.google.com/group/sleekxmpp-discussion>`_
|
||||
`mailing list <http://groups.google.com/group/slixmpp-discussion>`_
|
||||
or join the chat room at `sleek@conference.jabber.org
|
||||
<xmpp:sleek@conference.jabber.org?join>`_.
|
||||
|
||||
If you have not yet installed SleekXMPP, do so now by either checking out a version
|
||||
from `Github <http://github.com/fritzy/SleekXMPP>`_, or installing it using ``pip``
|
||||
If you have not yet installed Slixmpp, do so now by either checking out a version
|
||||
from `Github <http://github.com/fritzy/Slixmpp>`_, or installing it using ``pip``
|
||||
or ``easy_install``.
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
pip install sleekxmpp # Or: easy_install sleekxmpp
|
||||
pip install slixmpp # Or: easy_install slixmpp
|
||||
|
||||
|
||||
Many XMPP applications eventually graduate to requiring to run as a server
|
||||
@@ -30,7 +30,7 @@ The first difference is that we will add an additional import statement:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from sleekxmpp.componentxmpp import ComponentXMPP
|
||||
from slixmpp.componentxmpp import ComponentXMPP
|
||||
|
||||
Likewise, we will change the bot's class definition to match:
|
||||
|
||||
@@ -48,7 +48,7 @@ a MUC component, the following could be used:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
muc = ComponentXMPP('muc.sleekxmpp.com', '******', 'sleekxmpp.com', 5555)
|
||||
muc = ComponentXMPP('muc.slixmpp.com', '******', 'slixmpp.com', 5555)
|
||||
|
||||
.. note::
|
||||
|
||||
@@ -62,10 +62,10 @@ with presence.
|
||||
The other, main difference with components is that the
|
||||
``'from'`` value for every stanza must be explicitly set, since
|
||||
components may send stanzas from multiple JIDs. To do so,
|
||||
the :meth:`~sleekxmpp.basexmpp.BaseXMPP.send_message()` and
|
||||
:meth:`~sleekxmpp.basexmpp.BaseXMPP.send_presence()` accept the parameters
|
||||
the :meth:`~slixmpp.basexmpp.BaseXMPP.send_message()` and
|
||||
:meth:`~slixmpp.basexmpp.BaseXMPP.send_presence()` accept the parameters
|
||||
``mfrom`` and ``pfrom``, respectively. For any method that uses
|
||||
:class:`~sleekxmpp.stanza.iq.Iq` stanzas, ``ifrom`` may be used.
|
||||
:class:`~slixmpp.stanza.iq.Iq` stanzas, ``ifrom`` may be used.
|
||||
|
||||
|
||||
Final Product
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
.. _echobot:
|
||||
|
||||
===============================
|
||||
SleekXMPP Quickstart - Echo Bot
|
||||
Slixmpp Quickstart - Echo Bot
|
||||
===============================
|
||||
|
||||
.. note::
|
||||
|
||||
If you have any issues working through this quickstart guide
|
||||
or the other tutorials here, please either send a message to the
|
||||
`mailing list <http://groups.google.com/group/sleekxmpp-discussion>`_
|
||||
`mailing list <http://groups.google.com/group/slixmpp-discussion>`_
|
||||
or join the chat room at `sleek@conference.jabber.org
|
||||
<xmpp:sleek@conference.jabber.org?join>`_.
|
||||
|
||||
If you have not yet installed SleekXMPP, do so now by either checking out a version
|
||||
from `Github <http://github.com/fritzy/SleekXMPP>`_, or installing it using ``pip``
|
||||
If you have not yet installed Slixmpp, do so now by either checking out a version
|
||||
from `Github <http://github.com/fritzy/Slixmpp>`_, or installing it using ``pip``
|
||||
or ``easy_install``.
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
pip install sleekxmpp # Or: easy_install sleekxmpp
|
||||
pip install slixmpp # Or: easy_install slixmpp
|
||||
|
||||
|
||||
As a basic starting project, we will create an echo bot which will reply to any
|
||||
@@ -48,7 +48,7 @@ To get started, here is a brief outline of the structure that the final project
|
||||
import getpass
|
||||
from optparse import OptionParser
|
||||
|
||||
import sleekxmpp
|
||||
import slixmpp
|
||||
|
||||
'''Here we will create out echo bot class'''
|
||||
|
||||
@@ -61,7 +61,7 @@ To get started, here is a brief outline of the structure that the final project
|
||||
|
||||
Default Encoding
|
||||
----------------
|
||||
XMPP requires support for UTF-8 and so SleekXMPP must use UTF-8 as well. In
|
||||
XMPP requires support for UTF-8 and so Slixmpp must use UTF-8 as well. In
|
||||
Python3 this is simple because Unicode is the default string type. For Python2.6+
|
||||
the situation is not as easy because standard strings are simply byte arrays and
|
||||
use ASCII. We can get Python to use UTF-8 as the default encoding by including:
|
||||
@@ -69,13 +69,13 @@ use ASCII. We can get Python to use UTF-8 as the default encoding by including:
|
||||
.. code-block:: python
|
||||
|
||||
if sys.version_info < (3, 0):
|
||||
from sleekxmpp.util.misc_ops import setdefaultencoding
|
||||
from slixmpp.util.misc_ops import setdefaultencoding
|
||||
setdefaultencoding('utf8')
|
||||
|
||||
.. warning::
|
||||
|
||||
Until we are able to ensure that SleekXMPP will always use Unicode in Python2.6+, this
|
||||
may cause issues embedding SleekXMPP into other applications which assume ASCII encoding.
|
||||
Until we are able to ensure that Slixmpp will always use Unicode in Python2.6+, this
|
||||
may cause issues embedding Slixmpp into other applications which assume ASCII encoding.
|
||||
|
||||
Creating the EchoBot Class
|
||||
--------------------------
|
||||
@@ -85,14 +85,14 @@ clients. Since our echo bot will only be responding to a few people, and won't n
|
||||
to remember thousands of users, we will use a client connection. A client connection
|
||||
is the same type that you use with your standard IM client such as Pidgin or Psi.
|
||||
|
||||
SleekXMPP comes with a :class:`ClientXMPP <sleekxmpp.clientxmpp.ClientXMPP>` class
|
||||
which we can extend to add our message echoing feature. :class:`ClientXMPP <sleekxmpp.clientxmpp.ClientXMPP>`
|
||||
Slixmpp comes with a :class:`ClientXMPP <slixmpp.clientxmpp.ClientXMPP>` class
|
||||
which we can extend to add our message echoing feature. :class:`ClientXMPP <slixmpp.clientxmpp.ClientXMPP>`
|
||||
requires the parameters ``jid`` and ``password``, so we will let our ``EchoBot`` class accept those
|
||||
as well.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
class EchoBot(sleekxmpp.ClientXMPP):
|
||||
class EchoBot(slixmpp.ClientXMPP):
|
||||
|
||||
def __init__(self, jid, password):
|
||||
super(EchoBot, self).__init__(jid, password)
|
||||
@@ -132,8 +132,8 @@ Our event handler, like every event handler, accepts a single parameter which ty
|
||||
that was received that caused the event. In this case, ``event`` will just be an empty dictionary since
|
||||
there is no associated data.
|
||||
|
||||
Our first task of sending an initial presence is done using :meth:`send_presence <sleekxmpp.basexmpp.BaseXMPP.send_presence>`.
|
||||
Calling :meth:`send_presence <sleekxmpp.basexmpp.BaseXMPP.send_presence>` without any arguments will send the simplest
|
||||
Our first task of sending an initial presence is done using :meth:`send_presence <slixmpp.basexmpp.BaseXMPP.send_presence>`.
|
||||
Calling :meth:`send_presence <slixmpp.basexmpp.BaseXMPP.send_presence>` without any arguments will send the simplest
|
||||
stanza allowed in XMPP:
|
||||
|
||||
.. code-block:: xml
|
||||
@@ -141,17 +141,17 @@ stanza allowed in XMPP:
|
||||
<presence />
|
||||
|
||||
|
||||
The second requirement is fulfilled using :meth:`get_roster <sleekxmpp.clientxmpp.ClientXMPP.get_roster>`, which
|
||||
The second requirement is fulfilled using :meth:`get_roster <slixmpp.clientxmpp.ClientXMPP.get_roster>`, which
|
||||
will send an IQ stanza requesting the roster to the server and then wait for the response. You may be wondering
|
||||
what :meth:`get_roster <sleekxmpp.clientxmpp.ClientXMPP.get_roster>` returns since we are not saving any return
|
||||
what :meth:`get_roster <slixmpp.clientxmpp.ClientXMPP.get_roster>` returns since we are not saving any return
|
||||
value. The roster data is saved by an internal handler to ``self.roster``, and in the case of a :class:`ClientXMPP
|
||||
<sleekxmpp.clientxmpp.ClientXMPP>` instance to ``self.client_roster``. (The difference between ``self.roster`` and
|
||||
<slixmpp.clientxmpp.ClientXMPP>` instance to ``self.client_roster``. (The difference between ``self.roster`` and
|
||||
``self.client_roster`` is that ``self.roster`` supports storing roster information for multiple JIDs, which is useful
|
||||
for components, whereas ``self.client_roster`` stores roster data for just the client's JID.)
|
||||
|
||||
It is possible for a timeout to occur while waiting for the server to respond, which can happen if the
|
||||
network is excessively slow or the server is no longer responding. In that case, an :class:`IQTimeout
|
||||
<sleekxmpp.exceptions.IQTimeout>` is raised. Similarly, an :class:`IQError <sleekxmpp.exceptions.IQError>` exception can
|
||||
<slixmpp.exceptions.IQTimeout>` is raised. Similarly, an :class:`IQError <slixmpp.exceptions.IQError>` exception can
|
||||
be raised if the request contained bad data or requested the roster for the wrong user. In either case, you can wrap the
|
||||
``get_roster()`` call in a ``try``/``except`` block to retry the roster retrieval process.
|
||||
|
||||
@@ -201,7 +201,7 @@ Let's take a closer look at the ``.reply()`` method used above. For message stan
|
||||
which is then used as the value of the ``<body />`` element of the message.
|
||||
Setting the appropriate ``to`` JID is also handled by ``.reply()``.
|
||||
|
||||
Another way to have sent the reply message would be to use :meth:`send_message <sleekxmpp.basexmpp.BaseXMPP.send_message>`,
|
||||
Another way to have sent the reply message would be to use :meth:`send_message <slixmpp.basexmpp.BaseXMPP.send_message>`,
|
||||
which is a convenience method for generating and sending a message based on the values passed to it. If we were to use
|
||||
this method, the above code would look as so:
|
||||
|
||||
@@ -229,13 +229,13 @@ Whichever method you choose to use, the results in action will look like this:
|
||||
XMPP does not require stanzas sent by a client to include a ``from`` attribute, and
|
||||
leaves that responsibility to the XMPP server. However, if a sent stanza does
|
||||
include a ``from`` attribute, it must match the full JID of the client or some
|
||||
servers will reject it. SleekXMPP thus leaves out the ``from`` attribute when replying
|
||||
servers will reject it. Slixmpp thus leaves out the ``from`` attribute when replying
|
||||
using a client connection.
|
||||
|
||||
Command Line Arguments and Logging
|
||||
----------------------------------
|
||||
|
||||
While this isn't part of SleekXMPP itself, we do want our echo bot program to be able
|
||||
While this isn't part of Slixmpp itself, we do want our echo bot program to be able
|
||||
to accept a JID and password from the command line instead of hard coding them. We will
|
||||
use the ``optparse`` module for this, though there are several alternative methods, including
|
||||
the newer ``argparse`` module.
|
||||
@@ -305,7 +305,7 @@ the ``EchoBot.__init__`` method instead.
|
||||
|
||||
If you are using the OpenFire server, you will need to include an additional
|
||||
configuration step. OpenFire supports a different version of SSL than what
|
||||
most servers and SleekXMPP support.
|
||||
most servers and Slixmpp support.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -313,11 +313,11 @@ the ``EchoBot.__init__`` method instead.
|
||||
xmpp.ssl_version = ssl.PROTOCOL_SSLv3
|
||||
|
||||
Now we're ready to connect and begin echoing messages. If you have the package
|
||||
``dnspython`` installed, then the :meth:`sleekxmpp.clientxmpp.ClientXMPP` method
|
||||
``dnspython`` installed, then the :meth:`slixmpp.clientxmpp.ClientXMPP` method
|
||||
will perform a DNS query to find the appropriate server to connect to for the
|
||||
given JID. If you do not have ``dnspython``, then SleekXMPP will attempt to
|
||||
given JID. If you do not have ``dnspython``, then Slixmpp will attempt to
|
||||
connect to the hostname used by the JID, unless an address tuple is supplied
|
||||
to :meth:`sleekxmpp.clientxmpp.ClientXMPP`.
|
||||
to :meth:`slixmpp.clientxmpp.ClientXMPP`.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -346,19 +346,19 @@ to :meth:`sleekxmpp.clientxmpp.ClientXMPP`.
|
||||
else:
|
||||
print('Unable to connect')
|
||||
|
||||
To begin responding to messages, you'll see we called :meth:`sleekxmpp.basexmpp.BaseXMPP.process`
|
||||
To begin responding to messages, you'll see we called :meth:`slixmpp.basexmpp.BaseXMPP.process`
|
||||
which will start the event handling, send queue, and XML reader threads. It will also call
|
||||
the :meth:`sleekxmpp.plugins.base.base_plugin.post_init` method on all registered plugins. By
|
||||
passing ``block=True`` to :meth:`sleekxmpp.basexmpp.BaseXMPP.process` we are running the
|
||||
main processing loop in the main thread of execution. The :meth:`sleekxmpp.basexmpp.BaseXMPP.process`
|
||||
call will not return until after SleekXMPP disconnects. If you need to run the client in the background
|
||||
the :meth:`slixmpp.plugins.base.base_plugin.post_init` method on all registered plugins. By
|
||||
passing ``block=True`` to :meth:`slixmpp.basexmpp.BaseXMPP.process` we are running the
|
||||
main processing loop in the main thread of execution. The :meth:`slixmpp.basexmpp.BaseXMPP.process`
|
||||
call will not return until after Slixmpp disconnects. If you need to run the client in the background
|
||||
for another program, use ``block=False`` to spawn the processing loop in its own thread.
|
||||
|
||||
.. note::
|
||||
|
||||
Before 1.0, controlling the blocking behaviour of :meth:`sleekxmpp.basexmpp.BaseXMPP.process` was
|
||||
Before 1.0, controlling the blocking behaviour of :meth:`slixmpp.basexmpp.BaseXMPP.process` was
|
||||
done via the ``threaded`` argument. This arrangement was a source of confusion because some users
|
||||
interpreted that as controlling whether or not SleekXMPP used threads at all, instead of how
|
||||
interpreted that as controlling whether or not Slixmpp used threads at all, instead of how
|
||||
the processing loop itself was spawned.
|
||||
|
||||
The statements ``xmpp.process(threaded=False)`` and ``xmpp.process(block=True)`` are equivalent.
|
||||
@@ -370,7 +370,7 @@ The Final Product
|
||||
-----------------
|
||||
|
||||
Here then is what the final result should look like after working through the guide above. The code
|
||||
can also be found in the SleekXMPP `examples directory <http://github.com/fritzy/SleekXMPP/tree/master/examples>`_.
|
||||
can also be found in the Slixmpp `examples directory <http://github.com/fritzy/Slixmpp/tree/master/examples>`_.
|
||||
|
||||
.. compound::
|
||||
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
Send/Receive IQ Stanzas
|
||||
=======================
|
||||
|
||||
Unlike :class:`~sleekxmpp.stanza.message.Message` and
|
||||
:class:`~sleekxmpp.stanza.presence.Presence` stanzas which only use
|
||||
text data for basic usage, :class:`~sleekxmpp.stanza.iq.Iq` stanzas
|
||||
Unlike :class:`~slixmpp.stanza.message.Message` and
|
||||
:class:`~slixmpp.stanza.presence.Presence` stanzas which only use
|
||||
text data for basic usage, :class:`~slixmpp.stanza.iq.Iq` stanzas
|
||||
require using XML payloads, and generally entail creating a new
|
||||
SleekXMPP plugin to provide the necessary convenience methods to
|
||||
Slixmpp plugin to provide the necessary convenience methods to
|
||||
make working with them easier.
|
||||
|
||||
Basic Use
|
||||
---------
|
||||
|
||||
XMPP's use of :class:`~sleekxmpp.stanza.iq.Iq` stanzas is built around
|
||||
XMPP's use of :class:`~slixmpp.stanza.iq.Iq` stanzas is built around
|
||||
namespaced ``<query />`` elements. For clients, just sending the
|
||||
empty ``<query />`` element will suffice for retrieving information. For
|
||||
example, a very basic implementation of service discovery would just
|
||||
@@ -26,18 +26,18 @@ need to be able to send:
|
||||
Creating Iq Stanzas
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
SleekXMPP provides built-in support for creating basic :class:`~sleekxmpp.stanza.iq.Iq`
|
||||
Slixmpp provides built-in support for creating basic :class:`~slixmpp.stanza.iq.Iq`
|
||||
stanzas this way. The relevant methods are:
|
||||
|
||||
* :meth:`~sleekxmpp.basexmpp.BaseXMPP.make_iq`
|
||||
* :meth:`~sleekxmpp.basexmpp.BaseXMPP.make_iq_get`
|
||||
* :meth:`~sleekxmpp.basexmpp.BaseXMPP.make_iq_set`
|
||||
* :meth:`~sleekxmpp.basexmpp.BaseXMPP.make_iq_result`
|
||||
* :meth:`~sleekxmpp.basexmpp.BaseXMPP.make_iq_error`
|
||||
* :meth:`~sleekxmpp.basexmpp.BaseXMPP.make_iq_query`
|
||||
* :meth:`~slixmpp.basexmpp.BaseXMPP.make_iq`
|
||||
* :meth:`~slixmpp.basexmpp.BaseXMPP.make_iq_get`
|
||||
* :meth:`~slixmpp.basexmpp.BaseXMPP.make_iq_set`
|
||||
* :meth:`~slixmpp.basexmpp.BaseXMPP.make_iq_result`
|
||||
* :meth:`~slixmpp.basexmpp.BaseXMPP.make_iq_error`
|
||||
* :meth:`~slixmpp.basexmpp.BaseXMPP.make_iq_query`
|
||||
|
||||
These methods all follow the same pattern: create or modify an existing
|
||||
:class:`~sleekxmpp.stanza.iq.Iq` stanza, set the ``'type'`` value based
|
||||
:class:`~slixmpp.stanza.iq.Iq` stanza, set the ``'type'`` value based
|
||||
on the method name, and finally add a ``<query />`` element with the given
|
||||
namespace. For example, to produce the query above, you would use:
|
||||
|
||||
@@ -50,14 +50,14 @@ namespace. For example, to produce the query above, you would use:
|
||||
Sending Iq Stanzas
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Once an :class:`~sleekxmpp.stanza.iq.Iq` stanza is created, sending it
|
||||
over the wire is done using its :meth:`~sleekxmpp.stanza.iq.Iq.send()`
|
||||
Once an :class:`~slixmpp.stanza.iq.Iq` stanza is created, sending it
|
||||
over the wire is done using its :meth:`~slixmpp.stanza.iq.Iq.send()`
|
||||
method, like any other stanza object. However, there are a few extra
|
||||
options to control how to wait for the query's response.
|
||||
|
||||
These options are:
|
||||
|
||||
* ``block``: The default behaviour is that :meth:`~sleekxmpp.stanza.iq.Iq.send()`
|
||||
* ``block``: The default behaviour is that :meth:`~slixmpp.stanza.iq.Iq.send()`
|
||||
will block until a response is received and the response stanza will be the
|
||||
return value. Setting ``block`` to ``False`` will cause the call to return
|
||||
immediately. In which case, you will need to arrange some way to capture
|
||||
@@ -90,11 +90,11 @@ These options are:
|
||||
# ... later if we need to cancel
|
||||
self.remove_handler(cb_name)
|
||||
|
||||
Properly working with :class:`~sleekxmpp.stanza.iq.Iq` stanzas requires
|
||||
Properly working with :class:`~slixmpp.stanza.iq.Iq` stanzas requires
|
||||
handling the intended, normal flow, error responses, and timed out
|
||||
requests. To make this easier, two exceptions may be thrown by
|
||||
:meth:`~sleekxmpp.stanza.iq.Iq.send()`: :exc:`~sleekxmpp.exceptions.IqError`
|
||||
and :exc:`~sleekxmpp.exceptions.IqTimeout`. These exceptions only
|
||||
:meth:`~slixmpp.stanza.iq.Iq.send()`: :exc:`~slixmpp.exceptions.IqError`
|
||||
and :exc:`~slixmpp.exceptions.IqTimeout`. These exceptions only
|
||||
apply to the default, blocking calls.
|
||||
|
||||
.. code-block:: python
|
||||
@@ -110,7 +110,7 @@ apply to the default, blocking calls.
|
||||
pass
|
||||
|
||||
If you do not care to distinguish between errors and timeouts, then you
|
||||
can combine both cases with a generic :exc:`~sleekxmpp.exceptions.XMPPError`
|
||||
can combine both cases with a generic :exc:`~slixmpp.exceptions.XMPPError`
|
||||
exception:
|
||||
|
||||
.. code-block:: python
|
||||
@@ -124,9 +124,9 @@ exception:
|
||||
Advanced Use
|
||||
------------
|
||||
|
||||
Going beyond the basics provided by SleekXMPP requires building at least a
|
||||
rudimentary SleekXMPP plugin to create a :term:`stanza object` for
|
||||
interfacting with the :class:`~sleekxmpp.stanza.iq.Iq` payload.
|
||||
Going beyond the basics provided by Slixmpp requires building at least a
|
||||
rudimentary Slixmpp plugin to create a :term:`stanza object` for
|
||||
interfacting with the :class:`~slixmpp.stanza.iq.Iq` payload.
|
||||
|
||||
.. seealso::
|
||||
|
||||
@@ -135,13 +135,13 @@ interfacting with the :class:`~sleekxmpp.stanza.iq.Iq` payload.
|
||||
* :ref:`using-handlers-matchers`
|
||||
|
||||
|
||||
The typical way to respond to :class:`~sleekxmpp.stanza.iq.Iq` requests is
|
||||
The typical way to respond to :class:`~slixmpp.stanza.iq.Iq` requests is
|
||||
to register stream handlers. As an example, suppose we create a stanza class
|
||||
named ``CustomXEP`` which uses the XML element ``<query xmlns="custom-xep" />``,
|
||||
and has a :attr:`~sleekxmpp.xmlstream.stanzabase.ElementBase.plugin_attrib` value
|
||||
and has a :attr:`~slixmpp.xmlstream.stanzabase.ElementBase.plugin_attrib` value
|
||||
of ``custom_xep``.
|
||||
|
||||
There are two types of incoming :class:`~sleekxmpp.stanza.iq.Iq` requests:
|
||||
There are two types of incoming :class:`~slixmpp.stanza.iq.Iq` requests:
|
||||
``get`` and ``set``. You can register a handler that will accept both and then
|
||||
filter by type as needed, as so:
|
||||
|
||||
@@ -167,7 +167,7 @@ filter by type as needed, as so:
|
||||
|
||||
If you want to filter out query types beforehand, you can adjust the matching
|
||||
filter by using ``@type=get`` or ``@type=set`` if you are using the recommended
|
||||
:class:`~sleekxmpp.xmlstream.matcher.stanzapath.StanzaPath` matcher.
|
||||
:class:`~slixmpp.xmlstream.matcher.stanzapath.StanzaPath` matcher.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
|
||||
@@ -8,20 +8,20 @@ Mulit-User Chat (MUC) Bot
|
||||
|
||||
If you have any issues working through this quickstart guide
|
||||
or the other tutorials here, please either send a message to the
|
||||
`mailing list <http://groups.google.com/group/sleekxmpp-discussion>`_
|
||||
`mailing list <http://groups.google.com/group/slixmpp-discussion>`_
|
||||
or join the chat room at `sleek@conference.jabber.org
|
||||
<xmpp:sleek@conference.jabber.org?join>`_.
|
||||
|
||||
If you have not yet installed SleekXMPP, do so now by either checking out a version
|
||||
from `Github <http://github.com/fritzy/SleekXMPP>`_, or installing it using ``pip``
|
||||
If you have not yet installed Slixmpp, do so now by either checking out a version
|
||||
from `Github <http://github.com/fritzy/Slixmpp>`_, or installing it using ``pip``
|
||||
or ``easy_install``.
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
pip install sleekxmpp # Or: easy_install sleekxmpp
|
||||
pip install slixmpp # Or: easy_install slixmpp
|
||||
|
||||
|
||||
Now that you've got the basic gist of using SleekXMPP by following the
|
||||
Now that you've got the basic gist of using Slixmpp by following the
|
||||
echobot example (:ref:`echobot`), we can use one of the bundled plugins
|
||||
to create a very popular XMPP starter project: a `Multi-User Chat`_
|
||||
(MUC) bot. Our bot will login to an XMPP server, join an MUC chat room
|
||||
@@ -36,7 +36,7 @@ Joining The Room
|
||||
|
||||
As usual, our code will be based on the pattern explained in :ref:`echobot`.
|
||||
To start, we create an ``MUCBot`` class based on
|
||||
:class:`ClientXMPP <sleekxmpp.clientxmpp.ClientXMPP>` and which accepts
|
||||
:class:`ClientXMPP <slixmpp.clientxmpp.ClientXMPP>` and which accepts
|
||||
parameters for the JID of the MUC room to join, and the nick that the
|
||||
bot will use inside the chat room. We also register an
|
||||
:term:`event handler` for the :term:`session_start` event.
|
||||
@@ -44,12 +44,12 @@ bot will use inside the chat room. We also register an
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import sleekxmpp
|
||||
import slixmpp
|
||||
|
||||
class MUCBot(sleekxmpp.ClientXMPP):
|
||||
class MUCBot(slixmpp.ClientXMPP):
|
||||
|
||||
def __init__(self, jid, password, room, nick):
|
||||
sleekxmpp.ClientXMPP.__init__(self, jid, password)
|
||||
slixmpp.ClientXMPP.__init__(self, jid, password)
|
||||
|
||||
self.room = room
|
||||
self.nick = nick
|
||||
@@ -81,7 +81,7 @@ the roster. Next, we want to join the group chat, so we call the
|
||||
|
||||
.. note::
|
||||
|
||||
The :attr:`plugin <sleekxmpp.basexmpp.BaseXMPP.plugin>` attribute is
|
||||
The :attr:`plugin <slixmpp.basexmpp.BaseXMPP.plugin>` attribute is
|
||||
dictionary that maps to instances of plugins that we have previously
|
||||
registered, by their names.
|
||||
|
||||
@@ -115,7 +115,7 @@ event inside the bot's ``__init__`` function.
|
||||
.. code-block:: python
|
||||
|
||||
def __init__(self, jid, password, room, nick):
|
||||
sleekxmpp.ClientXMPP.__init__(self, jid, password)
|
||||
slixmpp.ClientXMPP.__init__(self, jid, password)
|
||||
|
||||
self.room = room
|
||||
self.nick = nick
|
||||
@@ -159,7 +159,7 @@ event so it's a good idea to register an event handler for it.
|
||||
.. code-block:: python
|
||||
|
||||
def __init__(self, jid, password, room, nick):
|
||||
sleekxmpp.ClientXMPP.__init__(self, jid, password)
|
||||
slixmpp.ClientXMPP.__init__(self, jid, password)
|
||||
|
||||
self.room = room
|
||||
self.nick = nick
|
||||
|
||||
@@ -8,16 +8,16 @@ Enable HTTP Proxy Support
|
||||
|
||||
If you have any issues working through this quickstart guide
|
||||
or the other tutorials here, please either send a message to the
|
||||
`mailing list <http://groups.google.com/group/sleekxmpp-discussion>`_
|
||||
`mailing list <http://groups.google.com/group/slixmpp-discussion>`_
|
||||
or join the chat room at `sleek@conference.jabber.org
|
||||
<xmpp:sleek@conference.jabber.org?join>`_.
|
||||
|
||||
In some instances, you may wish to route XMPP traffic through
|
||||
an HTTP proxy, probably to get around restrictive firewalls.
|
||||
SleekXMPP provides support for basic HTTP proxying with DIGEST
|
||||
Slixmpp provides support for basic HTTP proxying with DIGEST
|
||||
authentication.
|
||||
|
||||
Enabling proxy support is done in two steps. The first is to instruct SleekXMPP
|
||||
Enabling proxy support is done in two steps. The first is to instruct Slixmpp
|
||||
to use a proxy, and the second is to configure the proxy details:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -5,25 +5,25 @@ Sign in, Send a Message, and Disconnect
|
||||
|
||||
If you have any issues working through this quickstart guide
|
||||
or the other tutorials here, please either send a message to the
|
||||
`mailing list <http://groups.google.com/group/sleekxmpp-discussion>`_
|
||||
`mailing list <http://groups.google.com/group/slixmpp-discussion>`_
|
||||
or join the chat room at `sleek@conference.jabber.org
|
||||
<xmpp:sleek@conference.jabber.org?join>`_.
|
||||
|
||||
A common use case for SleekXMPP is to send one-off messages from
|
||||
A common use case for Slixmpp is to send one-off messages from
|
||||
time to time. For example, one use case could be sending out a notice when
|
||||
a shell script finishes a task.
|
||||
|
||||
We will create our one-shot bot based on the pattern explained in :ref:`echobot`. To
|
||||
start, we create a client class based on :class:`ClientXMPP <sleekxmpp.clientxmpp.ClientXMPP>` and
|
||||
start, we create a client class based on :class:`ClientXMPP <slixmpp.clientxmpp.ClientXMPP>` and
|
||||
register a handler for the :term:`session_start` event. We will also accept parameters
|
||||
for the JID that will receive our message, and the string content of the message.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import sleekxmpp
|
||||
import slixmpp
|
||||
|
||||
|
||||
class SendMsgBot(sleekxmpp.ClientXMPP):
|
||||
class SendMsgBot(slixmpp.ClientXMPP):
|
||||
|
||||
def __init__(self, jid, password, recipient, msg):
|
||||
super(SendMsgBot, self).__init__(jid, password)
|
||||
@@ -38,7 +38,7 @@ for the JID that will receive our message, and the string content of the message
|
||||
self.get_roster()
|
||||
|
||||
Note that as in :ref:`echobot`, we need to include send an initial presence and request
|
||||
the roster. Next, we want to send our message, and to do that we will use :meth:`send_message <sleekxmpp.basexmpp.BaseXMPP.send_message>`.
|
||||
the roster. Next, we want to send our message, and to do that we will use :meth:`send_message <slixmpp.basexmpp.BaseXMPP.send_message>`.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -48,12 +48,12 @@ the roster. Next, we want to send our message, and to do that we will use :meth:
|
||||
|
||||
self.send_message(mto=self.recipient, mbody=self.msg)
|
||||
|
||||
Finally, we need to disconnect the client using :meth:`disconnect <sleekxmpp.xmlstream.XMLStream.disconnect>`.
|
||||
Finally, we need to disconnect the client using :meth:`disconnect <slixmpp.xmlstream.XMLStream.disconnect>`.
|
||||
Now, sent stanzas are placed in a queue to pass them to the send thread. If we were to call
|
||||
:meth:`disconnect <sleekxmpp.xmlstream.XMLStream.disconnect>` without any parameters, then it is possible
|
||||
:meth:`disconnect <slixmpp.xmlstream.XMLStream.disconnect>` without any parameters, then it is possible
|
||||
for the client to disconnect before the send queue is processed and the message is actually
|
||||
sent on the wire. To ensure that our message is processed, we use
|
||||
:meth:`disconnect(wait=True) <sleekxmpp.xmlstream.XMLStream.disconnect>`.
|
||||
:meth:`disconnect(wait=True) <slixmpp.xmlstream.XMLStream.disconnect>`.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@@ -68,7 +68,7 @@ sent on the wire. To ensure that our message is processed, we use
|
||||
.. warning::
|
||||
|
||||
If you happen to be adding stanzas to the send queue faster than the send thread
|
||||
can process them, then :meth:`disconnect(wait=True) <sleekxmpp.xmlstream.XMLStream.disconnect>`
|
||||
can process them, then :meth:`disconnect(wait=True) <slixmpp.xmlstream.XMLStream.disconnect>`
|
||||
will block and not disconnect.
|
||||
|
||||
Final Product
|
||||
|
||||
Reference in New Issue
Block a user