xsdata.formats.generators module

class xsdata.formats.generators.AbstractGenerator[source]

Bases: abc.ABC

templates_dir: Optional[pathlib.Path] = None
template(name)[source]
Parameters

name (str) –

Return type

Template

abstract render(classes)[source]
Parameters

classes (List[Class]) –

Return type

Iterator[Tuple[Path, str, str]]

classmethod module_name(name)[source]
Parameters

name (str) –

Return type

str

classmethod package_name(name)[source]
Parameters

name (str) –

Return type

str

class xsdata.formats.generators.PythonAbstractGenerator[source]

Bases: xsdata.formats.generators.AbstractGenerator, abc.ABC

xml_type_map = {'Element': 'Element', 'Any': 'Wildcard', 'AnyAttribute': 'Attributes', 'Attribute': 'Attribute', None: 'Text'}
classmethod process_class(obj, parents=None)[source]

Normalize all class instance fields, extends, name and the inner classes recursively.

Parameters
Return type

Class

classmethod process_enumerations(obj)[source]
Parameters

obj (Class) –

classmethod process_attributes(obj, parents_list)[source]

Process class attributes and prevent duplicate attribute names.

Parameters
classmethod sanitize_attribute_names(obj)[source]

Append xml type to attribute name if it’s not unique in the list.

Prefer keeping intact element attributes.

Parameters

obj (Class) –

classmethod hash_attributes_names(obj)[source]

Replace attribute names with b64 hash of the local name.

This is a last resort to create unique class attribute names.

Parameters

obj (Class) –

classmethod has_duplicate_attrs(obj)[source]

Check if given class includes duplicate attribute names.

Parameters

obj (Class) –

Return type

bool

classmethod unset_attributes_local_names(obj)[source]

Unset attribute local name when it’s not necessary.

Examples:
  • xs:any

  • xs:anyAttribute

  • field name is equal to local name

Parameters

obj (Class) –

classmethod process_extension(extension)[source]
Parameters

extension (Extension) –

classmethod process_attribute(target, attr, parents)[source]

Normalize attribute properties.

Parameters
classmethod process_import(package)[source]

Normalize import package properties.

Parameters

package (Package) –

Return type

Package

classmethod module_name(name)[source]
Parameters

name (str) –

Return type

str

classmethod package_name(name)[source]
Parameters

name (str) –

Return type

str

classmethod class_name(name)[source]

Convert class names to pascal case.

Parameters

name (str) –

Return type

str

classmethod type_name(attr_type)[source]

Convert xsd types to python or apply class name conventions after stripping any reference prefix.

Parameters

attr_type (AttrType) –

Return type

str

classmethod attribute_name(name)[source]

Strip reference prefix and turn to snake case.

If the name is one of the python reserved words append the prefix _value

Parameters

name (str) –

Return type

str

classmethod enumeration_name(name)[source]

Strip reference prefix and turn to snake case.

If the name is one of the python reserved words append the prefix _value

Parameters

name (str) –

Return type

str

classmethod attribute_display_type(attr, parents)[source]

Normalize attribute type.

Steps:
  • If type alias is present use class name normalization

  • Otherwise use the type name normalization

  • Prepend outer class names and quote result for forward references

  • Wrap the result with List if the field accepts a list of values

  • Wrap the result with Optional if the field default value is None

Parameters
Return type

str

classmethod attribute_default(attr, ns_map=None)[source]

Normalize default value/factory by the attribute type.

Parameters
Return type

Any