Package xmlschema_acue :: Package validators :: Module groups :: Class XsdGroup

Class XsdGroup

source code



A class for XSD 1.0 model group definitions.

<group
  id = ID
  maxOccurs = (nonNegativeInteger | unbounded)  : 1
  minOccurs = nonNegativeInteger : 1
  name = NCName
  ref = QName
  {any attributes with non-schema namespace . . .}>
  Content: (annotation?, (all | choice | sequence)?)
</group>

<all
  id = ID
  maxOccurs = 1 : 1
  minOccurs = (0 | 1) : 1
  {any attributes with non-schema namespace . . .}>
  Content: (annotation?, element*)
</all>

<choice
  id = ID
  maxOccurs = (nonNegativeInteger | unbounded)  : 1
  minOccurs = nonNegativeInteger : 1
  {any attributes with non-schema namespace . . .}>
  Content: (annotation?, (element | group | choice | sequence | any)*)
</choice>

<sequence
  id = ID
  maxOccurs = (nonNegativeInteger | unbounded)  : 1
  minOccurs = nonNegativeInteger : 1
  {any attributes with non-schema namespace . . .}>
  Content: (annotation?, (element | group | choice | sequence | any)*)
</sequence>

Instance Methods
 
build(self) source code
 
admitted_restriction(self, model) source code
 
is_restriction(self, other, check_occurs=True) source code
 
is_element_restriction(self, other) source code
 
is_sequence_restriction(self, other) source code
 
is_all_restriction(self, other) source code
 
is_choice_restriction(self, other) source code

Inherited from xsdbase.XsdComponent: __setattr__, get_global, match, tostring

Inherited from xsdbase.XsdValidator: __str__, __unicode__

Inherited from models.ModelGroup: __delitem__, __getitem__, __len__, __setitem__, clear, insert, iter_subelements

Inherited from xsdbase.ParticleMixin: is_ambiguous, is_missing, is_over, is_single, is_univocal

Class Variables
  mixed = False
  model = None
  redefine = None

Inherited from xsdbase.XsdComponent: name, parent, qualified

Inherited from xsdbase.ParticleMixin: max_occurs, min_occurs

Method Details

__init__(self, elem, schema, parent, name=None)
(Constructor)

source code 
Decorators:
Overrides: models.ModelGroup.__init__

__repr__(self)
(Representation operator)

source code 
Decorators:
Overrides: models.ModelGroup.__repr__

copy(self)

source code 
Decorators:
Overrides: xsdbase.XsdValidator.copy

__copy__(self)

source code 
Decorators:
Overrides: xsdbase.XsdValidator.copy

children_validation_error(self, validation, elem, index, particle, occurs=0, expected=None, source=None, namespaces=None, **_kwargs)

source code 

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

:param validation: the validation mode. Can be 'lax' or 'strict'. :param elem: the instance Element. :param index: the child index. :param particle: the XSD component (subgroup or element) associated to the child. :param occurs: the child tag occurs. :param expected: the expected element tags/object names. :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:

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)

schema_elem(self)

source code 

The reference element of the schema for the component instance.

Decorators:
  • @property
Overrides: xsdbase.XsdComponent.schema_elem
(inherited documentation)

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)

ref(self)

source code 
Decorators:
  • @property

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: xsdbase.XsdValidator.iter_components
(inherited documentation)

is_empty(self)

source code 
Decorators:
Overrides: xsdbase.ParticleMixin.is_empty

iter_elements(self, depth=0)

source code 

A generator function iterating model's elements. Raises `XMLSchemaModelDepthError` if the argument *depth* is over `MAX_MODEL_DEPTH` value.

:param depth: guard for protect model nesting bombs, incremented at each deepest recursion.

Decorators:
Overrides: models.ModelGroup.iter_elements
(inherited documentation)

sort_children(self, elements, default_namespace=None)

source code 

Sort elements by group order, that maybe partial in case of 'all' or 'choice' ordering. The not matching elements are appended at the end.

Decorators:

iter_decode(self, elem, validation='lax', converter=None, **kwargs)

source code 

Creates an iterator for decoding an Element content.

:param elem: the Element that has to be decoded. :param validation: the validation mode, can be 'lax', 'strict' or 'skip. :param converter: an :class:`XMLSchemaConverter` subclass or instance. :param kwargs: keyword arguments for the decoding process. :return: yields a list of 3-tuples (key, decoded data, decoder), eventually preceded by a sequence of validation or decoding errors.

Decorators:
Overrides: xsdbase.ValidationMixin.iter_decode

iter_encode(self, element_data, validation='lax', converter=None, **kwargs)

source code 

Creates an iterator for encoding data to a list containing Element data.

:param element_data: an ElementData instance with unencoded data. :param validation: the validation mode: can be 'lax', 'strict' or 'skip'. :param converter: an :class:`XMLSchemaConverter` subclass or instance. :param kwargs: Keyword arguments for the encoding process. :return: Yields a couple with the text of the Element and a list of 3-tuples (key, decoded data, decoder), eventually preceded by a sequence of validation or encoding errors.

Decorators:
Overrides: xsdbase.ValidationMixin.iter_encode

update_occurs(self, counter)

source code 

Update group occurrences.

:param counter: a Counter object that trace occurrences for elements and groups.

Decorators:

all_errors(self)

source code 

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

Decorators:
  • @property

check_model(self)

source code 

Checks if the model group is deterministic. Types matching of same elements and Unique Particle Attribution Constraint are checked. Raises an `XMLSchemaModelError` at first violated constraint.

Decorators:

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:

has_occurs_restriction(self, other)

source code 
Decorators:
Overrides: xsdbase.ParticleMixin.has_occurs_restriction

id(self)

source code 

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

Decorators:
  • @property

is_emptiable(self)

source code 
Decorators:
Overrides: xsdbase.ParticleMixin.is_emptiable

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_pointless(self, parent)

source code 

Returns `True` if the group may be eliminated without affecting the model, `False` otherwise. A group is pointless if one of those conditions is verified:

  • the group is empty
  • minOccurs == maxOccurs == 1 and the group has one child
  • minOccurs == maxOccurs == 1 and the group and its parent have a sequence model
  • minOccurs == maxOccurs == 1 and the group and its parent have a choice model

Ref: https://www.w3.org/TR/2004/REC-xmlschema_acue-1-20041028/#coss-particle

:param parent: effective parent of the model group.

Decorators:

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_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:

iter_model(self, depth=0)

source code 

A generator function iterating elements and groups of a model group. Skips pointless groups, iterating deeper through them. Raises `XMLSchemaModelDepthError` if the argument *depth* is over `MAX_MODEL_DEPTH` value.

:param depth: guard for protect model nesting bombs, incremented at each deepest recursion.

Decorators:

local_name(self)

source code 
Decorators:
  • @property

maps(self)

source code 

Property that references to schema's global maps.

Decorators:
  • @property

namespaces(self)

source code 

Property that references to schema's namespace mapping.

Decorators:
  • @property

occurs(self)

source code 
Decorators:
  • @property

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

qualified_name(self)

source code 
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_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