Mercurial > libervia-backend
diff src/memory/params.py @ 1534:a5e0393a06cd
plugin ip, params: plugin IP discovery, first draft:
- a dedicated plugin now manage IP discovery, for now it uses external website, but it should implement XEP-0279 soon
- a permission is requested to user for calling an external website. Once the permission is granted (it's global), it is not asked anymore.
- the ip is discovered on demand, and cache is kept for the session.
- memory.params.getParamA has a new parameter use_default, which allow to get None when a parameter is not set, instead of the default value.
This allow to detected when we need to do the first permission request. memory.getParamA don't have this parameter.
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 29 Sep 2015 17:54:22 +0200 |
parents | fbe86b5d156f |
children | 42285d993e68 |
line wrap: on
line diff
--- a/src/memory/params.py Tue Sep 29 17:54:21 2015 +0200 +++ b/src/memory/params.py Tue Sep 29 17:54:22 2015 +0200 @@ -348,7 +348,7 @@ @param node: XML param node @param attr: name of the attribute to get (e.g.: 'value' or 'type') @param value: user defined value - @return: str + @return: value (can be str, bool, int, list, None) """ if attr == 'value': value_to_use = value if value is not None else node.getAttribute(attr) # we use value (user defined) if it exist, else we use node's default value @@ -444,7 +444,7 @@ """ Same as getParamA but for bridge: convert non string value to string """ return self.__type_to_string(self.getParamA(name, category, attr, profile_key)) - def getParamA(self, name, category, attr="value", profile_key=C.PROF_KEY_NONE): + def getParamA(self, name, category, attr="value", use_default=True, profile_key=C.PROF_KEY_NONE): """Helper method to get a specific attribute. /!\ This method would return encrypted password values, @@ -452,6 +452,8 @@ @param name: name of the parameter @param category: category of the parameter @param attr: name of the attribute (default: "value") + @parm use_default(bool): if True and attr=='value', return default value if not set + else return None if not set @param profile: owner of the param (@ALL@ for everyone) @return: attribute """ @@ -466,6 +468,8 @@ if node[0] == C.GENERAL: value = self._getParam(category, name, C.GENERAL) + if value is None and attr=='value' and not use_default: + return value return self._getAttr(node[1], attr, value) assert node[0] == C.INDIVIDUAL @@ -481,6 +485,8 @@ if attr == "value": value = self._getParam(category, name, profile=profile) + if value is None and attr=='value' and not use_default: + return value return self._getAttr(node[1], attr, value) def asyncGetStringParamA(self, name, category, attr="value", security_limit=C.NO_SECURITY_LIMIT, profile_key=C.PROF_KEY_NONE): @@ -495,7 +501,7 @@ @param category: category of the parameter @param attr: name of the attribute (default: "value") @param profile: owner of the param (@ALL@ for everyone) - @return: Deferred + @return (defer.Deferred): parameter value, with corresponding type (bool, int, list, etc) """ node = self._getParamNode(name, category) if not node: @@ -769,6 +775,7 @@ @param profile_key (str): %(doc_profile_key)s @return: a deferred None value when everything is done """ + # FIXME: setParam should accept the right type for value, not only str ! if profile_key != C.PROF_KEY_NONE: profile = self.getProfileName(profile_key) if not profile: