aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz Diener <[email protected]>2017-12-14 12:52:33 +0100
committerLorenz Diener <[email protected]>2017-12-14 12:52:33 +0100
commit12f8a689963517e863d9ab4e743fa90ee723f43f (patch)
tree1c5d07eef0d4089df7e7ea36685b3ce70dd0df7f /mastodon
parentf63b20d92906e479d7548d90c057eebe7f064bd4 (diff)
downloadmastodon.py-12f8a689963517e863d9ab4e743fa90ee723f43f.tar.gz
Add dict attribute access
Diffstat (limited to 'mastodon')
-rw-r--r--mastodon/Mastodon.py15
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):
Powered by cgit v1.2.3 (git 2.41.0)