summaryrefslogtreecommitdiff
path: root/python/qpid/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/qpid/__init__.py')
-rw-r--r--python/qpid/__init__.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/python/qpid/__init__.py b/python/qpid/__init__.py
index 4363f175fb..4aeccae38e 100644
--- a/python/qpid/__init__.py
+++ b/python/qpid/__init__.py
@@ -18,3 +18,26 @@
#
import spec, codec, connection, content, peer, delegate, client
+
+class Struct:
+
+ def __init__(self, type):
+ self.__dict__["type"] = type
+ self.__dict__["_values"] = {}
+
+ def _check(self, attr):
+ field = self.type.fields.byname.get(attr)
+ if field == None:
+ raise AttributeError(attr)
+ return field
+
+ def __setattr__(self, attr, value):
+ self._check(attr)
+ self._values[attr] = value
+
+ def __getattr__(self, attr):
+ field = self._check(attr)
+ return self._values.get(attr, field.default())
+
+ def __str__(self):
+ return "%s %s" % (self.type.type, self._values)