Example #1
0
def load(specfile, *errata):
  for name in (specfile,) + errata:
    if not os.path.exists(name):
      raise IOError("No such file or directory: '%s'" % name)

  doc = mllib.xml_parse(specfile)
  major = doc["amqp/@major"]
  minor = doc["amqp/@minor"]

  if major == "0" and minor == "10":
    return None
  else:
    return spec08.load(specfile, *errata)
Example #2
0
def load_types_from_xml(file):
  spec = mllib.xml_parse(file)
  domains = dict([(qualify(d), pythonize(d["@type"]))
                  for d in spec.query["amqp/domain", included] + \
                    spec.query["amqp/class/domain", included]])
  type_decls = \
      spec.query["amqp/class/command", included] + \
      spec.query["amqp/class/control", included] + \
      spec.query["amqp/class/command/result/struct", included] + \
      spec.query["amqp/class/struct", included] + \
      spec.query["amqp/class/domain/enum", included] + \
      spec.query["amqp/domain/enum", included] + \
      spec.query["amqp/type"]
  types = [make(nd, domains) for nd in type_decls]
  return types
Example #3
0
def load_types_from_xml(file):
    spec = mllib.xml_parse(file)
    domains = dict([(qualify(d), pythonize(d["@type"]))
                    for d in spec.query["amqp/domain", included] + \
                      spec.query["amqp/class/domain", included]])
    type_decls = \
        spec.query["amqp/class/command", included] + \
        spec.query["amqp/class/control", included] + \
        spec.query["amqp/class/command/result/struct", included] + \
        spec.query["amqp/class/struct", included] + \
        spec.query["amqp/class/domain/enum", included] + \
        spec.query["amqp/domain/enum", included] + \
        spec.query["amqp/type"]
    types = [make(nd, domains) for nd in type_decls]
    return types
Example #4
0
File: protocol.py Project: rhs/amp
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#
import mllib, os, sys

doc = mllib.xml_parse(os.path.join(os.path.dirname(__file__), "transport.xml"))
mdoc = mllib.xml_parse(os.path.join(os.path.dirname(__file__), "messaging.xml"))

def eq(attr, value):
  return lambda nd: nd[attr] == value

TYPES = doc.query["amqp/section/type", eq("@class", "composite")] + \
    mdoc.query["amqp/section/type", eq("@class", "composite")]
RESTRICTIONS = {}
COMPOSITES = {}

for type in doc.query["amqp/section/type"] + mdoc.query["amqp/section/type"]:
  source = type["@source"]
  if source:
    RESTRICTIONS[type["@name"]] = source
  if type["@class"] == "composite":
Example #5
0
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#
import mllib, os, sys

doc = mllib.xml_parse(os.path.join(os.path.dirname(__file__), "transport.xml"))
mdoc = mllib.xml_parse(os.path.join(os.path.dirname(__file__),
                                    "messaging.xml"))
tdoc = mllib.xml_parse(
    os.path.join(os.path.dirname(__file__), "transactions.xml"))
sdoc = mllib.xml_parse(os.path.join(os.path.dirname(__file__), "security.xml"))


def eq(attr, value):
    return lambda nd: nd[attr] == value

TYPES = doc.query["amqp/section/type", eq("@class", "composite")] + \
    mdoc.query["amqp/section/type", eq("@class", "composite")] + \
    tdoc.query["amqp/section/type", eq("@class", "composite")] + \
    sdoc.query["amqp/section/type", eq("@class", "composite")] + \
    mdoc.query["amqp/section/type", eq("@provides", "section")]
Example #6
0
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#

from __future__ import print_function
import mllib, optparse, os, sys

xml = os.path.join(os.path.dirname(__file__), "types.xml")
doc = mllib.xml_parse(xml)

print("/* generated from %s */" % xml)
print("#ifndef _PROTON_ENCODINGS_H")
print("#define _PROTON_ENCODINGS_H 1")
print()
print("#define PNE_DESCRIPTOR          (0x00)")

for enc in doc.query["amqp/section/type/encoding"]:
    name = enc["@name"] or enc.parent["@name"]
    # XXX: a bit hacky
    if name == "ieee-754":
        name = enc.parent["@name"]
    cname = "PNE_" + name.replace("-", "_").upper()
    print("#define %s%s(%s)" % (cname, " " * (20 - len(cname)), enc["@code"]))
Example #7
0
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#
import mllib, os, sys

doc = mllib.xml_parse(os.path.join(os.path.dirname(__file__), "transport.xml"))
mdoc = mllib.xml_parse(os.path.join(os.path.dirname(__file__), "messaging.xml"))
tdoc = mllib.xml_parse(os.path.join(os.path.dirname(__file__), "transactions.xml"))
sdoc = mllib.xml_parse(os.path.join(os.path.dirname(__file__), "security.xml"))

def eq(attr, value):
  return lambda nd: nd[attr] == value

TYPES = doc.query["amqp/section/type", eq("@class", "composite")] + \
    mdoc.query["amqp/section/type", eq("@class", "composite")] + \
    tdoc.query["amqp/section/type", eq("@class", "composite")] + \
    sdoc.query["amqp/section/type", eq("@class", "composite")] + \
    mdoc.query["amqp/section/type", eq("@provides", "section")]
RESTRICTIONS = {}
COMPOSITES = {}
Example #8
0
vars = globals()

def make(nd):
  return vars["make_%s" % nd.name](nd)

from qpid_config import amqp_spec as file
pclfile = "%s.ops.pcl" % file

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:
  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:
Example #9
0
def load(specfile, *errata):
  doc = mllib.xml_parse(specfile)
  spec_root = doc["amqp"]
  spec = Spec(int(spec_root["@major"]), int(spec_root["@minor"]), specfile)

  for root in [spec_root] + map(lambda x: mllib.xml_parse(x)["amqp"], errata):
    # constants
    for nd in root.query["constant"]:
      val = nd["@value"]
      if val.startswith("0x"): val = int(val, 16)
      else: val = int(val)
      const = Constant(spec, pythonize(nd["@name"]), val, nd["@class"],
                       get_docs(nd))
      try:
        spec.constants.add(const)
      except ValueError, e:
        pass
        #print "Warning:", e

    # domains are typedefs
    structs = []
    for nd in root.query["domain"]:
      type = nd["@type"]
      if type == None:
        st_nd = nd["struct"]
        code = st_nd["@type"]
        if code not in (None, "", "none"):
          code = int(code)
        type = Struct(width(st_nd["@size"]), code, width(st_nd["@pack"], 2))
        if type.type != None:
          spec.structs[type.type] = type
        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"]:
      cname = pythonize(c_nd["@name"])
      if spec.classes.byname.has_key(cname):
        klass = spec.classes.byname[cname]
      else:
        klass = Class(spec, cname, int(c_nd["@index"]), c_nd["@handler"],
                      get_docs(c_nd))
        spec.classes.add(klass)

      added_methods = []
      load_fields(c_nd, klass.fields, spec.domains.byname)
      for m_nd in c_nd.query["method"]:
        mname = pythonize(m_nd["@name"])
        if klass.methods.byname.has_key(mname):
          meth = klass.methods.byname[mname]
        else:
          meth = Method(klass, mname,
                        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))
          klass.methods.add(meth)
          added_methods.append(meth)
        load_fields(m_nd, meth.fields, spec.domains.byname)
      # 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
Example #10
0
File: util.py Project: grkvlt/amqp
def load_xml(name):
  xml_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), name)
  return mllib.xml_parse(xml_file)
Example #11
0
def load(specfile, *errata):
    doc = mllib.xml_parse(specfile)
    spec_root = doc["amqp"]
    spec = Spec(int(spec_root["@major"]), int(spec_root["@minor"]), specfile)

    for root in [spec_root] + map(lambda x: mllib.xml_parse(x)["amqp"],
                                  errata):
        # constants
        for nd in root.query["constant"]:
            val = nd["@value"]
            if val.startswith("0x"): val = int(val, 16)
            else: val = int(val)
            const = Constant(spec, pythonize(nd["@name"]), val, nd["@class"],
                             get_docs(nd))
            try:
                spec.constants.add(const)
            except ValueError, e:
                pass
                #print "Warning:", e

        # domains are typedefs
        structs = []
        for nd in root.query["domain"]:
            type = nd["@type"]
            if type == None:
                st_nd = nd["struct"]
                code = st_nd["@type"]
                if code not in (None, "", "none"):
                    code = int(code)
                type = Struct(width(st_nd["@size"]), code,
                              width(st_nd["@pack"], 2))
                if type.type != None:
                    spec.structs[type.type] = type
                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"]:
            cname = pythonize(c_nd["@name"])
            if spec.classes.byname.has_key(cname):
                klass = spec.classes.byname[cname]
            else:
                klass = Class(spec, cname, int(c_nd["@index"]),
                              c_nd["@handler"], get_docs(c_nd))
                spec.classes.add(klass)

            added_methods = []
            load_fields(c_nd, klass.fields, spec.domains.byname)
            for m_nd in c_nd.query["method"]:
                mname = pythonize(m_nd["@name"])
                if klass.methods.byname.has_key(mname):
                    meth = klass.methods.byname[mname]
                else:
                    meth = Method(klass, mname, 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))
                    klass.methods.add(meth)
                    added_methods.append(meth)
                load_fields(m_nd, meth.fields, spec.domains.byname)
            # 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