Mercurial > libervia-backend
comparison sat/plugins/plugin_xep_0297.py @ 2624:56f94936df1e
code style reformatting using black
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 27 Jun 2018 20:14:46 +0200 |
parents | 26edcf3a30eb |
children | 5060cbeec01e |
comparison
equal
deleted
inserted
replaced
2623:49533de4540b | 2624:56f94936df1e |
---|---|
19 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 19 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | 20 |
21 from sat.core.constants import Const as C | 21 from sat.core.constants import Const as C |
22 from sat.core.i18n import _, D_ | 22 from sat.core.i18n import _, D_ |
23 from sat.core.log import getLogger | 23 from sat.core.log import getLogger |
24 | |
24 log = getLogger(__name__) | 25 log = getLogger(__name__) |
25 | 26 |
26 from wokkel import disco, iwokkel | 27 from wokkel import disco, iwokkel |
28 | |
27 try: | 29 try: |
28 from twisted.words.protocols.xmlstream import XMPPHandler | 30 from twisted.words.protocols.xmlstream import XMPPHandler |
29 except ImportError: | 31 except ImportError: |
30 from wokkel.subprotocols import XMPPHandler | 32 from wokkel.subprotocols import XMPPHandler |
31 from zope.interface import implements | 33 from zope.interface import implements |
39 C.PI_IMPORT_NAME: u"XEP-0297", | 41 C.PI_IMPORT_NAME: u"XEP-0297", |
40 C.PI_TYPE: u"XEP", | 42 C.PI_TYPE: u"XEP", |
41 C.PI_PROTOCOLS: [u"XEP-0297"], | 43 C.PI_PROTOCOLS: [u"XEP-0297"], |
42 C.PI_MAIN: "XEP_0297", | 44 C.PI_MAIN: "XEP_0297", |
43 C.PI_HANDLER: u"yes", | 45 C.PI_HANDLER: u"yes", |
44 C.PI_DESCRIPTION: D_(u"""Implementation of Stanza Forwarding""") | 46 C.PI_DESCRIPTION: D_(u"""Implementation of Stanza Forwarding"""), |
45 } | 47 } |
46 | 48 |
47 | 49 |
48 class XEP_0297(object): | 50 class XEP_0297(object): |
49 # FIXME: check this implementation which doesn't seems to be used | 51 # FIXME: check this implementation which doesn't seems to be used |
68 element.defaultUri = uri | 70 element.defaultUri = uri |
69 for child in element.children: | 71 for child in element.children: |
70 if isinstance(child, domish.Element) and not child.uri: | 72 if isinstance(child, domish.Element) and not child.uri: |
71 XEP_0297.updateUri(child, uri) | 73 XEP_0297.updateUri(child, uri) |
72 | 74 |
73 def forward(self, stanza, to_jid, stamp, body='', profile_key=C.PROF_KEY_NONE): | 75 def forward(self, stanza, to_jid, stamp, body="", profile_key=C.PROF_KEY_NONE): |
74 """Forward a message to the given JID. | 76 """Forward a message to the given JID. |
75 | 77 |
76 @param stanza (domish.Element): original stanza to be forwarded. | 78 @param stanza (domish.Element): original stanza to be forwarded. |
77 @param to_jid (JID): recipient JID. | 79 @param to_jid (JID): recipient JID. |
78 @param stamp (datetime): offset-aware timestamp of the original reception. | 80 @param stamp (datetime): offset-aware timestamp of the original reception. |
80 @param profile_key (unicode): %(doc_profile_key)s | 82 @param profile_key (unicode): %(doc_profile_key)s |
81 @return: a Deferred when the message has been sent | 83 @return: a Deferred when the message has been sent |
82 """ | 84 """ |
83 # FIXME: this method is not used and doesn't use mess_data which should be used for client.sendMessageData | 85 # 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 | 86 # should it be deprecated? A method constructing the element without sending it seems more natural |
85 log.warning(u"THIS METHOD IS DEPRECATED") # FIXME: we use this warning until we check the method | 87 log.warning( |
86 msg = domish.Element((None, 'message')) | 88 u"THIS METHOD IS DEPRECATED" |
87 msg['to'] = to_jid.full() | 89 ) # FIXME: we use this warning until we check the method |
88 msg['type'] = stanza['type'] | 90 msg = domish.Element((None, "message")) |
91 msg["to"] = to_jid.full() | |
92 msg["type"] = stanza["type"] | |
89 | 93 |
90 body_elt = domish.Element((None, 'body')) | 94 body_elt = domish.Element((None, "body")) |
91 if body: | 95 if body: |
92 body_elt.addContent(body) | 96 body_elt.addContent(body) |
93 | 97 |
94 forwarded_elt = domish.Element((NS_SF, 'forwarded')) | 98 forwarded_elt = domish.Element((NS_SF, "forwarded")) |
95 delay_elt = self.host.plugins['XEP-0203'].delay(stamp) | 99 delay_elt = self.host.plugins["XEP-0203"].delay(stamp) |
96 forwarded_elt.addChild(delay_elt) | 100 forwarded_elt.addChild(delay_elt) |
97 if not stanza.uri: # None or '' | 101 if not stanza.uri: # None or '' |
98 XEP_0297.updateUri(stanza, 'jabber:client') | 102 XEP_0297.updateUri(stanza, "jabber:client") |
99 forwarded_elt.addChild(stanza) | 103 forwarded_elt.addChild(stanza) |
100 | 104 |
101 msg.addChild(body_elt) | 105 msg.addChild(body_elt) |
102 msg.addChild(forwarded_elt) | 106 msg.addChild(forwarded_elt) |
103 | 107 |
104 client = self.host.getClient(profile_key) | 108 client = self.host.getClient(profile_key) |
105 return client.sendMessageData({u'xml': msg}) | 109 return client.sendMessageData({u"xml": msg}) |
106 | 110 |
107 | 111 |
108 class XEP_0297_handler(XMPPHandler): | 112 class XEP_0297_handler(XMPPHandler): |
109 implements(iwokkel.IDisco) | 113 implements(iwokkel.IDisco) |
110 | 114 |
111 def __init__(self, plugin_parent, profile): | 115 def __init__(self, plugin_parent, profile): |
112 self.plugin_parent = plugin_parent | 116 self.plugin_parent = plugin_parent |
113 self.host = plugin_parent.host | 117 self.host = plugin_parent.host |
114 self.profile = profile | 118 self.profile = profile |
115 | 119 |
116 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): | 120 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): |
117 return [disco.DiscoFeature(NS_SF)] | 121 return [disco.DiscoFeature(NS_SF)] |
118 | 122 |
119 def getDiscoItems(self, requestor, target, nodeIdentifier=''): | 123 def getDiscoItems(self, requestor, target, nodeIdentifier=""): |
120 return [] | 124 return [] |