Mercurial > libervia-backend
comparison libervia/backend/plugins/plugin_xep_0103.py @ 4270:0d7bb4df2343
Reformatted code base using black.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 19 Jun 2024 18:44:57 +0200 |
parents | 4b842c1fb686 |
children |
comparison
equal
deleted
inserted
replaced
4269:64a85ce8be70 | 4270:0d7bb4df2343 |
---|---|
46 | 46 |
47 def __init__(self, host): | 47 def __init__(self, host): |
48 log.info(_("XEP-0103 (URL Address Information) plugin initialization")) | 48 log.info(_("XEP-0103 (URL Address Information) plugin initialization")) |
49 host.register_namespace("url-data", NS_URL_DATA) | 49 host.register_namespace("url-data", NS_URL_DATA) |
50 | 50 |
51 def get_url_data_elt( | 51 def get_url_data_elt(self, url: str, **kwargs) -> domish.Element: |
52 self, | |
53 url: str, | |
54 **kwargs | |
55 ) -> domish.Element: | |
56 """Generate the element describing the URL | 52 """Generate the element describing the URL |
57 | 53 |
58 @param url: URL to use | 54 @param url: URL to use |
59 @param extra: extra metadata describing how to access the URL | 55 @param extra: extra metadata describing how to access the URL |
60 @return: ``<url-data/>`` element | 56 @return: ``<url-data/>`` element |
61 """ | 57 """ |
62 url_data_elt = domish.Element((NS_URL_DATA, "url-data")) | 58 url_data_elt = domish.Element((NS_URL_DATA, "url-data")) |
63 url_data_elt["target"] = url | 59 url_data_elt["target"] = url |
64 return url_data_elt | 60 return url_data_elt |
65 | 61 |
66 def parse_url_data_elt( | 62 def parse_url_data_elt(self, url_data_elt: domish.Element) -> Dict[str, Any]: |
67 self, | |
68 url_data_elt: domish.Element | |
69 ) -> Dict[str, Any]: | |
70 """Parse <url-data/> element | 63 """Parse <url-data/> element |
71 | 64 |
72 @param url_data_elt: <url-data/> element | 65 @param url_data_elt: <url-data/> element |
73 a parent element can also be used | 66 a parent element can also be used |
74 @return: url-data data. It's a dict whose keys correspond to | 67 @return: url-data data. It's a dict whose keys correspond to |
75 [get_url_data_elt] parameters | 68 [get_url_data_elt] parameters |
76 @raise exceptions.NotFound: no <url-data/> element has been found | 69 @raise exceptions.NotFound: no <url-data/> element has been found |
77 """ | 70 """ |
78 if url_data_elt.name != "url-data": | 71 if url_data_elt.name != "url-data": |
79 try: | 72 try: |
80 url_data_elt = next( | 73 url_data_elt = next(url_data_elt.elements(NS_URL_DATA, "url-data")) |
81 url_data_elt.elements(NS_URL_DATA, "url-data") | |
82 ) | |
83 except StopIteration: | 74 except StopIteration: |
84 raise exceptions.NotFound | 75 raise exceptions.NotFound |
85 try: | 76 try: |
86 data: Dict[str, Any] = {"url": url_data_elt["target"]} | 77 data: Dict[str, Any] = {"url": url_data_elt["target"]} |
87 except KeyError: | 78 except KeyError: |