mirror of
https://github.com/balkian/gists.git
synced 2024-11-24 02:12:29 +00:00
Add 'repos/1b3cb1d48c75d2172d88/' from commit '76a53f6703c856eb322eaf24b12dd1cf0de0b687'
git-subtree-dir: repos/1b3cb1d48c75d2172d88 git-subtree-mainline:3111b48793
git-subtree-split:76a53f6703
This commit is contained in:
commit
ae01b4a7e5
27
repos/1b3cb1d48c75d2172d88/tweeply.py
Normal file
27
repos/1b3cb1d48c75d2172d88/tweeply.py
Normal file
@ -0,0 +1,27 @@
|
||||
class MessageProperty(property):
|
||||
def __init__(self, path, *args, **kwargs):
|
||||
property.__init__(self, *args, **kwargs)
|
||||
self.path = path
|
||||
|
||||
def _target(self, dic):
|
||||
path = self.path
|
||||
dest = dic
|
||||
lastkey = path[-1]
|
||||
for p in path[:-1]:
|
||||
if p not in dest or not dest[p]:
|
||||
dest[p] = {}
|
||||
dest = dest[p]
|
||||
return dest, lastkey
|
||||
|
||||
def __get__(self, container, _type=None):
|
||||
dest, lastkey = self._target(container)
|
||||
return dest[lastkey]
|
||||
|
||||
|
||||
def __set__(self, container, value):
|
||||
dest, lastkey = self._target(container)
|
||||
dest[lastkey] = value
|
||||
|
||||
def __delete__(self, container):
|
||||
dest, lastkey = self._target(container)
|
||||
del dest[lastkey]
|
Loading…
Reference in New Issue
Block a user