From c9900041bf70ac76a4eb8753965fe24426ba8cd4 Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Wed, 7 Nov 2007 20:46:36 +0000 Subject: added factory for structs, and made default spec loading based on AMQP_SPEC environment variable git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@592888 13f79535-47bb-0310-9956-ffa450edef68 --- python/qpid/__init__.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'python/qpid/__init__.py') diff --git a/python/qpid/__init__.py b/python/qpid/__init__.py index 7afebaf73b..ff9cc04df8 100644 --- a/python/qpid/__init__.py +++ b/python/qpid/__init__.py @@ -21,10 +21,19 @@ import spec, codec, connection, content, peer, delegate, client class Struct: - def __init__(self, type): + def __init__(self, type, *args, **kwargs): self.__dict__["type"] = type self.__dict__["_values"] = {} + if len(args) > len(self.type.fields): + raise TypeError("too many args") + + for a, f in zip(args, self.type.fields): + self.set(f.name, a) + + for k, a in kwargs.items(): + self.set(k, a) + def _check(self, attr): field = self.type.fields.byname.get(attr) if field == None: -- cgit v1.2.1