summaryrefslogtreecommitdiff
path: root/sleekxmpp/plugins/xep_0009/rpc.py
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2011-02-09 09:45:45 +0800
committerLance Stout <lancestout@gmail.com>2011-02-09 10:02:14 +0800
commit4b71fba64c8675aa891fd6a92eb6f0f045e4a48e (patch)
tree006b466ce33193dcacb62fe240a4bbab05e9f981 /sleekxmpp/plugins/xep_0009/rpc.py
parent1ed06bebcdbe82e0c528c98134e381f5b4dcccad (diff)
downloadslixmpp-4b71fba64c8675aa891fd6a92eb6f0f045e4a48e.tar.gz
slixmpp-4b71fba64c8675aa891fd6a92eb6f0f045e4a48e.tar.bz2
slixmpp-4b71fba64c8675aa891fd6a92eb6f0f045e4a48e.tar.xz
slixmpp-4b71fba64c8675aa891fd6a92eb6f0f045e4a48e.zip
Fix the xep_0009 import (no more relatives)
Also, remove trailing spaces in all files of this plugin
Diffstat (limited to 'sleekxmpp/plugins/xep_0009/rpc.py')
-rw-r--r--sleekxmpp/plugins/xep_0009/rpc.py88
1 files changed, 44 insertions, 44 deletions
diff --git a/sleekxmpp/plugins/xep_0009/rpc.py b/sleekxmpp/plugins/xep_0009/rpc.py
index 84afeb5f..fc306d31 100644
--- a/sleekxmpp/plugins/xep_0009/rpc.py
+++ b/sleekxmpp/plugins/xep_0009/rpc.py
@@ -6,8 +6,8 @@
See the file LICENSE for copying permission.
"""
-from .. import base
-from stanza.RPC import RPCQuery, MethodCall, MethodResponse
+from sleekxmpp.plugins import base
+from sleekxmpp.plugins.xep_0009.stanza.RPC import RPCQuery, MethodCall, MethodResponse
from sleekxmpp.stanza.iq import Iq
from sleekxmpp.xmlstream.handler.callback import Callback
from sleekxmpp.xmlstream.matcher.xpath import MatchXPath
@@ -27,15 +27,15 @@ class xep_0009(base.base_plugin):
self.xep = '0009'
self.description = 'Jabber-RPC'
#self.stanza = sleekxmpp.plugins.xep_0009.stanza
-
+
register_stanza_plugin(Iq, RPCQuery)
- register_stanza_plugin(RPCQuery, MethodCall)
+ register_stanza_plugin(RPCQuery, MethodCall)
register_stanza_plugin(RPCQuery, MethodResponse)
-
+
self.xmpp.registerHandler(
Callback('RPC Call', MatchXPath('{%s}iq/{%s}query/{%s}methodCall' % (self.xmpp.default_ns, RPCQuery.namespace, RPCQuery.namespace)),
self._handle_method_call)
- )
+ )
self.xmpp.registerHandler(
Callback('RPC Call', MatchXPath('{%s}iq/{%s}query/{%s}methodResponse' % (self.xmpp.default_ns, RPCQuery.namespace, RPCQuery.namespace)),
self._handle_method_response)
@@ -46,7 +46,7 @@ class xep_0009(base.base_plugin):
)
self.xmpp.add_event_handler('jabber_rpc_method_call', self._on_jabber_rpc_method_call)
self.xmpp.add_event_handler('jabber_rpc_method_response', self._on_jabber_rpc_method_response)
- self.xmpp.add_event_handler('jabber_rpc_method_fault', self._on_jabber_rpc_method_fault)
+ self.xmpp.add_event_handler('jabber_rpc_method_fault', self._on_jabber_rpc_method_fault)
self.xmpp.add_event_handler('jabber_rpc_error', self._on_jabber_rpc_error)
self.xmpp.add_event_handler('error', self._handle_error)
#self.activeCalls = []
@@ -54,7 +54,7 @@ class xep_0009(base.base_plugin):
def post_init(self):
base.base_plugin.post_init(self)
self.xmpp.plugin['xep_0030'].add_feature('jabber:iq:rpc')
- self.xmpp.plugin['xep_0030'].add_identity('automation','rpc')
+ self.xmpp.plugin['xep_0030'].add_identity('automation','rpc')
def make_iq_method_call(self, pto, pmethod, params):
iq = self.xmpp.makeIqSet()
@@ -64,7 +64,7 @@ class xep_0009(base.base_plugin):
iq['rpc_query']['method_call']['method_name'] = pmethod
iq['rpc_query']['method_call']['params'] = params
return iq;
-
+
def make_iq_method_response(self, pid, pto, params):
iq = self.xmpp.makeIqResult(pid)
iq.attrib['to'] = pto
@@ -78,7 +78,7 @@ class xep_0009(base.base_plugin):
iq.attrib['to'] = pto
iq.attrib['from'] = self.xmpp.boundjid.full
iq.enable('rpc_query')
- iq['rpc_query']['method_response']['params'] = None
+ iq['rpc_query']['method_response']['params'] = None
iq['rpc_query']['method_response']['fault'] = params
return iq
@@ -100,58 +100,58 @@ class xep_0009(base.base_plugin):
iq['error']['type'] = 'cancel'
iq['error']['condition'] = 'item-not-found'
return iq
-
+
def _undefined_condition(self, iq):
- payload = iq.get_payload()
- iq.reply().error().set_payload(payload)
+ payload = iq.get_payload()
+ iq.reply().error().set_payload(payload)
iq['error']['code'] = '500'
iq['error']['type'] = 'cancel'
iq['error']['condition'] = 'undefined-condition'
- return iq
+ return iq
def _forbidden(self, iq):
payload = iq.get_payload()
- iq.reply().error().set_payload(payload)
+ iq.reply().error().set_payload(payload)
iq['error']['code'] = '403'
iq['error']['type'] = 'auth'
iq['error']['condition'] = 'forbidden'
- return iq
+ return iq
def _recipient_unvailable(self, iq):
- payload = iq.get_payload()
- iq.reply().error().set_payload(payload)
+ payload = iq.get_payload()
+ iq.reply().error().set_payload(payload)
iq['error']['code'] = '404'
iq['error']['type'] = 'wait'
iq['error']['condition'] = 'recipient-unavailable'
- return iq
+ return iq
def _handle_method_call(self, iq):
type = iq['type']
if type == 'set':
log.debug("Incoming Jabber-RPC call from %s" % iq['from'])
- self.xmpp.event('jabber_rpc_method_call', iq)
+ 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'])
- self.xmpp.event('jabber_rpc_error', iq)
-
+ 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'])
- self.xmpp.event('jabber_rpc_method_response', iq)
-
+ log.debug("Incoming Jabber-RPC response from %s" % iq['from'])
+ self.xmpp.event('jabber_rpc_method_response', iq)
+
def _handle_error(self, iq):
print("['XEP-0009']._handle_error -> ERROR! Iq is '%s'" % iq)
print("#######################")
- print("### NOT IMPLEMENTED ###")
+ print("### NOT IMPLEMENTED ###")
print("#######################")
-
+
def _on_jabber_rpc_method_call(self, iq, forwarded=False):
"""
A default handler for Jabber-RPC method call. If another
@@ -161,7 +161,7 @@ class xep_0009(base.base_plugin):
forwarded set to True, then it will run as normal.
"""
if not forwarded and self.xmpp.event_handled('jabber_rpc_method_call') > 1:
- return
+ return
# Reply with error by default
error = self.client.plugin['xep_0009']._item_not_found(iq)
error.send()
@@ -175,7 +175,7 @@ class xep_0009(base.base_plugin):
forwarded set to True, then it will run as normal.
"""
if not forwarded and self.xmpp.event_handled('jabber_rpc_method_response') > 1:
- return
+ return
error = self.client.plugin['xep_0009']._recpient_unavailable(iq)
error.send()
@@ -186,12 +186,12 @@ class xep_0009(base.base_plugin):
If this handler is called by your own custom handler with
forwarded set to True, then it will run as normal.
- """
+ """
if not forwarded and self.xmpp.event_handled('jabber_rpc_method_fault') > 1:
- return
+ return
error = self.client.plugin['xep_0009']._recpient_unavailable(iq)
error.send()
-
+
def _on_jabber_rpc_error(self, iq, forwarded=False):
"""
A default handler for Jabber-RPC error response. If another
@@ -199,23 +199,23 @@ class xep_0009(base.base_plugin):
If this handler is called by your own custom handler with
forwarded set to True, then it will run as normal.
- """
+ """
if not forwarded and self.xmpp.event_handled('jabber_rpc_error') > 1:
- return
+ return
error = self.client.plugin['xep_0009']._recpient_unavailable(iq, iq.get_payload())
error.send()
-
- def _send_fault(self, iq, fault_xml): #
+
+ def _send_fault(self, iq, fault_xml): #
fault = self.make_iq_method_response_fault(iq['id'], iq['from'], fault_xml)
- fault.send()
-
+ fault.send()
+
def _send_error(self, iq):
- print("['XEP-0009']._send_error -> ERROR! Iq is '%s'" % iq)
+ print("['XEP-0009']._send_error -> ERROR! Iq is '%s'" % iq)
print("#######################")
- print("### NOT IMPLEMENTED ###")
+ print("### NOT IMPLEMENTED ###")
print("#######################")
-
+
def _extract_method(self, stanza):
xml = ET.fromstring("%s" % stanza)
return xml.find("./methodCall/methodName").text
- \ No newline at end of file
+