How to use the xmlschema.validators.exceptions.XMLSchemaParseError function in xmlschema

To help you get started, we’ve selected a few xmlschema examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sissaschool / xmlschema / xmlschema / validators / xsdbase.py View on Github external
def parse_error(self, *args, **kwargs):
        """Helper method overridden by XsdValidator.parse_error() in XSD components."""
        raise XMLSchemaParseError(*args)
github sissaschool / xmlschema / xmlschema / validators / xsdbase.py View on Github external
def parse_error(self, *args, **kwargs):
        """Helper method overridden by XsdValidator.parse_error() in XSD components."""
        raise XMLSchemaParseError(*args)
github sissaschool / xmlschema / xmlschema / validators / xsdbase.py View on Github external
elem = getattr(self, 'elem', None)
        else:
            raise XMLSchemaValueError("'elem' argument must be an Element instance, not %r." % elem)

        if isinstance(error, XMLSchemaParseError):
            error.validator = self
            error.namespaces = getattr(self, 'namespaces', None)
            error.elem = elem
            error.source = getattr(self, 'source', None)
        elif isinstance(error, Exception):
            message = unicode_type(error).strip()
            if message[0] in '\'"' and message[0] == message[-1]:
                message = message.strip('\'"')
            error = XMLSchemaParseError(self, message, elem)
        elif isinstance(error, string_base_type):
            error = XMLSchemaParseError(self, error, elem)
        else:
            raise XMLSchemaValueError("'error' argument must be an exception or a string, not %r." % error)

        if validation == 'lax':
            self.errors.append(error)
        else:
            raise error
github sissaschool / xmlschema / xmlschema / validators / xsdbase.py View on Github external
pass
        elif elem is None:
            elem = getattr(self, 'elem', None)
        else:
            raise XMLSchemaValueError("'elem' argument must be an Element instance, not %r." % elem)

        if isinstance(error, XMLSchemaParseError):
            error.validator = self
            error.namespaces = getattr(self, 'namespaces', None)
            error.elem = elem
            error.source = getattr(self, 'source', None)
        elif isinstance(error, Exception):
            message = unicode_type(error).strip()
            if message[0] in '\'"' and message[0] == message[-1]:
                message = message.strip('\'"')
            error = XMLSchemaParseError(self, message, elem)
        elif isinstance(error, string_base_type):
            error = XMLSchemaParseError(self, error, elem)
        else:
            raise XMLSchemaValueError("'error' argument must be an exception or a string, not %r." % error)

        if validation == 'lax':
            self.errors.append(error)
        else:
            raise error
github sissaschool / xmlschema / xmlschema / validators / simple_types.py View on Github external
if base_qname == self.name:
                    if self.redefine is None:
                        self.parse_error("wrong definition with self-reference", elem)
                        base_type = self.maps.type[XSD_ANY_ATOMIC_TYPE]
                    else:
                        base_type = self.base_type
                else:
                    if self.redefine is not None:
                        self.parse_error("wrong redefinition without self-reference", elem)

                    try:
                        base_type = self.maps.lookup_type(base_qname)
                    except KeyError:
                        self.parse_error("unknown type %r." % elem.attrib['base'])
                        base_type = self.maps.types[XSD_ANY_ATOMIC_TYPE]
                    except XMLSchemaParseError as err:
                        self.parse_error(err)
                        base_type = self.maps.types[XSD_ANY_ATOMIC_TYPE]
                    else:
                        if isinstance(base_type, tuple):
                            self.parse_error("circularity definition between %r and %r" % (self, base_qname), elem)
                            base_type = self.maps.types[XSD_ANY_ATOMIC_TYPE]

            if base_type.is_simple() and base_type.name == XSD_ANY_SIMPLE_TYPE:
                self.parse_error("wrong base type {!r}, an atomic type required")
            elif base_type.is_complex():
                if base_type.mixed and base_type.is_emptiable():
                    child = self._parse_child_component(elem, strict=False)
                    if child is None:
                        self.parse_error("an xs:simpleType definition expected")
                    elif child.tag != XSD_SIMPLE_TYPE:
                        # See: "http://www.w3.org/TR/xmlschema-2/#element-restriction"
github sissaschool / xmlschema / xmlschema / validators / xsdbase.py View on Github external
elem = getattr(self, 'elem', None)
        else:
            raise XMLSchemaValueError("'elem' argument must be an Element instance, not %r." % elem)

        if isinstance(error, XMLSchemaParseError):
            error.validator = self
            error.namespaces = getattr(self, 'namespaces', None)
            error.elem = elem
            error.source = getattr(self, 'source', None)
        elif isinstance(error, Exception):
            message = unicode_type(error).strip()
            if message[0] in '\'"' and message[0] == message[-1]:
                message = message.strip('\'"')
            error = XMLSchemaParseError(self, message, elem)
        elif isinstance(error, string_base_type):
            error = XMLSchemaParseError(self, error, elem)
        else:
            raise XMLSchemaValueError("'error' argument must be an exception or a string, not %r." % error)

        if validation == 'lax':
            self.errors.append(error)
        else:
            raise error
github sissaschool / xmlschema / xmlschema / validators / xsdbase.py View on Github external
attribute of the validator, if it's present.
        :param validation: overrides the default validation mode of the validator.
        """
        if validation not in XSD_VALIDATION_MODES:
            validation = self.validation
        if validation == 'skip':
            return

        if is_etree_element(elem):
            pass
        elif elem is None:
            elem = getattr(self, 'elem', None)
        else:
            raise XMLSchemaValueError("'elem' argument must be an Element instance, not %r." % elem)

        if isinstance(error, XMLSchemaParseError):
            error.validator = self
            error.namespaces = getattr(self, 'namespaces', None)
            error.elem = elem
            error.source = getattr(self, 'source', None)
        elif isinstance(error, Exception):
            message = unicode_type(error).strip()
            if message[0] in '\'"' and message[0] == message[-1]:
                message = message.strip('\'"')
            error = XMLSchemaParseError(self, message, elem)
        elif isinstance(error, string_base_type):
            error = XMLSchemaParseError(self, error, elem)
        else:
            raise XMLSchemaValueError("'error' argument must be an exception or a string, not %r." % error)

        if validation == 'lax':
            self.errors.append(error)