Mercurial > libervia-backend
annotate sat/plugins/plugin_xep_0447.py @ 3897:4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
rel 379
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 21 Sep 2022 22:28:20 +0200 |
parents | |
children | 0ff265725489 |
rev | line source |
---|---|
3897
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 # Copyright (C) 2009-2022 Jérôme Poisson (goffi@goffi.org) |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 # This program is free software: you can redistribute it and/or modify |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 # it under the terms of the GNU Affero General Public License as published by |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # the Free Software Foundation, either version 3 of the License, or |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # (at your option) any later version. |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 # This program is distributed in the hope that it will be useful, |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # GNU Affero General Public License for more details. |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 # You should have received a copy of the GNU Affero General Public License |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 from typing import Optional, Dict, List, Tuple, Union, Any |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 from twisted.words.xish import domish |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from sat.core.constants import Const as C |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from sat.core.i18n import _ |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from sat.core.log import getLogger |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from sat.core import exceptions |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 log = getLogger(__name__) |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 PLUGIN_INFO = { |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 C.PI_NAME: "Stateless File Sharing", |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 C.PI_IMPORT_NAME: "XEP-0447", |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 C.PI_TYPE: "XEP", |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 C.PI_MODES: C.PLUG_MODE_BOTH, |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 C.PI_PROTOCOLS: ["XEP-0447"], |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 C.PI_DEPENDENCIES: ["XEP-0103", "XEP-0446"], |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 C.PI_MAIN: "XEP_0447", |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 C.PI_HANDLER: "no", |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 C.PI_DESCRIPTION: _("""Implementation of XEP-0447 (Stateless File Sharing)"""), |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 } |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 NS_SFS = "urn:xmpp:sfs:0" |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 class XEP_0447: |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 namespace = NS_SFS |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 def __init__(self, host): |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 log.info(_("XEP-0447 (Stateless File Sharing) plugin initialization")) |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 host.registerNamespace("sfs", NS_SFS) |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 self._u = host.plugins["XEP-0103"] |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 self._m = host.plugins["XEP-0446"] |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 def get_file_sharing_elt( |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 self, |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 sources: List[Dict[str, Any]], |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 disposition: Optional[str] = None, |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 name: Optional[str] = None, |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 media_type: Optional[str] = None, |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 desc: Optional[str] = None, |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 size: Optional[int] = None, |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 file_hash: Optional[Tuple[str, str]] = None, |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 date: Optional[Union[float, int]] = None, |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 width: Optional[int] = None, |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 height: Optional[int] = None, |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 length: Optional[int] = None, |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 thumbnail: Optional[str] = None, |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 **kwargs, |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 ) -> domish.Element: |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 """Generate the <file-sharing/> element |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 @param extra: extra metadata describing how to access the URL |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 @return: ``<sfs/>`` element |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 """ |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 file_sharing_elt = domish.Element((NS_SFS, "file-sharing")) |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 if disposition is not None: |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 file_sharing_elt["disposition"] = disposition |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 file_sharing_elt.addChild( |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 self._m.get_file_metadata_elt( |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 name=name, |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 media_type=media_type, |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 desc=desc, |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 size=size, |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 file_hash=file_hash, |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 date=date, |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 width=width, |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 height=height, |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 length=length, |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 thumbnail=thumbnail, |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 ) |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 ) |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 sources_elt = file_sharing_elt.addElement("sources") |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 for source_data in sources: |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 if "url" in source_data: |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 sources_elt.addChild( |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 self._u.get_url_data_elt(**source_data) |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 ) |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 else: |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 raise NotImplementedError( |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 f"source data not implemented: {source_data}" |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 ) |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 return file_sharing_elt |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 def parse_file_sharing_elt( |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 self, |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 file_sharing_elt: domish.Element |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 ) -> Dict[str, Any]: |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 """Parse <file-sharing/> element and return file-sharing data |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 @param file_sharing_elt: <file-sharing/> element |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 @return: file-sharing data. It a dict whose keys correspond to |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 [get_file_sharing_elt] parameters |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 """ |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 if file_sharing_elt.name != "file-sharing": |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 try: |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 file_sharing_elt = next( |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 file_sharing_elt.elements(NS_SFS, "file-sharing") |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 ) |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 except StopIteration: |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 raise exceptions.NotFound |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 try: |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 data = self._m.parse_file_metadata_elt(file_sharing_elt) |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 except exceptions.NotFound: |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 data = {} |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 disposition = file_sharing_elt.getAttribute("disposition") |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 if disposition is not None: |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 data["disposition"] = disposition |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 sources = data["sources"] = [] |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 try: |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 sources_elt = next(file_sharing_elt.elements(NS_SFS, "sources")) |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 except StopIteration: |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 raise ValueError(f"<sources/> element is missing: {file_sharing_elt.toXml()}") |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 for elt in sources_elt.elements(): |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 if elt.name == "url-data" and elt.uri == self._u.namespace: |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 source_data = self._u.parse_url_data_elt(elt) |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 else: |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 log.warning(f"unmanaged file sharing element: {elt.toXml}") |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 continue |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 sources.append(source_data) |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 |
4b7106eede0c
plugin XEP-0447: Stateless File Sharing implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 return data |