xsdata.codegen.handlers package

Submodules

Module contents

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

Bases: xsdata.codegen.mixins.HandlerInterface

Convert classes with a single attribute derived from xs:union where all types are enumerations to standalone enumeration.

Parameters

container (ContainerInterface) –

container: xsdata.codegen.mixins.ContainerInterface
process(target)[source]

Merge enumeration unions attributes.

Lookup for the source class in the local namespace or inner class list.

Parameters

target (Class) –

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

Bases: xsdata.codegen.mixins.HandlerInterface

Replace attribute groups with the source class attributes.

Parameters

container (ContainerInterface) –

container: xsdata.codegen.mixins.ContainerInterface
process(target)[source]

Iterate over all group attributes and apply handler logic.

Group attributes can refer to attributes or other group attributes, repeat until there is no group attribute left.

Parameters

target (Class) –

process_attribute(target, attr)[source]

Find the source class the attribute refers to and copy its attributes to the target class.

Raises

AnalyzerValueError – if source class is not found.

Parameters
class xsdata.codegen.handlers.AttributeMergeHandler[source]

Bases: xsdata.codegen.mixins.HandlerInterface

Merge same type attributes and their restrictions.

classmethod process(target)[source]

Detect same type attributes in order to merge them together with their restrictions.

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

Parameters

target (Class) –

class xsdata.codegen.handlers.AttributeMismatchHandler[source]

Bases: xsdata.codegen.mixins.HandlerInterface

Classes can not container attributes derived from xs:enumeration and any other schema element. Although very rare it can happen in silly cases when the author of the schema is trying to restrict the enum type with another xs:simpleType.

Apart from visibility about the origin of the enumeration values it doesn’t serve any other purpose. In this case simply drop non enum attributes

<xsd:simpleType name="ApplicableSizesType">
<xsd:restriction>
  <xsd:simpleType>
    <xsd:list itemType="SizeType"/>
  </xsd:simpleType>
  <xsd:enumeration value="small medium large"/>
  <xsd:enumeration value="2 4 6 8 10 12 14 16 18"/>
</xsd:restriction>
</xsd:simpleType>
classmethod process(target)[source]

Drop non enum attributes from enum classes.

Parameters

target (Class) –

class xsdata.codegen.handlers.AttributeMixedContentHandler[source]

Bases: xsdata.codegen.mixins.HandlerInterface

Add/Update a wildcard field for classes that support mixed content.

classmethod process(target)[source]

Add or update an existing an xs:anyType derived attribute if the target class supports mixed content.

Parameters

target (Class) –

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

Bases: xsdata.codegen.mixins.HandlerInterface

Apply substitution attributes to the given class recursively.

Parameters

container (ContainerInterface) –

container: xsdata.codegen.mixins.ContainerInterface
substitutions: Optional[Dict[str, List[xsdata.codegen.models.Attr]]] = None
process(target)[source]

Search and process attributes not derived from xs:enumeration or xs:any.

Build the substitutions map if it’s not initialized yet.

Parameters

target (Class) –

process_attribute(target, attr)[source]

Check if the given attribute matches any substitution class in order to clone it’s attributes to the target class.

The cloned attributes are placed below the attribute the are supposed to substitute.

Parameters
create_substitutions()[source]

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

classmethod create_substitution(source)[source]

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

Parameters

source (Class) –

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: xsdata.codegen.mixins.ContainerInterface
dependencies: Dict
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(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

attr_type (AttrType) –

Return type

Optional[Class]

process_inner_type(target, attr, attr_type)[source]

Process an attributes type that depends on an inner type.

If there is a matching simple type inner class copy the inner type attribute properties.

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

Process an attributes type that depends on any global type.

Steps:
  1. Reset absent or dummy attribute types with a warning.

  2. Copy attribute properties from a simple type.

  3. Set circular flag for the rest non enumerations.

Parameters
classmethod copy_attribute_properties(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
set_circular_flag(source, target, attr_type)[source]

Update circular reference flag.

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

Check if any source dependencies recursively match the target class.

Parameters
Return type

bool

cached_dependencies(source)[source]

Returns from cache the source class dependencies as a collection of qualified names.

Parameters

source (Class) –

Return type

Tuple[str]

classmethod reset_attribute_type(attr_type)[source]

Reset the attribute type to native string.

Parameters

attr_type (AttrType) –

classmethod filter_types(types)[source]

Remove duplicate and invalid types.

Invalid:
  1. xs:error

  2. xs:anyType and xs:anySimpleType when there are other types present

Parameters

types (List[AttrType]) –

Return type

List[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) –

REMOVE_EXTENSION = 0
FLATTEN_EXTENSION = 1
IGNORE_EXTENSION = 2
container: xsdata.codegen.mixins.ContainerInterface
process(target)[source]

Iterate and process the target class’s extensions in reverser order.

The reverse order is necessary in order to maintain the correct attributes ordering during cloning.

Parameters

target (Class) –

process_extension(target, extension)[source]

Slit the process of extension into schema data types and user defined types.

Parameters
classmethod process_native_extension(target, extension)[source]

Native type flatten handler.

In case of enumerations copy the native data type to all enum members, otherwise create a default text value with the extension attributes.

Parameters
process_dependency_extension(target, extension)[source]

User defined type flatten handler.

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.

Compare source and target classes and either remove the extension completely, copy all source attributes to the target class or leave the extension alone.

Parameters
find_dependency(attr_type)[source]

Find dependency for the given extension type with priority.

Search priority: xs:SimpleType > xs:ComplexType

Parameters

attr_type (AttrType) –

Return type

Optional[Class]

classmethod compare_attributes(source, target)[source]

Compare the attributes of the two classes and return whether the source class can and should be flattened.

Remove:
  1. Source is the Target

  2. Target includes all the source attributes

Flatten:
  1. Source includes some of the target attributes

  2. The source class is marked to be forced flattened

  3. Source class includes an attribute that needs to be last

  4. Target class includes an attribute that needs to be last

  5. Source class is a simple type

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 add_default_attribute(target, extension)[source]

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

Parameters
classmethod get_or_create_attribute(target, name, tag)[source]

Find or create for the given parameters an attribute in the target class.

Parameters
Return type

Attr