Package xmlschema_acue :: Package validators :: Module simple_types :: Class XsdAtomicBuiltin

Class XsdAtomicBuiltin

source code


Class for defining XML Schema built-in simpleType atomic datatypes. An instance contains a Python's type transformation and a list of validator functions. The 'base_type' is not used for validation, but only for reference to the XML Schema restriction hierarchy.

Type conversion methods:

Instance Methods

Inherited from xsdbase.XsdType: is_key

Inherited from xsdbase.XsdComponent: get_global, match, tostring

Inherited from xsdbase.XsdValidator: __copy__, __str__, __unicode__, copy

Static Methods

Inherited from XsdAtomic: is_list

Class Variables

Inherited from XsdSimpleType: max_length, min_length, patterns, validators, white_space

Inherited from xsdbase.XsdType: abstract, base_type, derivation, redefine

Inherited from xsdbase.XsdComponent: name, parent, qualified

Method Details

__init__(self, elem, schema, name, python_type, base_type=None, admitted_facets=None, facets=None, to_python=None, from_python=None)
(Constructor)

source code 

:param name: the XSD type's qualified name. :param python_type: the correspondent Python's type. If a tuple or list of types is provided uses the first and consider the others as compatible types. :param base_type: the reference base type, None if it's a primitive type. :param admitted_facets: admitted facets tags for type (required for primitive types). :param facets: optional facets validators. :param to_python: optional decode function. :param from_python: optional encode function.

Decorators:
Overrides: xsdbase.XsdValidator.__init__

__repr__(self)
(Representation operator)

source code 
Decorators:
Overrides: xsdbase.XsdComponent.__repr__

admitted_facets(self)

source code 
Decorators:
  • @property
Overrides: XsdSimpleType.admitted_facets

iter_decode(self, obj, validation='lax', **kwargs)

source code 

Creates an iterator for decoding an XML source to a Python object.

:param source: the XML data source. The argument type depends by implementation. :param validation: the validation mode. Can be 'lax', 'strict' or 'skip. :param args: additional arguments for the decoder API. :param kwargs: keyword arguments for the decoder API. :return: Yields a decoded object, eventually preceded by a sequence of validation or decoding errors.

Decorators:
Overrides: xsdbase.ValidationMixin.iter_decode
(inherited documentation)

iter_encode(self, obj, validation='lax', **kwargs)

source code 

Creates an iterator for Encode data to an Element.

:param obj: The data that has to be encoded. :param validation: The validation mode. Can be 'lax', 'strict' or 'skip'. :param args: additional arguments for the encoder API. :param kwargs: keyword arguments for the encoder API. :return: Yields an Element, eventually preceded by a sequence of validation or encoding errors.

Decorators:
Overrides: xsdbase.ValidationMixin.iter_encode
(inherited documentation)

__setattr__(self, name, value)

source code 
Decorators:
Overrides: xsdbase.XsdComponent.__setattr__

all_errors(self)

source code 

A list with all the building errors of the XSD validator and its components.

Decorators:
  • @property

built(self)

source code 

Property that is ``True`` if schema validator has been fully parsed and built, ``False`` otherwise.

Decorators:
  • @property
Overrides: xsdbase.XsdValidator.built
(inherited documentation)

content_type_label(self)

source code 
Decorators:
  • @property

decode(self, source, *args, **kwargs)

source code 

Decodes XML data using the XSD schema/component.

:param source: the source of XML data. For a schema can be a path to a file or an URI of a resource or an opened file-like object or an Element Tree instance or a string containing XML data. For other XSD components can be a string for an attribute or a simple type validators, or an ElementTree's Element otherwise. :param args: arguments that maybe passed to :func:`XMLSchema.iter_decode`. :param kwargs: keyword arguments from the ones included in the optional arguments of the :func:`XMLSchema.iter_decode`. :return: a dictionary like object if the XSD component is an element, a group or a complex type; a list if the XSD component is an attribute group; a simple data type object otherwise. If *validation* argument is 'lax' a 2-items tuple is returned, where the first item is the decoded object and the second item is a list containing the errors. :raises: :exc:`XMLSchemaValidationError` if the object is not decodable by the XSD component, or also if it's invalid when ``validation='strict'`` is provided.

Decorators:

decode_error(self, validation, obj, decoder, reason=None, source=None, namespaces=None, **_kwargs)

source code 

Helper method for generating decode errors. Incompatible with 'skip' validation mode. Il validation mode is 'lax' returns the error, otherwise raises the error.

:param validation: an error-compatible validation mode: can be 'lax' or 'strict'. :param obj: the not validated XML data. :param decoder: the XML data decoder. :param reason: the detailed reason of failed validation. :param source: the XML resource that contains the error. :param namespaces: is an optional mapping from namespace prefix to URI. :param _kwargs: keyword arguments of the validation process that are not used.

Decorators:

default_namespace(self)

source code 

Property that references to schema's default namespaces.

Decorators:
  • @property

encode(self, obj, *args, **kwargs)

source code 

Encodes data to XML using the XSD schema/component.

:param obj: the data to be encoded to XML. :param args: arguments that maybe passed to :func:`XMLSchema.iter_encode`. :param kwargs: keyword arguments from the ones included in the optional arguments of the :func:`XMLSchema.iter_encode`. :return: An element tree's Element if the original data is a structured data or a string if it's simple type datum. If *validation* argument is 'lax' a 2-items tuple is returned, where the first item is the encoded object and the second item is a list containing the errors. :raises: :exc:`XMLSchemaValidationError` if the object is not encodable by the XSD component, or also if it's invalid when ``validation='strict'`` is provided.

Decorators:

encode_error(self, validation, obj, encoder, reason=None, source=None, namespaces=None, **_kwargs)

source code 

Helper method for generating encode errors. Incompatible with 'skip' validation mode. Il validation mode is 'lax' returns the error, otherwise raises the error.

:param validation: an error-compatible validation mode: can be 'lax' or 'strict'. :param obj: the not validated XML data. :param encoder: the XML encoder. :param reason: the detailed reason of failed validation. :param source: the XML resource that contains the error. :param namespaces: is an optional mapping from namespace prefix to URI. :param _kwargs: keyword arguments of the validation process that are not used.

Decorators:

final(self)

source code 
Decorators:
  • @property

get_facet(self, tag)

source code 
Decorators:
Overrides: XsdSimpleType.get_facet

has_mixed_content(self)

source code 
Decorators:
Overrides: xsdbase.XsdType.has_mixed_content

has_simple_content(self)

source code 
Decorators:
Overrides: xsdbase.XsdType.has_simple_content

id(self)

source code 

The ``'id'`` attribute of the component tag, ``None`` if missing.

Decorators:
  • @property

is_atomic()
Static Method

source code 
Decorators:
Overrides: xsdbase.XsdType.is_atomic

is_complex()
Static Method

source code 
Decorators:
Overrides: xsdbase.XsdType.is_complex

is_derived(self, other, derivation=None)

source code 
Decorators:
Overrides: xsdbase.XsdType.is_derived

is_element_only(self)

source code 
Decorators:
Overrides: xsdbase.XsdType.is_element_only

is_emptiable(self)

source code 
Decorators:
Overrides: xsdbase.XsdType.is_emptiable

is_empty(self)

source code 
Decorators:
Overrides: xsdbase.XsdType.is_empty

is_global(self)

source code 

Is `True` if the instance is a global component, `False` if it's local.

Decorators:
  • @property

is_matching(self, name, default_namespace=None)

source code 

Returns `True` if the component name is matching the name provided as argument, `False` otherwise.

:param name: a local or fully-qualified name. :param default_namespace: used if it's not None and not empty for completing the name argument in case it's a local name.

Decorators:

is_simple()
Static Method

source code 
Decorators:
Overrides: xsdbase.XsdType.is_simple

is_valid(self, source, use_defaults=True)

source code 

Like :meth:`validate` except that do not raises an exception but returns ``True`` if the XML document is valid, ``False`` if it's invalid.

:param source: the source of XML data. For a schema can be a path to a file or an URI of a resource or an opened file-like object or an Element Tree instance or a string containing XML data. For other XSD components can be a string for an attribute or a simple type validators, or an ElementTree's Element otherwise. :param use_defaults: indicates whether to use default values for filling missing data.

Decorators:

iter_ancestors(self, xsd_classes=None)

source code 

Creates an iterator for XSD ancestor components, schema excluded. Stops when the component is global or if the ancestor is not an instance of the specified class/classes.

:param xsd_classes: provide a class or a tuple of classes to iterates over only a specific classes of components.

Decorators:

iter_components(self, xsd_classes=None)

source code 

Creates an iterator for XSD subcomponents.

:param xsd_classes: provide a class or a tuple of classes to iterates over only a specific classes of components.

Decorators:
Overrides: XsdValidator.iter_components

iter_errors(self, source, path=None, use_defaults=True, namespaces=None)

source code 

Creates an iterator for the errors generated by the validation of an XML data against the XSD schema/component instance.

:param source: the source of XML data. For a schema can be a path to a file or an URI of a resource or an opened file-like object or an Element Tree instance or a string containing XML data. For other XSD components can be a string for an attribute or a simple type validators, or an ElementTree's Element otherwise. :param path: is an optional XPath expression that defines the parts of the document that have to be validated. The XPath expression considers the schema as the root element with global elements as its children. :param use_defaults: Use schema's default values for filling missing data. :param namespaces: is an optional mapping from namespace prefix to URI.

Decorators:

local_name(self)

source code 
Decorators:
  • @property

maps(self)

source code 

Property that references to schema's global maps.

Decorators:
  • @property

max_value(self)

source code 
Decorators:
  • @property

min_value(self)

source code 
Decorators:
  • @property

namespaces(self)

source code 

Property that references to schema's namespace mapping.

Decorators:
  • @property

normalize(self, text)

source code 

Normalize and restrict value-space with pre-lexical and lexical facets. The normalized string is returned. Returns the argument if it isn't a string.

:param text: text string encoded value. :return: normalized string.

Decorators:

parse_error(self, error, elem=None)

source code 

Helper method for registering parse errors. Does nothing if validation mode is 'skip'. Il validation mode is 'lax' collects the error, otherwise raise the error.

:param error: can be a parse error or an error message. :param elem: the Element instance related to the error, for default uses the 'elem' attribute of the validator, if it's present.

Decorators:

prefixed_name(self)

source code 
Decorators:
  • @property

primitive_type(self)

source code 
Decorators:
  • @property

qualified_name(self)

source code 
Decorators:
  • @property

schema_elem(self)

source code 

The reference element of the schema for the component instance.

Decorators:
  • @property

source(self)

source code 

Property that references to schema source.

Decorators:
  • @property

target_namespace(self)

source code 

Property that references to schema's targetNamespace.

Decorators:
  • @property

to_dict(self, source, *args, **kwargs)

source code 

Decodes XML data using the XSD schema/component.

:param source: the source of XML data. For a schema can be a path to a file or an URI of a resource or an opened file-like object or an Element Tree instance or a string containing XML data. For other XSD components can be a string for an attribute or a simple type validators, or an ElementTree's Element otherwise. :param args: arguments that maybe passed to :func:`XMLSchema.iter_decode`. :param kwargs: keyword arguments from the ones included in the optional arguments of the :func:`XMLSchema.iter_decode`. :return: a dictionary like object if the XSD component is an element, a group or a complex type; a list if the XSD component is an attribute group; a simple data type object otherwise. If *validation* argument is 'lax' a 2-items tuple is returned, where the first item is the decoded object and the second item is a list containing the errors. :raises: :exc:`XMLSchemaValidationError` if the object is not decodable by the XSD component, or also if it's invalid when ``validation='strict'`` is provided.

Decorators:

to_etree(self, obj, *args, **kwargs)

source code 

Encodes data to XML using the XSD schema/component.

:param obj: the data to be encoded to XML. :param args: arguments that maybe passed to :func:`XMLSchema.iter_encode`. :param kwargs: keyword arguments from the ones included in the optional arguments of the :func:`XMLSchema.iter_encode`. :return: An element tree's Element if the original data is a structured data or a string if it's simple type datum. If *validation* argument is 'lax' a 2-items tuple is returned, where the first item is the encoded object and the second item is a list containing the errors. :raises: :exc:`XMLSchemaValidationError` if the object is not encodable by the XSD component, or also if it's invalid when ``validation='strict'`` is provided.

Decorators:

validate(self, source, use_defaults=True, namespaces=None)

source code 

Validates an XML data against the XSD schema/component instance.

:param source: the source of XML data. For a schema can be a path to a file or an URI of a resource or an opened file-like object or an Element Tree instance or a string containing XML data. For other XSD components can be a string for an attribute or a simple type validators, or an ElementTree's Element otherwise. :param use_defaults: indicates whether to use default values for filling missing data. :param namespaces: is an optional mapping from namespace prefix to URI. :raises: :exc:`XMLSchemaValidationError` if XML *data* instance is not a valid.

Decorators:

validation_attempted(self)

source code 

Property that returns the *validation status* of the XSD validator. It can be 'full', 'partial' or 'none'.

| https://www.w3.org/TR/xmlschema-1/#e-validation_attempted | https://www.w3.org/TR/2012/REC-xmlschema11-1-20120405/#e-validation_attempted

Decorators:
  • @property
Overrides: xsdbase.XsdValidator.validation_attempted
(inherited documentation)

validation_error(self, validation, error, obj=None, source=None, namespaces=None, **_kwargs)

source code 

Helper method for generating and updating validation errors. Incompatible with 'skip' validation mode. Il validation mode is 'lax' returns the error, otherwise raises the error.

:param validation: an error-compatible validation mode: can be 'lax' or 'strict'. :param error: an error instance or the detailed reason of failed validation. :param obj: the instance related to the error. :param source: the XML resource related to the validation process. :param namespaces: is an optional mapping from namespace prefix to URI. :param _kwargs: keyword arguments of the validation process that are not used.

Decorators:

validity(self)

source code 

Property that returns the XSD validator's validity. It can be ‘valid’, ‘invalid’ or ‘notKnown’.

| https://www.w3.org/TR/xmlschema-1/#e-validity | https://www.w3.org/TR/2012/REC-xmlschema11-1-20120405/#e-validity

Decorators:
  • @property