diff options
-rw-r--r-- | mastodon/Mastodon.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 9c97b79..722c4d5 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -1393,6 +1393,20 @@ class Mastodon: | |||
1393 | return (date_time_utc - epoch_utc).total_seconds() | 1393 | return (date_time_utc - epoch_utc).total_seconds() |
1394 | 1394 | ||
1395 | @staticmethod | 1395 | @staticmethod |
1396 | def __json_allow_dict_attrs(json_object): | ||
1397 | """ | ||
1398 | Makes it possible to use attribute notation to access a dicts | ||
1399 | elements, while still allowing the dict to act as a dict. | ||
1400 | """ | ||
1401 | class AttribAccessDict(dict): | ||
1402 | def __getattr__(self, attr): | ||
1403 | return self[attr] | ||
1404 | |||
1405 | if isinstance(json_object, dict): | ||
1406 | return AttribAccessDict(json_object) | ||
1407 | return json_object | ||
1408 | |||
1409 | @staticmethod | ||
1396 | def __json_date_parse(json_object): | 1410 | def __json_date_parse(json_object): |
1397 | """ | 1411 | """ |
1398 | Parse dates in certain known json fields, if possible. | 1412 | Parse dates in certain known json fields, if possible. |
@@ -1428,6 +1442,7 @@ class Mastodon: | |||
1428 | def __json_hooks(json_object): | 1442 | def __json_hooks(json_object): |
1429 | json_object = Mastodon.__json_date_parse(json_object) | 1443 | json_object = Mastodon.__json_date_parse(json_object) |
1430 | json_object = Mastodon.__json_id_to_bignum(json_object) | 1444 | json_object = Mastodon.__json_id_to_bignum(json_object) |
1445 | json_object = Mastodon.__json_allow_dict_attrs(json_object) | ||
1431 | return json_object | 1446 | return json_object |
1432 | 1447 | ||
1433 | def __api_request(self, method, endpoint, params={}, files={}, do_ratelimiting=True): | 1448 | def __api_request(self, method, endpoint, params={}, files={}, do_ratelimiting=True): |