示例#1
0
 def get_type(self, qname):
     """Return a xsd.Type object from this schema"""
     try:
         return self._types[qname]
     except KeyError:
         known_items = ', '.join(self._types.keys())
         raise exceptions.LookupError(
             ("No type '%s' in namespace %s. " + "Available types are: %s")
             % (qname.localname, qname.namespace, known_items or ' - '))
示例#2
0
 def get_attribute_group(self, qname):
     """Return a xsd.AttributeGroup object from this schema"""
     try:
         return self._attribute_groups[qname]
     except KeyError:
         known_items = ', '.join(self._attribute_groups.keys())
         raise exceptions.LookupError(
             ("No attributeGroup '%s' in namespace %s. " +
              "Available attributeGroups are: %s") %
             (qname.localname, qname.namespace, known_items or ' - '))
示例#3
0
 def _get_instance(self, qname, items, item_name):
     try:
         return items[qname]
     except KeyError:
         known_items = ', '.join(items.keys())
         raise exceptions.LookupError(
             ("No %(item_name)s '%(localname)s' in namespace %(namespace)s. "
              + "Available %(item_name_plural)s are: %(known_items)s") % {
                  'item_name': item_name,
                  'item_name_plural': item_name + 's',
                  'localname': qname.localname,
                  'namespace': qname.namespace,
                  'known_items': known_items or ' - '
              })
示例#4
0
 def _resolve_dict(val):
     try:
         for key, obj in val.items():
             new = obj.resolve()
             assert new is not None, "resolve() should return an object"
             val[key] = new
     except exceptions.LookupError as exc:
         raise exceptions.LookupError(
             ("Unable to resolve %(item_name)s %(qname)s in "
              "%(file)s. (via %(parent)s)") % {
                  'item_name': exc.item_name,
                  'qname': exc.qname,
                  'file': exc.location,
                  'parent': obj.qname,
              })
示例#5
0
 def _get_component(self, qname, items, item_name):
     try:
         return items[qname]
     except KeyError:
         known_items = ", ".join(items.keys())
         raise exceptions.LookupError(
             ("No %(item_name)s '%(localname)s' in namespace %(namespace)s. "
              + "Available %(item_name_plural)s are: %(known_items)s") % {
                  "item_name": item_name,
                  "item_name_plural": item_name + "s",
                  "localname": qname.localname,
                  "namespace": qname.namespace,
                  "known_items": known_items or " - ",
              },
             qname=qname,
             item_name=item_name,
             location=self._location,
         )
示例#6
0
    def get_type(self, qname):
        """Return a global xsd.Type object with the given qname"""
        qname = self._create_qname(qname)

        # Handle XSD namespace items
        if qname.namespace == const.NS_XSD:
            try:
                return xsd_builtins.default_types[qname]
            except KeyError:
                raise exceptions.LookupError("No such type %r" % qname.text)

        try:
            schema = self._get_schema_document(qname.namespace)
            return schema.get_type(qname)
        except exceptions.NamespaceError:
            raise exceptions.NamespaceError(
                ("Unable to resolve type %s. " +
                 "No schema available for the namespace %r.") %
                (qname.text, qname.namespace))