Add dict attribute access
This commit is contained in:
pare
f63b20d929
commit
12f8a68996
S'han modificat 1 arxius amb 15 adicions i 0 eliminacions
|
@ -1392,6 +1392,20 @@ class Mastodon:
|
|||
|
||||
return (date_time_utc - epoch_utc).total_seconds()
|
||||
|
||||
@staticmethod
|
||||
def __json_allow_dict_attrs(json_object):
|
||||
"""
|
||||
Makes it possible to use attribute notation to access a dicts
|
||||
elements, while still allowing the dict to act as a dict.
|
||||
"""
|
||||
class AttribAccessDict(dict):
|
||||
def __getattr__(self, attr):
|
||||
return self[attr]
|
||||
|
||||
if isinstance(json_object, dict):
|
||||
return AttribAccessDict(json_object)
|
||||
return json_object
|
||||
|
||||
@staticmethod
|
||||
def __json_date_parse(json_object):
|
||||
"""
|
||||
|
@ -1428,6 +1442,7 @@ class Mastodon:
|
|||
def __json_hooks(json_object):
|
||||
json_object = Mastodon.__json_date_parse(json_object)
|
||||
json_object = Mastodon.__json_id_to_bignum(json_object)
|
||||
json_object = Mastodon.__json_allow_dict_attrs(json_object)
|
||||
return json_object
|
||||
|
||||
def __api_request(self, method, endpoint, params={}, files={}, do_ratelimiting=True):
|
||||
|
|
Loading…
Referencia en una nova incidència