summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsylvain thenault <sylvain.thenault@logilab.fr>2009-03-26 20:10:54 +0100
committersylvain thenault <sylvain.thenault@logilab.fr>2009-03-26 20:10:54 +0100
commitce497c294968e677da963a67334d32385694b7f5 (patch)
tree429271eefae0ea1981f685a5e459cb25f44e4223
parentbfbfa5e3d82854cc93993a04d44d4fa6ce3fb17a (diff)
downloadlogilab-common-ce497c294968e677da963a67334d32385694b7f5.tar.gz
new dictattr simple type
-rw-r--r--__init__.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/__init__.py b/__init__.py
index d59632d..7697ed1 100644
--- a/__init__.py
+++ b/__init__.py
@@ -35,6 +35,16 @@ class attrdict(dict):
except KeyError:
raise AttributeError(attr)
+class dictattr(dict):
+ def __init__(self, proxy):
+ self.__proxy = proxy
+
+ def __getitem__(self, attr):
+ try:
+ return getattr(self.__proxy, attr)
+ except AttributeError:
+ raise KeyError(attr)
+
class nullobject(object):
def __nonzero__(self):
return False