diff options
author | Lorenz Diener <[email protected]> | 2017-12-14 13:16:28 +0100 |
---|---|---|
committer | Lorenz Diener <[email protected]> | 2017-12-14 13:16:28 +0100 |
commit | af81088fb08525e617b8f1fad7deeabc47588c10 (patch) | |
tree | 4d26a31c19c996df47e6b048fc5e4fb4e0ecf6d5 /mastodon | |
parent | 12f8a689963517e863d9ab4e743fa90ee723f43f (diff) | |
download | mastodon.py-af81088fb08525e617b8f1fad7deeabc47588c10.tar.gz |
Make attribute-style access better
Diffstat (limited to 'mastodon')
-rw-r--r-- | mastodon/Mastodon.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 722c4d5..13c3e38 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -1400,8 +1400,15 @@ class Mastodon: | |||
1400 | """ | 1400 | """ |
1401 | class AttribAccessDict(dict): | 1401 | class AttribAccessDict(dict): |
1402 | def __getattr__(self, attr): | 1402 | def __getattr__(self, attr): |
1403 | return self[attr] | 1403 | if attr in self: |
1404 | 1404 | return self[attr] | |
1405 | else: | ||
1406 | raise AttributeError() | ||
1407 | |||
1408 | def __setattr__(self, attr, val): | ||
1409 | if attr in self: | ||
1410 | raise AttributeError("Attribute-style access is read only") | ||
1411 | super().__setattr__(attr, val) | ||
1405 | if isinstance(json_object, dict): | 1412 | if isinstance(json_object, dict): |
1406 | return AttribAccessDict(json_object) | 1413 | return AttribAccessDict(json_object) |
1407 | return json_object | 1414 | return json_object |