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.
This commit is contained in:
parent
5cee4fbab7
commit
76aadbb3fb
1 changed files with 3299 additions and 3300 deletions
|
|
@ -529,17 +529,18 @@ class Params(object):
|
|||
|
||||
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 @@ class Params(object):
|
|||
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 @@ class Params(object):
|
|||
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 @@ class Params(object):
|
|||
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 @@ class Params(object):
|
|||
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")
|
||||
|
|
|
|||
Loading…
Reference in a new issue