Mercurial > libervia-backend
comparison sat/plugins/plugin_xep_0020.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 | be6d91572633 |
children |
comparison
equal
deleted
inserted
replaced
4036:c4464d7ae97b | 4037:524856bd7b19 |
---|---|
49 | 49 |
50 class XEP_0020(object): | 50 class XEP_0020(object): |
51 def __init__(self, host): | 51 def __init__(self, host): |
52 log.info(_("Plugin XEP_0020 initialization")) | 52 log.info(_("Plugin XEP_0020 initialization")) |
53 | 53 |
54 def getHandler(self, client): | 54 def get_handler(self, client): |
55 return XEP_0020_handler() | 55 return XEP_0020_handler() |
56 | 56 |
57 def getFeatureElt(self, elt): | 57 def get_feature_elt(self, elt): |
58 """Check element's children to find feature elements | 58 """Check element's children to find feature elements |
59 | 59 |
60 @param elt(domish.Element): parent element of the feature element | 60 @param elt(domish.Element): parent element of the feature element |
61 @return: feature elements | 61 @return: feature elements |
62 @raise exceptions.NotFound: no feature element found | 62 @raise exceptions.NotFound: no feature element found |
65 feature_elt = next(elt.elements(NS_FEATURE_NEG, "feature")) | 65 feature_elt = next(elt.elements(NS_FEATURE_NEG, "feature")) |
66 except StopIteration: | 66 except StopIteration: |
67 raise exceptions.NotFound | 67 raise exceptions.NotFound |
68 return feature_elt | 68 return feature_elt |
69 | 69 |
70 def _getForm(self, elt, namespace): | 70 def _get_form(self, elt, namespace): |
71 """Return the first child data form | 71 """Return the first child data form |
72 | 72 |
73 @param elt(domish.Element): parent of the data form | 73 @param elt(domish.Element): parent of the data form |
74 @param namespace (None, unicode): form namespace or None to ignore | 74 @param namespace (None, unicode): form namespace or None to ignore |
75 @return (None, data_form.Form): data form or None is nothing is found | 75 @return (None, data_form.Form): data form or None is nothing is found |
82 else: | 82 else: |
83 return data_form.Form.fromElement(form_elt) | 83 return data_form.Form.fromElement(form_elt) |
84 else: | 84 else: |
85 return data_form.findForm(elt, namespace) | 85 return data_form.findForm(elt, namespace) |
86 | 86 |
87 def getChoosedOptions(self, feature_elt, namespace): | 87 def get_choosed_options(self, feature_elt, namespace): |
88 """Return choosed feature for feature element | 88 """Return choosed feature for feature element |
89 | 89 |
90 @param feature_elt(domish.Element): feature domish element | 90 @param feature_elt(domish.Element): feature domish element |
91 @param namespace (None, unicode): form namespace or None to ignore | 91 @param namespace (None, unicode): form namespace or None to ignore |
92 @return (dict): feature name as key, and choosed option as value | 92 @return (dict): feature name as key, and choosed option as value |
93 @raise exceptions.NotFound: not data form is found | 93 @raise exceptions.NotFound: not data form is found |
94 """ | 94 """ |
95 form = self._getForm(feature_elt, namespace) | 95 form = self._get_form(feature_elt, namespace) |
96 if form is None: | 96 if form is None: |
97 raise exceptions.NotFound | 97 raise exceptions.NotFound |
98 result = {} | 98 result = {} |
99 for field in form.fields: | 99 for field in form.fields: |
100 values = form.fields[field].values | 100 values = form.fields[field].values |
115 @param negotiable_values(iterable): acceptable values for this negotiation | 115 @param negotiable_values(iterable): acceptable values for this negotiation |
116 first corresponding value will be returned | 116 first corresponding value will be returned |
117 @param namespace (None, unicode): form namespace or None to ignore | 117 @param namespace (None, unicode): form namespace or None to ignore |
118 @raise KeyError: name is not found in data form fields | 118 @raise KeyError: name is not found in data form fields |
119 """ | 119 """ |
120 form = self._getForm(feature_elt, namespace) | 120 form = self._get_form(feature_elt, namespace) |
121 options = [option.value for option in form.fields[name].options] | 121 options = [option.value for option in form.fields[name].options] |
122 for value in negotiable_values: | 122 for value in negotiable_values: |
123 if value in options: | 123 if value in options: |
124 return value | 124 return value |
125 return None | 125 return None |
126 | 126 |
127 def chooseOption(self, options, namespace): | 127 def choose_option(self, options, namespace): |
128 """Build a feature element with choosed options | 128 """Build a feature element with choosed options |
129 | 129 |
130 @param options(dict): dict with feature as key and choosed option as value | 130 @param options(dict): dict with feature as key and choosed option as value |
131 @param namespace (None, unicode): form namespace or None to ignore | 131 @param namespace (None, unicode): form namespace or None to ignore |
132 """ | 132 """ |
134 x_form = data_form.Form("submit", formNamespace=namespace) | 134 x_form = data_form.Form("submit", formNamespace=namespace) |
135 x_form.makeFields(options) | 135 x_form.makeFields(options) |
136 feature_elt.addChild(x_form.toElement()) | 136 feature_elt.addChild(x_form.toElement()) |
137 return feature_elt | 137 return feature_elt |
138 | 138 |
139 def proposeFeatures(self, options_dict, namespace): | 139 def propose_features(self, options_dict, namespace): |
140 """Build a feature element with options to propose | 140 """Build a feature element with options to propose |
141 | 141 |
142 @param options_dict(dict): dict with feature as key and iterable of acceptable options as value | 142 @param options_dict(dict): dict with feature as key and iterable of acceptable options as value |
143 @param namespace(None, unicode): feature namespace | 143 @param namespace(None, unicode): feature namespace |
144 """ | 144 """ |