From ecd124dd068ea381555fca3c42c402c46da0cba1 Mon Sep 17 00:00:00 2001 From: Sangeeth Saravanaraj Date: Thu, 22 Jan 2015 16:40:03 +0530 Subject: Boilerplate for xep_0332 --- sleekxmpp/plugins/xep_0332/__init__.py | 15 ++++++++++++++ sleekxmpp/plugins/xep_0332/http.py | 37 ++++++++++++++++++++++++++++++++++ sleekxmpp/plugins/xep_0332/stanza.py | 19 +++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 sleekxmpp/plugins/xep_0332/__init__.py create mode 100644 sleekxmpp/plugins/xep_0332/http.py create mode 100644 sleekxmpp/plugins/xep_0332/stanza.py (limited to 'sleekxmpp/plugins/xep_0332') diff --git a/sleekxmpp/plugins/xep_0332/__init__.py b/sleekxmpp/plugins/xep_0332/__init__.py new file mode 100644 index 00000000..3f80ce82 --- /dev/null +++ b/sleekxmpp/plugins/xep_0332/__init__.py @@ -0,0 +1,15 @@ +""" + SleekXMPP: The Sleek XMPP Library + Implementation of HTTP over XMPP transport + http://xmpp.org/extensions/xep-0332.html + Copyright (C) 2015 Riptide IO, sangeeth@riptideio.com + This file is part of SleekXMPP. + + See the file LICENSE for copying permission. +""" + +from sleekxmpp.plugins.base import register_plugin + +from sleekxmpp.plugins.xep_0332.http import XEP_0332 + +register_plugin(XEP_0332) diff --git a/sleekxmpp/plugins/xep_0332/http.py b/sleekxmpp/plugins/xep_0332/http.py new file mode 100644 index 00000000..7b9628e3 --- /dev/null +++ b/sleekxmpp/plugins/xep_0332/http.py @@ -0,0 +1,37 @@ +""" + SleekXMPP: The Sleek XMPP Library + Implementation of HTTP over XMPP transport + http://xmpp.org/extensions/xep-0332.html + Copyright (C) 2015 Riptide IO, sangeeth@riptideio.com + This file is part of SleekXMPP. + + See the file LICENSE for copying permission. +""" + +import logging + +from sleekxmpp.plugins.base import BasePlugin + + +log = logging.getLogger(__name__) + + +class XEP_0332(BasePlugin): + """ + XEP-0332: HTTP over XMPP transport + """ + + name = 'xep_0332' + description = 'XEP-0332: HTTP over XMPP transport' + dependencies = set(['xep_0030', 'xep_0047', 'xep_0131']) #: xep 1, 137 and 166 are missing + default_config = {} + + def plugin_init(self): + log.debug("XEP_0332:: plugin_init()") + + def plugin_end(self): + log.debug("XEP_0332:: plugin_end()") + + def session_bind(self, jid): + log.debug("XEP_0332:: session_bind()") + diff --git a/sleekxmpp/plugins/xep_0332/stanza.py b/sleekxmpp/plugins/xep_0332/stanza.py new file mode 100644 index 00000000..9d651d5d --- /dev/null +++ b/sleekxmpp/plugins/xep_0332/stanza.py @@ -0,0 +1,19 @@ +""" + SleekXMPP: The Sleek XMPP Library + Implementation of HTTP over XMPP transport + http://xmpp.org/extensions/xep-0332.html + Copyright (C) 2015 Riptide IO, sangeeth@riptideio.com + This file is part of SleekXMPP. + + See the file LICENSE for copying permission. +""" + +from sleekxmpp.xmlstream import ElementBase + + +class Req(ElementBase): + pass + + +class Resp(ElementBase): + pass -- cgit v1.2.3 From 0fe057b5c3f462275cf8dbf321c2ebec61de1bfe Mon Sep 17 00:00:00 2001 From: Sangeeth Saravanaraj Date: Tue, 27 Jan 2015 15:13:57 +0530 Subject: Boilerplate for Stanzas - request and response --- sleekxmpp/plugins/xep_0332/__init__.py | 1 + sleekxmpp/plugins/xep_0332/stanza.py | 19 ------------------- sleekxmpp/plugins/xep_0332/stanza/__init__.py | 12 ++++++++++++ sleekxmpp/plugins/xep_0332/stanza/request.py | 21 +++++++++++++++++++++ sleekxmpp/plugins/xep_0332/stanza/response.py | 21 +++++++++++++++++++++ 5 files changed, 55 insertions(+), 19 deletions(-) delete mode 100644 sleekxmpp/plugins/xep_0332/stanza.py create mode 100644 sleekxmpp/plugins/xep_0332/stanza/__init__.py create mode 100644 sleekxmpp/plugins/xep_0332/stanza/request.py create mode 100644 sleekxmpp/plugins/xep_0332/stanza/response.py (limited to 'sleekxmpp/plugins/xep_0332') diff --git a/sleekxmpp/plugins/xep_0332/__init__.py b/sleekxmpp/plugins/xep_0332/__init__.py index 3f80ce82..bdb951fc 100644 --- a/sleekxmpp/plugins/xep_0332/__init__.py +++ b/sleekxmpp/plugins/xep_0332/__init__.py @@ -11,5 +11,6 @@ from sleekxmpp.plugins.base import register_plugin from sleekxmpp.plugins.xep_0332.http import XEP_0332 +from sleekxmpp.plugins.xep_0332 import stanza register_plugin(XEP_0332) diff --git a/sleekxmpp/plugins/xep_0332/stanza.py b/sleekxmpp/plugins/xep_0332/stanza.py deleted file mode 100644 index 9d651d5d..00000000 --- a/sleekxmpp/plugins/xep_0332/stanza.py +++ /dev/null @@ -1,19 +0,0 @@ -""" - SleekXMPP: The Sleek XMPP Library - Implementation of HTTP over XMPP transport - http://xmpp.org/extensions/xep-0332.html - Copyright (C) 2015 Riptide IO, sangeeth@riptideio.com - This file is part of SleekXMPP. - - See the file LICENSE for copying permission. -""" - -from sleekxmpp.xmlstream import ElementBase - - -class Req(ElementBase): - pass - - -class Resp(ElementBase): - pass diff --git a/sleekxmpp/plugins/xep_0332/stanza/__init__.py b/sleekxmpp/plugins/xep_0332/stanza/__init__.py new file mode 100644 index 00000000..5d686710 --- /dev/null +++ b/sleekxmpp/plugins/xep_0332/stanza/__init__.py @@ -0,0 +1,12 @@ +""" + SleekXMPP: The Sleek XMPP Library + Implementation of HTTP over XMPP transport + http://xmpp.org/extensions/xep-0332.html + Copyright (C) 2015 Riptide IO, sangeeth@riptideio.com + This file is part of SleekXMPP. + + See the file LICENSE for copying permission. +""" + +from sleekxmpp.plugins.xep_0332.stanza.request import * +from sleekxmpp.plugins.xep_0332.stanza.response import * diff --git a/sleekxmpp/plugins/xep_0332/stanza/request.py b/sleekxmpp/plugins/xep_0332/stanza/request.py new file mode 100644 index 00000000..3d75b534 --- /dev/null +++ b/sleekxmpp/plugins/xep_0332/stanza/request.py @@ -0,0 +1,21 @@ +""" + SleekXMPP: The Sleek XMPP Library + Implementation of HTTP over XMPP transport + http://xmpp.org/extensions/xep-0332.html + Copyright (C) 2015 Riptide IO, sangeeth@riptideio.com + This file is part of SleekXMPP. + + See the file LICENSE for copying permission. +""" + +from sleekxmpp import Iq +from sleekxmpp.xmlstream import ElementBase, register_stanza_plugin +from sleekxmpp.plugins.xep_0131.stanza import Headers + + +class Request(ElementBase): + pass + + +register_stanza_plugin(Iq, Request) +register_stanza_plugin(Request, Headers) diff --git a/sleekxmpp/plugins/xep_0332/stanza/response.py b/sleekxmpp/plugins/xep_0332/stanza/response.py new file mode 100644 index 00000000..7f8180bb --- /dev/null +++ b/sleekxmpp/plugins/xep_0332/stanza/response.py @@ -0,0 +1,21 @@ +""" + SleekXMPP: The Sleek XMPP Library + Implementation of HTTP over XMPP transport + http://xmpp.org/extensions/xep-0332.html + Copyright (C) 2015 Riptide IO, sangeeth@riptideio.com + This file is part of SleekXMPP. + + See the file LICENSE for copying permission. +""" + +from sleekxmpp import Iq +from sleekxmpp.xmlstream import ElementBase, register_stanza_plugin +from sleekxmpp.plugins.xep_0131.stanza import Headers + + +class Response(ElementBase): + pass + + +register_stanza_plugin(Iq, Response) +register_stanza_plugin(Response, Headers) -- cgit v1.2.3 From e1f25604ecbf5d6c196080cd8394191c7ea459c9 Mon Sep 17 00:00:00 2001 From: Sangeeth Saravanaraj Date: Wed, 28 Jan 2015 14:52:15 +0530 Subject: Added callbacks, registered stanzas, added features, etc. --- sleekxmpp/plugins/xep_0332/__init__.py | 2 +- sleekxmpp/plugins/xep_0332/http.py | 40 +++++++++++++++++++++++++++ sleekxmpp/plugins/xep_0332/stanza/__init__.py | 3 +- sleekxmpp/plugins/xep_0332/stanza/request.py | 40 +++++++++++++++++++++++---- sleekxmpp/plugins/xep_0332/stanza/response.py | 37 +++++++++++++++++++++---- 5 files changed, 107 insertions(+), 15 deletions(-) (limited to 'sleekxmpp/plugins/xep_0332') diff --git a/sleekxmpp/plugins/xep_0332/__init__.py b/sleekxmpp/plugins/xep_0332/__init__.py index bdb951fc..cdbfa5d5 100644 --- a/sleekxmpp/plugins/xep_0332/__init__.py +++ b/sleekxmpp/plugins/xep_0332/__init__.py @@ -11,6 +11,6 @@ from sleekxmpp.plugins.base import register_plugin from sleekxmpp.plugins.xep_0332.http import XEP_0332 -from sleekxmpp.plugins.xep_0332 import stanza +# from sleekxmpp.plugins.xep_0332 import stanza register_plugin(XEP_0332) diff --git a/sleekxmpp/plugins/xep_0332/http.py b/sleekxmpp/plugins/xep_0332/http.py index 7b9628e3..f91cc1ff 100644 --- a/sleekxmpp/plugins/xep_0332/http.py +++ b/sleekxmpp/plugins/xep_0332/http.py @@ -10,8 +10,20 @@ import logging +from sleekxmpp import Iq + +from sleekxmpp.xmlstream import register_stanza_plugin +from sleekxmpp.xmlstream.handler import Callback +from sleekxmpp.xmlstream.matcher import StanzaPath + from sleekxmpp.plugins.base import BasePlugin +from sleekxmpp.plugins.xep_0332.stanza import NAMESPACE +from sleekxmpp.plugins.xep_0332.stanza.request import Request +from sleekxmpp.plugins.xep_0332.stanza.response import Response + +from sleekxmpp.plugins.xep_0131.stanza import Headers + log = logging.getLogger(__name__) @@ -29,9 +41,37 @@ 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) + register_stanza_plugin(Iq, Response) + register_stanza_plugin(Request, Headers) + register_stanza_plugin(Response, Headers) + 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(NAMESPACE) def session_bind(self, jid): log.debug("XEP_0332:: session_bind()") + self.xmpp['xep_0030'].add_feature(NAMESPACE) + + def _handle_request(self): + log.debug("XEP_0332:: _handle_request()") + + def _handle_response(self): + log.debug("XEP_0332:: _handle_response()") + + def send_request(self, method=None, resource=None, headers=None, data=None, **kwargs): + log.debug("XEP_0332:: send_request()") + + def send_response(self, status_code=None, headers=None, data=None, **kwargs): + log.debug("XEP_0332:: send_response()") diff --git a/sleekxmpp/plugins/xep_0332/stanza/__init__.py b/sleekxmpp/plugins/xep_0332/stanza/__init__.py index 5d686710..5d9283c7 100644 --- a/sleekxmpp/plugins/xep_0332/stanza/__init__.py +++ b/sleekxmpp/plugins/xep_0332/stanza/__init__.py @@ -8,5 +8,4 @@ See the file LICENSE for copying permission. """ -from sleekxmpp.plugins.xep_0332.stanza.request import * -from sleekxmpp.plugins.xep_0332.stanza.response import * +NAMESPACE = 'urn:xmpp:http' diff --git a/sleekxmpp/plugins/xep_0332/stanza/request.py b/sleekxmpp/plugins/xep_0332/stanza/request.py index 3d75b534..ea2650c0 100644 --- a/sleekxmpp/plugins/xep_0332/stanza/request.py +++ b/sleekxmpp/plugins/xep_0332/stanza/request.py @@ -8,14 +8,42 @@ See the file LICENSE for copying permission. """ -from sleekxmpp import Iq -from sleekxmpp.xmlstream import ElementBase, register_stanza_plugin -from sleekxmpp.plugins.xep_0131.stanza import Headers +from sleekxmpp.xmlstream import ElementBase +from sleekxmpp.plugins.xep_0332.stanza import NAMESPACE class Request(ElementBase): - pass + """ + All HTTP communication is done using the `Request`/`Response` paradigm. + Each HTTP Request is made sending an `iq` stanza containing a `req` element + to the server. Each `iq` stanza sent is of type `set`. + + Examples: + + + +
b.com
+
+
+
+ + + + +
b.com
+
text/html
+
...
+
+ + <html><header/><body><p>Beautiful home page.</p></body></html> + +
+
+ """ + + name = 'request' + namespace = NAMESPACE + interfaces = set(('method', 'resource', 'version')) + plugin_attrib = 'req' -register_stanza_plugin(Iq, Request) -register_stanza_plugin(Request, Headers) diff --git a/sleekxmpp/plugins/xep_0332/stanza/response.py b/sleekxmpp/plugins/xep_0332/stanza/response.py index 7f8180bb..4dc14344 100644 --- a/sleekxmpp/plugins/xep_0332/stanza/response.py +++ b/sleekxmpp/plugins/xep_0332/stanza/response.py @@ -8,14 +8,39 @@ See the file LICENSE for copying permission. """ -from sleekxmpp import Iq -from sleekxmpp.xmlstream import ElementBase, register_stanza_plugin -from sleekxmpp.plugins.xep_0131.stanza import Headers +from sleekxmpp.xmlstream import ElementBase +from sleekxmpp.plugins.xep_0332.stanza import NAMESPACE class Response(ElementBase): - pass + """ + When the HTTP Server responds, it does so by sending an `iq` stanza + response (type=`result`) back to the client containing the `resp` element. + Since response are asynchronous, and since multiple requests may be active + at the same time, responses may be returned in a different order than the + in which the original requests were made. -register_stanza_plugin(Iq, Response) -register_stanza_plugin(Response, Headers) + Examples: + + + +
Fri, 03 May 2013 16:39:54GMT-4
+
Clayster
+
text/turtle
+
...
+
Close
+
+ + + ... + + +
+
+ """ + + name = 'response' + namespace = NAMESPACE + interfaces = set(('statusCode', 'statusMessage', 'version')) + plugin_attrib = 'resp' -- cgit v1.2.3 From a96f608469e74d39d3e7a2a86399dbb724ffadec Mon Sep 17 00:00:00 2001 From: Sangeeth Saravanaraj Date: Thu, 29 Jan 2015 08:33:40 +0530 Subject: Composing request and response. --- sleekxmpp/plugins/xep_0332/__init__.py | 3 +- sleekxmpp/plugins/xep_0332/http.py | 94 +++++++++++++++++++++------ sleekxmpp/plugins/xep_0332/stanza/__init__.py | 4 +- sleekxmpp/plugins/xep_0332/stanza/data.py | 29 +++++++++ sleekxmpp/plugins/xep_0332/stanza/request.py | 26 +++++++- sleekxmpp/plugins/xep_0332/stanza/response.py | 17 ++++- 6 files changed, 146 insertions(+), 27 deletions(-) create mode 100644 sleekxmpp/plugins/xep_0332/stanza/data.py (limited to 'sleekxmpp/plugins/xep_0332') diff --git a/sleekxmpp/plugins/xep_0332/__init__.py b/sleekxmpp/plugins/xep_0332/__init__.py index cdbfa5d5..27755faa 100644 --- a/sleekxmpp/plugins/xep_0332/__init__.py +++ b/sleekxmpp/plugins/xep_0332/__init__.py @@ -10,7 +10,8 @@ from sleekxmpp.plugins.base import register_plugin +from sleekxmpp.plugins.xep_0332 import stanza from sleekxmpp.plugins.xep_0332.http import XEP_0332 -# from sleekxmpp.plugins.xep_0332 import stanza + register_plugin(XEP_0332) diff --git a/sleekxmpp/plugins/xep_0332/http.py b/sleekxmpp/plugins/xep_0332/http.py index f91cc1ff..166e6ec3 100644 --- a/sleekxmpp/plugins/xep_0332/http.py +++ b/sleekxmpp/plugins/xep_0332/http.py @@ -17,11 +17,7 @@ from sleekxmpp.xmlstream.handler import Callback from sleekxmpp.xmlstream.matcher import StanzaPath from sleekxmpp.plugins.base import BasePlugin - -from sleekxmpp.plugins.xep_0332.stanza import NAMESPACE -from sleekxmpp.plugins.xep_0332.stanza.request import Request -from sleekxmpp.plugins.xep_0332.stanza.response import Response - +from sleekxmpp.plugins.xep_0332.stanza import Request, Response, Data from sleekxmpp.plugins.xep_0131.stanza import Headers @@ -35,8 +31,23 @@ class XEP_0332(BasePlugin): name = 'xep_0332' description = 'XEP-0332: HTTP over XMPP transport' - dependencies = set(['xep_0030', 'xep_0047', 'xep_0131']) #: xep 1, 137 and 166 are missing - default_config = {} + + #: xep_0047 not included. + #: xep_0001, 0137 and 0166 are missing + dependencies = set(['xep_0030', 'xep_0131']) + + #: TODO: Do we really need to mention the supported_headers?! + default_config = { + 'supported_headers': set([ + 'Content-Length', 'Transfer-Encoding', 'DateTime', + 'Accept-Charset', 'Location', 'Content-ID', 'Description', + 'Content-Language', 'Content-Transfer-Encoding', 'Timestamp', + 'Expires', 'User-Agent', 'Host', 'Proxy-Authorization', 'Date', + 'WWW-Authenticate', 'Accept-Encoding', 'Server', 'Error-Info', + 'Identifier', 'Content-Location', 'Content-Encoding', 'Distribute', + 'Accept', 'Proxy-Authenticate', 'ETag', 'Expect', 'Content-Type' + ]) + } def plugin_init(self): log.debug("XEP_0332:: plugin_init()") @@ -48,30 +59,75 @@ class XEP_0332(BasePlugin): 'HTTP Response', StanzaPath('iq/resp'), self._handle_response )) - register_stanza_plugin(Iq, Request) - register_stanza_plugin(Iq, Response) - register_stanza_plugin(Request, Headers) - register_stanza_plugin(Response, Headers) + 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(NAMESPACE) + self.xmpp['xep_0030'].del_feature('urn:xmpp:http') + for header in self.supported_headers: + self.xmpp['xep_0030'].del_feature( + feature='%s#%s' % (Headers.namespace, header) + ) def session_bind(self, jid): log.debug("XEP_0332:: session_bind()") - self.xmpp['xep_0030'].add_feature(NAMESPACE) - - def _handle_request(self): + self.xmpp['xep_0030'].add_feature('urn:xmpp:http') + for header in self.supported_headers: + self.xmpp['xep_0030'].add_feature( + '%s#%s' % (Headers.namespace, header) + ) + # TODO: Do we need to add the supported headers to xep_0131? + # self.xmpp['xep_0131'].supported_headers.add(header) + + def _handle_request(self, iq): log.debug("XEP_0332:: _handle_request()") + print iq - def _handle_response(self): + def _handle_response(self, iq): log.debug("XEP_0332:: _handle_response()") + print iq - def send_request(self, method=None, resource=None, headers=None, data=None, **kwargs): + def send_request(self, to=None, method=None, resource=None, headers=None, + data=None, **kwargs): log.debug("XEP_0332:: send_request()") - - def send_response(self, status_code=None, headers=None, data=None, **kwargs): + iq = self.xmpp.Iq() + iq['from'] = self.xmpp.boundjid + iq['to'] = to + iq['type'] = 'set' + iq['req']['headers'] = headers + iq['req']['method'] = method + iq['req']['resource'] = resource + iq['req']['version'] = '1.1' # TODO: set this implicitly + 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()") + 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']['version'] = '1.1' # TODO: set this implicitly + 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)) diff --git a/sleekxmpp/plugins/xep_0332/stanza/__init__.py b/sleekxmpp/plugins/xep_0332/stanza/__init__.py index 5d9283c7..eeab3f31 100644 --- a/sleekxmpp/plugins/xep_0332/stanza/__init__.py +++ b/sleekxmpp/plugins/xep_0332/stanza/__init__.py @@ -8,4 +8,6 @@ See the file LICENSE for copying permission. """ -NAMESPACE = 'urn:xmpp:http' +from sleekxmpp.plugins.xep_0332.stanza.request import Request +from sleekxmpp.plugins.xep_0332.stanza.response import Response +from sleekxmpp.plugins.xep_0332.stanza.data import Data diff --git a/sleekxmpp/plugins/xep_0332/stanza/data.py b/sleekxmpp/plugins/xep_0332/stanza/data.py new file mode 100644 index 00000000..e77d2585 --- /dev/null +++ b/sleekxmpp/plugins/xep_0332/stanza/data.py @@ -0,0 +1,29 @@ +""" + SleekXMPP: The Sleek XMPP Library + Implementation of HTTP over XMPP transport + http://xmpp.org/extensions/xep-0332.html + Copyright (C) 2015 Riptide IO, sangeeth@riptideio.com + This file is part of SleekXMPP. + + See the file LICENSE for copying permission. +""" + +from sleekxmpp.xmlstream import ElementBase + + +class Data(ElementBase): + """ + The data element. + """ + name = 'data' + namespace = '' + interfaces = set(['data']) + plugin_attrib = 'data' + + def get_data(self): + print "Data:: get_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 ea2650c0..51e565e5 100644 --- a/sleekxmpp/plugins/xep_0332/stanza/request.py +++ b/sleekxmpp/plugins/xep_0332/stanza/request.py @@ -9,7 +9,6 @@ """ from sleekxmpp.xmlstream import ElementBase -from sleekxmpp.plugins.xep_0332.stanza import NAMESPACE class Request(ElementBase): @@ -43,7 +42,28 @@ class Request(ElementBase): """ name = 'request' - namespace = NAMESPACE - interfaces = set(('method', 'resource', 'version')) + namespace = 'urn:xmpp:http' + interfaces = set(['method', 'resource', 'version']) plugin_attrib = 'req' + def get_method(self): + print "Request:: get_method()" + + def set_method(self, method): + print "Request:: set_method()" + self._set_attr('method', method) + + def get_resource(self): + print "Request:: get_resource()" + + def set_resource(self, resource): + print "Request:: set_resource()" + self._set_attr('resource', resource) + + def get_version(self): + print "Request:: get_version()" + + 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 4dc14344..d863efa3 100644 --- a/sleekxmpp/plugins/xep_0332/stanza/response.py +++ b/sleekxmpp/plugins/xep_0332/stanza/response.py @@ -9,7 +9,6 @@ """ from sleekxmpp.xmlstream import ElementBase -from sleekxmpp.plugins.xep_0332.stanza import NAMESPACE class Response(ElementBase): @@ -41,6 +40,18 @@ class Response(ElementBase): """ name = 'response' - namespace = NAMESPACE - interfaces = set(('statusCode', 'statusMessage', 'version')) + namespace = 'urn:xmpp:http' + interfaces = set(['code', 'version']) plugin_attrib = 'resp' + + def get_code(self): + print "Response:: get_code()" + + def set_code(self, code): + print "Response:: set_code()" + self._set_attr('statusCode', str(code)) + self._set_attr('statusMessage', str(code)) + + def set_version(self, version='1.1'): + print "Response:: set_version()" + self._set_attr('version', version) -- cgit v1.2.3 From c16b86220047e2a2b77c585d6b0d72f5087c1371 Mon Sep 17 00:00:00 2001 From: Sangeeth Saravanaraj Date: Tue, 3 Feb 2015 12:33:25 +0530 Subject: Raise http_request and http_response events. --- sleekxmpp/plugins/xep_0332/http.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'sleekxmpp/plugins/xep_0332') diff --git a/sleekxmpp/plugins/xep_0332/http.py b/sleekxmpp/plugins/xep_0332/http.py index 166e6ec3..06ba1477 100644 --- a/sleekxmpp/plugins/xep_0332/http.py +++ b/sleekxmpp/plugins/xep_0332/http.py @@ -91,10 +91,12 @@ class XEP_0332(BasePlugin): 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): @@ -107,12 +109,13 @@ class XEP_0332(BasePlugin): iq['req']['method'] = method iq['req']['resource'] = resource iq['req']['version'] = '1.1' # TODO: set this implicitly - iq['req']['data'] = data + if data: + 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)) + 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): @@ -124,7 +127,8 @@ class XEP_0332(BasePlugin): iq['resp']['headers'] = headers iq['resp']['code'] = code iq['resp']['version'] = '1.1' # TODO: set this implicitly - iq['resp']['data'] = data + if data: + iq['resp']['data'] = data print iq # return iq.send(timeout=kwargs.get('timeout', None), # block=kwargs.get('block', True), -- cgit v1.2.3 From 8bc70264efd17390fbe795e359a7cbb0442fd0d1 Mon Sep 17 00:00:00 2001 From: Sangeeth Saravanaraj Date: Thu, 5 Feb 2015 17:35:04 +0530 Subject: misc updates.. --- sleekxmpp/plugins/xep_0332/http.py | 62 +++++++++++++++------------ sleekxmpp/plugins/xep_0332/stanza/data.py | 9 ++-- sleekxmpp/plugins/xep_0332/stanza/request.py | 14 +++--- sleekxmpp/plugins/xep_0332/stanza/response.py | 14 +++--- 4 files changed, 53 insertions(+), 46 deletions(-) (limited to 'sleekxmpp/plugins/xep_0332') 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: - +
b.com
@@ -35,7 +35,7 @@ class Request(ElementBase):
...
- <html><header/><body><p>Beautiful home page.</p></body></html> + ...
@@ -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) -- cgit v1.2.3 From 61a7cecb319c5628973906250ed973f21883cfd4 Mon Sep 17 00:00:00 2001 From: Sangeeth Saravanaraj Date: Wed, 29 Apr 2015 14:44:25 +0530 Subject: Prefixed request, response and data with http. Avoided (plugin_attrib) name collision with other plugins. --- sleekxmpp/plugins/xep_0332/http.py | 56 ++++++++++++++++----------- sleekxmpp/plugins/xep_0332/stanza/__init__.py | 6 +-- sleekxmpp/plugins/xep_0332/stanza/data.py | 4 +- sleekxmpp/plugins/xep_0332/stanza/request.py | 18 ++++++--- sleekxmpp/plugins/xep_0332/stanza/response.py | 13 +++++-- 5 files changed, 59 insertions(+), 38 deletions(-) (limited to 'sleekxmpp/plugins/xep_0332') diff --git a/sleekxmpp/plugins/xep_0332/http.py b/sleekxmpp/plugins/xep_0332/http.py index 36b6995f..acaef505 100644 --- a/sleekxmpp/plugins/xep_0332/http.py +++ b/sleekxmpp/plugins/xep_0332/http.py @@ -17,7 +17,9 @@ from sleekxmpp.xmlstream.handler import Callback from sleekxmpp.xmlstream.matcher import StanzaPath from sleekxmpp.plugins.base import BasePlugin -from sleekxmpp.plugins.xep_0332.stanza import Request, Response, Data +from sleekxmpp.plugins.xep_0332.stanza import ( + HTTPRequest, HTTPResponse, HTTPData +) from sleekxmpp.plugins.xep_0131.stanza import Headers @@ -50,18 +52,26 @@ class XEP_0332(BasePlugin): } def plugin_init(self): - 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) + self.xmpp.register_handler( + Callback( + 'HTTP Request', + StanzaPath('iq/http-req'), + self._handle_request + ) + ) + self.xmpp.register_handler( + Callback( + 'HTTP Response', + StanzaPath('iq/http-resp'), + self._handle_response + ) + ) + register_stanza_plugin(Iq, HTTPRequest, iterable=True) + register_stanza_plugin(Iq, HTTPResponse, iterable=True) + register_stanza_plugin(HTTPRequest, Headers, iterable=True) + register_stanza_plugin(HTTPRequest, HTTPData, iterable=True) + register_stanza_plugin(HTTPResponse, Headers, iterable=True) + register_stanza_plugin(HTTPResponse, HTTPData, iterable=True) # TODO: Should we register any api's here? self.api.register() def plugin_end(self): @@ -94,12 +104,12 @@ class XEP_0332(BasePlugin): iq['from'] = self.xmpp.boundjid iq['to'] = to iq['type'] = 'set' - iq['req']['headers'] = headers - iq['req']['method'] = method - iq['req']['resource'] = resource - iq['req']['version'] = '1.1' # TODO: set this implicitly + iq['http-req']['headers'] = headers + iq['http-req']['method'] = method + iq['http-req']['resource'] = resource + iq['http-req']['version'] = '1.1' # TODO: set this implicitly if data is not None: - iq['req']['data'] = data + iq['http-req']['http-data'] = data return iq.send( timeout=kwargs.get('timeout', None), block=kwargs.get('block', True), @@ -113,12 +123,12 @@ class XEP_0332(BasePlugin): 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 + iq['http-resp']['headers'] = headers + iq['http-resp']['code'] = code + iq['http-resp']['message'] = message + iq['http-resp']['version'] = '1.1' # TODO: set this implicitly if data is not None: - iq['resp']['data'] = data + iq['http-resp']['http-data'] = data return iq.send( timeout=kwargs.get('timeout', None), block=kwargs.get('block', True), diff --git a/sleekxmpp/plugins/xep_0332/stanza/__init__.py b/sleekxmpp/plugins/xep_0332/stanza/__init__.py index eeab3f31..201824b7 100644 --- a/sleekxmpp/plugins/xep_0332/stanza/__init__.py +++ b/sleekxmpp/plugins/xep_0332/stanza/__init__.py @@ -8,6 +8,6 @@ See the file LICENSE for copying permission. """ -from sleekxmpp.plugins.xep_0332.stanza.request import Request -from sleekxmpp.plugins.xep_0332.stanza.response import Response -from sleekxmpp.plugins.xep_0332.stanza.data import Data +from sleekxmpp.plugins.xep_0332.stanza.request import HTTPRequest +from sleekxmpp.plugins.xep_0332.stanza.response import HTTPResponse +from sleekxmpp.plugins.xep_0332.stanza.data import HTTPData diff --git a/sleekxmpp/plugins/xep_0332/stanza/data.py b/sleekxmpp/plugins/xep_0332/stanza/data.py index 9a08426b..765536eb 100644 --- a/sleekxmpp/plugins/xep_0332/stanza/data.py +++ b/sleekxmpp/plugins/xep_0332/stanza/data.py @@ -11,14 +11,14 @@ from sleekxmpp.xmlstream import ElementBase -class Data(ElementBase): +class HTTPData(ElementBase): """ The data element. """ name = 'data' namespace = 'urn:xmpp:http' interfaces = set(['data']) - plugin_attrib = 'data' + plugin_attrib = 'http-data' is_extension = True def get_data(self, encoding='text'): diff --git a/sleekxmpp/plugins/xep_0332/stanza/request.py b/sleekxmpp/plugins/xep_0332/stanza/request.py index 07618727..9a298e57 100644 --- a/sleekxmpp/plugins/xep_0332/stanza/request.py +++ b/sleekxmpp/plugins/xep_0332/stanza/request.py @@ -11,16 +11,19 @@ from sleekxmpp.xmlstream import ElementBase -class Request(ElementBase): +class HTTPRequest(ElementBase): """ All HTTP communication is done using the `Request`/`Response` paradigm. - Each HTTP Request is made sending an `iq` stanza containing a `req` element - to the server. Each `iq` stanza sent is of type `set`. + Each HTTP Request is made sending an `iq` stanza containing a `req` + element to the server. Each `iq` stanza sent is of type `set`. Examples: - +
b.com
@@ -28,7 +31,10 @@ class Request(ElementBase):
- +
b.com
text/html
@@ -44,7 +50,7 @@ class Request(ElementBase): name = 'request' namespace = 'urn:xmpp:http' interfaces = set(['method', 'resource', 'version']) - plugin_attrib = 'req' + plugin_attrib = 'http-req' def get_method(self): return self._get_attr('method', None) diff --git a/sleekxmpp/plugins/xep_0332/stanza/response.py b/sleekxmpp/plugins/xep_0332/stanza/response.py index 0fc46de8..6804ade9 100644 --- a/sleekxmpp/plugins/xep_0332/stanza/response.py +++ b/sleekxmpp/plugins/xep_0332/stanza/response.py @@ -11,7 +11,7 @@ from sleekxmpp.xmlstream import ElementBase -class Response(ElementBase): +class HTTPResponse(ElementBase): """ When the HTTP Server responds, it does so by sending an `iq` stanza @@ -21,8 +21,13 @@ class Response(ElementBase): in which the original requests were made. Examples: - - + +
Fri, 03 May 2013 16:39:54GMT-4
Clayster
@@ -42,7 +47,7 @@ class Response(ElementBase): name = 'response' namespace = 'urn:xmpp:http' interfaces = set(['code', 'message', 'version']) - plugin_attrib = 'resp' + plugin_attrib = 'http-resp' def get_code(self): code = self._get_attr('statusCode', None) -- cgit v1.2.3 From d60a652259c74aaea4a250c542ce5ceaeb81f177 Mon Sep 17 00:00:00 2001 From: Sangeeth Saravanaraj Date: Fri, 1 May 2015 14:32:36 +0530 Subject: data need not be prefixed with http.. --- sleekxmpp/plugins/xep_0332/http.py | 4 ++-- sleekxmpp/plugins/xep_0332/stanza/data.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'sleekxmpp/plugins/xep_0332') diff --git a/sleekxmpp/plugins/xep_0332/http.py b/sleekxmpp/plugins/xep_0332/http.py index acaef505..5c1cfc0d 100644 --- a/sleekxmpp/plugins/xep_0332/http.py +++ b/sleekxmpp/plugins/xep_0332/http.py @@ -109,7 +109,7 @@ class XEP_0332(BasePlugin): iq['http-req']['resource'] = resource iq['http-req']['version'] = '1.1' # TODO: set this implicitly if data is not None: - iq['http-req']['http-data'] = data + iq['http-req']['data'] = data return iq.send( timeout=kwargs.get('timeout', None), block=kwargs.get('block', True), @@ -128,7 +128,7 @@ class XEP_0332(BasePlugin): iq['http-resp']['message'] = message iq['http-resp']['version'] = '1.1' # TODO: set this implicitly if data is not None: - iq['http-resp']['http-data'] = data + iq['http-resp']['data'] = data return iq.send( timeout=kwargs.get('timeout', None), block=kwargs.get('block', True), diff --git a/sleekxmpp/plugins/xep_0332/stanza/data.py b/sleekxmpp/plugins/xep_0332/stanza/data.py index 765536eb..a3678038 100644 --- a/sleekxmpp/plugins/xep_0332/stanza/data.py +++ b/sleekxmpp/plugins/xep_0332/stanza/data.py @@ -18,7 +18,7 @@ class HTTPData(ElementBase): name = 'data' namespace = 'urn:xmpp:http' interfaces = set(['data']) - plugin_attrib = 'http-data' + plugin_attrib = 'data' is_extension = True def get_data(self, encoding='text'): -- cgit v1.2.3 From 1345b7c1d0b3c121471034521e9028cd43569cb7 Mon Sep 17 00:00:00 2001 From: Sangeeth Saravanaraj Date: Fri, 1 May 2015 15:34:53 +0530 Subject: Misc updates for send_error() --- sleekxmpp/plugins/xep_0332/http.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sleekxmpp/plugins/xep_0332') diff --git a/sleekxmpp/plugins/xep_0332/http.py b/sleekxmpp/plugins/xep_0332/http.py index 5c1cfc0d..03d88b65 100644 --- a/sleekxmpp/plugins/xep_0332/http.py +++ b/sleekxmpp/plugins/xep_0332/http.py @@ -136,12 +136,12 @@ class XEP_0332(BasePlugin): timeout_callback=kwargs.get('timeout_callback', None) ) - def send_error(self, to=None, ecode=500, etype='wait', + 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['type'] = 'error' iq['error']['code'] = ecode iq['error']['type'] = etype iq['error']['condition'] = econd -- cgit v1.2.3 From eeab646bfa0d4787a2611f9c07514ddbb10ee441 Mon Sep 17 00:00:00 2001 From: Sangeeth Saravanaraj Date: Sat, 1 Aug 2015 17:47:03 +0530 Subject: Retaining 'id' in the response and error stanzas --- sleekxmpp/plugins/xep_0332/http.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'sleekxmpp/plugins/xep_0332') diff --git a/sleekxmpp/plugins/xep_0332/http.py b/sleekxmpp/plugins/xep_0332/http.py index 03d88b65..92e2546f 100644 --- a/sleekxmpp/plugins/xep_0332/http.py +++ b/sleekxmpp/plugins/xep_0332/http.py @@ -127,6 +127,8 @@ class XEP_0332(BasePlugin): iq['http-resp']['code'] = code iq['http-resp']['message'] = message iq['http-resp']['version'] = '1.1' # TODO: set this implicitly + if 'id' in kwargs: + iq['id'] = kwargs["id"] if data is not None: iq['http-resp']['data'] = data return iq.send( @@ -145,6 +147,8 @@ class XEP_0332(BasePlugin): iq['error']['code'] = ecode iq['error']['type'] = etype iq['error']['condition'] = econd + if 'id' in kwargs: + iq['id'] = kwargs["id"] return iq.send( timeout=kwargs.get('timeout', None), block=kwargs.get('block', True), -- cgit v1.2.3 From 18e5abb9ddc1689e7e5963cf40259a2685eed9b5 Mon Sep 17 00:00:00 2001 From: Sangeeth Saravanaraj Date: Thu, 27 Aug 2015 13:24:01 +0530 Subject: adding 'id' to self['xep_0332'].send_request() --- sleekxmpp/plugins/xep_0332/http.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sleekxmpp/plugins/xep_0332') diff --git a/sleekxmpp/plugins/xep_0332/http.py b/sleekxmpp/plugins/xep_0332/http.py index 92e2546f..70bcafa6 100644 --- a/sleekxmpp/plugins/xep_0332/http.py +++ b/sleekxmpp/plugins/xep_0332/http.py @@ -108,6 +108,8 @@ class XEP_0332(BasePlugin): iq['http-req']['method'] = method iq['http-req']['resource'] = resource iq['http-req']['version'] = '1.1' # TODO: set this implicitly + if 'id' in kwargs: + iq['id'] = kwargs["id"] if data is not None: iq['http-req']['data'] = data return iq.send( -- cgit v1.2.3