Mercurial > libervia-backend
comparison sat/plugins/plugin_xep_0297.py @ 3028:ab2696e34d29
Python 3 port:
/!\ this is a huge commit
/!\ starting from this commit, SàT is needs Python 3.6+
/!\ SàT maybe be instable or some feature may not work anymore, this will improve with time
This patch port backend, bridge and frontends to Python 3.
Roughly this has been done this way:
- 2to3 tools has been applied (with python 3.7)
- all references to python2 have been replaced with python3 (notably shebangs)
- fixed files not handled by 2to3 (notably the shell script)
- several manual fixes
- fixed issues reported by Python 3 that where not handled in Python 2
- replaced "async" with "async_" when needed (it's a reserved word from Python 3.7)
- replaced zope's "implements" with @implementer decorator
- temporary hack to handle data pickled in database, as str or bytes may be returned,
to be checked later
- fixed hash comparison for password
- removed some code which is not needed anymore with Python 3
- deactivated some code which needs to be checked (notably certificate validation)
- tested with jp, fixed reported issues until some basic commands worked
- ported Primitivus (after porting dependencies like urwid satext)
- more manual fixes
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 13 Aug 2019 19:08:41 +0200 |
parents | 003b8b4b56a7 |
children | 9d0df638c8b4 |
comparison
equal
deleted
inserted
replaced
3027:ff5bcb12ae60 | 3028:ab2696e34d29 |
---|---|
1 #!/usr/bin/env python2 | 1 #!/usr/bin/env python3 |
2 # -*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
3 | 3 |
4 # SAT plugin for Stanza Forwarding (XEP-0297) | 4 # SAT plugin for Stanza Forwarding (XEP-0297) |
5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) | 5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) |
6 # Copyright (C) 2013-2016 Adrien Cossa (souliane@mailoo.org) | 6 # Copyright (C) 2013-2016 Adrien Cossa (souliane@mailoo.org) |
28 | 28 |
29 try: | 29 try: |
30 from twisted.words.protocols.xmlstream import XMPPHandler | 30 from twisted.words.protocols.xmlstream import XMPPHandler |
31 except ImportError: | 31 except ImportError: |
32 from wokkel.subprotocols import XMPPHandler | 32 from wokkel.subprotocols import XMPPHandler |
33 from zope.interface import implements | 33 from zope.interface import implementer |
34 | 34 |
35 from twisted.words.xish import domish | 35 from twisted.words.xish import domish |
36 | 36 |
37 PLUGIN_INFO = { | 37 PLUGIN_INFO = { |
38 C.PI_NAME: u"Stanza Forwarding", | 38 C.PI_NAME: "Stanza Forwarding", |
39 C.PI_IMPORT_NAME: u"XEP-0297", | 39 C.PI_IMPORT_NAME: "XEP-0297", |
40 C.PI_TYPE: u"XEP", | 40 C.PI_TYPE: "XEP", |
41 C.PI_PROTOCOLS: [u"XEP-0297"], | 41 C.PI_PROTOCOLS: ["XEP-0297"], |
42 C.PI_MAIN: "XEP_0297", | 42 C.PI_MAIN: "XEP_0297", |
43 C.PI_HANDLER: u"yes", | 43 C.PI_HANDLER: "yes", |
44 C.PI_DESCRIPTION: D_(u"""Implementation of Stanza Forwarding"""), | 44 C.PI_DESCRIPTION: D_("""Implementation of Stanza Forwarding"""), |
45 } | 45 } |
46 | 46 |
47 | 47 |
48 class XEP_0297(object): | 48 class XEP_0297(object): |
49 # FIXME: check this implementation which doesn't seems to be used | 49 # FIXME: check this implementation which doesn't seems to be used |
50 | 50 |
51 def __init__(self, host): | 51 def __init__(self, host): |
52 log.info(_(u"Stanza Forwarding plugin initialization")) | 52 log.info(_("Stanza Forwarding plugin initialization")) |
53 self.host = host | 53 self.host = host |
54 | 54 |
55 def getHandler(self, client): | 55 def getHandler(self, client): |
56 return XEP_0297_handler(self, client.profile) | 56 return XEP_0297_handler(self, client.profile) |
57 | 57 |
81 @return: a Deferred when the message has been sent | 81 @return: a Deferred when the message has been sent |
82 """ | 82 """ |
83 # FIXME: this method is not used and doesn't use mess_data which should be used for client.sendMessageData | 83 # FIXME: this method is not used and doesn't use mess_data which should be used for client.sendMessageData |
84 # should it be deprecated? A method constructing the element without sending it seems more natural | 84 # should it be deprecated? A method constructing the element without sending it seems more natural |
85 log.warning( | 85 log.warning( |
86 u"THIS METHOD IS DEPRECATED" | 86 "THIS METHOD IS DEPRECATED" |
87 ) # FIXME: we use this warning until we check the method | 87 ) # FIXME: we use this warning until we check the method |
88 msg = domish.Element((None, "message")) | 88 msg = domish.Element((None, "message")) |
89 msg["to"] = to_jid.full() | 89 msg["to"] = to_jid.full() |
90 msg["type"] = stanza["type"] | 90 msg["type"] = stanza["type"] |
91 | 91 |
102 | 102 |
103 msg.addChild(body_elt) | 103 msg.addChild(body_elt) |
104 msg.addChild(forwarded_elt) | 104 msg.addChild(forwarded_elt) |
105 | 105 |
106 client = self.host.getClient(profile_key) | 106 client = self.host.getClient(profile_key) |
107 return client.sendMessageData({u"xml": msg}) | 107 return client.sendMessageData({"xml": msg}) |
108 | 108 |
109 | 109 |
110 @implementer(iwokkel.IDisco) | |
110 class XEP_0297_handler(XMPPHandler): | 111 class XEP_0297_handler(XMPPHandler): |
111 implements(iwokkel.IDisco) | |
112 | 112 |
113 def __init__(self, plugin_parent, profile): | 113 def __init__(self, plugin_parent, profile): |
114 self.plugin_parent = plugin_parent | 114 self.plugin_parent = plugin_parent |
115 self.host = plugin_parent.host | 115 self.host = plugin_parent.host |
116 self.profile = profile | 116 self.profile = profile |