summaryrefslogtreecommitdiff
path: root/python/qpid/spec.py
diff options
context:
space:
mode:
authorRafael H. Schloming <rhs@apache.org>2007-08-09 19:57:10 +0000
committerRafael H. Schloming <rhs@apache.org>2007-08-09 19:57:10 +0000
commit921cf9ab4c5a43f898065e875c3120152d4e81e5 (patch)
treee3f6b7f7e95e10958daa4c1711f94c9eb26b6b85 /python/qpid/spec.py
parent66578b1a1d6d54e0335a0a105eabe74e60e8e4c7 (diff)
downloadqpid-python-921cf9ab4c5a43f898065e875c3120152d4e81e5.tar.gz
added support for parsing structs and results into the spec metadata
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@564362 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'python/qpid/spec.py')
-rw-r--r--python/qpid/spec.py60
1 files changed, 49 insertions, 11 deletions
diff --git a/python/qpid/spec.py b/python/qpid/spec.py
index 9bbe709ed9..f9d305c133 100644
--- a/python/qpid/spec.py
+++ b/python/qpid/spec.py
@@ -42,7 +42,9 @@ class SpecContainer:
def add(self, item):
if self.byname.has_key(item.name):
raise ValueError("duplicate name: %s" % item)
- if self.byid.has_key(item.id):
+ if item.id == None:
+ item.id = len(self)
+ elif self.byid.has_key(item.id):
raise ValueError("duplicate id: %s" % item)
self.indexes[item] = len(self.items)
self.items.append(item)
@@ -144,15 +146,26 @@ class Domain(Metadata):
PRINT=["name", "type"]
- def __init__(self, spec, id, name, type, description, docs):
+ def __init__(self, spec, name, type, description, docs):
Metadata.__init__(self)
self.spec = spec
- self.id = id
+ self.id = None
self.name = name
self.type = type
self.description = description
self.docs = docs
+class Struct(Metadata):
+
+ PRINT=["size", "type", "pack"]
+
+ def __init__(self, size, type, pack):
+ Metadata.__init__(self)
+ self.size = size
+ self.type = type
+ self.pack = pack
+ self.fields = SpecContainer()
+
class Class(Metadata):
PRINT=["name", "id"]
@@ -177,7 +190,7 @@ class Method(Metadata):
PRINT=["name", "id"]
- def __init__(self, klass, name, id, content, responses, synchronous,
+ def __init__(self, klass, name, id, content, responses, result, synchronous,
description, docs):
Metadata.__init__(self)
self.klass = klass
@@ -185,6 +198,7 @@ class Method(Metadata):
self.id = id
self.content = content
self.responses = responses
+ self.result = result
self.synchronous = synchronous
self.fields = SpecContainer()
self.description = description
@@ -224,8 +238,8 @@ class Method(Metadata):
if f.docs:
s += "\n\n" + "\n\n".join([fill(f.docs[0], 4, f.name)] +
[fill(d, 4) for d in f.docs[1:]])
- if self.responses:
- s += "\n\nValid responses: "
+ if self.responses:
+ s += "\n\nValid responses: "
for r in self.responses:
s += r.name + " "
return s
@@ -243,8 +257,8 @@ class Method(Metadata):
"content": None,
"uuid": "",
"rfc1982_long": 0,
- "rfc1982_long_set": []
- }
+ "rfc1982_long_set": [],
+ "long_struct": None}
def define_method(self, name):
g = {Method.METHOD: self}
@@ -281,6 +295,16 @@ class Field(Metadata):
self.description = description
self.docs = docs
+def get_result(nd, spec):
+ result = nd["result"]
+ if not result: return None
+ name = result["@domain"]
+ if name != None: return spec.domains.byname[name]
+ st_nd = result["struct"]
+ st = Struct(st_nd["@size"], st_nd["@type"], st_nd["@pack"])
+ load_fields(st_nd, st.fields, spec.domains.byname)
+ return st
+
def get_desc(nd):
label = nd["@label"]
if not label:
@@ -321,11 +345,24 @@ def load(specfile, *errata):
spec.constants.add(const)
except ValueError, e:
print "Warning:", e
+
# domains are typedefs
+ structs = []
for nd in root.query["domain"]:
- spec.domains.add(Domain(spec, nd.index(), pythonize(nd["@name"]),
- pythonize(nd["@type"]), get_desc(nd),
- get_docs(nd)))
+ type = nd["@type"]
+ if type == None:
+ st_nd = nd["struct"]
+ type = Struct(st_nd["@size"], st_nd["@type"], st_nd["@pack"])
+ structs.append((type, st_nd))
+ else:
+ type = pythonize(type)
+ domain = Domain(spec, pythonize(nd["@name"]), type, get_desc(nd),
+ get_docs(nd))
+ spec.domains.add(domain)
+
+ # structs
+ for st, st_nd in structs:
+ load_fields(st_nd, st.fields, spec.domains.byname)
# classes
for c_nd in root.query["class"]:
@@ -348,6 +385,7 @@ def load(specfile, *errata):
int(m_nd["@index"]),
m_nd["@content"] == "1",
[pythonize(nd["@name"]) for nd in m_nd.query["response"]],
+ get_result(m_nd, spec),
m_nd["@synchronous"] == "1",
get_desc(m_nd),
get_docs(m_nd))