mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-29 13:27:47 +00:00
Small fixed to PyrogramType
This commit is contained in:
parent
d62bc1d8ba
commit
cffafa8c61
@ -24,6 +24,9 @@ class PyrogramType:
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return dumps(self, cls=Encoder, indent=4)
|
return dumps(self, cls=Encoder, indent=4)
|
||||||
|
|
||||||
|
def __getitem__(self, item):
|
||||||
|
return getattr(self, item)
|
||||||
|
|
||||||
|
|
||||||
def remove_none(obj):
|
def remove_none(obj):
|
||||||
if isinstance(obj, (list, tuple, set)):
|
if isinstance(obj, (list, tuple, set)):
|
||||||
@ -37,8 +40,4 @@ def remove_none(obj):
|
|||||||
class Encoder(JSONEncoder):
|
class Encoder(JSONEncoder):
|
||||||
def default(self, o: PyrogramType):
|
def default(self, o: PyrogramType):
|
||||||
content = {i: getattr(o, i) for i in filter(lambda x: not x.startswith("_"), o.__dict__)}
|
content = {i: getattr(o, i) for i in filter(lambda x: not x.startswith("_"), o.__dict__)}
|
||||||
|
return remove_none(OrderedDict([("_", "pyrogram:" + o.__class__.__name__)] + [i for i in content.items()]))
|
||||||
return OrderedDict(
|
|
||||||
[("_", "pyrogram:{}".format(o.__class__.__name__))]
|
|
||||||
+ [i for i in remove_none(content).items()]
|
|
||||||
)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user