xsdata.utils.classes module¶
-
class
xsdata.utils.classes.
ClassUtils
[source]¶ Bases:
object
-
INCLUDES_NONE
= 0¶
-
INCLUDES_SOME
= 1¶
-
INCLUDES_ALL
= 2¶
-
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.
-
classmethod
sanitize_attribute_restrictions
(attr)[source]¶ Sanitize attribute required flag by comparing the min/max occurrences restrictions.
- Parameters
attr (
Attr
) –
-
classmethod
sanitize_attribute_sequence
(attrs, index)[source]¶ Reset the attribute at the given index if it has no siblings with the sequential restriction.
-
classmethod
sanitize_attribute_name
(attr)[source]¶ Sanitize attribute name in preparation for duplicate attrbute names handler.
- Steps:
Remove non alpha numerical values
2. Handle Enum negative numerical values 2. Remove namespaces prefixes 3. Ensure name not empty 4. Ensure name starts with a letter
- Parameters
attr (
Attr
) –
-
classmethod
sanitize_duplicate_attribute_names
(attrs)[source]¶ Sanitize duplicate attribute names that might exist by applying rename strategies.
- Steps:
1. If more than two attributes share the same name or if they are enumerations append a numerical index to the attribute names. 2. If one of the two fields has a specific namespace prepend it to the name. If possible rename the second field. 3. Append the xml type to the name of one of the two attributes. if possible rename the second field or the field with xml type attribute.
-
classmethod
merge_duplicate_attributes
(target)[source]¶ Flatten duplicate attributes.
Remove duplicate fields in case of attributes or enumerations otherwise convert fields to lists. Two attributes are considered equal if they have the same name and types and namespace.
- Parameters
target (
Class
) –
-
classmethod
copy_attributes
(source, target, extension)[source]¶ Copy the attributes from the source class to the target class and remove the extension that links the two classes together.
The new attributes are prepended in the list unless if they are supposed to be last in a sequence.
-
classmethod
clone_attribute
(attr, restrictions, prefix=None)[source]¶ Clone the given attribute and merge its restrictions with the given instance.
Prepend the given namespace prefix to the attribute name if available.
- Parameters
attr (
Attr
) –restrictions (
Restrictions
) –
- Return type
-
classmethod
merge_attribute_type
(source, target, attr, attr_type)[source]¶ Replace the given attribute type with the types of the single field source class.
If the source class has more than one or no fields a warning will be logged and the target attribute type will change to simple string.
-
classmethod
copy_inner_classes
(source, target)[source]¶ Copy safely inner classes from source to target class.
- Checks:
Inner is the target class, skip and mark as self reference
Inner with same name exists, skip
-
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.
-
classmethod
update_abstract_classes
(classes)[source]¶ Update classes with the same qualified name to set implied abstract flags.
If a non abstract xs:element exists in the list mark the rest xs:complexType(s) as abstract.
-
classmethod
create_mixed_attribute
(target)[source]¶ Add an xs:anyType attribute to the given class if it supports mixed content and doesn’t have a wildcard attribute yet.
- Parameters
target (
Class
) –
-
classmethod
create_default_attribute
(item, extension)[source]¶ Add a default value field to the given class based on the extension type.
-
classmethod
create_reference_attribute
(source, qname)[source]¶ Create an attribute with type that refers to the given source class and namespaced qualified name.
-