mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2026-11-02 20:30:26 -06:00
LGTM: Membership test with a non-container
Silence false positive by using isinstance(value, dict). Also clean up and optimize most common cases. https://pagure.io/freeipa/issue/7344 Signed-off-by: Christian Heimes <cheimes@redhat.com> Reviewed-By: Fraser Tweedale <ftweedal@redhat.com>
This commit is contained in:
1 parent
a4f36eec0a
commit
d3f43a6737
1 file changed
+12
-8
+12
-8
@@ -223,25 +223,29 @@ def xml_unwrap(value, encoding='UTF-8'):
|
||||
:param value: The value to unwrap.
|
||||
:param encoding: The Unicode encoding to use (defaults to ``'UTF-8'``).
|
||||
"""
|
||||
if type(value) in (list, tuple):
|
||||
if isinstance(value, (unicode, int, float, bool)):
|
||||
# most common first
|
||||
return value
|
||||
elif value is None:
|
||||
return value
|
||||
elif isinstance(value, bytes):
|
||||
return value.decode(encoding)
|
||||
elif isinstance(value, (list, tuple)):
|
||||
return tuple(xml_unwrap(v, encoding) for v in value)
|
||||
if type(value) is dict:
|
||||
elif isinstance(value, dict):
|
||||
if '__dns_name__' in value:
|
||||
return DNSName(value['__dns_name__'])
|
||||
else:
|
||||
return dict(
|
||||
(k, xml_unwrap(v, encoding)) for (k, v) in value.items()
|
||||
)
|
||||
if isinstance(value, bytes):
|
||||
return value.decode(encoding)
|
||||
if isinstance(value, Binary):
|
||||
elif isinstance(value, Binary):
|
||||
assert type(value.data) is bytes
|
||||
return value.data
|
||||
if isinstance(value, DateTime):
|
||||
elif isinstance(value, DateTime):
|
||||
# xmlprc DateTime is converted to string of %Y%m%dT%H:%M:%S format
|
||||
return datetime.datetime.strptime(str(value), "%Y%m%dT%H:%M:%S")
|
||||
assert type(value) in (unicode, int, float, bool, type(None))
|
||||
return value
|
||||
raise TypeError(value)
|
||||
|
||||
|
||||
def xml_dumps(params, version, methodname=None, methodresponse=False,
|
||||
|
||||
Reference in new issue
Block a user