xsdata.codegen.handlers package

Submodules

Module contents

class xsdata.codegen.handlers.AttributeEnumUnionHandler(container)[source]

Bases: xsdata.codegen.mixins.HandlerInterface

Convert simple types with a single field which is a union of enums to a standalone enumeration.

Parameters

container (ContainerInterface) –

container: ContainerInterface = None
process(target)[source]
Parameters

target (Class) –

class xsdata.codegen.handlers.AttributeGroupHandler(container)[source]

Bases: xsdata.codegen.mixins.HandlerInterface

Expand attribute groups with all source class attributes recursively.

Parameters

container (ContainerInterface) –

container: ContainerInterface = None
process(target)[source]
Parameters

target (Class) –

process_attribute(target, attr)[source]
Parameters
class xsdata.codegen.handlers.AttributeImpliedHandler[source]

Bases: xsdata.codegen.mixins.HandlerInterface

Add implied attributes.

Scenarios:
  1. Mixed content class with missing wildcard attribute

Add an xs:anyType attribute to the given class if it supports mixed content and doesn’t have a wildcard attribute yet.

classmethod process(target)[source]
Parameters

target (Class) –

class xsdata.codegen.handlers.AttributeMergeHandler[source]

Bases: xsdata.codegen.mixins.HandlerInterface

Merge same type attributes and their restrictions.

Two attributes are considered equal if they have the same name, types and namespace.

classmethod process(target)[source]
Parameters

target (Class) –

class xsdata.codegen.handlers.AttributeMismatchHandler[source]

Bases: xsdata.codegen.mixins.HandlerInterface

Normalize attributes that can not coexist together in the same class by moving them to an existing inner class or to a new one.

classmethod process(target)[source]
Parameters

target (Class) –

class xsdata.codegen.handlers.AttributeSubstitutionHandler(container)[source]

Bases: xsdata.codegen.mixins.HandlerInterface

Apply substitution attributes to the given class recursively.

Substitution attributes are placed below the attribute the are supposed to substitute. Exclude enumerations and wildcard attributes from the process.

Parameters

container (ContainerInterface) –

container: ContainerInterface = None
substitutions: Optional[Dict[lxml.etree.QName, List[xsdata.codegen.models.Attr]]] = None
process(target)[source]
Parameters

target (Class) –

process_attribute(target, attr)[source]
Parameters
create_substitutions()[source]

Create reference attributes for all the classes substitutions and group them by their fully qualified name.

classmethod create_substitution(source, qname)[source]

Create an attribute with type that refers to the given source class and namespaced qualified name.

Parameters
  • source (Class) –

  • qname (QName) –

Return type

Attr

class xsdata.codegen.handlers.AttributeTypeHandler(container, dependencies=<factory>)[source]

Bases: xsdata.codegen.mixins.HandlerInterface

Minimize class attributes complexity by filtering and flattening types.

Parameters
container: ContainerInterface = None
dependencies: Dict = None
process(target)[source]

Process the given class attributes and their types.

Ensure all types are unique.

Parameters

target (Class) –

process_type(target, attr, attr_type)[source]

Process attribute type, split process for xml schema and user defined types.

Ignore forward references to inner classes.

Parameters
classmethod process_native_type(attr, attr_type)[source]

Reset attribute type if the attribute has a pattern restriction as they are not yet supported.

Parameters
find_dependency(target, attr_type)[source]

Find dependency for the given attribute.

Avoid conflicts by search in order:
  1. Non element/complexType

  2. Non abstract

  3. anything

Parameters
Return type

Optional[Class]

process_dependency_type(target, attr, attr_type)[source]

Process user defined attribute types, split process between complex and simple types.

Reset absent attribute types with a warning.

Complex Type: xs:Element and xs:ComplexType Simple stype: the rest

Parameters
classmethod process_simple_dependency(source, target, attr, attr_type)[source]

Replace the given attribute type with the types of the single field source class.

Ignore enumerations and gracefully handle dump types with no attributes.

Raises

AnalyzerValueError if the source class has more than one attributes

Parameters
process_complex_dependency(source, target, attr, attr_type)[source]

Process complex attribute type.

Abstract: If it can not be flattened remove abstract flag Non abstract: check for circular references.

Parameters
is_circular_dependency(source, target, seen=None)[source]

Check if any source dependencies recursively match the target class.

Parameters
Return type

bool

cached_dependencies(source)[source]
Parameters

source (Class) –

Return type

Tuple[QName]

classmethod reset_attribute_type(attr_type)[source]

Reset the attribute type to native string.

Parameters

attr_type (AttrType) –

class xsdata.codegen.handlers.ClassExtensionHandler(container)[source]

Bases: xsdata.codegen.mixins.HandlerInterface

Reduce class extensions by copying or creating new attributes.

Parameters

container (ContainerInterface) –

INCLUDES_NONE = 0
INCLUDES_SOME = 1
INCLUDES_ALL = 2
container: ContainerInterface = None
process(target)[source]
Parameters

target (Class) –

process_extension(target, extension)[source]
Parameters
classmethod process_native_extension(target, extension)[source]

Native type flatten extension handler, ignore enumerations.

Parameters
process_dependency_extension(target, extension)[source]
Parameters
classmethod process_simple_extension(source, target, ext)[source]

Simple flatten extension handler for common classes eg SimpleType, Restriction.

Steps:
  1. If target is source: drop the extension.

  2. If source is enumeration and target isn’t create default value attribute.

  3. If both source and target are enumerations copy all attributes.

  4. If both source and target are not enumerations copy all attributes.

  5. If target is enumeration: drop the extension.

Parameters
classmethod process_complex_extension(source, target, ext)[source]

Complex flatten extension handler for primary classes eg ComplexType, Element.

Drop extension when:
  • source includes all target attributes

Copy all attributes when:
  • source includes some of the target attributes

  • source has suffix attribute and target has at least one attribute

  • target has at least one suffix attribute

  • source or target class is abstract

Parameters
find_dependency(target, attr_type)[source]

Find dependency for the given extension type with priority.

Search priority: xs:SimpleType > xs:ComplexType

Parameters
Return type

Optional[Class]

classmethod compare_attributes(source, target)[source]

Compare the attributes of the two classes and return whether the source includes all, some or none of the target attributes.

Parameters
Return type

int

classmethod copy_extension_type(target, extension)[source]

Add the given extension type to all target attributes types and remove it from the target class extensions.

Parameters
classmethod create_default_attribute(item, extension)[source]

Add a default value field to the given class based on the extension type.

Parameters