Skip to content
This repository has been archived by the owner on Feb 19, 2020. It is now read-only.

Cleanup #310

Merged
merged 2 commits into from Aug 18, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.rst
Expand Up @@ -3,7 +3,7 @@ SleekXMPP

SleekXMPP is an MIT licensed XMPP library for Python 2.6/3.1+,
and is featured in examples in
`XMPP: The Definitive Guide <http://oreilly.com/catalog/9780596521271>`_
`XMPP: The Definitive Guide <http://oreilly.com/catalog/9780596521271>`_
by Kevin Smith, Remko Tronçon, and Peter Saint-Andre. If you've arrived
here from reading the Definitive Guide, please see the notes on updating
the examples to the latest version of SleekXMPP.
Expand Down Expand Up @@ -52,7 +52,7 @@ The latest source code for SleekXMPP may be found on `Github


Installing DNSPython
---------------------
--------------------
If you are using Python3 and wish to use dnspython, you will have to checkout and
install the ``python3`` branch::

Expand Down Expand Up @@ -144,7 +144,7 @@ SleekXMPP projects::


if __name__ == '__main__':
# Ideally use optparse or argparse to get JID,
# Ideally use optparse or argparse to get JID,
# password, and log level.

logging.basicConfig(level=logging.DEBUG,
Expand All @@ -158,15 +158,15 @@ SleekXMPP projects::
Credits
-------
**Main Author:** Nathan Fritz
`fritzy@netflint.net <xmpp:fritzy@netflint.net?message>`_,
`fritzy@netflint.net <xmpp:fritzy@netflint.net?message>`_,
`@fritzy <http://twitter.com/fritzy>`_

Nathan is also the author of XMPPHP and `Seesmic-AS3-XMPP
<http://code.google.com/p/seesmic-as3-xmpp/>`_, and a former member of
<http://code.google.com/p/seesmic-as3-xmpp/>`_, and a former member of
the XMPP Council.

**Co-Author:** Lance Stout
`lancestout@gmail.com <xmpp:lancestout@gmail.com?message>`_,
`lancestout@gmail.com <xmpp:lancestout@gmail.com?message>`_,
`@lancestout <http://twitter.com/lancestout>`_

**Contributors:**
Expand Down
8 changes: 4 additions & 4 deletions examples/IoT_TestDevice.py
Expand Up @@ -179,13 +179,13 @@ def refresh(self,fields):
# node=opts.nodeid,
# jid=xmpp.boundjid.full)

myDevice = TheDevice(opts.nodeid);
myDevice = TheDevice(opts.nodeid)
# myDevice._add_field(name="Relay", typename="numeric", unit="Bool");
myDevice._add_field(name="Temperature", typename="numeric", unit="C");
myDevice._add_field(name="Temperature", typename="numeric", unit="C")
myDevice._set_momentary_timestamp("2013-03-07T16:24:30")
myDevice._add_field_momentary_data("Temperature", "23.4", flags={"automaticReadout": "true"});
myDevice._add_field_momentary_data("Temperature", "23.4", flags={"automaticReadout": "true"})

xmpp['xep_0323'].register_node(nodeId=opts.nodeid, device=myDevice, commTimeout=10);
xmpp['xep_0323'].register_node(nodeId=opts.nodeid, device=myDevice, commTimeout=10)
xmpp.beClientOrServer(server=True)
while not(xmpp.testForRelease()):
xmpp.connect()
Expand Down
2 changes: 1 addition & 1 deletion examples/roster_browser.py
Expand Up @@ -68,7 +68,7 @@ def start(self, event):
try:
self.get_roster()
except IqError as err:
print('Error: %' % err.iq['error']['condition'])
print('Error: %s' % err.iq['error']['condition'])
except IqTimeout:
print('Error: Request timed out')
self.send_presence()
Expand Down
3 changes: 1 addition & 2 deletions sleekxmpp/basexmpp.py
Expand Up @@ -25,7 +25,6 @@
from sleekxmpp.stanza import Message, Presence, Iq, StreamError
from sleekxmpp.stanza.roster import Roster
from sleekxmpp.stanza.nick import Nick
from sleekxmpp.stanza.htmlim import HTMLIM

from sleekxmpp.xmlstream import XMLStream, JID
from sleekxmpp.xmlstream import ET, register_stanza_plugin
Expand Down Expand Up @@ -245,7 +244,7 @@ def process(self, *args, **kwargs):
self.plugin[name].post_inited = True
return XMLStream.process(self, *args, **kwargs)

def register_plugin(self, plugin, pconfig={}, module=None):
def register_plugin(self, plugin, pconfig=None, module=None):
"""Register and configure a plugin for use in this stream.

:param plugin: The name of the plugin class. Plugin names must
Expand Down
10 changes: 7 additions & 3 deletions sleekxmpp/clientxmpp.py
Expand Up @@ -52,16 +52,20 @@ class ClientXMPP(BaseXMPP):

:param jid: The JID of the XMPP user account.
:param password: The password for the XMPP user account.
:param ssl: **Deprecated.**
:param plugin_config: A dictionary of plugin configurations.
:param plugin_whitelist: A list of approved plugins that
will be loaded when calling
:meth:`~sleekxmpp.basexmpp.BaseXMPP.register_plugins()`.
:param escape_quotes: **Deprecated.**
"""

def __init__(self, jid, password, plugin_config={}, plugin_whitelist=[],
escape_quotes=True, sasl_mech=None, lang='en'):
def __init__(self, jid, password, plugin_config=None, plugin_whitelist=None, escape_quotes=True, sasl_mech=None,
lang='en'):
if not plugin_whitelist:
plugin_whitelist = []
if not plugin_config:
plugin_config = {}

BaseXMPP.__init__(self, jid, 'jabber:client')

self.escape_quotes = escape_quotes
Expand Down
9 changes: 7 additions & 2 deletions sleekxmpp/componentxmpp.py
Expand Up @@ -49,8 +49,13 @@ class ComponentXMPP(BaseXMPP):
Defaults to ``False``.
"""

def __init__(self, jid, secret, host=None, port=None,
plugin_config={}, plugin_whitelist=[], use_jc_ns=False):
def __init__(self, jid, secret, host=None, port=None, plugin_config=None, plugin_whitelist=None, use_jc_ns=False):

if not plugin_whitelist:
plugin_whitelist = []
if not plugin_config:
plugin_config = {}

if use_jc_ns:
default_ns = 'jabber:client'
else:
Expand Down
10 changes: 5 additions & 5 deletions sleekxmpp/features/feature_mechanisms/mechanisms.py
Expand Up @@ -187,14 +187,14 @@ def _send_auth(self):
except sasl.SASLCancelled:
self.attempted_mechs.add(self.mech.name)
self._send_auth()
except sasl.SASLFailed:
self.attempted_mechs.add(self.mech.name)
self._send_auth()
except sasl.SASLMutualAuthFailed:
log.error("Mutual authentication failed! " + \
"A security breach is possible.")
self.attempted_mechs.add(self.mech.name)
self.xmpp.disconnect()
except sasl.SASLFailed:
self.attempted_mechs.add(self.mech.name)
self._send_auth()
else:
resp.send(now=True)

Expand All @@ -207,13 +207,13 @@ def _handle_challenge(self, stanza):
resp['value'] = self.mech.process(stanza['value'])
except sasl.SASLCancelled:
self.stanza.Abort(self.xmpp).send()
except sasl.SASLFailed:
self.stanza.Abort(self.xmpp).send()
except sasl.SASLMutualAuthFailed:
log.error("Mutual authentication failed! " + \
"A security breach is possible.")
self.attempted_mechs.add(self.mech.name)
self.xmpp.disconnect()
except sasl.SASLFailed:
self.stanza.Abort(self.xmpp).send()
else:
if resp.get_value() == '':
resp.del_value()
Expand Down
2 changes: 1 addition & 1 deletion sleekxmpp/plugins/google/auth/stanza.py
Expand Up @@ -24,7 +24,7 @@ def setup(self, xml):
print('setting up google extension')

def get_client_uses_full_bind_result(self):
return self.parent()._get_attr(self.disovery_attr) == 'true'
return self.parent()._get_attr(self.discovery_attr) == 'true'

def set_client_uses_full_bind_result(self, value):
print('>>>', value)
Expand Down
2 changes: 1 addition & 1 deletion sleekxmpp/plugins/google/nosave/stanza.py
Expand Up @@ -52,7 +52,7 @@ def set_jid(self, value):
def get_source(self):
return JID(self._get_attr('source', ''))

def set_source(self):
def set_source(self, value):
self._set_attr('source', str(value))


Expand Down
2 changes: 0 additions & 2 deletions sleekxmpp/plugins/google/settings/settings.py
Expand Up @@ -6,8 +6,6 @@
See the file LICENSE for copying permission.
"""

import logging

from sleekxmpp.stanza import Iq
from sleekxmpp.xmlstream.handler import Callback
from sleekxmpp.xmlstream.matcher import StanzaPath
Expand Down
1 change: 0 additions & 1 deletion sleekxmpp/plugins/xep_0004/stanza/form.py
Expand Up @@ -151,7 +151,6 @@ def get_fields(self, use_dict=False):
return fields

def get_instructions(self):
instructions = ''
instsXML = self.xml.findall('{%s}instructions' % self.namespace)
return "\n".join([instXML.text for instXML in instsXML])

Expand Down
3 changes: 2 additions & 1 deletion sleekxmpp/plugins/xep_0009/remote.py
Expand Up @@ -697,7 +697,8 @@ def new_session_with_client(cls, client, callback=None):
if(client.boundjid.bare in cls._sessions):
raise RemoteException("There already is a session associated with these credentials!")
else:
cls._sessions[client.boundjid.bare] = client;
cls._sessions[client.boundjid.bare] = client

def _session_close_callback():
with Remote._lock:
del cls._sessions[client.boundjid.bare]
Expand Down
4 changes: 2 additions & 2 deletions sleekxmpp/plugins/xep_0009/rpc.py
Expand Up @@ -61,7 +61,7 @@ def make_iq_method_call(self, pto, pmethod, params):
iq.enable('rpc_query')
iq['rpc_query']['method_call']['method_name'] = pmethod
iq['rpc_query']['method_call']['params'] = params
return iq;
return iq

def make_iq_method_response(self, pid, pto, params):
iq = self.xmpp.makeIqResult(pid)
Expand Down Expand Up @@ -93,7 +93,7 @@ def make_iq_method_response_fault(self, pid, pto, params):

def _item_not_found(self, iq):
payload = iq.get_payload()
iq.reply().error().set_payload(payload);
iq.reply().error().set_payload(payload)
iq['error']['code'] = '404'
iq['error']['type'] = 'cancel'
iq['error']['condition'] = 'item-not-found'
Expand Down
9 changes: 6 additions & 3 deletions sleekxmpp/plugins/xep_0030/disco.py
Expand Up @@ -324,7 +324,7 @@ def get_info(self, jid=None, node=None, local=None,
callback -- Optional callback to execute when a reply is
received instead of blocking and waiting for
the reply.
timeout_callback -- Optional callback to execute when no result
timeout_callback -- Optional callback to execute when no result
has been received in timeout seconds.
"""
if local is None:
Expand Down Expand Up @@ -408,7 +408,7 @@ def get_items(self, jid=None, node=None, local=False, **kwargs):
iterator -- If True, return a result set iterator using
the XEP-0059 plugin, if the plugin is loaded.
Otherwise the parameter is ignored.
timeout_callback -- Optional callback to execute when no result
timeout_callback -- Optional callback to execute when no result
has been received in timeout seconds.
"""
if local or local is None and jid is None:
Expand Down Expand Up @@ -604,7 +604,7 @@ def del_features(self, jid=None, node=None, **kwargs):
"""
self.api['del_features'](jid, node, None, kwargs)

def _run_node_handler(self, htype, jid, node=None, ifrom=None, data={}):
def _run_node_handler(self, htype, jid, node=None, ifrom=None, data=None):
"""
Execute the most specific node handler for the given
JID/node combination.
Expand All @@ -615,6 +615,9 @@ def _run_node_handler(self, htype, jid, node=None, ifrom=None, data={}):
node -- The node requested.
data -- Optional, custom data to pass to the handler.
"""
if not data:
data = {}

return self.api[htype](jid, node, ifrom, data)

def _handle_disco_info(self, iq):
Expand Down