Mercurial > libervia-backend
comparison sat/plugins/plugin_xep_0359.py @ 3103:f0f48b4deb35
plugin XEP-0359: handle origin-id
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 30 Dec 2019 20:44:05 +0100 |
parents | ab2696e34d29 |
children | 9d0df638c8b4 |
comparison
equal
deleted
inserted
replaced
3102:7574f795bd1e | 3103:f0f48b4deb35 |
---|---|
16 # GNU Affero General Public License for more details. | 16 # GNU Affero General Public License for more details. |
17 | 17 |
18 # You should have received a copy of the GNU Affero General Public License | 18 # You should have received a copy of the GNU Affero General Public License |
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 import uuid | |
22 from zope.interface import implementer | |
23 from twisted.words.protocols.jabber import xmlstream | |
24 from wokkel import disco | |
21 from sat.core.constants import Const as C | 25 from sat.core.constants import Const as C |
22 from sat.core import exceptions | 26 from sat.core import exceptions |
23 from sat.core.i18n import _ | 27 from sat.core.i18n import _ |
24 from sat.core.log import getLogger | 28 from sat.core.log import getLogger |
25 from twisted.words.protocols.jabber import xmlstream | |
26 from zope.interface import implementer | |
27 from wokkel import disco | |
28 | 29 |
29 log = getLogger(__name__) | 30 log = getLogger(__name__) |
30 | 31 |
31 | 32 |
32 PLUGIN_INFO = { | 33 PLUGIN_INFO = { |
86 """ | 87 """ |
87 sid_elt = element.addElement((NS_SID, "stanza-id")) | 88 sid_elt = element.addElement((NS_SID, "stanza-id")) |
88 sid_elt["by"] = client.jid.userhost() if by is None else by.userhost() | 89 sid_elt["by"] = client.jid.userhost() if by is None else by.userhost() |
89 sid_elt["id"] = stanza_id | 90 sid_elt["id"] = stanza_id |
90 | 91 |
92 def getOriginId(self, element): | |
93 """Return origin-id if found in element | |
94 | |
95 @param element(domish.Element): element to parse | |
96 @return (unicode, None): origin-id if found | |
97 """ | |
98 try: | |
99 origin_elt = next(element.elements(NS_SID, "origin-id")) | |
100 except StopIteration: | |
101 return None | |
102 else: | |
103 return origin_elt.getAttribute("id") | |
104 | |
105 def addOriginId(self, element, origin_id=None): | |
106 """Add a <origin-id/> to a stanza | |
107 | |
108 @param element(domish.Element): stanza where the <origin-id/> must be added | |
109 @param origin_id(str): id to use, None to automatically generate | |
110 @return (str): origin_id | |
111 """ | |
112 if origin_id is None: | |
113 origin_id = str(uuid.uuid4()) | |
114 sid_elt = element.addElement((NS_SID, "origin-id")) | |
115 sid_elt["id"] = origin_id | |
116 return origin_id | |
117 | |
91 def getHandler(self, client): | 118 def getHandler(self, client): |
92 return XEP_0359_handler() | 119 return XEP_0359_handler() |
93 | 120 |
94 | 121 |
95 @implementer(disco.IDisco) | 122 @implementer(disco.IDisco) |