Some .Net compatibility

This commit is contained in:
Fabian Dill
2021-03-19 04:14:59 +01:00
parent bbe51c4cc7
commit 218fb0298f
2 changed files with 15 additions and 3 deletions

View File

@@ -61,12 +61,23 @@ _encode = JSONEncoder(
def encode(obj):
return _encode(_scan_for_TypedTuples(obj))
def get_any_version(data: dict) -> Version:
data = {key.lower(): value for key, value in data.items()} # .NET version classes have capitalized keys
return Version(int(data["major"]), int(data["minor"]), int(data["build"]))
whitelist = {"NetworkPlayer": NetworkPlayer,
"NetworkItem": NetworkItem,
"Version": Version}
}
custom_hooks = {
"Version": get_any_version
}
def _object_hook(o: typing.Any) -> typing.Any:
if isinstance(o, dict):
hook = custom_hooks.get(o.get("class", None), None)
if hook:
return hook(o)
cls = whitelist.get(o.get("class", None), None)
if cls:
for key in tuple(o):