Compare commits
56 Commits
slix-1.1
...
slix-1.2.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
36824379c3 | ||
|
|
a0a37c19ff | ||
|
|
1b5fe57a5e | ||
|
|
5da31db0c7 | ||
|
|
f8cea760b6 | ||
|
|
5ef01ecdd1 | ||
|
|
62aafe0ee7 | ||
|
|
cf3f36ac52 | ||
|
|
b88d2ecd77 | ||
|
|
e691850a2b | ||
|
|
d4bff8dee6 | ||
|
|
187c350805 | ||
|
|
96d1c26f90 | ||
|
|
46a90749f8 | ||
|
|
0c63a4bbda | ||
|
|
e4696e0471 | ||
|
|
8217dc5239 | ||
|
|
2586abc0d3 | ||
|
|
28f84ab3d9 | ||
|
|
813b45aded | ||
|
|
3a9b45e4f2 | ||
|
|
b8e091233e | ||
|
|
0edeefd977 | ||
|
|
6ba53cf1ff | ||
|
|
d7758eb7f4 | ||
|
|
125336aeee | ||
|
|
7cd1cf32ae | ||
|
|
d099e353a4 | ||
|
|
1e4a301c6e | ||
|
|
f53b12d227 | ||
|
|
e2562dcccf | ||
|
|
7b69ae3738 | ||
|
|
ab6df235d7 | ||
|
|
52cd8f4b22 | ||
|
|
e28318c271 | ||
|
|
39ee833c29 | ||
|
|
9019e2bc71 | ||
|
|
9208bf5bf1 | ||
|
|
f0f1698e46 | ||
|
|
eccd7f1c98 | ||
|
|
2587d82af8 | ||
|
|
7ea121b115 | ||
|
|
bb81fbbdfc | ||
|
|
1a00a08b7d | ||
|
|
90ea2a3411 | ||
|
|
8fc6814b6d | ||
|
|
ffced0ed9a | ||
|
|
e7248d9af9 | ||
|
|
6b1a04f59d | ||
|
|
4905407092 | ||
|
|
bd6ec10939 | ||
|
|
e15e6735f1 | ||
|
|
67afd6a462 | ||
|
|
2e2b97c53b | ||
|
|
a35df7fe1f | ||
|
|
fbc8562779 |
14
CONTRIBUTING.rst
Normal file
14
CONTRIBUTING.rst
Normal file
@@ -0,0 +1,14 @@
|
||||
Contributing to the Slixmpp project
|
||||
===================================
|
||||
|
||||
To contribute, the preferred way is to commit your changes on some
|
||||
publicly-available git repository (on a fork `on github
|
||||
<https://github.com/poezio/slixmpp>`_ or on your own repository) and to
|
||||
notify the developers with either:
|
||||
- a ticket `on the bug tracker <https://dev.poez.io/new>`_
|
||||
- a pull request on github
|
||||
- a simple message on `the XMPP MUC <xmpp:slixmpp@muc.poez.io>`_
|
||||
|
||||
Even though Slixmpp’s github repository is just a read-only mirror, we can
|
||||
still be notified of the pull requests and fetch your mirror manually to
|
||||
integrate your changes.
|
||||
17
README.rst
17
README.rst
@@ -12,8 +12,8 @@ Building
|
||||
--------
|
||||
|
||||
Slixmpp can make use of cython to improve performance on critical modules.
|
||||
To do that, cython3 is necessary along with libidn headers. Otherwise,
|
||||
no compilation is needed. Building is done by running setup.py::
|
||||
To do that, **cython3** is necessary along with **libidn** headers.
|
||||
Otherwise, no compilation is needed. Building is done by running setup.py::
|
||||
|
||||
python3 setup.py build_ext --inplace
|
||||
|
||||
@@ -102,8 +102,17 @@ Slixmpp projects::
|
||||
Slixmpp Credits
|
||||
---------------
|
||||
|
||||
**Maintainer of the slixmpp fork:** Florent Le Coz
|
||||
`louiz@louiz.org <xmpp:louiz@louiz.org?message>`_,
|
||||
**Maintainers:**
|
||||
- Florent Le Coz (`louiz@louiz.org <xmpp:louiz@louiz.org?message>`_),
|
||||
- Mathieu Pasquet (`mathieui@mathieui.net <xmpp:mathieui@mathieui.net?message>`_),
|
||||
|
||||
**Contributors:**
|
||||
- Emmanuel Gil Peyrot (`Link mauve <xmpp:linkmauve@linkmauve.fr?message>`_)
|
||||
- Sam Whited (`Sam Whited <mailto:sam@samwhited.com>`_)
|
||||
- Dan Sully (`Dan Sully <mailto:daniel@electricalrain.com>`_)
|
||||
- Gasper Zejn (`Gasper Zejn <mailto:zejn@kiberpipa.org>`_)
|
||||
- Krzysztof Kotlenga (`Krzysztof Kotlenga <mailto:pocek@users.sf.net>`_)
|
||||
- Tsukasa Hiiragi (`Tsukasa Hiiragi <mailto:bakalolka@gmail.com>`_)
|
||||
|
||||
Credits (SleekXMPP)
|
||||
-------------------
|
||||
|
||||
@@ -259,8 +259,8 @@ Event Index
|
||||
|
||||
Signal that a connection to the XMPP server has been lost and the current
|
||||
stream session has ended. Currently equivalent to :term:`disconnected`, but
|
||||
future implementation of `XEP-0198: Stream Management <http://xmpp.org/extensions/xep-0198.html>`_
|
||||
will distinguish the two events.
|
||||
implementations of `XEP-0198: Stream Management <http://xmpp.org/extensions/xep-0198.html>`_
|
||||
distinguish between the two events.
|
||||
|
||||
Plugins that maintain session-based state should clear themselves when
|
||||
this event is fired.
|
||||
|
||||
@@ -70,7 +70,7 @@ as well.
|
||||
class EchoBot(slixmpp.ClientXMPP):
|
||||
|
||||
def __init__(self, jid, password):
|
||||
super(EchoBot, self).__init__(jid, password)
|
||||
super().__init__(jid, password)
|
||||
|
||||
Handling Session Start
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
@@ -83,7 +83,7 @@ started. To do that, we will register an event handler for the :term:`session_st
|
||||
.. code-block:: python
|
||||
|
||||
def __init__(self, jid, password):
|
||||
super(EchoBot, self).__init__(jid, password)
|
||||
super().__init__(jid, password)
|
||||
|
||||
self.add_event_handler('session_start', self.start)
|
||||
|
||||
@@ -153,7 +153,7 @@ whenever a messsage is received.
|
||||
.. code-block:: python
|
||||
|
||||
def __init__(self, jid, password):
|
||||
super(EchoBot, self).__init__(jid, password)
|
||||
super().__init__(jid, password)
|
||||
|
||||
self.add_event_handler('session_start', self.start)
|
||||
self.add_event_handler('message', self.message)
|
||||
@@ -329,7 +329,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 Slixmpp `examples directory <http://github.com/fritzy/Slixmpp/tree/master/examples>`_.
|
||||
can also be found in the Slixmpp `examples directory <http://git.poez.io/slixmpp/tree/examples>`_.
|
||||
|
||||
.. compound::
|
||||
|
||||
|
||||
@@ -63,13 +63,13 @@ has been established:
|
||||
def start(self, event):
|
||||
self.get_roster()
|
||||
self.send_presence()
|
||||
self.plugin['xep_0045'].joinMUC(self.room,
|
||||
self.nick,
|
||||
wait=True)
|
||||
self.plugin['xep_0045'].join_muc(self.room,
|
||||
self.nick,
|
||||
wait=True)
|
||||
|
||||
Note that as in :ref:`echobot`, we need to include send an initial presence and request
|
||||
the roster. Next, we want to join the group chat, so we call the
|
||||
``joinMUC`` method of the MUC plugin.
|
||||
``join_muc`` method of the MUC plugin.
|
||||
|
||||
.. note::
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ for the JID that will receive our message, and the string content of the message
|
||||
class SendMsgBot(slixmpp.ClientXMPP):
|
||||
|
||||
def __init__(self, jid, password, recipient, msg):
|
||||
super(SendMsgBot, self).__init__(jid, password)
|
||||
super().__init__(jid, password)
|
||||
|
||||
self.recipient = recipient
|
||||
self.msg = msg
|
||||
|
||||
@@ -61,7 +61,7 @@ operation using these stanzas without doing any complex operations such as
|
||||
checking an ACL, etc.
|
||||
|
||||
You may find it necessary at some point to revert a particular node or JID to
|
||||
using the default, static handlers. To do so, use the method ``make_static()``.
|
||||
using the default, static handlers. To do so, use the method ``restore_defaults()``.
|
||||
You may also elect to only convert a given set of actions instead.
|
||||
|
||||
Creating a Node Handler
|
||||
|
||||
@@ -68,7 +68,7 @@ class CommandBot(slixmpp.ClientXMPP):
|
||||
session. Additional, custom data may be saved
|
||||
here to persist across handler callbacks.
|
||||
"""
|
||||
form = self['xep_0004'].makeForm('form', 'Greeting')
|
||||
form = self['xep_0004'].make_form('form', 'Greeting')
|
||||
form['instructions'] = 'Send a custom greeting to a JID'
|
||||
form.addField(var='greeting',
|
||||
ftype='text-single',
|
||||
|
||||
@@ -94,7 +94,7 @@ class CommandUserBot(slixmpp.ClientXMPP):
|
||||
# label="Your greeting" />
|
||||
# </x>
|
||||
|
||||
form = self['xep_0004'].makeForm(ftype='submit')
|
||||
form = self['xep_0004'].make_form(ftype='submit')
|
||||
form.addField(var='greeting',
|
||||
value=session['greeting'])
|
||||
|
||||
|
||||
100
examples/confirm_answer.py
Executable file
100
examples/confirm_answer.py
Executable file
@@ -0,0 +1,100 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Slixmpp: The Slick XMPP Library
|
||||
Copyright (C) 2015 Emmanuel Gil Peyrot
|
||||
This file is part of Slixmpp.
|
||||
|
||||
See the file LICENSE for copying permission.
|
||||
"""
|
||||
|
||||
import logging
|
||||
from getpass import getpass
|
||||
from argparse import ArgumentParser
|
||||
|
||||
import slixmpp
|
||||
from slixmpp.exceptions import XMPPError
|
||||
from slixmpp import asyncio
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class AnswerConfirm(slixmpp.ClientXMPP):
|
||||
|
||||
"""
|
||||
A basic client demonstrating how to confirm or deny an HTTP request.
|
||||
"""
|
||||
|
||||
def __init__(self, jid, password, trusted):
|
||||
slixmpp.ClientXMPP.__init__(self, jid, password)
|
||||
|
||||
self.add_event_handler("http_confirm", self.confirm)
|
||||
self.add_event_handler("session_start", self.start)
|
||||
|
||||
def start(self, *args):
|
||||
self.make_presence().send()
|
||||
|
||||
def prompt(self, stanza):
|
||||
confirm = stanza['confirm']
|
||||
print('Received confirm request %s from %s to access %s using '
|
||||
'method %s' % (
|
||||
confirm['id'], stanza['from'], confirm['url'],
|
||||
confirm['method'])
|
||||
)
|
||||
result = input("Do you accept (y/N)? ")
|
||||
return 'y' == result.lower()
|
||||
|
||||
def confirm(self, stanza):
|
||||
if self.prompt(stanza):
|
||||
reply = stanza.reply()
|
||||
else:
|
||||
reply = stanza.reply()
|
||||
reply.enable('error')
|
||||
reply['error']['type'] = 'auth'
|
||||
reply['error']['code'] = '401'
|
||||
reply['error']['condition'] = 'not-authorized'
|
||||
reply.append(stanza['confirm'])
|
||||
reply.send()
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Setup the command line arguments.
|
||||
parser = ArgumentParser()
|
||||
parser.add_argument("-q","--quiet", help="set logging to ERROR",
|
||||
action="store_const",
|
||||
dest="loglevel",
|
||||
const=logging.ERROR,
|
||||
default=logging.INFO)
|
||||
parser.add_argument("-d","--debug", help="set logging to DEBUG",
|
||||
action="store_const",
|
||||
dest="loglevel",
|
||||
const=logging.DEBUG,
|
||||
default=logging.INFO)
|
||||
|
||||
# JID and password options.
|
||||
parser.add_argument("-j", "--jid", dest="jid",
|
||||
help="JID to use")
|
||||
parser.add_argument("-p", "--password", dest="password",
|
||||
help="password to use")
|
||||
|
||||
# Other options.
|
||||
parser.add_argument("-t", "--trusted", nargs='*',
|
||||
help="List of trusted JIDs")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
# Setup logging.
|
||||
logging.basicConfig(level=args.loglevel,
|
||||
format='%(levelname)-8s %(message)s')
|
||||
|
||||
if args.jid is None:
|
||||
args.jid = input("Username: ")
|
||||
if args.password is None:
|
||||
args.password = getpass("Password: ")
|
||||
|
||||
xmpp = AnswerConfirm(args.jid, args.password, args.trusted)
|
||||
xmpp.register_plugin('xep_0070')
|
||||
|
||||
# Connect to the XMPP server and start processing XMPP stanzas.
|
||||
xmpp.connect()
|
||||
xmpp.process()
|
||||
125
examples/confirm_ask.py
Executable file
125
examples/confirm_ask.py
Executable file
@@ -0,0 +1,125 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Slixmpp: The Slick XMPP Library
|
||||
Copyright (C) 2015 Emmanuel Gil Peyrot
|
||||
This file is part of Slixmpp.
|
||||
|
||||
See the file LICENSE for copying permission.
|
||||
"""
|
||||
|
||||
import sys
|
||||
|
||||
import logging
|
||||
from getpass import getpass
|
||||
from argparse import ArgumentParser
|
||||
|
||||
import slixmpp
|
||||
from slixmpp.exceptions import XMPPError, IqError
|
||||
from slixmpp import asyncio
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class AskConfirm(slixmpp.ClientXMPP):
|
||||
|
||||
"""
|
||||
A basic client asking an entity if they confirm the access to an HTTP URL.
|
||||
"""
|
||||
|
||||
def __init__(self, jid, password, recipient, id, url, method):
|
||||
slixmpp.ClientXMPP.__init__(self, jid, password)
|
||||
|
||||
self.recipient = recipient
|
||||
self.id = id
|
||||
self.url = url
|
||||
self.method = method
|
||||
|
||||
# Will be used to set the proper exit code.
|
||||
self.confirmed = asyncio.Future()
|
||||
|
||||
self.add_event_handler("session_start", self.start)
|
||||
self.add_event_handler("message", self.start)
|
||||
self.add_event_handler("http_confirm_message", self.confirm)
|
||||
|
||||
def confirm(self, message):
|
||||
print(message)
|
||||
if message['confirm']['id'] == self.id:
|
||||
if message['type'] == 'error':
|
||||
self.confirmed.set_result(False)
|
||||
else:
|
||||
self.confirmed.set_result(True)
|
||||
|
||||
@asyncio.coroutine
|
||||
def start(self, event):
|
||||
log.info('Sending confirm request %s to %s who wants to access %s using '
|
||||
'method %s...' % (self.id, self.recipient, self.url, self.method))
|
||||
try:
|
||||
confirmed = yield from self['xep_0070'].ask_confirm(self.recipient,
|
||||
id=self.id,
|
||||
url=self.url,
|
||||
method=self.method,
|
||||
message='Plz say yes or no for {method} {url} ({id}).')
|
||||
if isinstance(confirmed, slixmpp.Message):
|
||||
confirmed = yield from self.confirmed
|
||||
else:
|
||||
confirmed = True
|
||||
except IqError:
|
||||
confirmed = False
|
||||
if confirmed:
|
||||
print('Confirmed')
|
||||
else:
|
||||
print('Denied')
|
||||
self.disconnect()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Setup the command line arguments.
|
||||
parser = ArgumentParser()
|
||||
parser.add_argument("-q","--quiet", help="set logging to ERROR",
|
||||
action="store_const",
|
||||
dest="loglevel",
|
||||
const=logging.ERROR,
|
||||
default=logging.INFO)
|
||||
parser.add_argument("-d","--debug", help="set logging to DEBUG",
|
||||
action="store_const",
|
||||
dest="loglevel",
|
||||
const=logging.DEBUG,
|
||||
default=logging.INFO)
|
||||
|
||||
# JID and password options.
|
||||
parser.add_argument("-j", "--jid", dest="jid",
|
||||
help="JID to use")
|
||||
parser.add_argument("-p", "--password", dest="password",
|
||||
help="password to use")
|
||||
|
||||
# Other options.
|
||||
parser.add_argument("-r", "--recipient", required=True,
|
||||
help="Recipient JID")
|
||||
parser.add_argument("-i", "--id", required=True,
|
||||
help="id TODO")
|
||||
parser.add_argument("-u", "--url", required=True,
|
||||
help="URL the user tried to access")
|
||||
parser.add_argument("-m", "--method", required=True,
|
||||
help="HTTP method used")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
# Setup logging.
|
||||
logging.basicConfig(level=args.loglevel,
|
||||
format='%(levelname)-8s %(message)s')
|
||||
|
||||
if args.jid is None:
|
||||
args.jid = input("Username: ")
|
||||
if args.password is None:
|
||||
args.password = getpass("Password: ")
|
||||
|
||||
xmpp = AskConfirm(args.jid, args.password, args.recipient, args.id,
|
||||
args.url, args.method)
|
||||
xmpp.register_plugin('xep_0070')
|
||||
|
||||
# Connect to the XMPP server and start processing XMPP stanzas.
|
||||
xmpp.connect()
|
||||
xmpp.process(forever=False)
|
||||
sys.exit(0 if xmpp.confirmed else 1)
|
||||
@@ -67,11 +67,11 @@ class MUCBot(slixmpp.ClientXMPP):
|
||||
"""
|
||||
self.get_roster()
|
||||
self.send_presence()
|
||||
self.plugin['xep_0045'].joinMUC(self.room,
|
||||
self.nick,
|
||||
# If a room password is needed, use:
|
||||
# password=the_room_password,
|
||||
wait=True)
|
||||
self.plugin['xep_0045'].join_muc(self.room,
|
||||
self.nick,
|
||||
# If a room password is needed, use:
|
||||
# password=the_room_password,
|
||||
wait=True)
|
||||
|
||||
def muc_message(self, msg):
|
||||
"""
|
||||
|
||||
@@ -15,7 +15,7 @@ class PubsubClient(slixmpp.ClientXMPP):
|
||||
|
||||
def __init__(self, jid, password, server,
|
||||
node=None, action='nodes', data=''):
|
||||
super(PubsubClient, self).__init__(jid, password)
|
||||
super().__init__(jid, password)
|
||||
|
||||
self.register_plugin('xep_0030')
|
||||
self.register_plugin('xep_0059')
|
||||
|
||||
@@ -14,7 +14,7 @@ from slixmpp.xmlstream.handler import Callback
|
||||
class PubsubEvents(slixmpp.ClientXMPP):
|
||||
|
||||
def __init__(self, jid, password):
|
||||
super(PubsubEvents, self).__init__(jid, password)
|
||||
super().__init__(jid, password)
|
||||
|
||||
self.register_plugin('xep_0030')
|
||||
self.register_plugin('xep_0059')
|
||||
|
||||
@@ -22,7 +22,7 @@ from slixmpp import ClientXMPP
|
||||
class LocationBot(ClientXMPP):
|
||||
|
||||
def __init__(self, jid, password):
|
||||
super(LocationBot, self).__init__(jid, password)
|
||||
super().__init__(jid, password)
|
||||
|
||||
self.add_event_handler('session_start', self.start)
|
||||
self.add_event_handler('user_location_publish',
|
||||
|
||||
@@ -17,7 +17,7 @@ from slixmpp import ClientXMPP
|
||||
class TuneBot(ClientXMPP):
|
||||
|
||||
def __init__(self, jid, password):
|
||||
super(TuneBot, self).__init__(jid, password)
|
||||
super().__init__(jid, password)
|
||||
|
||||
# Check for the current song every 5 seconds.
|
||||
self.schedule('Check Current Tune', 5, self._update_tune, repeat=True)
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
:license: MIT, see LICENSE for more details
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
import threading
|
||||
|
||||
from slixmpp import plugins, roster, stanza
|
||||
from slixmpp.api import APIRegistry
|
||||
@@ -21,7 +21,6 @@ from slixmpp.exceptions import IqError, IqTimeout
|
||||
|
||||
from slixmpp.stanza import Message, Presence, Iq, StreamError
|
||||
from slixmpp.stanza.roster import Roster
|
||||
from slixmpp.stanza.nick import Nick
|
||||
|
||||
from slixmpp.xmlstream import XMLStream, JID
|
||||
from slixmpp.xmlstream import ET, register_stanza_plugin
|
||||
@@ -70,7 +69,7 @@ class BaseXMPP(XMLStream):
|
||||
#: redirections that will be followed before quitting.
|
||||
self.max_redirects = 5
|
||||
|
||||
self.session_bind_event = threading.Event()
|
||||
self.session_bind_event = asyncio.Event()
|
||||
|
||||
#: A dictionary mapping plugin names to plugins.
|
||||
self.plugin = PluginManager(self)
|
||||
@@ -194,7 +193,6 @@ class BaseXMPP(XMLStream):
|
||||
|
||||
# Initialize a few default stanza plugins.
|
||||
register_stanza_plugin(Iq, Roster)
|
||||
register_stanza_plugin(Message, Nick)
|
||||
|
||||
def start_stream_handler(self, xml):
|
||||
"""Save the stream ID once the streams have been established.
|
||||
@@ -687,7 +685,6 @@ class BaseXMPP(XMLStream):
|
||||
self.address = (host, port)
|
||||
self.default_domain = host
|
||||
self.dns_records = None
|
||||
self.reconnect_delay = None
|
||||
self.reconnect()
|
||||
|
||||
def _handle_message(self, msg):
|
||||
@@ -753,6 +750,9 @@ class BaseXMPP(XMLStream):
|
||||
|
||||
Update the roster with presence information.
|
||||
"""
|
||||
if self.roster[presence['from']].ignore_updates:
|
||||
return
|
||||
|
||||
if not self.is_component and not presence['to'].bare:
|
||||
presence['to'] = self.boundjid
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
:license: MIT, see LICENSE for more details
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
from slixmpp.stanza import StreamFeatures
|
||||
@@ -19,7 +20,7 @@ from slixmpp.basexmpp import BaseXMPP
|
||||
from slixmpp.exceptions import XMPPError
|
||||
from slixmpp.xmlstream import XMLStream
|
||||
from slixmpp.xmlstream.matcher import StanzaPath, MatchXPath
|
||||
from slixmpp.xmlstream.handler import Callback
|
||||
from slixmpp.xmlstream.handler import Callback, CoroutineCallback
|
||||
|
||||
# Flag indicating if DNS SRV records are available for use.
|
||||
try:
|
||||
@@ -104,9 +105,9 @@ class ClientXMPP(BaseXMPP):
|
||||
self.register_stanza(StreamFeatures)
|
||||
|
||||
self.register_handler(
|
||||
Callback('Stream Features',
|
||||
MatchXPath('{%s}features' % self.stream_ns),
|
||||
self._handle_stream_features))
|
||||
CoroutineCallback('Stream Features',
|
||||
MatchXPath('{%s}features' % self.stream_ns),
|
||||
self._handle_stream_features))
|
||||
self.register_handler(
|
||||
Callback('Roster Update',
|
||||
StanzaPath('iq@type=set/roster'),
|
||||
@@ -140,8 +141,11 @@ class ClientXMPP(BaseXMPP):
|
||||
will be used.
|
||||
|
||||
:param address: A tuple containing the server's host and port.
|
||||
:param use_tls: Indicates if TLS should be used for the
|
||||
connection. Defaults to ``True``.
|
||||
:param force_starttls: Indicates that negotiation should be aborted
|
||||
if the server does not advertise support for
|
||||
STARTTLS. Defaults to ``True``.
|
||||
:param disable_starttls: Disables TLS for the connection.
|
||||
Defaults to ``False``.
|
||||
:param use_ssl: Indicates if the older SSL connection method
|
||||
should be used. Defaults to ``False``.
|
||||
"""
|
||||
@@ -249,6 +253,7 @@ class ClientXMPP(BaseXMPP):
|
||||
self.bindfail = False
|
||||
self.features = set()
|
||||
|
||||
@asyncio.coroutine
|
||||
def _handle_stream_features(self, features):
|
||||
"""Process the received stream features.
|
||||
|
||||
@@ -257,7 +262,11 @@ class ClientXMPP(BaseXMPP):
|
||||
for order, name in self._stream_feature_order:
|
||||
if name in features['features']:
|
||||
handler, restart = self._stream_feature_handlers[name]
|
||||
if handler(features) and restart:
|
||||
if asyncio.iscoroutinefunction(handler):
|
||||
result = yield from handler(features)
|
||||
else:
|
||||
result = handler(features)
|
||||
if result and restart:
|
||||
# Don't continue if the feature requires
|
||||
# restarting the XML stream.
|
||||
return True
|
||||
|
||||
@@ -77,7 +77,7 @@ class IqTimeout(XMPPError):
|
||||
"""
|
||||
|
||||
def __init__(self, iq):
|
||||
super(IqTimeout, self).__init__(
|
||||
super().__init__(
|
||||
condition='remote-server-timeout',
|
||||
etype='cancel')
|
||||
|
||||
@@ -94,7 +94,7 @@ class IqError(XMPPError):
|
||||
"""
|
||||
|
||||
def __init__(self, iq):
|
||||
super(IqError, self).__init__(
|
||||
super().__init__(
|
||||
condition=iq['error']['condition'],
|
||||
text=iq['error']['text'],
|
||||
etype=iq['error']['type'])
|
||||
|
||||
@@ -13,7 +13,3 @@ from slixmpp.features.feature_bind.stanza import Bind
|
||||
|
||||
|
||||
register_plugin(FeatureBind)
|
||||
|
||||
|
||||
# Retain some backwards compatibility
|
||||
feature_bind = FeatureBind
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
See the file LICENSE for copying permission.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
from slixmpp.jid import JID
|
||||
@@ -34,6 +35,7 @@ class FeatureBind(BasePlugin):
|
||||
register_stanza_plugin(Iq, stanza.Bind)
|
||||
register_stanza_plugin(StreamFeatures, stanza.Bind)
|
||||
|
||||
@asyncio.coroutine
|
||||
def _handle_bind_resource(self, features):
|
||||
"""
|
||||
Handle requesting a specific resource.
|
||||
@@ -49,7 +51,7 @@ class FeatureBind(BasePlugin):
|
||||
if self.xmpp.requested_jid.resource:
|
||||
iq['bind']['resource'] = self.xmpp.requested_jid.resource
|
||||
|
||||
iq.send(callback=self._on_bind_response)
|
||||
yield from iq.send(callback=self._on_bind_response)
|
||||
|
||||
def _on_bind_response(self, response):
|
||||
self.xmpp.boundjid = JID(response['bind']['jid'])
|
||||
|
||||
@@ -16,7 +16,3 @@ from slixmpp.features.feature_mechanisms.stanza import Failure
|
||||
|
||||
|
||||
register_plugin(FeatureMechanisms)
|
||||
|
||||
|
||||
# Retain some backwards compatibility
|
||||
feature_mechanisms = FeatureMechanisms
|
||||
|
||||
@@ -29,7 +29,7 @@ class Mechanisms(ElementBase):
|
||||
"""
|
||||
"""
|
||||
results = []
|
||||
mechs = self.findall('{%s}mechanism' % self.namespace)
|
||||
mechs = self.xml.findall('{%s}mechanism' % self.namespace)
|
||||
if mechs:
|
||||
for mech in mechs:
|
||||
results.append(mech.text)
|
||||
@@ -47,7 +47,7 @@ class Mechanisms(ElementBase):
|
||||
def del_mechanisms(self):
|
||||
"""
|
||||
"""
|
||||
mechs = self.findall('{%s}mechanism' % self.namespace)
|
||||
mechs = self.xml.findall('{%s}mechanism' % self.namespace)
|
||||
if mechs:
|
||||
for mech in mechs:
|
||||
self.xml.remove(mech)
|
||||
|
||||
@@ -13,7 +13,3 @@ from slixmpp.features.feature_rosterver.stanza import RosterVer
|
||||
|
||||
|
||||
register_plugin(FeatureRosterVer)
|
||||
|
||||
|
||||
# Retain some backwards compatibility
|
||||
feature_rosterver = FeatureRosterVer
|
||||
|
||||
@@ -13,7 +13,3 @@ from slixmpp.features.feature_session.stanza import Session
|
||||
|
||||
|
||||
register_plugin(FeatureSession)
|
||||
|
||||
|
||||
# Retain some backwards compatibility
|
||||
feature_session = FeatureSession
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
See the file LICENSE for copying permission.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
from slixmpp.stanza import Iq, StreamFeatures
|
||||
@@ -34,6 +35,7 @@ class FeatureSession(BasePlugin):
|
||||
register_stanza_plugin(Iq, stanza.Session)
|
||||
register_stanza_plugin(StreamFeatures, stanza.Session)
|
||||
|
||||
@asyncio.coroutine
|
||||
def _handle_start_session(self, features):
|
||||
"""
|
||||
Handle the start of the session.
|
||||
@@ -44,7 +46,7 @@ class FeatureSession(BasePlugin):
|
||||
iq = self.xmpp.Iq()
|
||||
iq['type'] = 'set'
|
||||
iq.enable('session')
|
||||
iq.send(callback=self._on_start_session_response)
|
||||
yield from iq.send(callback=self._on_start_session_response)
|
||||
|
||||
def _on_start_session_response(self, response):
|
||||
self.xmpp.features.add('session')
|
||||
|
||||
@@ -13,7 +13,3 @@ from slixmpp.features.feature_starttls.stanza import *
|
||||
|
||||
|
||||
register_plugin(FeatureSTARTTLS)
|
||||
|
||||
|
||||
# Retain some backwards compatibility
|
||||
feature_starttls = FeatureSTARTTLS
|
||||
|
||||
@@ -79,7 +79,7 @@ def _validate_node(node):
|
||||
:returns: The local portion of a JID, as validated by nodeprep.
|
||||
"""
|
||||
if node is None:
|
||||
return None
|
||||
return ''
|
||||
|
||||
try:
|
||||
node = nodeprep(node)
|
||||
@@ -160,7 +160,7 @@ def _validate_resource(resource):
|
||||
:returns: The local portion of a JID, as validated by resourceprep.
|
||||
"""
|
||||
if resource is None:
|
||||
return None
|
||||
return ''
|
||||
|
||||
try:
|
||||
resource = resourceprep(resource)
|
||||
@@ -208,16 +208,15 @@ def _format_jid(local=None, domain=None, resource=None):
|
||||
|
||||
:return: A full or bare JID string.
|
||||
"""
|
||||
result = []
|
||||
if domain is None:
|
||||
return ''
|
||||
if local is not None:
|
||||
result.append(local)
|
||||
result.append('@')
|
||||
if domain is not None:
|
||||
result.append(domain)
|
||||
result = local + '@' + domain
|
||||
else:
|
||||
result = domain
|
||||
if resource is not None:
|
||||
result.append('/')
|
||||
result.append(resource)
|
||||
return ''.join(result)
|
||||
result += '/' + resource
|
||||
return result
|
||||
|
||||
|
||||
class InvalidJID(ValueError):
|
||||
@@ -300,19 +299,23 @@ class JID:
|
||||
:raises InvalidJID:
|
||||
"""
|
||||
|
||||
__slots__ = ('_node', '_domain', '_resource')
|
||||
__slots__ = ('_node', '_domain', '_resource', '_bare', '_full')
|
||||
|
||||
def __init__(self, jid=None):
|
||||
if not jid:
|
||||
self._node = None
|
||||
self._domain = None
|
||||
self._resource = None
|
||||
self._node = ''
|
||||
self._domain = ''
|
||||
self._resource = ''
|
||||
self._bare = ''
|
||||
self._full = ''
|
||||
return
|
||||
elif not isinstance(jid, JID):
|
||||
self._node, self._domain, self._resource = _parse_jid(jid)
|
||||
else:
|
||||
self._node = jid._node
|
||||
self._domain = jid._domain
|
||||
self._resource = jid._resource
|
||||
self._update_bare_full()
|
||||
|
||||
def unescape(self):
|
||||
"""Return an unescaped JID object.
|
||||
@@ -329,77 +332,94 @@ class JID:
|
||||
self._domain,
|
||||
self._resource)
|
||||
|
||||
def _update_bare_full(self):
|
||||
"""Format the given JID into a bare and a full JID.
|
||||
"""
|
||||
self._bare = (self._node + '@' + self._domain
|
||||
if self._node
|
||||
else self._domain)
|
||||
self._full = (self._bare + '/' + self._resource
|
||||
if self._resource
|
||||
else self._bare)
|
||||
|
||||
@property
|
||||
def node(self):
|
||||
return self._node or ''
|
||||
return self._node
|
||||
|
||||
@property
|
||||
def user(self):
|
||||
return self._node or ''
|
||||
return self._node
|
||||
|
||||
@property
|
||||
def local(self):
|
||||
return self._node or ''
|
||||
return self._node
|
||||
|
||||
@property
|
||||
def username(self):
|
||||
return self._node or ''
|
||||
return self._node
|
||||
|
||||
@property
|
||||
def domain(self):
|
||||
return self._domain or ''
|
||||
return self._domain
|
||||
|
||||
@property
|
||||
def server(self):
|
||||
return self._domain or ''
|
||||
return self._domain
|
||||
|
||||
@property
|
||||
def host(self):
|
||||
return self._domain or ''
|
||||
return self._domain
|
||||
|
||||
@property
|
||||
def resource(self):
|
||||
return self._resource or ''
|
||||
return self._resource
|
||||
|
||||
@property
|
||||
def bare(self):
|
||||
return _format_jid(self._node, self._domain)
|
||||
return self._bare
|
||||
|
||||
@property
|
||||
def full(self):
|
||||
return _format_jid(self._node, self._domain, self._resource)
|
||||
return self._full
|
||||
|
||||
@property
|
||||
def jid(self):
|
||||
return _format_jid(self._node, self._domain, self._resource)
|
||||
return self._full
|
||||
|
||||
@node.setter
|
||||
def node(self, value):
|
||||
self._node = _validate_node(value)
|
||||
self._update_bare_full()
|
||||
|
||||
@user.setter
|
||||
def user(self, value):
|
||||
self._node = _validate_node(value)
|
||||
self._update_bare_full()
|
||||
|
||||
@local.setter
|
||||
def local(self, value):
|
||||
self._node = _validate_node(value)
|
||||
self._update_bare_full()
|
||||
|
||||
@username.setter
|
||||
def username(self, value):
|
||||
self._node = _validate_node(value)
|
||||
self._update_bare_full()
|
||||
|
||||
@domain.setter
|
||||
def domain(self, value):
|
||||
self._domain = _validate_domain(value)
|
||||
self._update_bare_full()
|
||||
|
||||
@server.setter
|
||||
def server(self, value):
|
||||
self._domain = _validate_domain(value)
|
||||
self._update_bare_full()
|
||||
|
||||
@host.setter
|
||||
def host(self, value):
|
||||
self._domain = _validate_domain(value)
|
||||
self._update_bare_full()
|
||||
|
||||
@bare.setter
|
||||
def bare(self, value):
|
||||
@@ -407,26 +427,30 @@ class JID:
|
||||
assert not resource
|
||||
self._node = node
|
||||
self._domain = domain
|
||||
self._update_bare_full()
|
||||
|
||||
@resource.setter
|
||||
def resource(self, value):
|
||||
self._resource = _validate_resource(value)
|
||||
self._update_bare_full()
|
||||
|
||||
@full.setter
|
||||
def full(self, value):
|
||||
self._node, self._domain, self._resource = _parse_jid(value)
|
||||
self._update_bare_full()
|
||||
|
||||
@jid.setter
|
||||
def jid(self, value):
|
||||
self._node, self._domain, self._resource = _parse_jid(value)
|
||||
self._update_bare_full()
|
||||
|
||||
def __str__(self):
|
||||
"""Use the full JID as the string value."""
|
||||
return _format_jid(self._node, self._domain, self._resource)
|
||||
return self._full
|
||||
|
||||
def __repr__(self):
|
||||
"""Use the full JID as the representation."""
|
||||
return _format_jid(self._node, self._domain, self._resource)
|
||||
return self._full
|
||||
|
||||
# pylint: disable=W0212
|
||||
def __eq__(self, other):
|
||||
@@ -446,4 +470,4 @@ class JID:
|
||||
|
||||
def __hash__(self):
|
||||
"""Hash a JID based on the string version of its full JID."""
|
||||
return hash(_format_jid(self._node, self._domain, self._resource))
|
||||
return hash(self._full)
|
||||
|
||||
@@ -308,7 +308,7 @@ class BasePlugin(object):
|
||||
if key in self.default_config:
|
||||
self.config[key] = value
|
||||
else:
|
||||
super(BasePlugin, self).__setattr__(key, value)
|
||||
super().__setattr__(key, value)
|
||||
|
||||
def _init(self):
|
||||
"""Initialize plugin state, such as registering event handlers.
|
||||
|
||||
@@ -23,13 +23,13 @@ class GmailQuery(ElementBase):
|
||||
plugin_attrib = 'gmail'
|
||||
interfaces = set(('newer-than-time', 'newer-than-tid', 'q', 'search'))
|
||||
|
||||
def getSearch(self):
|
||||
def get_search(self):
|
||||
return self['q']
|
||||
|
||||
def setSearch(self, search):
|
||||
def set_search(self, search):
|
||||
self['q'] = search
|
||||
|
||||
def delSearch(self):
|
||||
def del_search(self):
|
||||
del self['q']
|
||||
|
||||
|
||||
@@ -40,17 +40,17 @@ class MailBox(ElementBase):
|
||||
interfaces = set(('result-time', 'total-matched', 'total-estimate',
|
||||
'url', 'threads', 'matched', 'estimate'))
|
||||
|
||||
def getThreads(self):
|
||||
def get_threads(self):
|
||||
threads = []
|
||||
for threadXML in self.xml.findall('{%s}%s' % (MailThread.namespace,
|
||||
MailThread.name)):
|
||||
threads.append(MailThread(xml=threadXML, parent=None))
|
||||
return threads
|
||||
|
||||
def getMatched(self):
|
||||
def get_matched(self):
|
||||
return self['total-matched']
|
||||
|
||||
def getEstimate(self):
|
||||
def get_estimate(self):
|
||||
return self['total-estimate'] == '1'
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ class MailThread(ElementBase):
|
||||
'senders', 'url', 'labels', 'subject', 'snippet'))
|
||||
sub_interfaces = set(('labels', 'subject', 'snippet'))
|
||||
|
||||
def getSenders(self):
|
||||
def get_senders(self):
|
||||
senders = []
|
||||
sendersXML = self.xml.find('{%s}senders' % self.namespace)
|
||||
if sendersXML is not None:
|
||||
@@ -77,10 +77,10 @@ class MailSender(ElementBase):
|
||||
plugin_attrib = 'sender'
|
||||
interfaces = set(('address', 'name', 'originator', 'unread'))
|
||||
|
||||
def getOriginator(self):
|
||||
def get_originator(self):
|
||||
return self.xml.attrib.get('originator', '0') == '1'
|
||||
|
||||
def getUnread(self):
|
||||
def get_unread(self):
|
||||
return self.xml.attrib.get('unread', '0') == '1'
|
||||
|
||||
|
||||
|
||||
@@ -14,9 +14,3 @@ from slixmpp.plugins.xep_0004.dataforms import XEP_0004
|
||||
|
||||
|
||||
register_plugin(XEP_0004)
|
||||
|
||||
|
||||
# Retain some backwards compatibility
|
||||
xep_0004 = XEP_0004
|
||||
xep_0004.makeForm = xep_0004.make_form
|
||||
xep_0004.buildForm = xep_0004.build_form
|
||||
|
||||
@@ -81,18 +81,6 @@ class Form(ElementBase):
|
||||
self.append(field)
|
||||
return field
|
||||
|
||||
def getXML(self, type='submit'):
|
||||
self['type'] = type
|
||||
log.warning("Form.getXML() is deprecated API compatibility " + \
|
||||
"with plugins/old_0004.py")
|
||||
return self.xml
|
||||
|
||||
def fromXML(self, xml):
|
||||
log.warning("Form.fromXML() is deprecated API compatibility " + \
|
||||
"with plugins/old_0004.py")
|
||||
n = Form(xml=xml)
|
||||
return n
|
||||
|
||||
def add_item(self, values):
|
||||
itemXML = ET.Element('{%s}item' % self.namespace)
|
||||
self.xml.append(itemXML)
|
||||
|
||||
@@ -14,7 +14,3 @@ from slixmpp.plugins.xep_0009.stanza import RPCQuery, MethodCall, MethodResponse
|
||||
|
||||
|
||||
register_plugin(XEP_0009)
|
||||
|
||||
|
||||
# Retain some backwards compatibility
|
||||
xep_0009 = XEP_0009
|
||||
|
||||
@@ -25,7 +25,7 @@ def fault2xml(fault):
|
||||
|
||||
def xml2fault(params):
|
||||
vals = []
|
||||
for value in params.findall('{%s}value' % _namespace):
|
||||
for value in params.xml.findall('{%s}value' % _namespace):
|
||||
vals.append(_xml2py(value))
|
||||
fault = dict()
|
||||
fault['code'] = vals[0]['faultCode']
|
||||
@@ -98,33 +98,34 @@ def xml2py(params):
|
||||
|
||||
def _xml2py(value):
|
||||
namespace = 'jabber:iq:rpc'
|
||||
if value.find('{%s}nil' % namespace) is not None:
|
||||
find_value = value.find
|
||||
if find_value('{%s}nil' % namespace) is not None:
|
||||
return None
|
||||
if value.find('{%s}i4' % namespace) is not None:
|
||||
return int(value.find('{%s}i4' % namespace).text)
|
||||
if value.find('{%s}int' % namespace) is not None:
|
||||
return int(value.find('{%s}int' % namespace).text)
|
||||
if value.find('{%s}boolean' % namespace) is not None:
|
||||
return bool(int(value.find('{%s}boolean' % namespace).text))
|
||||
if value.find('{%s}string' % namespace) is not None:
|
||||
return value.find('{%s}string' % namespace).text
|
||||
if value.find('{%s}double' % namespace) is not None:
|
||||
return float(value.find('{%s}double' % namespace).text)
|
||||
if value.find('{%s}base64' % namespace) is not None:
|
||||
return rpcbase64(value.find('{%s}base64' % namespace).text.encode())
|
||||
if value.find('{%s}Base64' % namespace) is not None:
|
||||
if find_value('{%s}i4' % namespace) is not None:
|
||||
return int(find_value('{%s}i4' % namespace).text)
|
||||
if find_value('{%s}int' % namespace) is not None:
|
||||
return int(find_value('{%s}int' % namespace).text)
|
||||
if find_value('{%s}boolean' % namespace) is not None:
|
||||
return bool(int(find_value('{%s}boolean' % namespace).text))
|
||||
if find_value('{%s}string' % namespace) is not None:
|
||||
return find_value('{%s}string' % namespace).text
|
||||
if find_value('{%s}double' % namespace) is not None:
|
||||
return float(find_value('{%s}double' % namespace).text)
|
||||
if find_value('{%s}base64' % namespace) is not None:
|
||||
return rpcbase64(find_value('{%s}base64' % namespace).text.encode())
|
||||
if find_value('{%s}Base64' % namespace) is not None:
|
||||
# Older versions of XEP-0009 used Base64
|
||||
return rpcbase64(value.find('{%s}Base64' % namespace).text.encode())
|
||||
if value.find('{%s}dateTime.iso8601' % namespace) is not None:
|
||||
return rpctime(value.find('{%s}dateTime.iso8601' % namespace).text)
|
||||
if value.find('{%s}struct' % namespace) is not None:
|
||||
return rpcbase64(find_value('{%s}Base64' % namespace).text.encode())
|
||||
if find_value('{%s}dateTime.iso8601' % namespace) is not None:
|
||||
return rpctime(find_value('{%s}dateTime.iso8601' % namespace).text)
|
||||
if find_value('{%s}struct' % namespace) is not None:
|
||||
struct = {}
|
||||
for member in value.find('{%s}struct' % namespace).findall('{%s}member' % namespace):
|
||||
for member in find_value('{%s}struct' % namespace).findall('{%s}member' % namespace):
|
||||
struct[member.find('{%s}name' % namespace).text] = _xml2py(member.find('{%s}value' % namespace))
|
||||
return struct
|
||||
if value.find('{%s}array' % namespace) is not None:
|
||||
if find_value('{%s}array' % namespace) is not None:
|
||||
array = []
|
||||
for val in value.find('{%s}array' % namespace).find('{%s}data' % namespace).findall('{%s}value' % namespace):
|
||||
for val in find_value('{%s}array' % namespace).find('{%s}data' % namespace).findall('{%s}value' % namespace):
|
||||
array.append(_xml2py(val))
|
||||
return array
|
||||
raise ValueError()
|
||||
|
||||
@@ -163,7 +163,7 @@ class ACL:
|
||||
|
||||
@classmethod
|
||||
def _next_token(cls, expression, index):
|
||||
new_index = expression.find('*', index)
|
||||
new_index = expression.xml.find('*', index)
|
||||
if new_index == 0:
|
||||
return ''
|
||||
else:
|
||||
@@ -182,7 +182,7 @@ class ACL:
|
||||
#! print "[TOKEN] '%s'" % token
|
||||
size = len(token)
|
||||
if size > 0:
|
||||
token_index = value.find(token, position)
|
||||
token_index = value.xml.find(token, position)
|
||||
if token_index == -1:
|
||||
return False
|
||||
else:
|
||||
|
||||
@@ -13,7 +13,3 @@ from slixmpp.plugins.xep_0012.last_activity import XEP_0012
|
||||
|
||||
|
||||
register_plugin(XEP_0012)
|
||||
|
||||
|
||||
# Retain some backwards compatibility
|
||||
xep_0004 = XEP_0012
|
||||
|
||||
@@ -66,7 +66,7 @@ class XEP_0012(BasePlugin):
|
||||
self.del_last_activity(jid)
|
||||
|
||||
def start_uptime(self, status=None):
|
||||
self.set_last_activity(jid, 0, status)
|
||||
self.set_last_activity(None, 0, status)
|
||||
|
||||
def set_last_activity(self, jid=None, seconds=None, status=None):
|
||||
self.api['set_last_activity'](jid, args={
|
||||
|
||||
@@ -15,8 +15,3 @@ from slixmpp.plugins.xep_0030.disco import XEP_0030
|
||||
|
||||
|
||||
register_plugin(XEP_0030)
|
||||
|
||||
# Retain some backwards compatibility
|
||||
xep_0030 = XEP_0030
|
||||
XEP_0030.getInfo = XEP_0030.get_info
|
||||
XEP_0030.make_static = XEP_0030.restore_defaults
|
||||
|
||||
@@ -137,7 +137,7 @@ class DiscoInfo(ElementBase):
|
||||
identity = (category, itype, lang)
|
||||
if identity in self._identities:
|
||||
self._identities.remove(identity)
|
||||
for id_xml in self.findall('{%s}identity' % self.namespace):
|
||||
for id_xml in self.xml.findall('{%s}identity' % self.namespace):
|
||||
id = (id_xml.attrib['category'],
|
||||
id_xml.attrib['type'],
|
||||
id_xml.attrib.get('{%s}lang' % self.xml_ns, None))
|
||||
@@ -163,7 +163,7 @@ class DiscoInfo(ElementBase):
|
||||
identities = set()
|
||||
else:
|
||||
identities = []
|
||||
for id_xml in self.findall('{%s}identity' % self.namespace):
|
||||
for id_xml in self.xml.findall('{%s}identity' % self.namespace):
|
||||
xml_lang = id_xml.attrib.get('{%s}lang' % self.xml_ns, None)
|
||||
if lang is None or xml_lang == lang:
|
||||
id = (id_xml.attrib['category'],
|
||||
@@ -205,7 +205,7 @@ class DiscoInfo(ElementBase):
|
||||
Arguments:
|
||||
lang -- Optional, standard xml:lang value.
|
||||
"""
|
||||
for id_xml in self.findall('{%s}identity' % self.namespace):
|
||||
for id_xml in self.xml.findall('{%s}identity' % self.namespace):
|
||||
if lang is None:
|
||||
self.xml.remove(id_xml)
|
||||
elif id_xml.attrib.get('{%s}lang' % self.xml_ns, None) == lang:
|
||||
@@ -239,7 +239,7 @@ class DiscoInfo(ElementBase):
|
||||
"""
|
||||
if feature in self._features:
|
||||
self._features.remove(feature)
|
||||
for feature_xml in self.findall('{%s}feature' % self.namespace):
|
||||
for feature_xml in self.xml.findall('{%s}feature' % self.namespace):
|
||||
if feature_xml.attrib['var'] == feature:
|
||||
self.xml.remove(feature_xml)
|
||||
return True
|
||||
@@ -251,7 +251,7 @@ class DiscoInfo(ElementBase):
|
||||
features = set()
|
||||
else:
|
||||
features = []
|
||||
for feature_xml in self.findall('{%s}feature' % self.namespace):
|
||||
for feature_xml in self.xml.findall('{%s}feature' % self.namespace):
|
||||
if dedupe:
|
||||
features.add(feature_xml.attrib['var'])
|
||||
else:
|
||||
@@ -272,5 +272,5 @@ class DiscoInfo(ElementBase):
|
||||
def del_features(self):
|
||||
"""Remove all features."""
|
||||
self._features = set()
|
||||
for feature_xml in self.findall('{%s}feature' % self.namespace):
|
||||
for feature_xml in self.xml.findall('{%s}feature' % self.namespace):
|
||||
self.xml.remove(feature_xml)
|
||||
|
||||
@@ -95,7 +95,7 @@ class DiscoItems(ElementBase):
|
||||
node -- Optional extra identifying information.
|
||||
"""
|
||||
if (jid, node) in self._items:
|
||||
for item_xml in self.findall('{%s}item' % self.namespace):
|
||||
for item_xml in self.xml.findall('{%s}item' % self.namespace):
|
||||
item = (item_xml.attrib['jid'],
|
||||
item_xml.attrib.get('node', None))
|
||||
if item == (jid, node):
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
"""
|
||||
|
||||
import logging
|
||||
import threading
|
||||
|
||||
from slixmpp import Iq
|
||||
from slixmpp.exceptions import XMPPError, IqError, IqTimeout
|
||||
@@ -48,7 +47,6 @@ class StaticDisco(object):
|
||||
self.nodes = {}
|
||||
self.xmpp = xmpp
|
||||
self.disco = disco
|
||||
self.lock = threading.RLock()
|
||||
|
||||
def add_node(self, jid=None, node=None, ifrom=None):
|
||||
"""
|
||||
@@ -59,48 +57,45 @@ class StaticDisco(object):
|
||||
jid -- The JID that will own the new stanzas.
|
||||
node -- The node that will own the new stanzas.
|
||||
"""
|
||||
with self.lock:
|
||||
if jid is None:
|
||||
jid = self.xmpp.boundjid.full
|
||||
if node is None:
|
||||
node = ''
|
||||
if ifrom is None:
|
||||
ifrom = ''
|
||||
if isinstance(ifrom, JID):
|
||||
ifrom = ifrom.full
|
||||
if (jid, node, ifrom) not in self.nodes:
|
||||
self.nodes[(jid, node, ifrom)] = {'info': DiscoInfo(),
|
||||
'items': DiscoItems()}
|
||||
self.nodes[(jid, node, ifrom)]['info']['node'] = node
|
||||
self.nodes[(jid, node, ifrom)]['items']['node'] = node
|
||||
if jid is None:
|
||||
jid = self.xmpp.boundjid.full
|
||||
if node is None:
|
||||
node = ''
|
||||
if ifrom is None:
|
||||
ifrom = ''
|
||||
if isinstance(ifrom, JID):
|
||||
ifrom = ifrom.full
|
||||
if (jid, node, ifrom) not in self.nodes:
|
||||
self.nodes[(jid, node, ifrom)] = {'info': DiscoInfo(),
|
||||
'items': DiscoItems()}
|
||||
self.nodes[(jid, node, ifrom)]['info']['node'] = node
|
||||
self.nodes[(jid, node, ifrom)]['items']['node'] = node
|
||||
|
||||
def get_node(self, jid=None, node=None, ifrom=None):
|
||||
with self.lock:
|
||||
if jid is None:
|
||||
jid = self.xmpp.boundjid.full
|
||||
if node is None:
|
||||
node = ''
|
||||
if ifrom is None:
|
||||
ifrom = ''
|
||||
if isinstance(ifrom, JID):
|
||||
ifrom = ifrom.full
|
||||
if (jid, node, ifrom) not in self.nodes:
|
||||
self.add_node(jid, node, ifrom)
|
||||
return self.nodes[(jid, node, ifrom)]
|
||||
if jid is None:
|
||||
jid = self.xmpp.boundjid.full
|
||||
if node is None:
|
||||
node = ''
|
||||
if ifrom is None:
|
||||
ifrom = ''
|
||||
if isinstance(ifrom, JID):
|
||||
ifrom = ifrom.full
|
||||
if (jid, node, ifrom) not in self.nodes:
|
||||
self.add_node(jid, node, ifrom)
|
||||
return self.nodes[(jid, node, ifrom)]
|
||||
|
||||
def node_exists(self, jid=None, node=None, ifrom=None):
|
||||
with self.lock:
|
||||
if jid is None:
|
||||
jid = self.xmpp.boundjid.full
|
||||
if node is None:
|
||||
node = ''
|
||||
if ifrom is None:
|
||||
ifrom = ''
|
||||
if isinstance(ifrom, JID):
|
||||
ifrom = ifrom.full
|
||||
if (jid, node, ifrom) not in self.nodes:
|
||||
return False
|
||||
return True
|
||||
if jid is None:
|
||||
jid = self.xmpp.boundjid.full
|
||||
if node is None:
|
||||
node = ''
|
||||
if ifrom is None:
|
||||
ifrom = ''
|
||||
if isinstance(ifrom, JID):
|
||||
ifrom = ifrom.full
|
||||
if (jid, node, ifrom) not in self.nodes:
|
||||
return False
|
||||
return True
|
||||
|
||||
# =================================================================
|
||||
# Node Handlers
|
||||
@@ -199,14 +194,13 @@ class StaticDisco(object):
|
||||
|
||||
The data parameter is not used.
|
||||
"""
|
||||
with self.lock:
|
||||
if not self.node_exists(jid, node):
|
||||
if not node:
|
||||
return DiscoInfo()
|
||||
else:
|
||||
raise XMPPError(condition='item-not-found')
|
||||
if not self.node_exists(jid, node):
|
||||
if not node:
|
||||
return DiscoInfo()
|
||||
else:
|
||||
return self.get_node(jid, node)['info']
|
||||
raise XMPPError(condition='item-not-found')
|
||||
else:
|
||||
return self.get_node(jid, node)['info']
|
||||
|
||||
def set_info(self, jid, node, ifrom, data):
|
||||
"""
|
||||
@@ -214,9 +208,8 @@ class StaticDisco(object):
|
||||
|
||||
The data parameter is a disco#info substanza.
|
||||
"""
|
||||
with self.lock:
|
||||
self.add_node(jid, node)
|
||||
self.get_node(jid, node)['info'] = data
|
||||
self.add_node(jid, node)
|
||||
self.get_node(jid, node)['info'] = data
|
||||
|
||||
def del_info(self, jid, node, ifrom, data):
|
||||
"""
|
||||
@@ -224,9 +217,8 @@ class StaticDisco(object):
|
||||
|
||||
The data parameter is not used.
|
||||
"""
|
||||
with self.lock:
|
||||
if self.node_exists(jid, node):
|
||||
self.get_node(jid, node)['info'] = DiscoInfo()
|
||||
if self.node_exists(jid, node):
|
||||
self.get_node(jid, node)['info'] = DiscoInfo()
|
||||
|
||||
def get_items(self, jid, node, ifrom, data):
|
||||
"""
|
||||
@@ -234,14 +226,13 @@ class StaticDisco(object):
|
||||
|
||||
The data parameter is not used.
|
||||
"""
|
||||
with self.lock:
|
||||
if not self.node_exists(jid, node):
|
||||
if not node:
|
||||
return DiscoItems()
|
||||
else:
|
||||
raise XMPPError(condition='item-not-found')
|
||||
if not self.node_exists(jid, node):
|
||||
if not node:
|
||||
return DiscoItems()
|
||||
else:
|
||||
return self.get_node(jid, node)['items']
|
||||
raise XMPPError(condition='item-not-found')
|
||||
else:
|
||||
return self.get_node(jid, node)['items']
|
||||
|
||||
def set_items(self, jid, node, ifrom, data):
|
||||
"""
|
||||
@@ -250,10 +241,9 @@ class StaticDisco(object):
|
||||
The data parameter may provide:
|
||||
items -- A set of items in tuple format.
|
||||
"""
|
||||
with self.lock:
|
||||
items = data.get('items', set())
|
||||
self.add_node(jid, node)
|
||||
self.get_node(jid, node)['items']['items'] = items
|
||||
items = data.get('items', set())
|
||||
self.add_node(jid, node)
|
||||
self.get_node(jid, node)['items']['items'] = items
|
||||
|
||||
def del_items(self, jid, node, ifrom, data):
|
||||
"""
|
||||
@@ -261,9 +251,8 @@ class StaticDisco(object):
|
||||
|
||||
The data parameter is not used.
|
||||
"""
|
||||
with self.lock:
|
||||
if self.node_exists(jid, node):
|
||||
self.get_node(jid, node)['items'] = DiscoItems()
|
||||
if self.node_exists(jid, node):
|
||||
self.get_node(jid, node)['items'] = DiscoItems()
|
||||
|
||||
def add_identity(self, jid, node, ifrom, data):
|
||||
"""
|
||||
@@ -275,13 +264,12 @@ class StaticDisco(object):
|
||||
name -- Optional human readable name for this identity.
|
||||
lang -- Optional standard xml:lang value.
|
||||
"""
|
||||
with self.lock:
|
||||
self.add_node(jid, node)
|
||||
self.get_node(jid, node)['info'].add_identity(
|
||||
data.get('category', ''),
|
||||
data.get('itype', ''),
|
||||
data.get('name', None),
|
||||
data.get('lang', None))
|
||||
self.add_node(jid, node)
|
||||
self.get_node(jid, node)['info'].add_identity(
|
||||
data.get('category', ''),
|
||||
data.get('itype', ''),
|
||||
data.get('name', None),
|
||||
data.get('lang', None))
|
||||
|
||||
def set_identities(self, jid, node, ifrom, data):
|
||||
"""
|
||||
@@ -291,10 +279,9 @@ class StaticDisco(object):
|
||||
identities -- A list of identities in tuple form:
|
||||
(category, type, name, lang)
|
||||
"""
|
||||
with self.lock:
|
||||
identities = data.get('identities', set())
|
||||
self.add_node(jid, node)
|
||||
self.get_node(jid, node)['info']['identities'] = identities
|
||||
identities = data.get('identities', set())
|
||||
self.add_node(jid, node)
|
||||
self.get_node(jid, node)['info']['identities'] = identities
|
||||
|
||||
def del_identity(self, jid, node, ifrom, data):
|
||||
"""
|
||||
@@ -306,13 +293,12 @@ class StaticDisco(object):
|
||||
name -- Optional human readable name for this identity.
|
||||
lang -- Optional, standard xml:lang value.
|
||||
"""
|
||||
with self.lock:
|
||||
if self.node_exists(jid, node):
|
||||
self.get_node(jid, node)['info'].del_identity(
|
||||
data.get('category', ''),
|
||||
data.get('itype', ''),
|
||||
data.get('name', None),
|
||||
data.get('lang', None))
|
||||
if self.node_exists(jid, node):
|
||||
self.get_node(jid, node)['info'].del_identity(
|
||||
data.get('category', ''),
|
||||
data.get('itype', ''),
|
||||
data.get('name', None),
|
||||
data.get('lang', None))
|
||||
|
||||
def del_identities(self, jid, node, ifrom, data):
|
||||
"""
|
||||
@@ -320,9 +306,8 @@ class StaticDisco(object):
|
||||
|
||||
The data parameter is not used.
|
||||
"""
|
||||
with self.lock:
|
||||
if self.node_exists(jid, node):
|
||||
del self.get_node(jid, node)['info']['identities']
|
||||
if self.node_exists(jid, node):
|
||||
del self.get_node(jid, node)['info']['identities']
|
||||
|
||||
def add_feature(self, jid, node, ifrom, data):
|
||||
"""
|
||||
@@ -331,10 +316,9 @@ class StaticDisco(object):
|
||||
The data parameter should include:
|
||||
feature -- The namespace of the supported feature.
|
||||
"""
|
||||
with self.lock:
|
||||
self.add_node(jid, node)
|
||||
self.get_node(jid, node)['info'].add_feature(
|
||||
data.get('feature', ''))
|
||||
self.add_node(jid, node)
|
||||
self.get_node(jid, node)['info'].add_feature(
|
||||
data.get('feature', ''))
|
||||
|
||||
def set_features(self, jid, node, ifrom, data):
|
||||
"""
|
||||
@@ -343,10 +327,9 @@ class StaticDisco(object):
|
||||
The data parameter should include:
|
||||
features -- The new set of supported features.
|
||||
"""
|
||||
with self.lock:
|
||||
features = data.get('features', set())
|
||||
self.add_node(jid, node)
|
||||
self.get_node(jid, node)['info']['features'] = features
|
||||
features = data.get('features', set())
|
||||
self.add_node(jid, node)
|
||||
self.get_node(jid, node)['info']['features'] = features
|
||||
|
||||
def del_feature(self, jid, node, ifrom, data):
|
||||
"""
|
||||
@@ -355,10 +338,9 @@ class StaticDisco(object):
|
||||
The data parameter should include:
|
||||
feature -- The namespace of the removed feature.
|
||||
"""
|
||||
with self.lock:
|
||||
if self.node_exists(jid, node):
|
||||
self.get_node(jid, node)['info'].del_feature(
|
||||
data.get('feature', ''))
|
||||
if self.node_exists(jid, node):
|
||||
self.get_node(jid, node)['info'].del_feature(
|
||||
data.get('feature', ''))
|
||||
|
||||
def del_features(self, jid, node, ifrom, data):
|
||||
"""
|
||||
@@ -366,10 +348,9 @@ class StaticDisco(object):
|
||||
|
||||
The data parameter is not used.
|
||||
"""
|
||||
with self.lock:
|
||||
if not self.node_exists(jid, node):
|
||||
return
|
||||
del self.get_node(jid, node)['info']['features']
|
||||
if not self.node_exists(jid, node):
|
||||
return
|
||||
del self.get_node(jid, node)['info']['features']
|
||||
|
||||
def add_item(self, jid, node, ifrom, data):
|
||||
"""
|
||||
@@ -381,12 +362,11 @@ class StaticDisco(object):
|
||||
non-addressable items.
|
||||
name -- Optional human readable name for the item.
|
||||
"""
|
||||
with self.lock:
|
||||
self.add_node(jid, node)
|
||||
self.get_node(jid, node)['items'].add_item(
|
||||
data.get('ijid', ''),
|
||||
node=data.get('inode', ''),
|
||||
name=data.get('name', ''))
|
||||
self.add_node(jid, node)
|
||||
self.get_node(jid, node)['items'].add_item(
|
||||
data.get('ijid', ''),
|
||||
node=data.get('inode', ''),
|
||||
name=data.get('name', ''))
|
||||
|
||||
def del_item(self, jid, node, ifrom, data):
|
||||
"""
|
||||
@@ -396,11 +376,10 @@ class StaticDisco(object):
|
||||
ijid -- JID of the item to remove.
|
||||
inode -- Optional extra identifying information.
|
||||
"""
|
||||
with self.lock:
|
||||
if self.node_exists(jid, node):
|
||||
self.get_node(jid, node)['items'].del_item(
|
||||
data.get('ijid', ''),
|
||||
node=data.get('inode', None))
|
||||
if self.node_exists(jid, node):
|
||||
self.get_node(jid, node)['items'].del_item(
|
||||
data.get('ijid', ''),
|
||||
node=data.get('inode', None))
|
||||
|
||||
def cache_info(self, jid, node, ifrom, data):
|
||||
"""
|
||||
@@ -410,12 +389,11 @@ class StaticDisco(object):
|
||||
containing the disco info to cache, or
|
||||
the disco#info substanza itself.
|
||||
"""
|
||||
with self.lock:
|
||||
if isinstance(data, Iq):
|
||||
data = data['disco_info']
|
||||
if isinstance(data, Iq):
|
||||
data = data['disco_info']
|
||||
|
||||
self.add_node(jid, node, ifrom)
|
||||
self.get_node(jid, node, ifrom)['info'] = data
|
||||
self.add_node(jid, node, ifrom)
|
||||
self.get_node(jid, node, ifrom)['info'] = data
|
||||
|
||||
def get_cached_info(self, jid, node, ifrom, data):
|
||||
"""
|
||||
@@ -423,8 +401,7 @@ class StaticDisco(object):
|
||||
|
||||
The data parameter is not used.
|
||||
"""
|
||||
with self.lock:
|
||||
if not self.node_exists(jid, node, ifrom):
|
||||
return None
|
||||
else:
|
||||
return self.get_node(jid, node, ifrom)['info']
|
||||
if not self.node_exists(jid, node, ifrom):
|
||||
return None
|
||||
else:
|
||||
return self.get_node(jid, node, ifrom)['info']
|
||||
|
||||
@@ -14,7 +14,3 @@ from slixmpp.plugins.xep_0033.addresses import XEP_0033
|
||||
|
||||
|
||||
register_plugin(XEP_0033)
|
||||
|
||||
# Retain some backwards compatibility
|
||||
xep_0033 = XEP_0033
|
||||
Addresses.addAddress = Addresses.add_address
|
||||
|
||||
@@ -117,15 +117,12 @@ for atype in ('all', 'bcc', 'cc', 'noreply', 'replyroom', 'replyto', 'to'):
|
||||
setattr(Addresses, "set_%s" % atype, set_multi)
|
||||
setattr(Addresses, "del_%s" % atype, del_multi)
|
||||
|
||||
# To retain backwards compatibility:
|
||||
setattr(Addresses, "get%s" % atype.title(), get_multi)
|
||||
setattr(Addresses, "set%s" % atype.title(), set_multi)
|
||||
setattr(Addresses, "del%s" % atype.title(), del_multi)
|
||||
if atype == 'all':
|
||||
Addresses.interfaces.add('addresses')
|
||||
setattr(Addresses, "getAddresses", get_multi)
|
||||
setattr(Addresses, "setAddresses", set_multi)
|
||||
setattr(Addresses, "delAddresses", del_multi)
|
||||
setattr(Addresses, "get_addresses", get_multi)
|
||||
setattr(Addresses, "set_addresses", set_multi)
|
||||
setattr(Addresses, "del_addresses", del_multi)
|
||||
|
||||
|
||||
|
||||
register_stanza_plugin(Addresses, Address, iterable=True)
|
||||
|
||||
@@ -29,82 +29,82 @@ class MUCPresence(ElementBase):
|
||||
affiliations = set(('', ))
|
||||
roles = set(('', ))
|
||||
|
||||
def getXMLItem(self):
|
||||
def get_xml_item(self):
|
||||
item = self.xml.find('{http://jabber.org/protocol/muc#user}item')
|
||||
if item is None:
|
||||
item = ET.Element('{http://jabber.org/protocol/muc#user}item')
|
||||
self.xml.append(item)
|
||||
return item
|
||||
|
||||
def getAffiliation(self):
|
||||
def get_affiliation(self):
|
||||
#TODO if no affilation, set it to the default and return default
|
||||
item = self.getXMLItem()
|
||||
item = self.get_xml_item()
|
||||
return item.get('affiliation', '')
|
||||
|
||||
def setAffiliation(self, value):
|
||||
item = self.getXMLItem()
|
||||
def set_affiliation(self, value):
|
||||
item = self.get_xml_item()
|
||||
#TODO check for valid affiliation
|
||||
item.attrib['affiliation'] = value
|
||||
return self
|
||||
|
||||
def delAffiliation(self):
|
||||
item = self.getXMLItem()
|
||||
def del_affiliation(self):
|
||||
item = self.get_xml_item()
|
||||
#TODO set default affiliation
|
||||
if 'affiliation' in item.attrib: del item.attrib['affiliation']
|
||||
return self
|
||||
|
||||
def getJid(self):
|
||||
item = self.getXMLItem()
|
||||
def get_jid(self):
|
||||
item = self.get_xml_item()
|
||||
return JID(item.get('jid', ''))
|
||||
|
||||
def setJid(self, value):
|
||||
item = self.getXMLItem()
|
||||
def set_jid(self, value):
|
||||
item = self.get_xml_item()
|
||||
if not isinstance(value, str):
|
||||
value = str(value)
|
||||
item.attrib['jid'] = value
|
||||
return self
|
||||
|
||||
def delJid(self):
|
||||
item = self.getXMLItem()
|
||||
def del_jid(self):
|
||||
item = self.get_xml_item()
|
||||
if 'jid' in item.attrib: del item.attrib['jid']
|
||||
return self
|
||||
|
||||
def getRole(self):
|
||||
item = self.getXMLItem()
|
||||
def get_role(self):
|
||||
item = self.get_xml_item()
|
||||
#TODO get default role, set default role if none
|
||||
return item.get('role', '')
|
||||
|
||||
def setRole(self, value):
|
||||
item = self.getXMLItem()
|
||||
def set_role(self, value):
|
||||
item = self.get_xml_item()
|
||||
#TODO check for valid role
|
||||
item.attrib['role'] = value
|
||||
return self
|
||||
|
||||
def delRole(self):
|
||||
item = self.getXMLItem()
|
||||
def del_role(self):
|
||||
item = self.get_xml_item()
|
||||
#TODO set default role
|
||||
if 'role' in item.attrib: del item.attrib['role']
|
||||
return self
|
||||
|
||||
def getNick(self):
|
||||
def get_nick(self):
|
||||
return self.parent()['from'].resource
|
||||
|
||||
def getRoom(self):
|
||||
def get_room(self):
|
||||
return self.parent()['from'].bare
|
||||
|
||||
def setNick(self, value):
|
||||
def set_nick(self, value):
|
||||
log.warning("Cannot set nick through mucpresence plugin.")
|
||||
return self
|
||||
|
||||
def setRoom(self, value):
|
||||
def set_room(self, value):
|
||||
log.warning("Cannot set room through mucpresence plugin.")
|
||||
return self
|
||||
|
||||
def delNick(self):
|
||||
def del_nick(self):
|
||||
log.warning("Cannot delete nick through mucpresence plugin.")
|
||||
return self
|
||||
|
||||
def delRoom(self):
|
||||
def del_room(self):
|
||||
log.warning("Cannot delete room through mucpresence plugin.")
|
||||
return self
|
||||
|
||||
@@ -121,7 +121,7 @@ class XEP_0045(BasePlugin):
|
||||
|
||||
def plugin_init(self):
|
||||
self.rooms = {}
|
||||
self.ourNicks = {}
|
||||
self.our_nicks = {}
|
||||
self.xep = '0045'
|
||||
# load MUC support in presence stanzas
|
||||
register_stanza_plugin(Presence, MUCPresence)
|
||||
@@ -160,6 +160,7 @@ class XEP_0045(BasePlugin):
|
||||
got_online = False
|
||||
if pr['muc']['room'] not in self.rooms.keys():
|
||||
return
|
||||
self.xmpp.roster[pr['from']].ignore_updates = True
|
||||
entry = pr['muc'].get_stanza_values()
|
||||
entry['show'] = pr['show']
|
||||
entry['status'] = pr['status']
|
||||
@@ -200,28 +201,28 @@ class XEP_0045(BasePlugin):
|
||||
"""
|
||||
self.xmpp.event('groupchat_subject', msg)
|
||||
|
||||
def jidInRoom(self, room, jid):
|
||||
def jid_in_room(self, room, jid):
|
||||
for nick in self.rooms[room]:
|
||||
entry = self.rooms[room][nick]
|
||||
if entry is not None and entry['jid'].full == jid:
|
||||
return True
|
||||
return False
|
||||
|
||||
def getNick(self, room, jid):
|
||||
def get_nick(self, room, jid):
|
||||
for nick in self.rooms[room]:
|
||||
entry = self.rooms[room][nick]
|
||||
if entry is not None and entry['jid'].full == jid:
|
||||
return nick
|
||||
|
||||
def configureRoom(self, room, form=None, ifrom=None):
|
||||
def configure_room(self, room, form=None, ifrom=None):
|
||||
if form is None:
|
||||
form = self.getRoomConfig(room, ifrom=ifrom)
|
||||
form = self.get_room_config(room, ifrom=ifrom)
|
||||
iq = self.xmpp.make_iq_set()
|
||||
iq['to'] = room
|
||||
if ifrom is not None:
|
||||
iq['from'] = ifrom
|
||||
query = ET.Element('{http://jabber.org/protocol/muc#owner}query')
|
||||
form = form.getXML('submit')
|
||||
form['type'] = 'submit'
|
||||
query.append(form)
|
||||
iq.append(query)
|
||||
# For now, swallow errors to preserve existing API
|
||||
@@ -233,7 +234,7 @@ class XEP_0045(BasePlugin):
|
||||
return False
|
||||
return True
|
||||
|
||||
def joinMUC(self, room, nick, maxhistory="0", password='', wait=False, pstatus=None, pshow=None, pfrom=None):
|
||||
def join_muc(self, room, nick, maxhistory="0", password='', wait=False, pstatus=None, pshow=None, pfrom=None):
|
||||
""" Join the specified room, requesting 'maxhistory' lines of history.
|
||||
"""
|
||||
stanza = self.xmpp.make_presence(pto="%s/%s" % (room, nick), pstatus=pstatus, pshow=pshow, pfrom=pfrom)
|
||||
@@ -257,7 +258,7 @@ class XEP_0045(BasePlugin):
|
||||
expect = ET.Element("{%s}presence" % self.xmpp.default_ns, {'from':"%s/%s" % (room, nick)})
|
||||
self.xmpp.send(stanza, expect)
|
||||
self.rooms[room] = {}
|
||||
self.ourNicks[room] = nick
|
||||
self.our_nicks[room] = nick
|
||||
|
||||
def destroy(self, room, reason='', altroom = '', ifrom=None):
|
||||
iq = self.xmpp.make_iq_set()
|
||||
@@ -282,7 +283,7 @@ class XEP_0045(BasePlugin):
|
||||
return False
|
||||
return True
|
||||
|
||||
def setAffiliation(self, room, jid=None, nick=None, affiliation='member', ifrom=None):
|
||||
def set_affiliation(self, room, jid=None, nick=None, affiliation='member', ifrom=None):
|
||||
""" Change room affiliation."""
|
||||
if affiliation not in ('outcast', 'member', 'admin', 'owner', 'none'):
|
||||
raise TypeError
|
||||
@@ -304,7 +305,7 @@ class XEP_0045(BasePlugin):
|
||||
return False
|
||||
return True
|
||||
|
||||
def setRole(self, room, nick, role):
|
||||
def set_role(self, room, nick, role):
|
||||
""" Change role property of a nick in a room.
|
||||
Typically, roles are temporary (they last only as long as you are in the
|
||||
room), whereas affiliations are permanent (they last across groupchat
|
||||
@@ -336,7 +337,7 @@ class XEP_0045(BasePlugin):
|
||||
msg.append(x)
|
||||
self.xmpp.send(msg)
|
||||
|
||||
def leaveMUC(self, room, nick, msg='', pfrom=None):
|
||||
def leave_muc(self, room, nick, msg='', pfrom=None):
|
||||
""" Leave the specified room.
|
||||
"""
|
||||
if msg:
|
||||
@@ -345,7 +346,7 @@ class XEP_0045(BasePlugin):
|
||||
self.xmpp.send_presence(pshow='unavailable', pto="%s/%s" % (room, nick), pfrom=pfrom)
|
||||
del self.rooms[room]
|
||||
|
||||
def getRoomConfig(self, room, ifrom=''):
|
||||
def get_room_config(self, room, ifrom=''):
|
||||
iq = self.xmpp.make_iq_get('http://jabber.org/protocol/muc#owner')
|
||||
iq['to'] = room
|
||||
iq['from'] = ifrom
|
||||
@@ -359,9 +360,9 @@ class XEP_0045(BasePlugin):
|
||||
form = result.xml.find('{http://jabber.org/protocol/muc#owner}query/{jabber:x:data}x')
|
||||
if form is None:
|
||||
raise ValueError
|
||||
return self.xmpp.plugin['xep_0004'].buildForm(form)
|
||||
return self.xmpp.plugin['xep_0004'].build_form(form)
|
||||
|
||||
def cancelConfig(self, room, ifrom=None):
|
||||
def cancel_config(self, room, ifrom=None):
|
||||
query = ET.Element('{http://jabber.org/protocol/muc#owner}query')
|
||||
x = ET.Element('{jabber:x:data}x', type='cancel')
|
||||
query.append(x)
|
||||
@@ -370,40 +371,40 @@ class XEP_0045(BasePlugin):
|
||||
iq['from'] = ifrom
|
||||
iq.send()
|
||||
|
||||
def setRoomConfig(self, room, config, ifrom=''):
|
||||
def set_room_config(self, room, config, ifrom=''):
|
||||
query = ET.Element('{http://jabber.org/protocol/muc#owner}query')
|
||||
x = config.getXML('submit')
|
||||
query.append(x)
|
||||
config['type'] = 'submit'
|
||||
query.append(config)
|
||||
iq = self.xmpp.make_iq_set(query)
|
||||
iq['to'] = room
|
||||
iq['from'] = ifrom
|
||||
iq.send()
|
||||
|
||||
def getJoinedRooms(self):
|
||||
def get_joined_rooms(self):
|
||||
return self.rooms.keys()
|
||||
|
||||
def getOurJidInRoom(self, roomJid):
|
||||
def get_our_jid_in_room(self, room_jid):
|
||||
""" Return the jid we're using in a room.
|
||||
"""
|
||||
return "%s/%s" % (roomJid, self.ourNicks[roomJid])
|
||||
return "%s/%s" % (room_jid, self.our_nicks[room_jid])
|
||||
|
||||
def getJidProperty(self, room, nick, jidProperty):
|
||||
def get_jid_property(self, room, nick, jid_property):
|
||||
""" Get the property of a nick in a room, such as its 'jid' or 'affiliation'
|
||||
If not found, return None.
|
||||
"""
|
||||
if room in self.rooms and nick in self.rooms[room] and jidProperty in self.rooms[room][nick]:
|
||||
return self.rooms[room][nick][jidProperty]
|
||||
if room in self.rooms and nick in self.rooms[room] and jid_property in self.rooms[room][nick]:
|
||||
return self.rooms[room][nick][jid_property]
|
||||
else:
|
||||
return None
|
||||
|
||||
def getRoster(self, room):
|
||||
def get_roster(self, room):
|
||||
""" Get the list of nicks in a room.
|
||||
"""
|
||||
if room not in self.rooms.keys():
|
||||
return None
|
||||
return self.rooms[room].keys()
|
||||
|
||||
def getUsersByAffiliation(cls, room, affiliation='member', ifrom=None):
|
||||
def get_users_by_affiliation(cls, room, affiliation='member', ifrom=None):
|
||||
if affiliation not in ('outcast', 'member', 'admin', 'owner', 'none'):
|
||||
raise TypeError
|
||||
query = ET.Element('{http://jabber.org/protocol/muc#admin}query')
|
||||
@@ -414,5 +415,4 @@ class XEP_0045(BasePlugin):
|
||||
return iq.send()
|
||||
|
||||
|
||||
xep_0045 = XEP_0045
|
||||
register_plugin(XEP_0045)
|
||||
|
||||
@@ -15,7 +15,3 @@ from slixmpp.plugins.xep_0047.ibb import XEP_0047
|
||||
|
||||
|
||||
register_plugin(XEP_0047)
|
||||
|
||||
|
||||
# Retain some backwards compatibility
|
||||
xep_0047 = XEP_0047
|
||||
|
||||
@@ -59,7 +59,7 @@ class XEP_0048(BasePlugin):
|
||||
for conf in bookmarks['conferences']:
|
||||
if conf['autojoin']:
|
||||
log.debug('Auto joining %s as %s', conf['jid'], conf['nick'])
|
||||
self.xmpp['xep_0045'].joinMUC(conf['jid'], conf['nick'],
|
||||
self.xmpp['xep_0045'].join_muc(conf['jid'], conf['nick'],
|
||||
password=conf['password'])
|
||||
|
||||
def set_bookmarks(self, bookmarks, method=None, **iqargs):
|
||||
|
||||
@@ -13,7 +13,3 @@ from slixmpp.plugins.xep_0050.adhoc import XEP_0050
|
||||
|
||||
|
||||
register_plugin(XEP_0050)
|
||||
|
||||
|
||||
# Retain some backwards compatibility
|
||||
xep_0050 = XEP_0050
|
||||
|
||||
@@ -100,7 +100,7 @@ class Command(ElementBase):
|
||||
self.del_actions()
|
||||
if values:
|
||||
self._set_sub_text('{%s}actions' % self.namespace, '', True)
|
||||
actions = self.find('{%s}actions' % self.namespace)
|
||||
actions = self.xml.find('{%s}actions' % self.namespace)
|
||||
for val in values:
|
||||
if val in self.next_actions:
|
||||
action = ET.Element('{%s}%s' % (self.namespace, val))
|
||||
@@ -111,7 +111,7 @@ class Command(ElementBase):
|
||||
Return the set of allowable next actions.
|
||||
"""
|
||||
actions = set()
|
||||
actions_xml = self.find('{%s}actions' % self.namespace)
|
||||
actions_xml = self.xml.find('{%s}actions' % self.namespace)
|
||||
if actions_xml is not None:
|
||||
for action in self.next_actions:
|
||||
action_xml = actions_xml.find('{%s}%s' % (self.namespace,
|
||||
@@ -136,7 +136,7 @@ class Command(ElementBase):
|
||||
('error', 'The command ran, but had errors')]
|
||||
"""
|
||||
notes = []
|
||||
notes_xml = self.findall('{%s}note' % self.namespace)
|
||||
notes_xml = self.xml.findall('{%s}note' % self.namespace)
|
||||
for note in notes_xml:
|
||||
notes.append((note.attrib.get('type', 'info'),
|
||||
note.text))
|
||||
@@ -167,7 +167,7 @@ class Command(ElementBase):
|
||||
"""
|
||||
Remove all notes associated with the command result.
|
||||
"""
|
||||
notes_xml = self.findall('{%s}note' % self.namespace)
|
||||
notes_xml = self.xml.findall('{%s}note' % self.namespace)
|
||||
for note in notes_xml:
|
||||
self.xml.remove(note)
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ class Telephone(ElementBase):
|
||||
'ISDN', 'PCS', 'PREF'])
|
||||
|
||||
def setup(self, xml=None):
|
||||
super(Telephone, self).setup(xml=xml)
|
||||
super().setup(xml=xml)
|
||||
## this blanks out numbers received from server
|
||||
##self._set_sub_text('NUMBER', '', keep=True)
|
||||
|
||||
|
||||
@@ -13,6 +13,3 @@ from slixmpp.plugins.xep_0059.rsm import ResultIterator, XEP_0059
|
||||
|
||||
|
||||
register_plugin(XEP_0059)
|
||||
|
||||
# Retain some backwards compatibility
|
||||
xep_0059 = XEP_0059
|
||||
|
||||
@@ -70,7 +70,7 @@ class Set(ElementBase):
|
||||
'count', 'index', 'last', 'max'))
|
||||
|
||||
def set_first_index(self, val):
|
||||
fi = self.find("{%s}first" % (self.namespace))
|
||||
fi = self.xml.find("{%s}first" % (self.namespace))
|
||||
if fi is not None:
|
||||
if val:
|
||||
fi.attrib['index'] = val
|
||||
@@ -82,7 +82,7 @@ class Set(ElementBase):
|
||||
self.xml.append(fi)
|
||||
|
||||
def get_first_index(self):
|
||||
fi = self.find("{%s}first" % (self.namespace))
|
||||
fi = self.xml.find("{%s}first" % (self.namespace))
|
||||
if fi is not None:
|
||||
return fi.attrib.get('index', '')
|
||||
|
||||
|
||||
@@ -13,7 +13,3 @@ from slixmpp.plugins.xep_0060 import stanza
|
||||
|
||||
|
||||
register_plugin(XEP_0060)
|
||||
|
||||
|
||||
# Retain some backwards compatibility
|
||||
xep_0060 = XEP_0060
|
||||
|
||||
@@ -206,7 +206,10 @@ class Options(ElementBase):
|
||||
return form
|
||||
|
||||
def set_options(self, value):
|
||||
self.xml.append(value.getXML())
|
||||
if isinstance(value, ElementBase):
|
||||
self.xml.append(value.xml)
|
||||
else:
|
||||
self.xml.append(value)
|
||||
return self
|
||||
|
||||
def del_options(self):
|
||||
@@ -238,7 +241,10 @@ class PublishOptions(ElementBase):
|
||||
if value is None:
|
||||
self.del_publish_options()
|
||||
else:
|
||||
self.xml.append(value.getXML())
|
||||
if isinstance(value, ElementBase):
|
||||
self.xml.append(value.xml)
|
||||
else:
|
||||
self.xml.append(value)
|
||||
return self
|
||||
|
||||
def del_publish_options(self):
|
||||
|
||||
@@ -14,7 +14,3 @@ from slixmpp.plugins.xep_0066.oob import XEP_0066
|
||||
|
||||
|
||||
register_plugin(XEP_0066)
|
||||
|
||||
|
||||
# Retain some backwards compatibility
|
||||
xep_0066 = XEP_0066
|
||||
|
||||
15
slixmpp/plugins/xep_0070/__init__.py
Normal file
15
slixmpp/plugins/xep_0070/__init__.py
Normal file
@@ -0,0 +1,15 @@
|
||||
"""
|
||||
Slixmpp: The Slick XMPP Library
|
||||
Copyright (C) 2015 Emmanuel Gil Peyrot
|
||||
This file is part of Slixmpp.
|
||||
|
||||
See the file LICENSE for copying permission.
|
||||
"""
|
||||
|
||||
from slixmpp.plugins.base import register_plugin
|
||||
|
||||
from slixmpp.plugins.xep_0070.stanza import Confirm
|
||||
from slixmpp.plugins.xep_0070.confirm import XEP_0070
|
||||
|
||||
|
||||
register_plugin(XEP_0070)
|
||||
86
slixmpp/plugins/xep_0070/confirm.py
Normal file
86
slixmpp/plugins/xep_0070/confirm.py
Normal file
@@ -0,0 +1,86 @@
|
||||
"""
|
||||
Slixmpp: The Slick XMPP Library
|
||||
Copyright (C) 2015 Emmanuel Gil Peyrot
|
||||
This file is part of Slixmpp.
|
||||
|
||||
See the file LICENSE for copying permission.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
from uuid import uuid4
|
||||
|
||||
from slixmpp.plugins import BasePlugin, register_plugin
|
||||
from slixmpp import future_wrapper, Iq, Message
|
||||
from slixmpp.exceptions import XMPPError, IqError, IqTimeout
|
||||
from slixmpp.jid import JID
|
||||
from slixmpp.xmlstream import JID, register_stanza_plugin
|
||||
from slixmpp.xmlstream.handler import Callback
|
||||
from slixmpp.xmlstream.matcher import StanzaPath
|
||||
from slixmpp.plugins.xep_0070 import stanza, Confirm
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class XEP_0070(BasePlugin):
|
||||
|
||||
"""
|
||||
XEP-0070 Verifying HTTP Requests via XMPP
|
||||
"""
|
||||
|
||||
name = 'xep_0070'
|
||||
description = 'XEP-0070: Verifying HTTP Requests via XMPP'
|
||||
dependencies = {'xep_0030'}
|
||||
stanza = stanza
|
||||
|
||||
def plugin_init(self):
|
||||
register_stanza_plugin(Iq, Confirm)
|
||||
register_stanza_plugin(Message, Confirm)
|
||||
|
||||
self.xmpp.register_handler(
|
||||
Callback('Confirm',
|
||||
StanzaPath('iq@type=get/confirm'),
|
||||
self._handle_iq_confirm))
|
||||
|
||||
self.xmpp.register_handler(
|
||||
Callback('Confirm',
|
||||
StanzaPath('message/confirm'),
|
||||
self._handle_message_confirm))
|
||||
|
||||
def plugin_end(self):
|
||||
self.xmpp.remove_handler('Confirm')
|
||||
self.xmpp['xep_0030'].del_feature(feature='http://jabber.org/protocol/http-auth')
|
||||
|
||||
def session_bind(self, jid):
|
||||
self.xmpp['xep_0030'].add_feature('http://jabber.org/protocol/http-auth')
|
||||
|
||||
@future_wrapper
|
||||
def ask_confirm(self, jid, id, url, method, *, ifrom=None, message=None):
|
||||
jid = JID(jid)
|
||||
if jid.resource:
|
||||
stanza = self.xmpp.Iq()
|
||||
stanza['type'] = 'get'
|
||||
else:
|
||||
stanza = self.xmpp.Message()
|
||||
stanza['thread'] = uuid4().hex
|
||||
stanza['from'] = ifrom
|
||||
stanza['to'] = jid
|
||||
stanza['confirm']['id'] = id
|
||||
stanza['confirm']['url'] = url
|
||||
stanza['confirm']['method'] = method
|
||||
if not jid.resource:
|
||||
if message is not None:
|
||||
stanza['body'] = message.format(id=id, url=url, method=method)
|
||||
stanza.send()
|
||||
return stanza
|
||||
else:
|
||||
return stanza.send()
|
||||
|
||||
def _handle_iq_confirm(self, iq):
|
||||
self.xmpp.event('http_confirm_iq', iq)
|
||||
self.xmpp.event('http_confirm', iq)
|
||||
|
||||
def _handle_message_confirm(self, message):
|
||||
self.xmpp.event('http_confirm_message', message)
|
||||
self.xmpp.event('http_confirm', message)
|
||||
17
slixmpp/plugins/xep_0070/stanza.py
Normal file
17
slixmpp/plugins/xep_0070/stanza.py
Normal file
@@ -0,0 +1,17 @@
|
||||
"""
|
||||
Slixmpp: The Slick XMPP Library
|
||||
Copyright (C) 2015 Emmanuel Gil Peyrot
|
||||
This file is part of Slixmpp.
|
||||
|
||||
See the file LICENSE for copying permission.
|
||||
"""
|
||||
|
||||
from slixmpp.xmlstream import ElementBase
|
||||
|
||||
|
||||
class Confirm(ElementBase):
|
||||
|
||||
name = 'confirm'
|
||||
namespace = 'http://jabber.org/protocol/http-auth'
|
||||
plugin_attrib = 'confirm'
|
||||
interfaces = {'id', 'url', 'method'}
|
||||
@@ -13,7 +13,3 @@ from slixmpp.plugins.xep_0077.register import XEP_0077
|
||||
|
||||
|
||||
register_plugin(XEP_0077)
|
||||
|
||||
|
||||
# Retain some backwards compatibility
|
||||
xep_0077 = XEP_0077
|
||||
|
||||
@@ -14,7 +14,3 @@ from slixmpp.plugins.xep_0078.legacyauth import XEP_0078
|
||||
|
||||
|
||||
register_plugin(XEP_0078)
|
||||
|
||||
|
||||
# Retain some backwards compatibility
|
||||
xep_0078 = XEP_0078
|
||||
|
||||
@@ -13,7 +13,3 @@ from slixmpp.plugins.xep_0085.chat_states import XEP_0085
|
||||
|
||||
|
||||
register_plugin(XEP_0085)
|
||||
|
||||
|
||||
# Retain some backwards compatibility
|
||||
xep_0085 = XEP_0085
|
||||
|
||||
@@ -50,7 +50,7 @@ class ChatState(ElementBase):
|
||||
def get_chat_state(self):
|
||||
parent = self.parent()
|
||||
for state in self.states:
|
||||
state_xml = parent.find('{%s}%s' % (self.namespace, state))
|
||||
state_xml = parent.xml.find('{%s}%s' % (self.namespace, state))
|
||||
if state_xml is not None:
|
||||
self.xml = state_xml
|
||||
return state
|
||||
@@ -68,7 +68,7 @@ class ChatState(ElementBase):
|
||||
def del_chat_state(self):
|
||||
parent = self.parent()
|
||||
for state in self.states:
|
||||
state_xml = parent.find('{%s}%s' % (self.namespace, state))
|
||||
state_xml = parent.xml.find('{%s}%s' % (self.namespace, state))
|
||||
if state_xml is not None:
|
||||
self.xml = ET.Element('')
|
||||
parent.xml.remove(state_xml)
|
||||
|
||||
@@ -13,7 +13,3 @@ from slixmpp.plugins.xep_0086.legacy_error import XEP_0086
|
||||
|
||||
|
||||
register_plugin(XEP_0086)
|
||||
|
||||
|
||||
# Retain some backwards compatibility
|
||||
xep_0086 = XEP_0086
|
||||
|
||||
@@ -14,7 +14,3 @@ from slixmpp.plugins.xep_0092.version import XEP_0092
|
||||
|
||||
|
||||
register_plugin(XEP_0092)
|
||||
|
||||
|
||||
# Retain some backwards compatibility
|
||||
xep_0092 = XEP_0092
|
||||
|
||||
@@ -14,7 +14,3 @@ from slixmpp.plugins.xep_0115.caps import XEP_0115
|
||||
|
||||
|
||||
register_plugin(XEP_0115)
|
||||
|
||||
|
||||
# Retain some backwards compatibility
|
||||
xep_0115 = XEP_0115
|
||||
|
||||
@@ -124,23 +124,19 @@ class StaticCaps(object):
|
||||
return None
|
||||
|
||||
def cache_caps(self, jid, node, ifrom, data):
|
||||
with self.static.lock:
|
||||
verstring = data.get('verstring', None)
|
||||
info = data.get('info', None)
|
||||
if not verstring or not info:
|
||||
return
|
||||
self.ver_cache[verstring] = info
|
||||
verstring = data.get('verstring', None)
|
||||
info = data.get('info', None)
|
||||
if not verstring or not info:
|
||||
return
|
||||
self.ver_cache[verstring] = info
|
||||
|
||||
def assign_verstring(self, jid, node, ifrom, data):
|
||||
with self.static.lock:
|
||||
if isinstance(jid, JID):
|
||||
jid = jid.full
|
||||
self.jid_vers[jid] = data.get('verstring', None)
|
||||
if isinstance(jid, JID):
|
||||
jid = jid.full
|
||||
self.jid_vers[jid] = data.get('verstring', None)
|
||||
|
||||
def get_verstring(self, jid, node, ifrom, data):
|
||||
with self.static.lock:
|
||||
return self.jid_vers.get(jid, None)
|
||||
return self.jid_vers.get(jid, None)
|
||||
|
||||
def get_caps(self, jid, node, ifrom, data):
|
||||
with self.static.lock:
|
||||
return self.ver_cache.get(data.get('verstring', None), None)
|
||||
return self.ver_cache.get(data.get('verstring', None), None)
|
||||
|
||||
@@ -5,7 +5,3 @@ from slixmpp.plugins.xep_0122.data_validation import XEP_0122
|
||||
|
||||
|
||||
register_plugin(XEP_0122)
|
||||
|
||||
|
||||
# Retain some backwards compatibility
|
||||
xep_0122 = XEP_0122
|
||||
|
||||
@@ -13,7 +13,3 @@ from slixmpp.plugins.xep_0128.extended_disco import XEP_0128
|
||||
|
||||
|
||||
register_plugin(XEP_0128)
|
||||
|
||||
|
||||
# Retain some backwards compatibility
|
||||
xep_0128 = XEP_0128
|
||||
|
||||
@@ -38,9 +38,8 @@ class StaticExtendedDisco(object):
|
||||
The data parameter may provide:
|
||||
data -- Either a single data form, or a list of data forms.
|
||||
"""
|
||||
with self.static.lock:
|
||||
self.del_extended_info(jid, node, ifrom, data)
|
||||
self.add_extended_info(jid, node, ifrom, data)
|
||||
self.del_extended_info(jid, node, ifrom, data)
|
||||
self.add_extended_info(jid, node, ifrom, data)
|
||||
|
||||
def add_extended_info(self, jid, node, ifrom, data):
|
||||
"""
|
||||
@@ -49,16 +48,15 @@ class StaticExtendedDisco(object):
|
||||
The data parameter may provide:
|
||||
data -- Either a single data form, or a list of data forms.
|
||||
"""
|
||||
with self.static.lock:
|
||||
self.static.add_node(jid, node)
|
||||
self.static.add_node(jid, node)
|
||||
|
||||
forms = data.get('data', [])
|
||||
if not isinstance(forms, list):
|
||||
forms = [forms]
|
||||
forms = data.get('data', [])
|
||||
if not isinstance(forms, list):
|
||||
forms = [forms]
|
||||
|
||||
info = self.static.get_node(jid, node)['info']
|
||||
for form in forms:
|
||||
info.append(form)
|
||||
info = self.static.get_node(jid, node)['info']
|
||||
for form in forms:
|
||||
info.append(form)
|
||||
|
||||
def del_extended_info(self, jid, node, ifrom, data):
|
||||
"""
|
||||
@@ -66,8 +64,7 @@ class StaticExtendedDisco(object):
|
||||
|
||||
The data parameter is not used.
|
||||
"""
|
||||
with self.static.lock:
|
||||
if self.static.node_exists(jid, node):
|
||||
info = self.static.get_node(jid, node)['info']
|
||||
for form in info['substanza']:
|
||||
info.xml.remove(form.xml)
|
||||
if self.static.node_exists(jid, node):
|
||||
info = self.static.get_node(jid, node)['info']
|
||||
for form in info['substanza']:
|
||||
info.xml.remove(form.xml)
|
||||
|
||||
@@ -13,7 +13,3 @@ from slixmpp.plugins.xep_0184.receipt import XEP_0184
|
||||
|
||||
|
||||
register_plugin(XEP_0184)
|
||||
|
||||
|
||||
# Retain some backwards compatibility
|
||||
xep_0184 = XEP_0184
|
||||
|
||||
@@ -32,7 +32,7 @@ class Request(ElementBase):
|
||||
|
||||
def get_request_receipt(self):
|
||||
parent = self.parent()
|
||||
if parent.find("{%s}request" % self.namespace) is not None:
|
||||
if parent.xml.find("{%s}request" % self.namespace) is not None:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
@@ -63,7 +63,7 @@ class Received(ElementBase):
|
||||
|
||||
def get_receipt(self):
|
||||
parent = self.parent()
|
||||
xml = parent.find("{%s}received" % self.namespace)
|
||||
xml = parent.xml.find("{%s}received" % self.namespace)
|
||||
if xml is not None:
|
||||
return xml.attrib.get('id', '')
|
||||
return ''
|
||||
|
||||
@@ -33,7 +33,7 @@ class XEP_0186(BasePlugin):
|
||||
iq['type'] = 'set'
|
||||
iq['from'] = ifrom
|
||||
iq.enable('invisible')
|
||||
iq.send(callback=callback, timeout=timeout)
|
||||
return iq.send(callback=callback, timeout=timeout)
|
||||
|
||||
def set_visible(self, ifrom=None, callback=None,
|
||||
timeout=None):
|
||||
@@ -41,4 +41,4 @@ class XEP_0186(BasePlugin):
|
||||
iq['type'] = 'set'
|
||||
iq['from'] = ifrom
|
||||
iq.enable('visible')
|
||||
iq.send(callback=callback, timeout=timeout)
|
||||
return iq.send(callback=callback, timeout=timeout)
|
||||
|
||||
@@ -99,7 +99,7 @@ class StreamManagement(ElementBase):
|
||||
interfaces = set(['required', 'optional'])
|
||||
|
||||
def get_required(self):
|
||||
return self.find('{%s}required' % self.namespace) is not None
|
||||
return self.xml.find('{%s}required' % self.namespace) is not None
|
||||
|
||||
def set_required(self, val):
|
||||
self.del_required()
|
||||
@@ -110,7 +110,7 @@ class StreamManagement(ElementBase):
|
||||
self._del_sub('required')
|
||||
|
||||
def get_optional(self):
|
||||
return self.find('{%s}optional' % self.namespace) is not None
|
||||
return self.xml.find('{%s}optional' % self.namespace) is not None
|
||||
|
||||
def set_optional(self, val):
|
||||
self.del_optional()
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
See the file LICENSE for copying permission.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
import threading
|
||||
import collections
|
||||
|
||||
from slixmpp.stanza import Message, Presence, Iq, StreamFeatures
|
||||
@@ -70,15 +70,10 @@ class XEP_0198(BasePlugin):
|
||||
return
|
||||
|
||||
self.window_counter = self.window
|
||||
self.window_counter_lock = threading.Lock()
|
||||
|
||||
self.enabled = threading.Event()
|
||||
self.enabled = False
|
||||
self.unacked_queue = collections.deque()
|
||||
|
||||
self.seq_lock = threading.Lock()
|
||||
self.handled_lock = threading.Lock()
|
||||
self.ack_lock = threading.Lock()
|
||||
|
||||
register_stanza_plugin(StreamFeatures, stanza.StreamManagement)
|
||||
self.xmpp.register_stanza(stanza.Enable)
|
||||
self.xmpp.register_stanza(stanza.Enabled)
|
||||
@@ -161,7 +156,7 @@ class XEP_0198(BasePlugin):
|
||||
|
||||
def session_end(self, event):
|
||||
"""Reset stream management state."""
|
||||
self.enabled.clear()
|
||||
self.enabled = False
|
||||
self.unacked_queue.clear()
|
||||
self.sm_id = None
|
||||
self.handled = 0
|
||||
@@ -171,15 +166,15 @@ class XEP_0198(BasePlugin):
|
||||
def send_ack(self):
|
||||
"""Send the current ack count to the server."""
|
||||
ack = stanza.Ack(self.xmpp)
|
||||
with self.handled_lock:
|
||||
ack['h'] = self.handled
|
||||
ack['h'] = self.handled
|
||||
self.xmpp.send_raw(str(ack))
|
||||
|
||||
def request_ack(self, e=None):
|
||||
"""Request an ack from the server."""
|
||||
req = stanza.RequestAck(self.xmpp)
|
||||
self.xmpp.send_queue.put(str(req))
|
||||
self.xmpp.send_raw(str(req))
|
||||
|
||||
@asyncio.coroutine
|
||||
def _handle_sm_feature(self, features):
|
||||
"""
|
||||
Enable or resume stream management.
|
||||
@@ -196,13 +191,21 @@ class XEP_0198(BasePlugin):
|
||||
return False
|
||||
if not self.sm_id:
|
||||
if 'bind' in self.xmpp.features:
|
||||
self.enabled.set()
|
||||
enable = stanza.Enable(self.xmpp)
|
||||
enable['resume'] = self.allow_resume
|
||||
enable.send()
|
||||
self.enabled = True
|
||||
self.handled = 0
|
||||
elif self.sm_id and self.allow_resume:
|
||||
self.enabled.set()
|
||||
self.unacked_queue.clear()
|
||||
|
||||
waiter = Waiter('enabled_or_failed',
|
||||
MatchMany([
|
||||
MatchXPath(stanza.Enabled.tag_name()),
|
||||
MatchXPath(stanza.Failed.tag_name())]))
|
||||
self.xmpp.register_handler(waiter)
|
||||
result = yield from waiter.wait()
|
||||
elif self.sm_id and self.allow_resume and 'bind' not in self.xmpp.features:
|
||||
self.enabled = True
|
||||
resume = stanza.Resume(self.xmpp)
|
||||
resume['h'] = self.handled
|
||||
resume['previd'] = self.sm_id
|
||||
@@ -216,7 +219,7 @@ class XEP_0198(BasePlugin):
|
||||
MatchXPath(stanza.Resumed.tag_name()),
|
||||
MatchXPath(stanza.Failed.tag_name())]))
|
||||
self.xmpp.register_handler(waiter)
|
||||
result = waiter.wait()
|
||||
result = yield from waiter.wait()
|
||||
if result is not None and result.name == 'resumed':
|
||||
return True
|
||||
return False
|
||||
@@ -250,7 +253,7 @@ class XEP_0198(BasePlugin):
|
||||
|
||||
Raises an :term:`sm_failed` event.
|
||||
"""
|
||||
self.enabled.clear()
|
||||
self.enabled = False
|
||||
self.unacked_queue.clear()
|
||||
self.xmpp.event('sm_failed', stanza)
|
||||
|
||||
@@ -262,21 +265,24 @@ class XEP_0198(BasePlugin):
|
||||
if ack['h'] == self.last_ack:
|
||||
return
|
||||
|
||||
with self.ack_lock:
|
||||
num_acked = (ack['h'] - self.last_ack) % MAX_SEQ
|
||||
num_unacked = len(self.unacked_queue)
|
||||
log.debug("Ack: %s, Last Ack: %s, " + \
|
||||
"Unacked: %s, Num Acked: %s, " + \
|
||||
"Remaining: %s",
|
||||
ack['h'],
|
||||
self.last_ack,
|
||||
num_unacked,
|
||||
num_acked,
|
||||
num_unacked - num_acked)
|
||||
for x in range(num_acked):
|
||||
seq, stanza = self.unacked_queue.popleft()
|
||||
self.xmpp.event('stanza_acked', stanza)
|
||||
self.last_ack = ack['h']
|
||||
num_acked = (ack['h'] - self.last_ack) % MAX_SEQ
|
||||
num_unacked = len(self.unacked_queue)
|
||||
log.debug("Ack: %s, Last Ack: %s, " + \
|
||||
"Unacked: %s, Num Acked: %s, " + \
|
||||
"Remaining: %s",
|
||||
ack['h'],
|
||||
self.last_ack,
|
||||
num_unacked,
|
||||
num_acked,
|
||||
num_unacked - num_acked)
|
||||
if num_acked > len(self.unacked_queue) or num_acked < 0:
|
||||
log.error('Inconsistent sequence numbers from the server,'
|
||||
' ignoring and replacing ours with them.')
|
||||
num_acked = len(self.unacked_queue)
|
||||
for x in range(num_acked):
|
||||
seq, stanza = self.unacked_queue.popleft()
|
||||
self.xmpp.event('stanza_acked', stanza)
|
||||
self.last_ack = ack['h']
|
||||
|
||||
def _handle_request_ack(self, req):
|
||||
"""Handle an ack request by sending an ack."""
|
||||
@@ -284,30 +290,27 @@ class XEP_0198(BasePlugin):
|
||||
|
||||
def _handle_incoming(self, stanza):
|
||||
"""Increment the handled counter for each inbound stanza."""
|
||||
if not self.enabled.is_set():
|
||||
if not self.enabled:
|
||||
return stanza
|
||||
|
||||
if isinstance(stanza, (Message, Presence, Iq)):
|
||||
with self.handled_lock:
|
||||
# Sequence numbers are mod 2^32
|
||||
self.handled = (self.handled + 1) % MAX_SEQ
|
||||
# Sequence numbers are mod 2^32
|
||||
self.handled = (self.handled + 1) % MAX_SEQ
|
||||
return stanza
|
||||
|
||||
def _handle_outgoing(self, stanza):
|
||||
"""Store outgoing stanzas in a queue to be acked."""
|
||||
if not self.enabled.is_set():
|
||||
if not self.enabled:
|
||||
return stanza
|
||||
|
||||
if isinstance(stanza, (Message, Presence, Iq)):
|
||||
seq = None
|
||||
with self.seq_lock:
|
||||
# Sequence numbers are mod 2^32
|
||||
self.seq = (self.seq + 1) % MAX_SEQ
|
||||
seq = self.seq
|
||||
# Sequence numbers are mod 2^32
|
||||
self.seq = (self.seq + 1) % MAX_SEQ
|
||||
seq = self.seq
|
||||
self.unacked_queue.append((seq, stanza))
|
||||
with self.window_counter_lock:
|
||||
self.window_counter -= 1
|
||||
if self.window_counter == 0:
|
||||
self.window_counter = self.window
|
||||
self.request_ack()
|
||||
self.window_counter -= 1
|
||||
if self.window_counter == 0:
|
||||
self.window_counter = self.window
|
||||
self.request_ack()
|
||||
return stanza
|
||||
|
||||
@@ -13,8 +13,3 @@ from slixmpp.plugins.xep_0199.ping import XEP_0199
|
||||
|
||||
|
||||
register_plugin(XEP_0199)
|
||||
|
||||
|
||||
# Backwards compatibility for names
|
||||
xep_0199 = XEP_0199
|
||||
xep_0199.sendPing = xep_0199.send_ping
|
||||
|
||||
@@ -95,18 +95,20 @@ class XEP_0199(BasePlugin):
|
||||
self.timeout = timeout
|
||||
|
||||
self.keepalive = True
|
||||
handler = lambda event=None: asyncio.ensure_future(self._keepalive(event))
|
||||
self.xmpp.schedule('Ping keepalive',
|
||||
self.interval,
|
||||
self._keepalive,
|
||||
handler,
|
||||
repeat=True)
|
||||
|
||||
def disable_keepalive(self, event=None):
|
||||
self.xmpp.cancel_schedule('Ping keepalive')
|
||||
|
||||
@asyncio.coroutine
|
||||
def _keepalive(self, event=None):
|
||||
log.debug("Keepalive ping...")
|
||||
try:
|
||||
rtt = self.ping(self.xmpp.boundjid.host, timeout=self.timeout)
|
||||
rtt = yield from self.ping(self.xmpp.boundjid.host, timeout=self.timeout)
|
||||
except IqTimeout:
|
||||
log.debug("Did not recieve ping back in time." + \
|
||||
"Requesting Reconnect.")
|
||||
@@ -172,8 +174,7 @@ class XEP_0199(BasePlugin):
|
||||
|
||||
log.debug('Pinging %s' % jid)
|
||||
try:
|
||||
yield from self.send_ping(jid, ifrom=ifrom, timeout=timeout,
|
||||
coroutine=True)
|
||||
yield from self.send_ping(jid, ifrom=ifrom, timeout=timeout)
|
||||
except IqError as e:
|
||||
if own_host:
|
||||
rtt = time.time() - start
|
||||
|
||||
@@ -14,7 +14,3 @@ from slixmpp.plugins.xep_0202.time import XEP_0202
|
||||
|
||||
|
||||
register_plugin(XEP_0202)
|
||||
|
||||
|
||||
# Retain some backwards compatibility
|
||||
xep_0202 = XEP_0202
|
||||
|
||||
@@ -14,6 +14,3 @@ from slixmpp.plugins.xep_0203.delay import XEP_0203
|
||||
|
||||
|
||||
register_plugin(XEP_0203)
|
||||
|
||||
# Retain some backwards compatibility
|
||||
xep_0203 = XEP_0203
|
||||
|
||||
@@ -14,7 +14,3 @@ from slixmpp.plugins.xep_0224.attention import XEP_0224
|
||||
|
||||
|
||||
register_plugin(XEP_0224)
|
||||
|
||||
|
||||
# Retain some backwards compatibility
|
||||
xep_0224 = XEP_0224
|
||||
|
||||
@@ -13,7 +13,3 @@ from slixmpp.plugins.xep_0249.invite import XEP_0249
|
||||
|
||||
|
||||
register_plugin(XEP_0249)
|
||||
|
||||
|
||||
# Retain some backwards compatibility
|
||||
xep_0249 = XEP_0249
|
||||
|
||||
13
slixmpp/plugins/xep_0256/__init__.py
Normal file
13
slixmpp/plugins/xep_0256/__init__.py
Normal file
@@ -0,0 +1,13 @@
|
||||
"""
|
||||
Slixmpp: The Slick XMPP Library
|
||||
Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
|
||||
This file is part of Slixmpp.
|
||||
|
||||
See the file LICENSE for copying permission.
|
||||
"""
|
||||
|
||||
from slixmpp.plugins.base import register_plugin
|
||||
|
||||
from slixmpp.plugins.xep_0256.last_activity_presence import XEP_0256, LastActivity
|
||||
|
||||
register_plugin(XEP_0256)
|
||||
27
slixmpp/plugins/xep_0256/last_activity_presence.py
Normal file
27
slixmpp/plugins/xep_0256/last_activity_presence.py
Normal file
@@ -0,0 +1,27 @@
|
||||
"""
|
||||
Slixmpp: The Slick XMPP Library
|
||||
Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
|
||||
This file is part of Slixmpp.
|
||||
|
||||
See the file LICENSE for copying permission.
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
from slixmpp import Presence
|
||||
from slixmpp.plugins import BasePlugin
|
||||
from slixmpp.xmlstream import register_stanza_plugin
|
||||
from slixmpp.plugins.xep_0012 import stanza, LastActivity
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class XEP_0256(BasePlugin):
|
||||
|
||||
name = 'xep_0256'
|
||||
description = 'XEP-0256: Last Activity in Presence'
|
||||
dependencies = set(['xep_0030'])
|
||||
stanza = stanza
|
||||
|
||||
def plugin_init(self):
|
||||
register_stanza_plugin(Presence, LastActivity)
|
||||
@@ -540,7 +540,7 @@ class XEP_0325(BasePlugin):
|
||||
fields = [f['name'] for f in iq['setResponse']['datas']]
|
||||
error_msg = None
|
||||
|
||||
if not iq['setResponse'].find('error') is None and not iq['setResponse']['error']['text'] == "":
|
||||
if not iq['setResponse'].xml.find('error') is None and not iq['setResponse']['error']['text'] == "":
|
||||
error_msg = iq['setResponse']['error']['text']
|
||||
|
||||
callback = self.sessions[seqnr]["callback"]
|
||||
|
||||
14
slixmpp/plugins/xep_0333/__init__.py
Normal file
14
slixmpp/plugins/xep_0333/__init__.py
Normal file
@@ -0,0 +1,14 @@
|
||||
"""
|
||||
slixmpp: The Slick XMPP Library
|
||||
Copyright (C) 2016 Emmanuel Gil Peyrot
|
||||
This file is part of slixmpp.
|
||||
|
||||
See the file LICENSE for copying permission.
|
||||
"""
|
||||
|
||||
from slixmpp.plugins.base import register_plugin
|
||||
|
||||
from slixmpp.plugins.xep_0333.stanza import Markable, Received, Displayed, Acknowledged
|
||||
from slixmpp.plugins.xep_0333.hints import XEP_0333
|
||||
|
||||
register_plugin(XEP_0333)
|
||||
53
slixmpp/plugins/xep_0333/hints.py
Normal file
53
slixmpp/plugins/xep_0333/hints.py
Normal file
@@ -0,0 +1,53 @@
|
||||
"""
|
||||
slixmpp: The Slick XMPP Library
|
||||
Copyright (C) 2016 Emmanuel Gil Peyrot
|
||||
This file is part of slixmpp.
|
||||
|
||||
See the file LICENSE for copying permission.
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
from slixmpp import Message
|
||||
from slixmpp.plugins import BasePlugin
|
||||
from slixmpp.xmlstream import register_stanza_plugin
|
||||
from slixmpp.plugins.xep_0333 import stanza, Markable, Received, Displayed, Acknowledged
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
class XEP_0333(BasePlugin):
|
||||
|
||||
name = 'xep_0333'
|
||||
description = 'XEP-0333: Chat Markers'
|
||||
stanza = stanza
|
||||
|
||||
def plugin_init(self):
|
||||
register_stanza_plugin(Message, Markable)
|
||||
register_stanza_plugin(Message, Received)
|
||||
register_stanza_plugin(Message, Displayed)
|
||||
register_stanza_plugin(Message, Acknowledged)
|
||||
|
||||
self.xmpp.register_handler(
|
||||
Callback('Received Chat Marker',
|
||||
StanzaPath('message/received'),
|
||||
self._handle_received))
|
||||
self.xmpp.register_handler(
|
||||
Callback('Displayed Chat Marker',
|
||||
StanzaPath('message/displayed'),
|
||||
self._handle_displayed))
|
||||
self.xmpp.register_handler(
|
||||
Callback('Acknowledged Chat Marker',
|
||||
StanzaPath('message/acknowledged'),
|
||||
self._handle_acknowledged))
|
||||
|
||||
def _handle_received(self, message):
|
||||
self.xmpp.event('marker_received', message)
|
||||
self.xmpp.event('marker', message)
|
||||
|
||||
def _handle_displayed(self, message):
|
||||
self.xmpp.event('marker_displayed', message)
|
||||
self.xmpp.event('marker', message)
|
||||
|
||||
def _handle_acknowledged(self, message):
|
||||
self.xmpp.event('marker_acknowledged', message)
|
||||
self.xmpp.event('marker', message)
|
||||
32
slixmpp/plugins/xep_0333/stanza.py
Normal file
32
slixmpp/plugins/xep_0333/stanza.py
Normal file
@@ -0,0 +1,32 @@
|
||||
"""
|
||||
slixmpp: The Slick XMPP Library
|
||||
Copyright (C) 2016 Emmanuel Gil Peyrot
|
||||
This file is part of slixmpp.
|
||||
|
||||
See the file LICENSE for copying permission.
|
||||
"""
|
||||
|
||||
from slixmpp.xmlstream import ElementBase
|
||||
|
||||
class Markable(ElementBase):
|
||||
name = 'markable'
|
||||
plugin_attrib = 'markable'
|
||||
namespace = 'urn:xmpp:chat-markers:0'
|
||||
|
||||
class Received(ElementBase):
|
||||
name = 'received'
|
||||
plugin_attrib = 'received'
|
||||
namespace = 'urn:xmpp:chat-markers:0'
|
||||
interfaces = {'id'}
|
||||
|
||||
class Displayed(ElementBase):
|
||||
name = 'displayed'
|
||||
plugin_attrib = 'displayed'
|
||||
namespace = 'urn:xmpp:chat-markers:0'
|
||||
interfaces = {'id'}
|
||||
|
||||
class Acknowledged(ElementBase):
|
||||
name = 'acknowledged'
|
||||
plugin_attrib = 'acknowledged'
|
||||
namespace = 'urn:xmpp:chat-markers:0'
|
||||
interfaces = {'id'}
|
||||
14
slixmpp/plugins/xep_0334/__init__.py
Normal file
14
slixmpp/plugins/xep_0334/__init__.py
Normal file
@@ -0,0 +1,14 @@
|
||||
"""
|
||||
Slixmpp: The Slick XMPP Library
|
||||
Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
|
||||
This file is part of Slixmpp.
|
||||
|
||||
See the file LICENSE for copying permission.
|
||||
"""
|
||||
|
||||
from slixmpp.plugins.base import register_plugin
|
||||
|
||||
from slixmpp.plugins.xep_0334.stanza import Store, NoStore, NoPermanentStore, NoCopy
|
||||
from slixmpp.plugins.xep_0334.hints import XEP_0334
|
||||
|
||||
register_plugin(XEP_0334)
|
||||
28
slixmpp/plugins/xep_0334/hints.py
Normal file
28
slixmpp/plugins/xep_0334/hints.py
Normal file
@@ -0,0 +1,28 @@
|
||||
"""
|
||||
Slixmpp: The Slick XMPP Library
|
||||
Copyright (C) 2016 Nathanael C. Fritz, Lance J.T. Stout
|
||||
This file is part of Slixmpp.
|
||||
|
||||
See the file LICENSE for copying permission.
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
from slixmpp import Message
|
||||
from slixmpp.plugins import BasePlugin
|
||||
from slixmpp.xmlstream import register_stanza_plugin
|
||||
from slixmpp.plugins.xep_0334 import stanza, Store, NoStore, NoPermanentStore, NoCopy
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
class XEP_0334(BasePlugin):
|
||||
|
||||
name = 'xep_0334'
|
||||
description = 'XEP-0334: Message Processing Hints'
|
||||
stanza = stanza
|
||||
|
||||
def plugin_init(self):
|
||||
register_stanza_plugin(Message, Store)
|
||||
register_stanza_plugin(Message, NoStore)
|
||||
register_stanza_plugin(Message, NoPermanentStore)
|
||||
register_stanza_plugin(Message, NoCopy)
|
||||
30
slixmpp/plugins/xep_0334/stanza.py
Normal file
30
slixmpp/plugins/xep_0334/stanza.py
Normal file
@@ -0,0 +1,30 @@
|
||||
"""
|
||||
slixmpp: The Slick XMPP Library
|
||||
Implementation of Message Processing Hints
|
||||
http://xmpp.org/extensions/xep-0334.html
|
||||
This file is part of slixmpp.
|
||||
|
||||
See the file LICENSE for copying permission.
|
||||
"""
|
||||
|
||||
from slixmpp.xmlstream import ElementBase
|
||||
|
||||
class Store(ElementBase):
|
||||
name = 'store'
|
||||
plugin_attrib = 'store'
|
||||
namespace = 'urn:xmpp:hints'
|
||||
|
||||
class NoPermanentStore(ElementBase):
|
||||
name = 'no-permanent-store'
|
||||
plugin_attrib = 'no-permanent-store'
|
||||
namespace = 'urn:xmpp:hints'
|
||||
|
||||
class NoStore(ElementBase):
|
||||
name = 'no-store'
|
||||
plugin_attrib = 'no-store'
|
||||
namespace = 'urn:xmpp:hints'
|
||||
|
||||
class NoCopy(ElementBase):
|
||||
name = 'no-copy'
|
||||
plugin_attrib = 'no-copy'
|
||||
namespace = 'urn:xmpp:hints'
|
||||
15
slixmpp/plugins/xep_0352/__init__.py
Normal file
15
slixmpp/plugins/xep_0352/__init__.py
Normal file
@@ -0,0 +1,15 @@
|
||||
"""
|
||||
Slixmpp: The Slick XMPP Library
|
||||
Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
|
||||
This file is part of Slixmpp.
|
||||
|
||||
See the file LICENSE for copying permission.
|
||||
"""
|
||||
|
||||
from slixmpp.plugins.base import register_plugin
|
||||
|
||||
from slixmpp.plugins.xep_0352.stanza import Active, Inactive, ClientStateIndication
|
||||
from slixmpp.plugins.xep_0352.csi import XEP_0352
|
||||
|
||||
|
||||
register_plugin(XEP_0352)
|
||||
76
slixmpp/plugins/xep_0352/csi.py
Normal file
76
slixmpp/plugins/xep_0352/csi.py
Normal file
@@ -0,0 +1,76 @@
|
||||
"""
|
||||
Slixmpp: The Slick XMPP Library
|
||||
Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
|
||||
This file is part of Slixmpp.
|
||||
|
||||
See the file LICENSE for copying permission.
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
from slixmpp.stanza import StreamFeatures
|
||||
from slixmpp.xmlstream import register_stanza_plugin
|
||||
from slixmpp.plugins.base import BasePlugin
|
||||
from slixmpp.plugins.xep_0352 import stanza, Active, Inactive, ClientStateIndication
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class XEP_0352(BasePlugin):
|
||||
|
||||
"""
|
||||
XEP-0352: Client State Indication
|
||||
"""
|
||||
|
||||
name = 'xep_0352'
|
||||
description = 'XEP-0352: Client State Indication'
|
||||
dependencies = set()
|
||||
stanza = stanza
|
||||
default_config = {
|
||||
"order": 12000,
|
||||
}
|
||||
|
||||
def plugin_init(self):
|
||||
"""Start the XEP-0352 plugin."""
|
||||
|
||||
self.enabled = False
|
||||
|
||||
register_stanza_plugin(StreamFeatures, ClientStateIndication)
|
||||
self.xmpp.register_stanza(stanza.Active)
|
||||
self.xmpp.register_stanza(stanza.Inactive)
|
||||
|
||||
self.xmpp.register_feature('csi',
|
||||
self._handle_csi_feature,
|
||||
restart=False,
|
||||
order=self.order)
|
||||
|
||||
|
||||
def plugin_end(self):
|
||||
if self.xmpp.is_component:
|
||||
return
|
||||
|
||||
self.xmpp.unregister_feature('csi', self.order)
|
||||
self.xmpp.remove_stanza(stanza.Active)
|
||||
self.xmpp.remove_stanza(stanza.Inactive)
|
||||
|
||||
def send_active(self):
|
||||
"""Send an 'active' state"""
|
||||
if self.enabled:
|
||||
self.xmpp.send_raw(str(stanza.Active(self.xmpp)))
|
||||
|
||||
def send_inactive(self):
|
||||
"""Send an 'active' state"""
|
||||
if self.enabled:
|
||||
self.xmpp.send_raw(str(stanza.Inactive(self.xmpp)))
|
||||
|
||||
def _handle_csi_feature(self, features):
|
||||
"""
|
||||
Enable CSI
|
||||
"""
|
||||
if 'csi' in self.xmpp.features:
|
||||
log.debug('CSI already enabled')
|
||||
return False
|
||||
self.enabled = True
|
||||
self.xmpp.event('csi_enabled', features)
|
||||
return False
|
||||
33
slixmpp/plugins/xep_0352/stanza.py
Normal file
33
slixmpp/plugins/xep_0352/stanza.py
Normal file
@@ -0,0 +1,33 @@
|
||||
"""
|
||||
Slixmpp: The Slick XMPP Library
|
||||
Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout
|
||||
This file is part of Slixmpp.
|
||||
|
||||
See the file LICENSE for copying permission.
|
||||
"""
|
||||
|
||||
from slixmpp.stanza import Error
|
||||
from slixmpp.xmlstream import ElementBase, StanzaBase
|
||||
|
||||
class ClientStateIndication(ElementBase):
|
||||
name = 'csi'
|
||||
namespace = 'urn:xmpp:csi:0'
|
||||
plugin_attrib = name
|
||||
|
||||
class Active(StanzaBase):
|
||||
name = 'active'
|
||||
plugin_attrib = 'active'
|
||||
namespace = 'urn:xmpp:csi:0'
|
||||
|
||||
def setup(self, xml):
|
||||
StanzaBase.setup(self, xml)
|
||||
self.xml.tag = self.tag_name()
|
||||
|
||||
class Inactive (StanzaBase):
|
||||
name = 'inactive'
|
||||
plugin_attrib = 'inactive'
|
||||
namespace = 'urn:xmpp:csi:0'
|
||||
|
||||
def setup(self, xml):
|
||||
StanzaBase.setup(self, xml)
|
||||
self.xml.tag = self.tag_name()
|
||||
@@ -56,6 +56,7 @@ class RosterNode(object):
|
||||
self.xmpp = xmpp
|
||||
self.jid = jid
|
||||
self.db = db
|
||||
self.ignore_updates = False
|
||||
self.auto_authorize = True
|
||||
self.auto_subscribe = True
|
||||
self.last_status = None
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
"""
|
||||
Slixmpp: The Slick XMPP Library
|
||||
Copyright (C) 2010 Nathanael C. Fritz
|
||||
This file is part of Slixmpp.
|
||||
|
||||
See the file LICENSE for copying permission.
|
||||
"""
|
||||
|
||||
# The nickname stanza has been moved to its own plugin, but the existing
|
||||
# references are kept for backwards compatibility.
|
||||
|
||||
from slixmpp.stanza import Message, Presence
|
||||
from slixmpp.xmlstream import register_stanza_plugin
|
||||
from slixmpp.plugins.xep_0172 import UserNick as Nick
|
||||
|
||||
register_stanza_plugin(Message, Nick)
|
||||
register_stanza_plugin(Presence, Nick)
|
||||
@@ -76,12 +76,6 @@ class Presence(RootStanza):
|
||||
if self.stream is not None and self.stream.use_presence_ids:
|
||||
self['id'] = self.stream.new_id()
|
||||
|
||||
def exception(self, e):
|
||||
"""
|
||||
Override exception passback for presence.
|
||||
"""
|
||||
pass
|
||||
|
||||
def set_show(self, show):
|
||||
"""
|
||||
Set the value of the <show> element.
|
||||
|
||||
@@ -340,9 +340,6 @@ class SlixTest(unittest.TestCase):
|
||||
self.xmpp.default_lang = None
|
||||
self.xmpp.peer_default_lang = None
|
||||
|
||||
# Simulate connecting for mock sockets.
|
||||
self.xmpp.auto_reconnect = False
|
||||
|
||||
# Must have the stream header ready for xmpp.process() to work.
|
||||
if not header:
|
||||
header = self.xmpp.stream_header
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import builtins
|
||||
import sys
|
||||
import hashlib
|
||||
|
||||
@@ -22,7 +23,6 @@ def bytes(text):
|
||||
if text is None:
|
||||
return b''
|
||||
|
||||
import builtins
|
||||
if isinstance(text, builtins.bytes):
|
||||
# We already have bytes, so do nothing
|
||||
return text
|
||||
@@ -80,10 +80,9 @@ def XOR(x, y):
|
||||
:param bytes y: A byte string
|
||||
:rtype: bytes
|
||||
"""
|
||||
result = b''
|
||||
for a, b in zip(x, y):
|
||||
result += bytes([a ^ b])
|
||||
return result
|
||||
# This operation is faster with a list comprehension than with a
|
||||
# generator, as of 2016 on python 3.5.
|
||||
return builtins.bytes([a ^ b for a, b in zip(x, y)])
|
||||
|
||||
|
||||
def hash(name):
|
||||
|
||||
@@ -9,5 +9,5 @@
|
||||
# We don't want to have to import the entire library
|
||||
# just to get the version info for setup.py
|
||||
|
||||
__version__ = '1.1'
|
||||
__version_info__ = (1, 1)
|
||||
__version__ = '1.2.1'
|
||||
__version_info__ = (1, 2, 1)
|
||||
|
||||
@@ -1,38 +1,10 @@
|
||||
"""
|
||||
A module that monkey patches the standard asyncio module to add an
|
||||
idle_call() method to the main loop. This method is used to execute a
|
||||
callback whenever the loop is not busy handling anything else. This means
|
||||
that it is a callback with lower priority than IO, timer, or even
|
||||
call_soon() ones. These callback are called only once each.
|
||||
asyncio-related utilities
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
from asyncio import events
|
||||
from functools import wraps
|
||||
|
||||
import collections
|
||||
|
||||
def idle_call(self, callback):
|
||||
if asyncio.iscoroutinefunction(callback):
|
||||
raise TypeError("coroutines cannot be used with idle_call()")
|
||||
handle = events.Handle(callback, [], self)
|
||||
self._idle.append(handle)
|
||||
|
||||
def my_run_once(self):
|
||||
if self._idle:
|
||||
self._ready.append(events.Handle(lambda: None, (), self))
|
||||
real_run_once(self)
|
||||
if self._idle:
|
||||
handle = self._idle.popleft()
|
||||
handle._run()
|
||||
|
||||
cls = asyncio.get_event_loop().__class__
|
||||
|
||||
cls._idle = collections.deque()
|
||||
cls.idle_call = idle_call
|
||||
real_run_once = cls._run_once
|
||||
cls._run_once = my_run_once
|
||||
|
||||
def future_wrapper(func):
|
||||
"""
|
||||
Make sure the result of a function call is an asyncio.Future()
|
||||
|
||||
@@ -10,8 +10,10 @@
|
||||
"""
|
||||
|
||||
import logging
|
||||
from queue import Queue, Empty
|
||||
import asyncio
|
||||
from asyncio import Queue, wait_for, TimeoutError
|
||||
|
||||
import slixmpp
|
||||
from slixmpp.xmlstream.handler.base import BaseHandler
|
||||
|
||||
|
||||
@@ -42,12 +44,13 @@ class Waiter(BaseHandler):
|
||||
:param payload: The matched
|
||||
:class:`~slixmpp.xmlstream.stanzabase.ElementBase` object.
|
||||
"""
|
||||
self._payload.put(payload)
|
||||
self._payload.put_nowait(payload)
|
||||
|
||||
def run(self, payload):
|
||||
"""Do not process this handler during the main event loop."""
|
||||
pass
|
||||
|
||||
@asyncio.coroutine
|
||||
def wait(self, timeout=None):
|
||||
"""Block an event handler while waiting for a stanza to arrive.
|
||||
|
||||
@@ -63,18 +66,13 @@ class Waiter(BaseHandler):
|
||||
value.
|
||||
"""
|
||||
if timeout is None:
|
||||
timeout = self.stream().response_timeout
|
||||
timeout = slixmpp.xmlstream.RESPONSE_TIMEOUT
|
||||
|
||||
elapsed_time = 0
|
||||
stanza = False
|
||||
while elapsed_time < timeout and not self.stream().stop.is_set():
|
||||
try:
|
||||
stanza = self._payload.get(True, 1)
|
||||
break
|
||||
except Empty:
|
||||
elapsed_time += 1
|
||||
if elapsed_time >= timeout:
|
||||
log.warning("Timed out waiting for %s", self.name)
|
||||
stanza = None
|
||||
try:
|
||||
stanza = yield from self._payload.get()
|
||||
except TimeoutError:
|
||||
log.warning("Timed out waiting for %s", self.name)
|
||||
self.stream().remove_handler(self.name)
|
||||
return stanza
|
||||
|
||||
|
||||
@@ -379,20 +379,6 @@ class ElementBase(object):
|
||||
#: .. versionadded:: 1.0-Beta5
|
||||
plugin_iterables = set()
|
||||
|
||||
#: A deprecated version of :attr:`plugin_iterables` that remains
|
||||
#: for backward compatibility. It required a parent stanza to
|
||||
#: know beforehand what stanza classes would be iterable::
|
||||
#:
|
||||
#: class DiscoItem(ElementBase):
|
||||
#: ...
|
||||
#:
|
||||
#: class DiscoInfo(ElementBase):
|
||||
#: subitem = (DiscoItem, )
|
||||
#: ...
|
||||
#:
|
||||
#: .. deprecated:: 1.0-Beta5
|
||||
subitem = set()
|
||||
|
||||
#: The default XML namespace: ``http://www.w3.org/XML/1998/namespace``.
|
||||
xml_ns = XML_NS
|
||||
|
||||
@@ -426,10 +412,6 @@ class ElementBase(object):
|
||||
else:
|
||||
self.parent = parent
|
||||
|
||||
if self.subitem is not None:
|
||||
for sub in self.subitem:
|
||||
self.plugin_iterables.add(sub)
|
||||
|
||||
if self.setup(xml):
|
||||
# If we generated our own XML, then everything is ready.
|
||||
return
|
||||
@@ -637,7 +619,7 @@ class ElementBase(object):
|
||||
plugin.values = value
|
||||
return self
|
||||
|
||||
def __getitem__(self, attrib):
|
||||
def __getitem__(self, full_attrib):
|
||||
"""Return the value of a stanza interface using dict-like syntax.
|
||||
|
||||
Example::
|
||||
@@ -664,24 +646,16 @@ class ElementBase(object):
|
||||
8. The plugin named ``'foo'``
|
||||
9. An empty string.
|
||||
|
||||
:param string attrib: The name of the requested stanza interface.
|
||||
:param string full_attrib: The name of the requested stanza interface.
|
||||
"""
|
||||
full_attrib = attrib
|
||||
attrib_lang = ('%s|' % attrib).split('|')
|
||||
attrib = attrib_lang[0]
|
||||
lang = attrib_lang[1] or None
|
||||
attrib, lang, *_ = ('%s|' % full_attrib).split('|')
|
||||
|
||||
kwargs = {}
|
||||
if lang and attrib in self.lang_interfaces:
|
||||
kwargs['lang'] = lang
|
||||
|
||||
kwargs = OrderedDict(kwargs)
|
||||
kwargs = {'lang': lang} if lang and attrib in self.lang_interfaces else {}
|
||||
|
||||
if attrib == 'substanzas':
|
||||
return self.iterables
|
||||
elif attrib in self.interfaces or attrib == 'lang':
|
||||
get_method = "get_%s" % attrib.lower()
|
||||
get_method2 = "get%s" % attrib.title()
|
||||
|
||||
if self.plugin_overrides:
|
||||
name = self.plugin_overrides.get(get_method, None)
|
||||
@@ -694,8 +668,6 @@ class ElementBase(object):
|
||||
|
||||
if hasattr(self, get_method):
|
||||
return getattr(self, get_method)(**kwargs)
|
||||
elif hasattr(self, get_method2):
|
||||
return getattr(self, get_method2)(**kwargs)
|
||||
else:
|
||||
if attrib in self.sub_interfaces:
|
||||
return self._get_sub_text(attrib, lang=lang)
|
||||
@@ -758,7 +730,6 @@ class ElementBase(object):
|
||||
if attrib in self.interfaces or attrib == 'lang':
|
||||
if value is not None:
|
||||
set_method = "set_%s" % attrib.lower()
|
||||
set_method2 = "set%s" % attrib.title()
|
||||
|
||||
if self.plugin_overrides:
|
||||
name = self.plugin_overrides.get(set_method, None)
|
||||
@@ -771,8 +742,6 @@ class ElementBase(object):
|
||||
|
||||
if hasattr(self, set_method):
|
||||
getattr(self, set_method)(value, **kwargs)
|
||||
elif hasattr(self, set_method2):
|
||||
getattr(self, set_method2)(value, **kwargs)
|
||||
else:
|
||||
if attrib in self.sub_interfaces:
|
||||
if lang == '*':
|
||||
@@ -845,7 +814,6 @@ class ElementBase(object):
|
||||
|
||||
if attrib in self.interfaces or attrib == 'lang':
|
||||
del_method = "del_%s" % attrib.lower()
|
||||
del_method2 = "del%s" % attrib.title()
|
||||
|
||||
if self.plugin_overrides:
|
||||
name = self.plugin_overrides.get(del_method, None)
|
||||
@@ -858,8 +826,6 @@ class ElementBase(object):
|
||||
|
||||
if hasattr(self, del_method):
|
||||
getattr(self, del_method)(**kwargs)
|
||||
elif hasattr(self, del_method2):
|
||||
getattr(self, del_method2)(**kwargs)
|
||||
else:
|
||||
if attrib in self.sub_interfaces:
|
||||
return self._del_sub(attrib, lang=lang)
|
||||
@@ -941,11 +907,17 @@ class ElementBase(object):
|
||||
stanzas = self.xml.findall(name)
|
||||
if not stanzas:
|
||||
return default
|
||||
result = None
|
||||
for stanza in stanzas:
|
||||
if stanza.attrib.get('{%s}lang' % XML_NS, default_lang) == lang:
|
||||
if stanza.text is None:
|
||||
return default
|
||||
return stanza.text
|
||||
result = stanza.text
|
||||
break
|
||||
if stanza.text:
|
||||
result = stanza.text
|
||||
if result is not None:
|
||||
return result
|
||||
return default
|
||||
|
||||
def _get_all_sub_text(self, name, default='', lang=None):
|
||||
@@ -1148,36 +1120,6 @@ class ElementBase(object):
|
||||
# Everything matched.
|
||||
return True
|
||||
|
||||
def find(self, xpath):
|
||||
"""Find an XML object in this stanza given an XPath expression.
|
||||
|
||||
Exposes ElementTree interface for backwards compatibility.
|
||||
|
||||
.. note::
|
||||
|
||||
Matching on attribute values is not supported in Python 2.6
|
||||
or Python 3.1
|
||||
|
||||
:param string xpath: An XPath expression matching a single
|
||||
desired element.
|
||||
"""
|
||||
return self.xml.find(xpath)
|
||||
|
||||
def findall(self, xpath):
|
||||
"""Find multiple XML objects in this stanza given an XPath expression.
|
||||
|
||||
Exposes ElementTree interface for backwards compatibility.
|
||||
|
||||
.. note::
|
||||
|
||||
Matching on attribute values is not supported in Python 2.6
|
||||
or Python 3.1.
|
||||
|
||||
:param string xpath: An XPath expression matching multiple
|
||||
desired elements.
|
||||
"""
|
||||
return self.xml.findall(xpath)
|
||||
|
||||
def get(self, key, default=None):
|
||||
"""Return the value of a stanza interface.
|
||||
|
||||
@@ -1305,20 +1247,6 @@ class ElementBase(object):
|
||||
if attr in self.xml.attrib:
|
||||
del self.xml.attrib[attr]
|
||||
|
||||
@property
|
||||
def attrib(self):
|
||||
"""Return the stanza object itself.
|
||||
|
||||
Older implementations of stanza objects used XML objects directly,
|
||||
requiring the use of ``.attrib`` to access attribute values.
|
||||
|
||||
Use of the dictionary syntax with the stanza object itself for
|
||||
accessing stanza interfaces is preferred.
|
||||
|
||||
.. deprecated:: 1.0
|
||||
"""
|
||||
return self
|
||||
|
||||
def _fix_ns(self, xpath, split=False, propagate_ns=True):
|
||||
return fix_ns(xpath, split=split,
|
||||
propagate_ns=propagate_ns,
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user