summaryrefslogtreecommitdiff
path: root/sleekxmpp/plugins/xep_0009
diff options
context:
space:
mode:
Diffstat (limited to 'sleekxmpp/plugins/xep_0009')
-rw-r--r--sleekxmpp/plugins/xep_0009/binding.py46
-rw-r--r--sleekxmpp/plugins/xep_0009/remote.py19
-rw-r--r--sleekxmpp/plugins/xep_0009/rpc.py8
3 files changed, 38 insertions, 35 deletions
diff --git a/sleekxmpp/plugins/xep_0009/binding.py b/sleekxmpp/plugins/xep_0009/binding.py
index ef34b580..b4395707 100644
--- a/sleekxmpp/plugins/xep_0009/binding.py
+++ b/sleekxmpp/plugins/xep_0009/binding.py
@@ -42,46 +42,46 @@ def py2xml(*args):
def _py2xml(*args):
for x in args:
- val = ET.Element("value")
+ val = ET.Element("{%s}value" % _namespace)
if x is None:
- nil = ET.Element("nil")
+ nil = ET.Element("{%s}nil" % _namespace)
val.append(nil)
elif type(x) is int:
- i4 = ET.Element("i4")
+ i4 = ET.Element("{%s}i4" % _namespace)
i4.text = str(x)
val.append(i4)
elif type(x) is bool:
- boolean = ET.Element("boolean")
+ boolean = ET.Element("{%s}boolean" % _namespace)
boolean.text = str(int(x))
val.append(boolean)
elif type(x) is str:
- string = ET.Element("string")
+ string = ET.Element("{%s}string" % _namespace)
string.text = x
val.append(string)
elif type(x) is float:
- double = ET.Element("double")
+ double = ET.Element("{%s}double" % _namespace)
double.text = str(x)
val.append(double)
elif type(x) is rpcbase64:
- b64 = ET.Element("base64")
+ b64 = ET.Element("{%s}base64" % _namespace)
b64.text = x.encoded()
val.append(b64)
elif type(x) is rpctime:
- iso = ET.Element("dateTime.iso8601")
+ iso = ET.Element("{%s}dateTime.iso8601" % _namespace)
iso.text = str(x)
val.append(iso)
elif type(x) in (list, tuple):
- array = ET.Element("array")
- data = ET.Element("data")
+ array = ET.Element("{%s}array" % _namespace)
+ data = ET.Element("{%s}data" % _namespace)
for y in x:
data.append(_py2xml(y))
array.append(data)
val.append(array)
elif type(x) is dict:
- struct = ET.Element("struct")
+ struct = ET.Element("{%s}struct" % _namespace)
for y in x.keys():
- member = ET.Element("member")
- name = ET.Element("name")
+ member = ET.Element("{%s}member" % _namespace)
+ name = ET.Element("{%s}name" % _namespace)
name.text = y
member.append(name)
member.append(_py2xml(x[y]))
@@ -105,18 +105,18 @@ def _xml2py(value):
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(value.find('{%s}boolean' % namespace).text)
+ 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') is not None:
- return rpcbase64(value.find('base64' % namespace).text)
- if value.find('{%s}Base64') is not None:
+ 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:
# Older versions of XEP-0009 used Base64
- return rpcbase64(value.find('Base64' % namespace).text)
- if value.find('{%s}dateTime.iso8601') is not None:
- return rpctime(value.find('{%s}dateTime.iso8601'))
+ 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:
struct = {}
for member in value.find('{%s}struct' % namespace).findall('{%s}member' % namespace):
@@ -138,13 +138,13 @@ class rpcbase64(object):
self.data = data
def decode(self):
- return base64.decodestring(self.data)
+ return base64.b64decode(self.data)
def __str__(self):
- return self.decode()
+ return self.decode().decode()
def encoded(self):
- return self.data
+ return self.data.decode()
diff --git a/sleekxmpp/plugins/xep_0009/remote.py b/sleekxmpp/plugins/xep_0009/remote.py
index 3cc0f520..8c08e8f3 100644
--- a/sleekxmpp/plugins/xep_0009/remote.py
+++ b/sleekxmpp/plugins/xep_0009/remote.py
@@ -20,7 +20,7 @@ log = logging.getLogger(__name__)
def _intercept(method, name, public):
def _resolver(instance, *args, **kwargs):
- log.debug("Locally calling %s.%s with arguments %s." % (instance.FQN(), method.__name__, args))
+ log.debug("Locally calling %s.%s with arguments %s.", instance.FQN(), method.__name__, args)
try:
value = method(instance, *args, **kwargs)
if value == NotImplemented:
@@ -113,6 +113,9 @@ class ACL:
def check(cls, rules, jid, resource):
if rules is None:
return cls.DENY # No rules means no access!
+ jid = str(jid) # Check the string representation of the JID.
+ if not jid:
+ return cls.DENY # Can't check an empty JID.
for rule in rules:
policy = cls._check(rule, jid, resource)
if policy is not None:
@@ -381,7 +384,7 @@ class Proxy(Endpoint):
try:
if attribute._rpc:
def _remote_call(*args, **kwargs):
- log.debug("Remotely calling '%s.%s' with arguments %s." % (self._endpoint.FQN(), attribute._rpc_name, args))
+ log.debug("Remotely calling '%s.%s' with arguments %s.", self._endpoint.FQN(), attribute._rpc_name, args)
return self._endpoint.session._call_remote(self._endpoint.target_jid, "%s.%s" % (self._endpoint.FQN(), attribute._rpc_name), self._callback, *args, **kwargs)
return _remote_call
except:
@@ -449,7 +452,7 @@ class RemoteSession(object):
self._event.wait()
def _notify(self, event):
- log.debug("RPC Session as %s started." % self._client.boundjid.full)
+ log.debug("RPC Session as %s started.", self._client.boundjid.full)
self._client.sendPresence()
self._event.set()
pass
@@ -461,7 +464,7 @@ class RemoteSession(object):
if name is None:
name = method.__name__
key = "%s.%s" % (endpoint, name)
- log.debug("Registering call handler for %s (%s)." % (key, method))
+ log.debug("Registering call handler for %s (%s).", key, method)
with self._lock:
if key in self._entries:
raise KeyError("A handler for %s has already been regisered!" % endpoint)
@@ -469,7 +472,7 @@ class RemoteSession(object):
return key
def _register_acl(self, endpoint, acl):
- log.debug("Registering ACL %s for endpoint %s." % (repr(acl), endpoint))
+ log.debug("Registering ACL %s for endpoint %s.", repr(acl), endpoint)
with self._lock:
self._acls[endpoint] = acl
@@ -562,7 +565,7 @@ class RemoteSession(object):
iq.send()
return future.get_value(30)
else:
- log.debug("[RemoteSession] _call_remote %s" % callback)
+ log.debug("[RemoteSession] _call_remote %s", callback)
self._register_callback(pid, callback)
iq.send()
@@ -601,11 +604,11 @@ class RemoteSession(object):
error.send()
except Exception as e:
if isinstance(e, KeyError):
- log.error("No handler available for %s!" % pmethod)
+ log.error("No handler available for %s!", pmethod)
error = self._client.plugin['xep_0009']._item_not_found(iq)
else:
traceback.print_exc(file=sys.stderr)
- log.error("An unexpected problem occurred invoking method %s!" % pmethod)
+ log.error("An unexpected problem occurred invoking method %s!", pmethod)
error = self._client.plugin['xep_0009']._undefined_condition(iq)
#! print "[REMOTE.PY] _handle_remote_procedure_call AN ERROR SHOULD BE SENT NOW %s " % e
error.send()
diff --git a/sleekxmpp/plugins/xep_0009/rpc.py b/sleekxmpp/plugins/xep_0009/rpc.py
index fc306d31..4f749f30 100644
--- a/sleekxmpp/plugins/xep_0009/rpc.py
+++ b/sleekxmpp/plugins/xep_0009/rpc.py
@@ -128,22 +128,22 @@ class xep_0009(base.base_plugin):
def _handle_method_call(self, iq):
type = iq['type']
if type == 'set':
- log.debug("Incoming Jabber-RPC call from %s" % iq['from'])
+ log.debug("Incoming Jabber-RPC call from %s", iq['from'])
self.xmpp.event('jabber_rpc_method_call', iq)
else:
if type == 'error' and ['rpc_query'] is None:
self.handle_error(iq)
else:
- log.debug("Incoming Jabber-RPC error from %s" % iq['from'])
+ log.debug("Incoming Jabber-RPC error from %s", iq['from'])
self.xmpp.event('jabber_rpc_error', iq)
def _handle_method_response(self, iq):
if iq['rpc_query']['method_response']['fault'] is not None:
- log.debug("Incoming Jabber-RPC fault from %s" % iq['from'])
+ log.debug("Incoming Jabber-RPC fault from %s", iq['from'])
#self._on_jabber_rpc_method_fault(iq)
self.xmpp.event('jabber_rpc_method_fault', iq)
else:
- log.debug("Incoming Jabber-RPC response from %s" % iq['from'])
+ log.debug("Incoming Jabber-RPC response from %s", iq['from'])
self.xmpp.event('jabber_rpc_method_response', iq)
def _handle_error(self, iq):