Mercurial > libervia-backend
diff sat/memory/params.py @ 3040:fee60f17ebac
jp: jp asyncio port:
/!\ this commit is huge. Jp is temporarily not working with `dbus` bridge /!\
This patch implements the port of jp to asyncio, so it is now correctly using the bridge
asynchronously, and it can be used with bridges like `pb`. This also simplify the code,
notably for things which were previously implemented with many callbacks (like pagination
with RSM).
During the process, some behaviours have been modified/fixed, in jp and backends, check
diff for details.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 25 Sep 2019 08:56:41 +0200 |
parents | ab2696e34d29 |
children | eec0c25c796b |
line wrap: on
line diff
--- a/sat/memory/params.py Wed Sep 25 08:53:38 2019 +0200 +++ b/sat/memory/params.py Wed Sep 25 08:56:41 2019 +0200 @@ -529,17 +529,18 @@ return d.addCallback(gotPlainPassword) - def __type_to_string(self, result): - """ convert result to string, according to its type """ + def _type_to_str(self, result): + """Convert result to string, according to its type """ if isinstance(result, bool): - return "true" if result else "false" - elif isinstance(result, int): + return C.boolConst(result) + elif isinstance(result, (list, set, tuple)): + return ', '.join(self._type_to_str(r) for r in result) + else: return str(result) - return result def getStringParamA(self, name, category, attr="value", profile_key=C.PROF_KEY_NONE): """ Same as getParamA but for bridge: convert non string value to string """ - return self.__type_to_string( + return self._type_to_str( self.getParamA(name, category, attr, profile_key=profile_key) ) @@ -599,15 +600,10 @@ 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, - ): + self, name, category, attr="value", security_limit=C.NO_SECURITY_LIMIT, + profile_key=C.PROF_KEY_NONE): d = self.asyncGetParamA(name, category, attr, security_limit, profile_key) - d.addCallback(self.__type_to_string) + d.addCallback(self._type_to_str) return d def asyncGetParamA( @@ -957,14 +953,8 @@ categories.append(cat.getAttribute("name")) return categories - def setParam( - self, - name, - value, - category, - security_limit=C.NO_SECURITY_LIMIT, - profile_key=C.PROF_KEY_NONE, - ): + def setParam(self, name, value, category, security_limit=C.NO_SECURITY_LIMIT, + profile_key=C.PROF_KEY_NONE): """Set a parameter, return None if the parameter is not in param xml. Parameter of type 'password' that are not the SàT profile password are @@ -994,13 +984,11 @@ return defer.succeed(None) if not self.checkSecurityLimit(node[1], security_limit): - log.warning( - _( - "Trying to set parameter '%(param)s' in category '%(cat)s' without authorization!!!" - % {"param": name, "cat": category} - ) - ) - return defer.succeed(None) + msg = _( + f"{profile!r} is trying to set parameter {name!r} in category " + f"{category!r} without authorization!!!") + log.warning(msg) + raise exceptions.PermissionError(msg) type_ = node[1].getAttribute("type") if type_ == "int": @@ -1010,12 +998,10 @@ try: int(value) except ValueError: - log.debug( - _( - "Trying to set parameter '%(param)s' in category '%(cat)s' with an non-integer value" - % {"param": name, "cat": category} - ) - ) + log.warning(_( + f"Trying to set parameter {name!r} in category {category!r} with" + f"an non-integer value" + )) return defer.succeed(None) if node[1].hasAttribute("constraint"): constraint = node[1].getAttribute("constraint")