Example #1
0
    def visit_import(self, node, parent):
        """
            <import
              id = ID
              namespace = anyURI
              schemaLocation = anyURI
              {any attributes with non-schema Namespace}...>
            Content: (annotation?)
            </import>
        """
        if not node.get('schemaLocation'):
            raise NotImplementedError("schemaLocation is required")
        namespace = node.get('namespace')
        location = node.get('schemaLocation')

        # Resolve import if it is a file
        location = absolute_location(location, self.schema._location)
        schema = self.parser_context.schema_objects.get(location)
        if schema:
            logger.debug("Returning existing schema: %r", location)
            self.schema._imports[namespace] = schema
            return schema

        schema_node = load_external(
            location, self.schema._transport, self.parser_context)
        schema = self.schema.__class__(
            schema_node, self.schema._transport, location, self.parser_context)

        self.schema._imports[namespace] = schema
        return schema
Example #2
0
    def visit_import(self, node, parent):
        """
            <import
              id = ID
              namespace = anyURI
              schemaLocation = anyURI
              {any attributes with non-schema Namespace}...>
            Content: (annotation?)
            </import>
        """
        if not node.get('schemaLocation'):
            raise NotImplementedError("schemaLocation is required")
        namespace = node.get('namespace')
        location = node.get('schemaLocation')

        # Resolve import if it is a file
        location = absolute_location(location, self.schema._location)
        schema = self.parser_context.schema_objects.get(location)
        if schema:
            logger.debug("Returning existing schema: %r", location)
            self.schema._imports[namespace] = schema
            return schema

        schema_node = load_external(location, self.schema._transport,
                                    self.parser_context)
        schema = self.schema.__class__(schema_node, self.schema._transport,
                                       location, self.parser_context)

        self.schema._imports[namespace] = schema
        return schema
Example #3
0
    def _load_content(self, location):
        """Load the XML content from the given location and return an
        lxml.Element object.

        :param location: The URL of the document to load
        :type location: string

        """
        if hasattr(location, 'read'):
            return parse_xml(location.read())
        return load_external(location, self.transport, self.location)
Example #4
0
    def _load_content(self, location):
        """Load the XML content from the given location and return an
        lxml.Element object.

        :param location: The URL of the document to load
        :type location: string

        """
        if hasattr(location, 'read'):
            return parse_xml(location.read())
        return load_external(location, self.transport, self.location)
    def visit_import(self, node, parent, namespace=None):
        if not node.get('schemaLocation'):
            raise NotImplementedError("schemaLocation is required")
        namespace = 'intschema+%s' % node.get('namespace')

        location = node.get('schemaLocation')
        if location.startswith('intschema+'):
            schema_node = self.schema_references[namespace]
            return self.visit_schema(schema_node)

        schema_node = load_external(location, self.schema_references)
        return self.visit_schema(schema_node)
Example #6
0
    def visit_include(self, node, parent):
        """
        <include
          id = ID
          schemaLocation = anyURI
          {any attributes with non-schema Namespace}...>
        Content: (annotation?)
        </include>
        """
        if not node.get('schemaLocation'):
            raise NotImplementedError("schemaLocation is required")
        location = node.get('schemaLocation')

        schema_node = load_external(
            location, self.schema._transport, self.parser_context,
            base_url=self.schema._base_url)
        return self.visit_schema(schema_node)
Example #7
0
    def visit_include(self, node, parent):
        """
        <include
          id = ID
          schemaLocation = anyURI
          {any attributes with non-schema Namespace}...>
        Content: (annotation?)
        </include>
        """
        if not node.get('schemaLocation'):
            raise NotImplementedError("schemaLocation is required")
        location = node.get('schemaLocation')

        schema_node = load_external(
            location, self.schema._transport, self.parser_context,
            base_url=self.schema._base_url)
        return self.visit_schema(schema_node)
Example #8
0
    def visit_import(self, node, parent):
        """
            <import
              id = ID
              namespace = anyURI
              schemaLocation = anyURI
              {any attributes with non-schema Namespace}...>
            Content: (annotation?)
            </import>
        """
        namespace = node.get('namespace')
        location = node.get('schemaLocation')

        # Use namespace as location if the schemaLocation is missing
        if not location:
            if namespace:
                location = namespace
            else:
                raise NotImplementedError("schemaLocation is required")

        # Resolve import if it is a file
        location = absolute_location(location, self.schema._base_url)
        schema = self.parser_context.schema_objects.get(location)
        if schema:
            logger.debug("Returning existing schema: %r", location)
            self.schema._imports[namespace] = schema
            return schema

        schema_node = load_external(
            location, self.schema._transport, self.parser_context)

        # If this schema location is 'internal' then retrieve the original
        # location since that is used as base url for sub include/imports
        if location in self.parser_context.schema_locations:
            base_url = self.parser_context.schema_locations[location]
        else:
            base_url = location

        schema = self.schema.__class__(
            schema_node, self.schema._transport, location,
            self.parser_context, base_url)

        self.schema._imports[namespace] = schema
        return schema
Example #9
0
    def visit_import(self, node, parent):
        """
            <import
              id = ID
              namespace = anyURI
              schemaLocation = anyURI
              {any attributes with non-schema Namespace}...>
            Content: (annotation?)
            </import>
        """
        namespace = node.get('namespace')
        location = node.get('schemaLocation')

        # Use namespace as location if the schemaLocation is missing
        if not location:
            if namespace:
                location = namespace
            else:
                raise NotImplementedError("schemaLocation is required")

        # Resolve import if it is a file
        location = absolute_location(location, self.schema._base_url)
        schema = self.parser_context.schema_objects.get(location)
        if schema:
            logger.debug("Returning existing schema: %r", location)
            self.schema._imports[namespace] = schema
            return schema

        schema_node = load_external(
            location, self.schema._transport, self.parser_context)

        # If this schema location is 'internal' then retrieve the original
        # location since that is used as base url for sub include/imports
        if location in self.parser_context.schema_locations:
            base_url = self.parser_context.schema_locations[location]
        else:
            base_url = location

        schema = self.schema.__class__(
            schema_node, self.schema._transport, location,
            self.parser_context, base_url)

        self.schema._imports[namespace] = schema
        return schema
Example #10
0
 def _load_content(self, location):
     if hasattr(location, 'read'):
         return self._parse_content(location.read())
     return load_external(
         location, self.transport, self._parser_context, self.location)
Example #11
0
 def _load_content(self, location):
     if hasattr(location, 'read'):
         return self._parse_content(location.read())
     return load_external(location, self.transport, self._parser_context,
                          self.location)