Make attribute-style access better
This commit is contained in:
pare
12f8a68996
commit
af81088fb0
S'han modificat 1 arxius amb 9 adicions i 2 eliminacions
|
@ -1400,8 +1400,15 @@ class Mastodon:
|
||||||
"""
|
"""
|
||||||
class AttribAccessDict(dict):
|
class AttribAccessDict(dict):
|
||||||
def __getattr__(self, attr):
|
def __getattr__(self, attr):
|
||||||
return self[attr]
|
if attr in self:
|
||||||
|
return self[attr]
|
||||||
|
else:
|
||||||
|
raise AttributeError()
|
||||||
|
|
||||||
|
def __setattr__(self, attr, val):
|
||||||
|
if attr in self:
|
||||||
|
raise AttributeError("Attribute-style access is read only")
|
||||||
|
super().__setattr__(attr, val)
|
||||||
if isinstance(json_object, dict):
|
if isinstance(json_object, dict):
|
||||||
return AttribAccessDict(json_object)
|
return AttribAccessDict(json_object)
|
||||||
return json_object
|
return json_object
|
||||||
|
|
Loading…
Referencia en una nova incidència