summaryrefslogtreecommitdiff
path: root/python/qpid/ops.py
diff options
context:
space:
mode:
authorRafael H. Schloming <rhs@apache.org>2010-02-15 06:49:30 +0000
committerRafael H. Schloming <rhs@apache.org>2010-02-15 06:49:30 +0000
commitd6be0fa66f6fca86a741b49c9ac3717a072a96d0 (patch)
tree6da856485eccc3c76ad804b836c7af580409d39b /python/qpid/ops.py
parent75b9098e465a9da8764514410c93f79beb1d3be0 (diff)
downloadqpid-python-d6be0fa66f6fca86a741b49c9ac3717a072a96d0.tar.gz
more futzing with setup.py; pulled specs into python/qpid package
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@910165 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'python/qpid/ops.py')
-rw-r--r--python/qpid/ops.py98
1 files changed, 52 insertions, 46 deletions
diff --git a/python/qpid/ops.py b/python/qpid/ops.py
index a8ba826857..ac1819e6da 100644
--- a/python/qpid/ops.py
+++ b/python/qpid/ops.py
@@ -144,7 +144,7 @@ def default(f):
else:
return None
-def make_compound(decl, base):
+def make_compound(decl, base, domains):
dict = {}
fields = decl.query["field"]
dict["__doc__"] = pydoc(decl, fields)
@@ -152,11 +152,13 @@ def make_compound(decl, base):
dict["SIZE"] = num(decl["@size"])
dict["CODE"] = code(decl)
dict["PACK"] = num(decl["@pack"])
- dict["FIELDS"] = [Field(pythonize(f["@name"]), resolve(f), default(f)) for f in fields]
+ dict["FIELDS"] = [Field(pythonize(f["@name"]), resolve(f, domains),
+ default(f))
+ for f in fields]
dict["ARGS"] = dict["FIELDS"] + base.UNENCODED
return str(studly(decl["@name"])), (base,), dict
-def make_restricted(decl):
+def make_restricted(decl, domains):
name = pythonize(decl["@name"])
dict = {}
choices = decl.query["choice"]
@@ -171,7 +173,7 @@ def make_restricted(decl):
dict["VALUES"] = values
return name, (Enum,), dict
-def make_type(decl):
+def make_type(decl, domains):
name = pythonize(decl["@name"])
dict = {}
dict["__doc__"] = pydoc(decl)
@@ -179,65 +181,55 @@ def make_type(decl):
dict["CODE"] = code(decl)
return str(studly(decl["@name"])), (Primitive,), dict
-def make_command(decl):
+def make_command(decl, domains):
decl.set_attr("name", "%s-%s" % (decl.parent["@name"], decl["@name"]))
decl.set_attr("size", "0")
decl.set_attr("pack", "2")
- name, bases, dict = make_compound(decl, Command)
+ name, bases, dict = make_compound(decl, Command, domains)
dict["RESULT"] = pythonize(decl["result/@type"]) or pythonize(decl["result/struct/@name"])
return name, bases, dict
-def make_control(decl):
+def make_control(decl, domains):
decl.set_attr("name", "%s-%s" % (decl.parent["@name"], decl["@name"]))
decl.set_attr("size", "0")
decl.set_attr("pack", "2")
- return make_compound(decl, Control)
+ return make_compound(decl, Control, domains)
-def make_struct(decl):
- return make_compound(decl, Compound)
+def make_struct(decl, domains):
+ return make_compound(decl, Compound, domains)
-def make_enum(decl):
+def make_enum(decl, domains):
decl.set_attr("name", decl.parent["@name"])
- return make_restricted(decl)
+ return make_restricted(decl, domains)
vars = globals()
-def make(nd):
- return vars["make_%s" % nd.name](nd)
+def make(nd, domains):
+ return vars["make_%s" % nd.name](nd, domains)
-from qpid_config import amqp_spec as file
-pclfile = "%s.ops.pcl" % file
+def qualify(nd, field="@name"):
+ cls = klass(nd)
+ if cls is None:
+ return pythonize(nd[field])
+ else:
+ return pythonize("%s.%s" % (cls["@name"], nd[field]))
+
+def resolve(nd, domains):
+ candidates = qualify(nd, "@type"), pythonize(nd["@type"])
+ for c in candidates:
+ if domains.has_key(c):
+ while domains.has_key(c):
+ c = domains[c]
+ return c
+ else:
+ return c
-if os.path.exists(pclfile) and \
- os.path.getmtime(pclfile) > os.path.getmtime(file):
- f = open(pclfile, "r")
- types = pickle.load(f)
- f.close()
-else:
+def load_types_from_xml(file):
spec = mllib.xml_parse(file)
-
- def qualify(nd, field="@name"):
- cls = klass(nd)
- if cls is None:
- return pythonize(nd[field])
- else:
- return pythonize("%s.%s" % (cls["@name"], nd[field]))
-
domains = dict([(qualify(d), pythonize(d["@type"]))
for d in spec.query["amqp/domain", included] + \
spec.query["amqp/class/domain", included]])
-
- def resolve(nd):
- candidates = qualify(nd, "@type"), pythonize(nd["@type"])
- for c in candidates:
- if domains.has_key(c):
- while domains.has_key(c):
- c = domains[c]
- return c
- else:
- return c
-
type_decls = \
spec.query["amqp/class/command", included] + \
spec.query["amqp/class/control", included] + \
@@ -246,12 +238,26 @@ else:
spec.query["amqp/class/domain/enum", included] + \
spec.query["amqp/domain/enum", included] + \
spec.query["amqp/type"]
- types = [make(nd) for nd in type_decls]
-
- if os.access(os.path.dirname(os.path.abspath(pclfile)), os.W_OK):
- f = open(pclfile, "w")
- pickle.dump(types, f)
+ types = [make(nd, domains) for nd in type_decls]
+ return types
+
+def load_types(file):
+ pclfile = "%s.ops.pcl" % file
+ if os.path.exists(pclfile) and \
+ os.path.getmtime(pclfile) > os.path.getmtime(file):
+ f = open(pclfile, "rb")
+ types = pickle.load(f)
f.close()
+ else:
+ types = load_types_from_xml(file)
+ if os.access(os.path.dirname(os.path.abspath(pclfile)), os.W_OK):
+ f = open(pclfile, "wb")
+ pickle.dump(types, f)
+ f.close()
+ return types
+
+from specs_config import amqp_spec as file
+types = load_types(file)
ENUMS = {}
PRIMITIVE = {}