To use:
git clone git://github.com/bluemoon/linkgrammar_module.git
cd linkgrammar_module
python setup.py build
sudo python setup.py install
class ObjectProxy(object):
def __init__(self, dictionary=None):
if dictionary:
for a, b in dictionary.items():
if isinstance(b, (list, tuple)):
setattr(self, a, [ObjectProxy(x)\
if isinstance(x, dict) else x for x in b])
else:
setattr(self, a, ObjectProxy(b)\
if isinstance(b, dict) else b)
def __repr__(self):
return '' % ', '.join(self.__dict__.keys())
def __getattr__(self, attr):
try:
return dict.__getattr__(self, attr)
except:
if not self.__dict__.has_key(attr):
self.__dict__[attr] = ObjectProxy()
return self.__dict__[attr]
def __setattr__(self, attr, value):
if self.__dict__.has_key(attr) or '__' in attr:
dict.__setattr__(self, attr, value)
else:
self.__dict__[attr] = value
a = ObjectProxy()
a.b.c.d = 3
a.m.d_ = 2
class Deferred(object):
def __init__(self):
self._callbacks = []
def add_callback(self, callback):
if hasattr(self, 'result'):
callback(self.result)
else:
self._callbacks.append(callback)
def callback(self, result):
assert not hasattr(self, 'result')
for cb in self._callbacks:
cb(result)
self.result = result
def defer(result):
d = Deferred()
d.result = result
return d