first commit

This commit is contained in:
2020-11-03 18:30:14 -08:00
commit 31d8522470
1881 changed files with 345408 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
from typing import ByteString, Dict, Iterable, Mapping, Text
def decode_dict(data: Dict[bytes, bytes]) -> Dict[str, str]:
"""
Recursively decode all byte-strings found in a dictionary
"""
ret = {}
for key, value in data.items():
if isinstance(key, ByteString):
key = key.decode()
if isinstance(value, (Mapping, Dict)):
ret[key] = decode_dict(value)
elif isinstance(value, ByteString):
ret[key] = value.decode()
elif isinstance(value, Iterable) and not isinstance(value, Text):
ret[key] = value.__new__(
x.decode() if isinstance(x, ByteString) else x for x in value
)
else:
ret[key] = value
return ret