mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-28 12:57:52 +00:00
Strip None fields away
This commit is contained in:
parent
3441db17b0
commit
676f9feba8
@ -47,6 +47,15 @@ class Object:
|
||||
pass
|
||||
|
||||
|
||||
def remove_none(obj):
|
||||
if isinstance(obj, (list, tuple, set)):
|
||||
return type(obj)(remove_none(x) for x in obj if x is not None)
|
||||
elif isinstance(obj, dict):
|
||||
return type(obj)((remove_none(k), remove_none(v)) for k, v in obj.items() if k is not None and v is not None)
|
||||
else:
|
||||
return obj
|
||||
|
||||
|
||||
class Encoder(JSONEncoder):
|
||||
def default(self, o: Object):
|
||||
try:
|
||||
@ -57,7 +66,10 @@ class Encoder(JSONEncoder):
|
||||
else:
|
||||
return repr(o)
|
||||
|
||||
return OrderedDict(
|
||||
[("_", objects.get(getattr(o, "ID", None), None))]
|
||||
+ [i for i in content.items()]
|
||||
)
|
||||
if "pyrogram" in objects.get(getattr(o, "ID", "")):
|
||||
return remove_none(OrderedDict([i for i in content.items()]))
|
||||
else:
|
||||
return OrderedDict(
|
||||
[("_", objects.get(getattr(o, "ID", None), None))]
|
||||
+ [i for i in content.items()]
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user