summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorRafael H. Schloming <rhs@apache.org>2007-01-30 21:44:41 +0000
committerRafael H. Schloming <rhs@apache.org>2007-01-30 21:44:41 +0000
commit6599f4a99d600656276b1f9b0ee8c0e803d523d1 (patch)
tree83172d60b52c23e6bb2bc03c96ae8b14da73187d /python
parent974bc27ea22dcef8fff373a1dafb83a3e58098b2 (diff)
downloadqpid-python-6599f4a99d600656276b1f9b0ee8c0e803d523d1.tar.gz
updated python spec parse to load from multiple files, changed default specs to include errata
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/branches/qpid.0-9@501586 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'python')
-rwxr-xr-xpython/hello-world3
-rw-r--r--python/qpid/spec.py88
-rw-r--r--python/qpid/testlib.py6
3 files changed, 57 insertions, 40 deletions
diff --git a/python/hello-world b/python/hello-world
index 823e395b2e..51c71baa5d 100755
--- a/python/hello-world
+++ b/python/hello-world
@@ -3,7 +3,8 @@ import qpid
from qpid.client import Client
from qpid.content import Content
-client = Client("127.0.0.1", 5672, qpid.spec.load("../specs/amqp.0-9.xml"))
+client = Client("127.0.0.1", 5672, qpid.spec.load("../specs/amqp.0-9.xml",
+ "../specs/amqp-errata.0-9.xml"))
client.start({"LOGIN": "guest", "PASSWORD": "guest"})
ch = client.channel(1)
ch.channel_open()
diff --git a/python/qpid/spec.py b/python/qpid/spec.py
index 3e8b9e37bd..ffd7b5a454 100644
--- a/python/qpid/spec.py
+++ b/python/qpid/spec.py
@@ -79,11 +79,12 @@ class Spec(Metadata):
PRINT=["major", "minor", "file"]
- def __init__(self, major, minor, file):
+ def __init__(self, major, minor, file, errata):
Metadata.__init__(self)
self.major = major
self.minor = minor
self.file = file
+ self.errata = errata
self.constants = SpecContainer()
self.classes = SpecContainer()
# methods indexed by classname_methname
@@ -267,43 +268,56 @@ def load_fields(nd, l, domains):
type = domains[type]
l.add(Field(pythonize(f_nd["@name"]), f_nd.index(), type, get_docs(f_nd)))
-def load(specfile):
+def load(specfile, *errata):
doc = xmlutil.parse(specfile)
- root = doc["amqp"][0]
- spec = Spec(int(root["@major"]), int(root["@minor"]), specfile)
-
- # constants
- for nd in root["constant"]:
- const = Constant(spec, pythonize(nd["@name"]), int(nd["@value"]),
- nd.get("@class"), get_docs(nd))
- spec.constants.add(const)
-
- # domains are typedefs
- domains = {}
- for nd in root["domain"]:
- domains[nd["@name"]] = nd["@type"]
-
- # classes
- for c_nd in root["class"]:
- klass = Class(spec, pythonize(c_nd["@name"]), int(c_nd["@index"]),
- c_nd["@handler"], get_docs(c_nd))
- load_fields(c_nd, klass.fields, domains)
- for m_nd in c_nd["method"]:
- meth = Method(klass, pythonize(m_nd["@name"]),
- int(m_nd["@index"]),
- m_nd.get_bool("@content", False),
- [pythonize(nd["@name"]) for nd in m_nd["response"]],
- m_nd.get_bool("@synchronous", False),
- m_nd.text,
- get_docs(m_nd))
- load_fields(m_nd, meth.fields, domains)
- klass.methods.add(meth)
- # resolve the responses
- for m in klass.methods:
- m.responses = [klass.methods.byname[r] for r in m.responses]
- for resp in m.responses:
- resp.response = True
- spec.classes.add(klass)
+ spec_root = doc["amqp"][0]
+ spec = Spec(int(spec_root["@major"]), int(spec_root["@minor"]), specfile, errata)
+
+ for root in [spec_root] + map(lambda x: xmlutil.parse(x)["amqp"][0], errata):
+ # constants
+ for nd in root["constant"]:
+ const = Constant(spec, pythonize(nd["@name"]), int(nd["@value"]),
+ nd.get("@class"), get_docs(nd))
+ spec.constants.add(const)
+
+ # domains are typedefs
+ domains = {}
+ for nd in root["domain"]:
+ domains[nd["@name"]] = nd["@type"]
+
+ # classes
+ for c_nd in root["class"]:
+ cname = pythonize(c_nd["@name"])
+ if root == spec_root:
+ klass = Class(spec, cname, int(c_nd["@index"]), c_nd["@handler"],
+ get_docs(c_nd))
+ spec.classes.add(klass)
+ else:
+ klass = spec.classes.byname[cname]
+
+ added_methods = []
+ load_fields(c_nd, klass.fields, domains)
+ for m_nd in c_nd["method"]:
+ mname = pythonize(m_nd["@name"])
+ if root == spec_root:
+ meth = Method(klass, mname,
+ int(m_nd["@index"]),
+ m_nd.get_bool("@content", False),
+ [pythonize(nd["@name"]) for nd in m_nd["response"]],
+ m_nd.get_bool("@synchronous", False),
+ m_nd.text,
+ get_docs(m_nd))
+ klass.methods.add(meth)
+ added_methods.append(meth)
+ else:
+ meth = klass.methods.byname[mname]
+ load_fields(m_nd, meth.fields, domains)
+ # resolve the responses
+ for m in added_methods:
+ m.responses = [klass.methods.byname[r] for r in m.responses]
+ for resp in m.responses:
+ resp.response = True
+
spec.post_load()
return spec
diff --git a/python/qpid/testlib.py b/python/qpid/testlib.py
index 980847c659..16d5c633f6 100644
--- a/python/qpid/testlib.py
+++ b/python/qpid/testlib.py
@@ -81,6 +81,7 @@ Options:
# Defaults
self.setBroker("localhost")
self.spec = "../specs/amqp.0-9.xml"
+ self.errata = "../specs/amqp-errata.0-9.xml"
self.verbose = 1
self.ignore = []
@@ -128,14 +129,15 @@ Options:
print "======================================="
return result.wasSuccessful()
- def connect(self, host=None, port=None, spec=None, user=None, password=None):
+ def connect(self, host=None, port=None, spec=None, errata=None, user=None, password=None):
"""Connect to the broker, returns a qpid.client.Client"""
host = host or self.host
port = port or self.port
spec = spec or self.spec
+ errata = errata or self.errata
user = user or self.user
password = password or self.password
- client = qpid.client.Client(host, port, qpid.spec.load(spec))
+ client = qpid.client.Client(host, port, qpid.spec.load(spec, errata))
client.start({"LOGIN": user, "PASSWORD": password})
return client