summaryrefslogtreecommitdiff
path: root/sleekxmpp
diff options
context:
space:
mode:
authorSangeeth Saravanaraj <sangeeth@riptideio.com>2015-02-05 17:35:04 +0530
committerSangeeth Saravanaraj <sangeeth@riptideio.com>2015-02-05 17:35:04 +0530
commit8bc70264efd17390fbe795e359a7cbb0442fd0d1 (patch)
tree818dacc3156e4f5ee085a38fe010f34bf820290c /sleekxmpp
parentc16b86220047e2a2b77c585d6b0d72f5087c1371 (diff)
downloadslixmpp-8bc70264efd17390fbe795e359a7cbb0442fd0d1.tar.gz
slixmpp-8bc70264efd17390fbe795e359a7cbb0442fd0d1.tar.bz2
slixmpp-8bc70264efd17390fbe795e359a7cbb0442fd0d1.tar.xz
slixmpp-8bc70264efd17390fbe795e359a7cbb0442fd0d1.zip
misc updates..
Diffstat (limited to 'sleekxmpp')
-rw-r--r--sleekxmpp/plugins/xep_0332/http.py62
-rw-r--r--sleekxmpp/plugins/xep_0332/stanza/data.py9
-rw-r--r--sleekxmpp/plugins/xep_0332/stanza/request.py14
-rw-r--r--sleekxmpp/plugins/xep_0332/stanza/response.py14
4 files changed, 53 insertions, 46 deletions
diff --git a/sleekxmpp/plugins/xep_0332/http.py b/sleekxmpp/plugins/xep_0332/http.py
index 06ba1477..36b6995f 100644
--- a/sleekxmpp/plugins/xep_0332/http.py
+++ b/sleekxmpp/plugins/xep_0332/http.py
@@ -50,26 +50,21 @@ class XEP_0332(BasePlugin):
}
def plugin_init(self):
- log.debug("XEP_0332:: plugin_init()")
-
self.xmpp.register_handler(Callback(
'HTTP Request', StanzaPath('iq/req'), self._handle_request
))
self.xmpp.register_handler(Callback(
'HTTP Response', StanzaPath('iq/resp'), self._handle_response
))
-
register_stanza_plugin(Iq, Request, iterable=True)
register_stanza_plugin(Iq, Response, iterable=True)
register_stanza_plugin(Request, Headers, iterable=True)
register_stanza_plugin(Request, Data, iterable=True)
register_stanza_plugin(Response, Headers, iterable=True)
register_stanza_plugin(Response, Data, iterable=True)
-
# TODO: Should we register any api's here? self.api.register()
def plugin_end(self):
- log.debug("XEP_0332:: plugin_end()")
self.xmpp.remove_handler('HTTP Request')
self.xmpp.remove_handler('HTTP Response')
self.xmpp['xep_0030'].del_feature('urn:xmpp:http')
@@ -79,7 +74,6 @@ class XEP_0332(BasePlugin):
)
def session_bind(self, jid):
- log.debug("XEP_0332:: session_bind()")
self.xmpp['xep_0030'].add_feature('urn:xmpp:http')
for header in self.supported_headers:
self.xmpp['xep_0030'].add_feature(
@@ -89,18 +83,13 @@ class XEP_0332(BasePlugin):
# self.xmpp['xep_0131'].supported_headers.add(header)
def _handle_request(self, iq):
- log.debug("XEP_0332:: _handle_request()")
- print iq
self.xmpp.event('http_request', iq)
def _handle_response(self, iq):
- log.debug("XEP_0332:: _handle_response()")
- print iq
self.xmpp.event('http_response', iq)
def send_request(self, to=None, method=None, resource=None, headers=None,
data=None, **kwargs):
- log.debug("XEP_0332:: send_request()")
iq = self.xmpp.Iq()
iq['from'] = self.xmpp.boundjid
iq['to'] = to
@@ -109,29 +98,46 @@ class XEP_0332(BasePlugin):
iq['req']['method'] = method
iq['req']['resource'] = resource
iq['req']['version'] = '1.1' # TODO: set this implicitly
- if data:
+ if data is not None:
iq['req']['data'] = data
- print iq
- return iq.send(timeout=kwargs.get('timeout', None),
- block=kwargs.get('block', True),
- callback=kwargs.get('callback', None),
- timeout_callback=kwargs.get('timeout_callback', None))
-
- def send_response(self, to=None, code=None, headers=None, data=None,
- **kwargs):
- log.debug("XEP_0332:: send_response()")
+ return iq.send(
+ timeout=kwargs.get('timeout', None),
+ block=kwargs.get('block', True),
+ callback=kwargs.get('callback', None),
+ timeout_callback=kwargs.get('timeout_callback', None)
+ )
+
+ def send_response(self, to=None, code=None, message=None, headers=None,
+ data=None, **kwargs):
iq = self.xmpp.Iq()
iq['from'] = self.xmpp.boundjid
iq['to'] = to
iq['type'] = 'result'
iq['resp']['headers'] = headers
iq['resp']['code'] = code
+ iq['resp']['message'] = message
iq['resp']['version'] = '1.1' # TODO: set this implicitly
- if data:
+ if data is not None:
iq['resp']['data'] = data
- print iq
- # return iq.send(timeout=kwargs.get('timeout', None),
- # block=kwargs.get('block', True),
- # callback=kwargs.get('callback', None),
- # timeout_callback=kwargs.get('timeout_callback', None))
-
+ return iq.send(
+ timeout=kwargs.get('timeout', None),
+ block=kwargs.get('block', True),
+ callback=kwargs.get('callback', None),
+ timeout_callback=kwargs.get('timeout_callback', None)
+ )
+
+ def send_error(self, to=None, ecode=500, etype='wait',
+ econd='internal-server-error', **kwargs):
+ iq = self.xmpp.Iq()
+ iq['type'] = 'error'
+ iq['from'] = self.xmpp.boundjid
+ iq['to'] = to
+ iq['error']['code'] = ecode
+ iq['error']['type'] = etype
+ iq['error']['condition'] = econd
+ return iq.send(
+ timeout=kwargs.get('timeout', None),
+ block=kwargs.get('block', True),
+ callback=kwargs.get('callback', None),
+ timeout_callback=kwargs.get('timeout_callback', None)
+ )
diff --git a/sleekxmpp/plugins/xep_0332/stanza/data.py b/sleekxmpp/plugins/xep_0332/stanza/data.py
index e77d2585..9a08426b 100644
--- a/sleekxmpp/plugins/xep_0332/stanza/data.py
+++ b/sleekxmpp/plugins/xep_0332/stanza/data.py
@@ -16,14 +16,15 @@ class Data(ElementBase):
The data element.
"""
name = 'data'
- namespace = ''
+ namespace = 'urn:xmpp:http'
interfaces = set(['data'])
plugin_attrib = 'data'
+ is_extension = True
- def get_data(self):
- print "Data:: get_data()"
+ def get_data(self, encoding='text'):
+ data = self._get_sub_text(encoding, None)
+ return str(data) if data is not None else data
def set_data(self, data, encoding='text'):
- print "Data:: set_data()"
self._set_sub_text(encoding, text=data)
diff --git a/sleekxmpp/plugins/xep_0332/stanza/request.py b/sleekxmpp/plugins/xep_0332/stanza/request.py
index 51e565e5..07618727 100644
--- a/sleekxmpp/plugins/xep_0332/stanza/request.py
+++ b/sleekxmpp/plugins/xep_0332/stanza/request.py
@@ -20,7 +20,7 @@ class Request(ElementBase):
Examples:
<iq type='set' from='a@b.com/browser' to='x@y.com' id='1'>
- <req xmlns='urn:xmpp:http' method='GET' resource='/api/user' version='1.1'>
+ <req xmlns='urn:xmpp:http' method='GET' resource='/api/users' version='1.1'>
<headers xmlns='http://jabber.org/protocol/shim'>
<header name='Host'>b.com</header>
</headers>
@@ -35,7 +35,7 @@ class Request(ElementBase):
<header name='Content-Length'>...</header>
</headers>
<data>
- <text>&lt;html&gt;&lt;header/&gt;&lt;body&gt;&lt;p&gt;Beautiful home page.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</text>
+ <text>...</text>
</data>
</req>
</iq>
@@ -47,23 +47,19 @@ class Request(ElementBase):
plugin_attrib = 'req'
def get_method(self):
- print "Request:: get_method()"
+ return self._get_attr('method', None)
def set_method(self, method):
- print "Request:: set_method()"
self._set_attr('method', method)
def get_resource(self):
- print "Request:: get_resource()"
+ return self._get_attr('resource', None)
def set_resource(self, resource):
- print "Request:: set_resource()"
self._set_attr('resource', resource)
def get_version(self):
- print "Request:: get_version()"
+ return self._get_attr('version', None)
def set_version(self, version='1.1'):
- print "Request:: set_version()"
self._set_attr('version', version)
-
diff --git a/sleekxmpp/plugins/xep_0332/stanza/response.py b/sleekxmpp/plugins/xep_0332/stanza/response.py
index d863efa3..0fc46de8 100644
--- a/sleekxmpp/plugins/xep_0332/stanza/response.py
+++ b/sleekxmpp/plugins/xep_0332/stanza/response.py
@@ -41,17 +41,21 @@ class Response(ElementBase):
name = 'response'
namespace = 'urn:xmpp:http'
- interfaces = set(['code', 'version'])
+ interfaces = set(['code', 'message', 'version'])
plugin_attrib = 'resp'
def get_code(self):
- print "Response:: get_code()"
+ code = self._get_attr('statusCode', None)
+ return int(code) if code is not None else code
def set_code(self, code):
- print "Response:: set_code()"
self._set_attr('statusCode', str(code))
- self._set_attr('statusMessage', str(code))
+
+ def get_message(self):
+ return self._get_attr('statusMessage', '')
+
+ def set_message(self, message):
+ self._set_attr('statusMessage', message)
def set_version(self, version='1.1'):
- print "Response:: set_version()"
self._set_attr('version', version)