Mercurial > libervia-backend
comparison sat/tools/common/uri.py @ 4037:524856bd7b19
massive refactoring to switch from camelCase to snake_case:
historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a
pre-PEP8 code, to use the same coding style as in Twisted.
However, snake_case is more readable and it's better to follow PEP8 best practices, so it
has been decided to move on full snake_case. Because Libervia has a huge codebase, this
ended with a ugly mix of camelCase and snake_case.
To fix that, this patch does a big refactoring by renaming every function and method
(including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case.
This is a massive change, and may result in some bugs.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 08 Apr 2023 13:54:42 +0200 |
parents | 67fc066ed2cd |
children |
comparison
equal
deleted
inserted
replaced
4036:c4464d7ae97b | 4037:524856bd7b19 |
---|---|
25 import urllib.request, urllib.parse, urllib.error | 25 import urllib.request, urllib.parse, urllib.error |
26 | 26 |
27 # FIXME: basic implementation, need to follow RFC 5122 | 27 # FIXME: basic implementation, need to follow RFC 5122 |
28 | 28 |
29 | 29 |
30 def parseXMPPUri(uri): | 30 def parse_xmpp_uri(uri): |
31 """Parse an XMPP uri and return a dict with various information | 31 """Parse an XMPP uri and return a dict with various information |
32 | 32 |
33 @param uri(unicode): uri to parse | 33 @param uri(unicode): uri to parse |
34 @return dict(unicode, unicode): data depending of the URI where key can be: | 34 @return dict(unicode, unicode): data depending of the URI where key can be: |
35 type: one of ("pubsub", TODO) | 35 type: one of ("pubsub", TODO) |
85 data["sub_type"] = "microblog" | 85 data["sub_type"] = "microblog" |
86 | 86 |
87 return data | 87 return data |
88 | 88 |
89 | 89 |
90 def addPairs(uri, pairs): | 90 def add_pairs(uri, pairs): |
91 for k, v in pairs.items(): | 91 for k, v in pairs.items(): |
92 uri.append( | 92 uri.append( |
93 ";" | 93 ";" |
94 + urllib.parse.quote_plus(k.encode("utf-8")) | 94 + urllib.parse.quote_plus(k.encode("utf-8")) |
95 + "=" | 95 + "=" |
96 + urllib.parse.quote_plus(v.encode("utf-8")) | 96 + urllib.parse.quote_plus(v.encode("utf-8")) |
97 ) | 97 ) |
98 | 98 |
99 | 99 |
100 def buildXMPPUri(type_: Optional[str] = None, **kwargs: str) -> str: | 100 def build_xmpp_uri(type_: Optional[str] = None, **kwargs: str) -> str: |
101 uri = ["xmpp:"] | 101 uri = ["xmpp:"] |
102 subtype = kwargs.pop("subtype", None) | 102 subtype = kwargs.pop("subtype", None) |
103 path = kwargs.pop("path") | 103 path = kwargs.pop("path") |
104 uri.append(urllib.parse.quote_plus(path.encode("utf-8")).replace("%40", "@")) | 104 uri.append(urllib.parse.quote_plus(path.encode("utf-8")).replace("%40", "@")) |
105 | 105 |
112 elif type_ == "pubsub": | 112 elif type_ == "pubsub": |
113 if subtype == "microblog" and not kwargs.get("node"): | 113 if subtype == "microblog" and not kwargs.get("node"): |
114 kwargs["node"] = "urn:xmpp:microblog:0" | 114 kwargs["node"] = "urn:xmpp:microblog:0" |
115 if kwargs: | 115 if kwargs: |
116 uri.append("?") | 116 uri.append("?") |
117 addPairs(uri, kwargs) | 117 add_pairs(uri, kwargs) |
118 else: | 118 else: |
119 raise NotImplementedError("{type_} URI are not handled yet".format(type_=type_)) | 119 raise NotImplementedError("{type_} URI are not handled yet".format(type_=type_)) |
120 | 120 |
121 return "".join(uri) | 121 return "".join(uri) |