xsdata.codegen.sanitizer module¶
-
class
xsdata.codegen.sanitizer.
ClassSanitizer
(container, config)[source]¶ Bases:
object
Prepare all the classes attributes for code generation and cleanup after the analyzer processors.
- Parameters
container (
ClassContainer
) –config (
GeneratorConfig
) –
-
container
: xsdata.codegen.container.ClassContainer¶
-
classmethod
process
(container, config)[source]¶ Iterate through all classes and run the sanitizer procedure.
- Parameters
container (
ClassContainer
) –config (
GeneratorConfig
) –
-
process_class
(target)[source]¶ Sanitize the attributes of the given class. After applying all the flattening handlers the attributes need to be further sanitized to squash common issues like duplicate attribute names.
- Steps:
Sanitize inner classes
Sanitize attributes default value
Sanitize attributes name
Sanitize attributes sequential flag
Sanitize duplicate attribute names
- Parameters
target (
Class
) –
-
group_compound_fields
(target)[source]¶ Group and process target attributes by the choice group.
- Parameters
target (
Class
) –
-
process_attribute_default
(target, attr)[source]¶ Sanitize attribute default value.
- Cases:
Ignore enumerations.
List fields can not have a fixed value.
Optional fields or xsi:type can not have a default or fixed value.
Convert string literal default value for enum fields.
-
process_attribute_default_enum
(target, attr)[source]¶ Convert string literal default value for enum fields.
Loop through all attributes types and search for enum sources. If an enum source exist map the default string literal value to a qualified name. If the source class in inner promote it to root classes.
-
promote_inner_class
(parent, inner)[source]¶ Convert inner class to root class.
- Steps:
Remove inner class from parent
Prepend parent name to inner class name.
Search and replace all matching attribute types.
Add inner class to the global class index.
-
resolve_conflicts
()[source]¶ Find classes with the same case insensitive qualified name and rename them.
-
rename_classes
(classes)[source]¶ Rename all the classes in the list.
Protect classes derived from xs:element if there is only one in the list.
-
rename_class
(target)[source]¶ Find the next available class identifier, save the original name in the class metadata and update the class qualified name and all classes that depend on the target class.
- Parameters
target (
Class
) –
-
next_qname
(namespace, name)[source]¶ Append the next available index number for the given namespace and local name.
-
rename_dependency
(target, search, replace)[source]¶ Search and replace the old qualified attribute type name with the new one if it exists in the target class attributes, extensions and inner classes.
-
find_enum
(source, attr_type)[source]¶ Find the enumeration source class for the given class and attribute type.
Search in root classes an inner class and exclude native types.
-
classmethod
process_attribute_restrictions
(attr)[source]¶ Sanitize attribute required flag by comparing the min/max occurrences restrictions.
- Parameters
attr (
Attr
) –
-
classmethod
process_attribute_sequence
(target, attr)[source]¶ Reset the attribute at the given index if it has no siblings with the sequential restriction.
-
classmethod
process_attribute_name
(attr)[source]¶ Sanitize attribute name in preparation for duplicate attribute names handler.
- Steps:
Remove non alpha numerical values
Handle Enum negative numerical values
Remove namespaces prefixes
Ensure name not empty
Ensure name starts with a letter
- Parameters
attr (
Attr
) –
-
classmethod
process_duplicate_attribute_names
(attrs)[source]¶ Sanitize duplicate attribute names that might exist by applying rename strategies.
-
classmethod
rename_attributes_with_index
(all_attrs, rename)[source]¶ Append the next available index number to all the rename attributes names.
-
classmethod
rename_attribute_by_preference
(a, b)[source]¶ Decide and rename one of the two given attributes.
When both attributes are derived from the same xs:tag and one of the two fields has a specific namespace prepend it to the name. Preferable rename the second attribute.
Otherwise append the derived from tag to the name of one of the two attributes. Preferably rename the second field or the field derived from xs:attribute.