aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/db/sql/base.py
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/db/sql/base.py')
-rw-r--r--mediagoblin/db/sql/base.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/mediagoblin/db/sql/base.py b/mediagoblin/db/sql/base.py
index 1db53c56..f1affc83 100644
--- a/mediagoblin/db/sql/base.py
+++ b/mediagoblin/db/sql/base.py
@@ -77,3 +77,19 @@ class GMGTableBase(object):
Base = declarative_base(cls=GMGTableBase)
+
+
+class DictReadAttrProxy(object):
+ """
+ Maps read accesses to obj['key'] to obj.key
+ and hides all the rest of the obj
+ """
+ def __init__(self, proxied_obj):
+ self.proxied_obj = proxied_obj
+
+ def __getitem__(self, key):
+ try:
+ return getattr(self.proxied_obj, key)
+ except AttributeError:
+ raise KeyError("%r is not an attribute on %r"
+ % (key, self.proxied_obj))