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.

Parameters
Return type

int

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.

Parameters
classmethod sanitize_attribute_name(attr)[source]

Sanitize attribute name in preparation for duplicate attrbute names handler.

Steps:
  1. 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.

Parameters

attrs (List[Attr]) –

Return type

None

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.

Parameters
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
Return type

Attr

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.

Parameters
classmethod copy_inner_classes(source, target)[source]

Copy safely inner classes from source to target class.

Checks:
  1. Inner is the target class, skip and mark as self reference

  2. Inner with same name exists, skip

Parameters
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 merge_redefined_classes(classes)[source]

Merge original and redefined classes.

Parameters

classes (List[Class]) –

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.

Parameters

classes (List[Class]) –

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.

Parameters
classmethod create_reference_attribute(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

classmethod find_attribute(attrs, attr)[source]

Return the position of the given attribute in the list.

Parameters
Return type

int

classmethod reset_attribute_type(attr_type)[source]

Reset the attribute type to native string.

Parameters

attr_type (AttrType) –