summaryrefslogtreecommitdiff
path: root/src/leap/mx/util/storage.py
diff options
context:
space:
mode:
authorIsis Lovecruft <isis@torproject.org>2013-02-17 15:23:54 +0000
committerIsis Lovecruft <isis@torproject.org>2013-02-17 15:23:54 +0000
commit66d60a58ef752f9c9692dd8bdb0f61a5c1dfdb17 (patch)
tree016980342b8e2610f0010efddcab489a8d30db0a /src/leap/mx/util/storage.py
parent364200c25e28d4996024dcf2f0644f5f20cde9ae (diff)
parent8d2fdc800de469420005f9c5deee4c342950ccc9 (diff)
Merge branch 'feature/check-recipient' into develop
Diffstat (limited to 'src/leap/mx/util/storage.py')
-rw-r--r--src/leap/mx/util/storage.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/leap/mx/util/storage.py b/src/leap/mx/util/storage.py
new file mode 100644
index 0000000..c4c797a
--- /dev/null
+++ b/src/leap/mx/util/storage.py
@@ -0,0 +1,42 @@
+
+class Storage(dict):
+ """
+ A Storage object is like a dictionary except `obj.foo` can be used
+ in addition to `obj['foo']`.
+
+ >>> o = Storage(a=1)
+ >>> o.a
+ 1
+ >>> o['a']
+ 1
+ >>> o.a = 2
+ >>> o['a']
+ 2
+ >>> del o.a
+ >>> o.a
+ None
+ """
+ def __getattr__(self, key):
+ try:
+ return self[key]
+ except KeyError, k:
+ return None
+
+ def __setattr__(self, key, value):
+ self[key] = value
+
+ def __delattr__(self, key):
+ try:
+ del self[key]
+ except KeyError, k:
+ raise AttributeError, k
+
+ def __repr__(self):
+ return '<Storage ' + dict.__repr__(self) + '>'
+
+ def __getstate__(self):
+ return dict(self)
+
+ def __setstate__(self, value):
+ for (k, v) in value.items():
+ self[k] = v