Remove all deprecated alias in the core of slixmpp, and wherever they were used.

This commit is contained in:
Emmanuel Gil Peyrot
2014-09-21 18:51:06 +02:00
committed by Florent Le Coz
parent 61f89eef2e
commit 7c3e61950d
29 changed files with 80 additions and 206 deletions

View File

@@ -29,7 +29,7 @@ in the future.
First Steps
-----------
Every plugin inherits from the class :mod:`base_plugin <slixmpp.plugins.base.base_plugin>`,
Every plugin inherits from the class :mod:`BasePlugin <slixmpp.plugins.base.BasePlugin`,
and must include a ``plugin_init`` method. While the
plugins distributed with Slixmpp must be placed in the plugins directory
``slixmpp/plugins`` to be loaded, custom plugins may be loaded from any
@@ -56,9 +56,9 @@ attribute.
as a tutorial for creating Slixmpp plugins.
"""
from slixmpp.plugins.base import base_plugin
from slixmpp.plugins.base import BasePlugin
class xep_0077(base_plugin):
class xep_0077(BasePlugin):
"""
XEP-0077 In-Band Registration
"""
@@ -81,7 +81,7 @@ call in a method named ``post_init`` which will be called once the plugin has
been loaded; by doing so we advertise that we can do registrations only after we
finish activating the plugin.
The ``post_init`` method needs to call ``base_plugin.post_init(self)``
The ``post_init`` method needs to call ``BasePlugin.post_init(self)``
which will mark that ``post_init`` has been called for the plugin. Once the
Slixmpp object begins processing, ``post_init`` will be called on any plugins
that have not already run ``post_init``. This allows you to register plugins and
@@ -94,7 +94,7 @@ does not automatically load plugin dependencies for you.
.. code-block:: python
def post_init(self):
base_plugin.post_init(self)
BasePlugin.post_init(self)
self.xmpp['xep_0030'].add_feature("jabber:iq:register")
Creating Custom Stanza Objects
@@ -347,7 +347,7 @@ method ``setForm`` which will take the names of the fields we wish to include.
# Add a blank field
reg.addField(field)
iq.reply().setPayload(reg.xml)
iq.reply().set_payload(reg.xml)
iq.send()
Note how we are able to access our ``Registration`` stanza object with
@@ -421,7 +421,7 @@ to the IQ reply.
...
def _sendError(self, iq, code, error_type, name, text=''):
iq.reply().setPayload(iq['register'].xml)
iq.reply().set_payload(iq['register'].xml)
iq.error()
iq['error']['code'] = code
iq['error']['type'] = error_type
@@ -464,7 +464,7 @@ component examples below for how to respond to this event.
if self.backend.register(iq['from'].bare, iq['register']):
# Successful registration
self.xmpp.event('registered_user', iq)
iq.reply().setPayload(iq['register'].xml)
iq.reply().set_payload(iq['register'].xml)
iq.send()
else:
# Conflicting registration
@@ -491,8 +491,8 @@ and that we specified the form fields we wish to use with
def __init__(self, jid, password):
slixmpp.componentxmpp.ComponentXMPP.__init__(self, jid, password, 'localhost', 8888)
self.registerPlugin('xep_0030')
self.registerPlugin('xep_0077')
self.register_plugin('xep_0030')
self.register_plugin('xep_0077')
self.plugin['xep_0077'].setForm('username', 'password')
self.add_event_handler("registered_user", self.reg)
@@ -500,11 +500,11 @@ and that we specified the form fields we wish to use with
def reg(self, iq):
msg = "Welcome! %s" % iq['register']['username']
self.sendMessage(iq['from'], msg, mfrom=self.fulljid)
self.send_message(iq['from'], msg, mfrom=self.fulljid)
def unreg(self, iq):
msg = "Bye! %s" % iq['register']['username']
self.sendMessage(iq['from'], msg, mfrom=self.fulljid)
self.send_message(iq['from'], msg, mfrom=self.fulljid)
**Congratulations!** We now have a basic, functioning implementation of
XEP-0077.
@@ -523,7 +523,7 @@ with some additional registration fields implemented.
as a tutorial for creating Slixmpp plugins.
"""
from slixmpp.plugins.base import base_plugin
from slixmpp.plugins.base import BasePlugin
from slixmpp.xmlstream.handler.callback import Callback
from slixmpp.xmlstream.matcher.xpath import MatchXPath
from slixmpp.xmlstream import ElementBase, ET, JID, register_stanza_plugin
@@ -589,7 +589,7 @@ with some additional registration fields implemented.
def unregister(self, jid):
del self.users[jid]
class xep_0077(base_plugin):
class xep_0077(BasePlugin):
"""
XEP-0077 In-Band Registration
"""
@@ -608,7 +608,7 @@ with some additional registration fields implemented.
register_stanza_plugin(Iq, Registration)
def post_init(self):
base_plugin.post_init(self)
BasePlugin.post_init(self)
self.xmpp['xep_0030'].add_feature("jabber:iq:register")
def __handleRegistration(self, iq):
@@ -634,7 +634,7 @@ with some additional registration fields implemented.
if self.backend.register(iq['from'].bare, iq['register']):
# Successful registration
self.xmpp.event('registered_user', iq)
iq.reply().setPayload(iq['register'].xml)
iq.reply().set_payload(iq['register'].xml)
iq.send()
else:
# Conflicting registration
@@ -666,11 +666,11 @@ with some additional registration fields implemented.
# Add a blank field
reg.addField(field)
iq.reply().setPayload(reg.xml)
iq.reply().set_payload(reg.xml)
iq.send()
def _sendError(self, iq, code, error_type, name, text=''):
iq.reply().setPayload(iq['register'].xml)
iq.reply().set_payload(iq['register'].xml)
iq.error()
iq['error']['code'] = code
iq['error']['type'] = error_type

View File

@@ -348,7 +348,7 @@ to :meth:`slixmpp.clientxmpp.ClientXMPP`.
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:`slixmpp.plugins.base.base_plugin.post_init` method on all registered plugins. By
the :meth:`slixmpp.plugins.base.BasePlugin.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

View File

@@ -36,7 +36,7 @@ Updated Code
.. code-block:: python
def handleIncomingMessage(self, message):
self.xmpp.sendMessage(message["from"], message["body"])
self.xmpp.send_message(message["from"], message["body"])
`View full source <http://github.com/legastero/xmpp-tdg/blob/master/code/EchoBot/EchoBot.py>`_ |
`View original code <http://github.com/remko/xmpp-tdg/blob/master/code/EchoBot/EchoBot.py>`_
@@ -86,7 +86,7 @@ Updated Code
"uri": self.url + "/" + message.user,
"user" : message.user, "message" : message.text }
for subscriberJID in self.backend.getSubscriberJIDs(message.user) :
self.xmpp.sendMessage(subscriberJID, body, mhtml=htmlBody)
self.xmpp.send_message(subscriberJID, body, mhtml=htmlBody)
`View full source <http://github.com/legastero/xmpp-tdg/blob/master/code/CheshiR/Bot.py>`_ |
`View original code <http://github.com/remko/xmpp-tdg/blob/master/code/CheshiR/Bot.py>`_
@@ -145,7 +145,7 @@ Example 14-4. (Page 220)
Like several previous examples, a needed change is to replace
``subscription["from"]`` with ``subscription["from"].jid`` because the
``BaseXMPP`` method ``makePresence`` requires the JID to be a string.
``BaseXMPP`` method ``make_presence`` requires the JID to be a string.
A correction needs to be made in ``handleXMPPPresenceProbe`` because a line was
left out of the original implementation; the variable ``user`` is undefined. The
@@ -154,7 +154,7 @@ JID of the user can be extracted from the presence stanza's ``from`` attribute.
Since this implementation of CheshiR uses an XMPP component, it must
include a ``from`` attribute in all messages that it sends. Adding the
``from`` attribute is done by including ``mfrom=self.xmpp.jid`` in calls to
``self.xmpp.sendMessage``.
``self.xmpp.send_message``.
Updated Code
~~~~~~~~~~~~
@@ -162,19 +162,19 @@ Updated Code
.. code-block:: python
def handleXMPPPresenceProbe(self, event) :
self.xmpp.sendPresence(pto = event["from"])
self.xmpp.send_presence(pto = event["from"])
def handleXMPPPresenceSubscription(self, subscription) :
if subscription["type"] == "subscribe" :
userJID = subscription["from"].jid
self.xmpp.sendPresenceSubscription(pto=userJID, ptype="subscribed")
self.xmpp.sendPresence(pto = userJID)
self.xmpp.sendPresenceSubscription(pto=userJID, ptype="subscribe")
self.xmpp.send_presence_subscription(pto=userJID, ptype="subscribed")
self.xmpp.send_presence(pto = userJID)
self.xmpp.send_presence_subscription(pto=userJID, ptype="subscribe")
def handleMessageAddedToBackend(self, message) :
body = message.user + ": " + message.text
for subscriberJID in self.backend.getSubscriberJIDs(message.user) :
self.xmpp.sendMessage(subscriberJID, body, mfrom=self.xmpp.jid)
self.xmpp.send_message(subscriberJID, body, mfrom=self.xmpp.jid)
`View full source <http://github.com/legastero/xmpp-tdg/blob/master/code/CheshiR/SimpleComponent.py>`_ |
`View original code <http://github.com/remko/xmpp-tdg/blob/master/code/CheshiR/SimpleComponent.py>`_
@@ -239,7 +239,7 @@ Updated Code
userJID = subscription["from"].jid
user = self.backend.getUserFromJID(userJID)
contactJID = subscription["to"]
self.xmpp.sendPresenceSubscription(
self.xmpp.send_presence_subscription(
pfrom=contactJID, pto=userJID, ptype="subscribed", pnick=user)
self.sendPresenceOfContactToUser(contactJID=contactJID, userJID=userJID)
if contactJID == self.componentDomain :