API Documentation: autosar_data

autosar_data

Provides functionality to read, modify and write Autosar arxml files, both separately and in projects consisting of multiple files.

Classes:

  • ArxmlFile
  • AutosarModel
  • AutosarVersion
  • Element
  • ElementType
  • ValidSubElementInfo

Variables:

  • version

AttributeName module-attribute

AttributeName: TypeAlias = Literal[
    "ACCESSKEY",
    "ALIGN",
    "ALLOW-BREAK",
    "ALT",
    "BASE",
    "BGCOLOR",
    "BINDING-TIME",
    "BLUEPRINT-VALUE",
    "BREAK",
    "CLASS",
    "COLNAME",
    "COLNUM",
    "COLOR",
    "COLS",
    "COLSEP",
    "COLWIDTH",
    "COORDS",
    "DEST",
    "EDIT-HEIGHT",
    "EDIT-WIDTH",
    "EDITFIT",
    "EDITSCALE",
    "ENUM-TABLE",
    "FILENAME",
    "FIT",
    "FLOAT",
    "FONT",
    "FRAME",
    "GENERATOR",
    "GID",
    "HEIGHT",
    "HELP-ENTRY",
    "HREF",
    "HTML-FIT",
    "HTML-HEIGHT",
    "HTML-SCALE",
    "HTML-WIDTH",
    "INDEX",
    "INTERVAL-TYPE",
    "ITEM-LABEL-POS",
    "KEEP-WITH-PREVIOUS",
    "L",
    "LEVEL",
    "MIME-TYPE",
    "MOREROWS",
    "NAME",
    "NAME-PATTERN",
    "NAMEEND",
    "NAMEST",
    "NOHREF",
    "NOTATION",
    "NOTE-TYPE",
    "ONBLUR",
    "ONCLICK",
    "ONDBLCLICK",
    "ONFOCUS",
    "ONKEYDOWN",
    "ONKEYPRESS",
    "ONKEYUP",
    "ONMOUSEDOWN",
    "ONMOUSEMOVE",
    "ONMOUSEOUT",
    "ONMOUSEOVER",
    "ONMOUSEUP",
    "ORIENT",
    "PGWIDE",
    "RESOLUTION-POLICY",
    "ROTATE",
    "ROWSEP",
    "S",
    "SCALE",
    "SD",
    "SHAPE",
    "SHORT-LABEL",
    "SHOW-CONTENT",
    "SHOW-RESOURCE-ALIAS-NAME",
    "SHOW-RESOURCE-CATEGORY",
    "SHOW-RESOURCE-LONG-NAME",
    "SHOW-RESOURCE-NUMBER",
    "SHOW-RESOURCE-PAGE",
    "SHOW-RESOURCE-SHORT-NAME",
    "SHOW-RESOURCE-TYPE",
    "SHOW-SEE",
    "SI",
    "SPANNAME",
    "STYLE",
    "T",
    "TABINDEX",
    "TABSTYLE",
    "TEX-RENDER",
    "TITLE",
    "TYPE",
    "UUID",
    "VALIDITY",
    "VALIGN",
    "VIEW",
    "WIDTH",
    "xml:space",
    "xmlns",
    "xmlns:xsi",
    "xsi:schemaLocation",
]

CharacterData module-attribute

CharacterData: TypeAlias = Union[EnumItem, str, int, float]

CharacterDataType module-attribute

CharacterDataType: TypeAlias = Union[
    CharacterDataTypeEnum,
    CharacterDataTypeFloat,
    CharacterDataTypeRestrictedString,
    CharacterDataTypeString,
    CharacterDataTypeUnsignedInt,
]

ElementContent module-attribute

ElementContent: TypeAlias = Union[Element, CharacterData]

ElementName module-attribute

ElementName: TypeAlias = str

EnumItem module-attribute

EnumItem: TypeAlias = str

IncompatibleItemError module-attribute

IncompatibleItemError: TypeAlias = Union[
    IncompatibleAttributeError,
    IncompatibleAttributeValueError,
    IncompatibleElementError,
]

VersionSpecification module-attribute

VersionSpecification: TypeAlias = Union[
    AutosarVersion, List[AutosarVersion]
]

ArxmlFile

Represents a file that is part of an AutosarModel

elements_dfs property

elements_dfs: ArxmlFileElementsDfsIterator

filename property

filename: str

model property

model: AutosarModel

Get the autosar model that is built from the ARXML files

version property

version: AutosarVersion

xml_standalone property

xml_standalone: bool

get the "xml_standalone" attribute from the header of the ARXML file

check_version_compatibility method descriptor

check_version_compatibility() -> List[
    IncompatibleItemError
]

Check if the data in the ARXML file is compatible with the given target version

elements_dfs_with_max_depth method descriptor

elements_dfs_with_max_depth(
    max_depth: int,
) -> ArxmlFileElementsDfsIterator

dfs iterator over all elements in this file, with a maximum depth

serialize method descriptor

serialize() -> str

Serialize the ARXML file to a string

ArxmlFileElementsDfsIterator

A depth first search iterator over all elements contained in the file that created this iterator

Attribute

An attribute on an element

attrname property

attrname: AttributeName

content class

content: CharacterData = <member 'content' of 'autosar_data.autosar_data.Attribute' objects>

AttributeIterator

Iterates over all attributes on an element

AttributeSpec

Specification of an attribute

attribute_name property

attribute_name: str

name of the attribute

required property

required: bool

is the attribute required or optional

value_spec property

value_spec: CharacterDataType

AutosarDataError

Bases: builtins.Exception

AutosarModel

Autosar data model. It contains all elements.

elements_dfs property

elements_dfs: Iterator[int, Element]

depth first dearch iterator over all elements in the model, regardless of their association with a file

files property

files: List[ArxmlFile]

a list of ArxmlFile objects containing all files in the model

identifiable_elements property

identifiable_elements: IdentifiablesIterator

List of all paths of identifiable elements in the model

root_element property

root_element: Element

The root element of the model,

check_references method descriptor

check_references() -> List[Element]

check all references in the model and return a list of elements containing invalid references

create_file method descriptor

create_file(
    filename: str, /, version: AutosarVersion = Ellipsis
) -> ArxmlFile

create a new file in the model

duplicate method descriptor

duplicate() -> AutosarModel

duplicate the model, creating a new independent copy

get_element_by_path method descriptor

get_element_by_path(path) -> Element

get an identifiable element in the model by its Autosar path

get_references_to method descriptor

get_references_to(target_path: str) -> List[Element]

get all reference elements which refer to the given Autosar path

load_buffer method descriptor

load_buffer(
    buffer: str, filename: str, /, strict: bool = False
) -> Tuple[ArxmlFile, List[str]]

load a buffer (string) as arxml

load_file method descriptor

load_file(
    filename: str, /, strict: bool = False
) -> Tuple[ArxmlFile, List[str]]

load a file as arxml

remove_file method descriptor

remove_file(file) -> None

remove a file from the model. Any elements belonging exclusively to that file will also be removed.

serialize_files method descriptor

serialize_files() -> Dict[str, str]

serialize all files individually, to generate a dict(filename, serialized content),

sort method descriptor

sort() -> None

sort the entire model in place. Takes all ordering constraints into account.

write method descriptor

write() -> None

write all files in the model to disk

AutosarVersion

AUTOSAR_00042 class

AUTOSAR_00042: AutosarVersion = AutosarVersion.AUTOSAR_00042

AUTOSAR_00043 class

AUTOSAR_00043: AutosarVersion = AutosarVersion.AUTOSAR_00043

AUTOSAR_00044 class

AUTOSAR_00044: AutosarVersion = AutosarVersion.AUTOSAR_00044

AUTOSAR_00045 class

AUTOSAR_00045: AutosarVersion = AutosarVersion.AUTOSAR_00045

AUTOSAR_00046 class

AUTOSAR_00046: AutosarVersion = AutosarVersion.AUTOSAR_00046

AUTOSAR_00047 class

AUTOSAR_00047: AutosarVersion = AutosarVersion.AUTOSAR_00047

AUTOSAR_00048 class

AUTOSAR_00048: AutosarVersion = AutosarVersion.AUTOSAR_00048

AUTOSAR_00049 class

AUTOSAR_00049: AutosarVersion = AutosarVersion.AUTOSAR_00049

AUTOSAR_00050 class

AUTOSAR_00050: AutosarVersion = AutosarVersion.AUTOSAR_00050

AUTOSAR_00051 class

AUTOSAR_00051: AutosarVersion = AutosarVersion.AUTOSAR_00051

AUTOSAR_00052 class

AUTOSAR_00052: AutosarVersion = AutosarVersion.AUTOSAR_00052

AUTOSAR_00053 class

AUTOSAR_00053: AutosarVersion = AutosarVersion.AUTOSAR_00053

AUTOSAR_4_0_1 class

AUTOSAR_4_0_1: AutosarVersion = AutosarVersion.AUTOSAR_4_0_1

AUTOSAR_4_0_2 class

AUTOSAR_4_0_2: AutosarVersion = AutosarVersion.AUTOSAR_4_0_2

AUTOSAR_4_0_3 class

AUTOSAR_4_0_3: AutosarVersion = AutosarVersion.AUTOSAR_4_0_3

AUTOSAR_4_1_1 class

AUTOSAR_4_1_1: AutosarVersion = AutosarVersion.AUTOSAR_4_1_1

AUTOSAR_4_1_2 class

AUTOSAR_4_1_2: AutosarVersion = AutosarVersion.AUTOSAR_4_1_2

AUTOSAR_4_1_3 class

AUTOSAR_4_1_3: AutosarVersion = AutosarVersion.AUTOSAR_4_1_3

AUTOSAR_4_2_1 class

AUTOSAR_4_2_1: AutosarVersion = AutosarVersion.AUTOSAR_4_2_1

AUTOSAR_4_2_2 class

AUTOSAR_4_2_2: AutosarVersion = AutosarVersion.AUTOSAR_4_2_2

AUTOSAR_4_3_0 class

AUTOSAR_4_3_0: AutosarVersion = AutosarVersion.AUTOSAR_4_3_0

LATEST class

LATEST: AutosarVersion = AutosarVersion.LATEST

CharacterDataTypeEnum

The character data in an element or attribute is an enum value

values property

values: List[str]

list of permitted enum values

CharacterDataTypeFloat

The character data in an element or attribute is a float

CharacterDataTypeRestrictedString

The character data in an element or attribute is a string that must match a regex

max_length property

max_length

max length (if any)

regex property

regex: str

validation regex

CharacterDataTypeString

The character data in an element or attribute is a string

max_length property

max_length

max length (if any)

preserve_whitespace property

preserve_whitespace

does this element preserve whitespace in its character data

CharacterDataTypeUnsignedInt

The character data in an element or attribute is an unsigned integer

ContentMode

The content mode of an element type

Bag class

Bag: ContentMode = Bag

The content mode of an element type

Characters class

Characters: ContentMode = Characters

The content mode of an element type

Choice class

Choice: ContentMode = Choice

The content mode of an element type

Mixed class

Mixed: ContentMode = Mixed

The content mode of an element type

Sequence class

Sequence: ContentMode = Sequence

The content mode of an element type

ContentType

The content type of an element

CharacterData class

CharacterData: ContentType = CharacterData

The content type of an element

Elements class

Elements: ContentType = Elements

The content type of an element

Mixed class

Mixed: ContentType = Mixed

The content type of an element

Element

An element in the Autosar data model

attributes property

attributes: AttributeIterator

character_data property

character_data: CharacterData

comment property

comment: str

content property

content: ElementContentIterator

content_item_count property

content_item_count: int

content_type property

content_type: ContentType

element_name property

element_name: ElementName

element_type property

element_type: ElementType

elements_dfs property

elements_dfs: Iterator[Tuple[int, Element]]

file_membership property

file_membership: Tuple[bool, FrozenSet[ArxmlFile]]

is_identifiable property

is_identifiable: bool

is_reference property

is_reference: bool

item_name property

item_name: str

min_version property

min_version: AutosarVersion

model property

model: AutosarModel

named_parent property

named_parent: Element

parent property

parent: Element

path property

path: str

position property

position: int

reference_target property

reference_target: Element

Set the reference target of a reference element

This is only valid for elements with a reference content type.

sub_elements property

sub_elements: ElementsIterator

xml_path property

xml_path: str

add_to_file method descriptor

add_to_file(file: ArxmlFile) -> None

add the element to a file. if necessary all parent elements of this element also become part of the file

attribute_value method descriptor

attribute_value(attrname_str) -> CharacterData

get the attribute value of a specific attribute. Returns None if that attribute is not set

create_copied_sub_element method descriptor

create_copied_sub_element() -> Element

Create a new sub-element by copying the given element and all its children

This creates a fully-independen copy. The function can copy elements between different models.

create_named_sub_element method descriptor

create_named_sub_element() -> Element

Create a new sub-element with the given element name and item name

create_sub_element method descriptor

create_sub_element() -> Element

Create a new sub-element with the given element name

elements_dfs_with_max_depth method descriptor

elements_dfs_with_max_depth(
    max_depth: int,
) -> Iterator[Tuple[int, Element]]

depth first search iterator for this element and all of its sub elements, with a maximum depth

get_bsw_sub_element method descriptor

get_bsw_sub_element() -> Element

get the sub element with the given definition ref. It is possible to specify either the full definition ref, or only the last part after the final '/'

get_named_sub_element method descriptor

get_named_sub_element() -> Element

Get the sub-element with the given item name, if it exists

get_or_create_named_sub_element method descriptor

get_or_create_named_sub_element() -> Element

Get or create a sub-element with the given element name and item name

get_or_create_sub_element method descriptor

get_or_create_sub_element() -> Element

Get or create a sub-element with the given element name

This is used to ensure that a sub-element with the given name exists.

get_sub_element method descriptor

get_sub_element() -> Element

Get a sub-element with the given element name

If multiple sub-elements with the same name exist, only the first one is returned.

get_sub_element_at method descriptor

get_sub_element_at() -> Element

Get a sub-element at the given position

The position is 0-based, and must be less than the number of sub-elements.

insert_character_content_item method descriptor

insert_character_content_item() -> None

for elements with ElementType mixed, this allows character data to be inserted at any point in the content of this element

list_valid_sub_elements method descriptor

list_valid_sub_elements() -> List[ValidSubElementInfo]

provide information about valid sub elements as a list of ValidSubElementInfo

move_element_here method descriptor

move_element_here() -> Element

Move the given element to become a sub-element of this element

remove_attribute method descriptor

remove_attribute() -> None

remove an attribute from the element

remove_character_content_item method descriptor

remove_character_content_item() -> None

remove one character content item from the given position

remove_character_data method descriptor

remove_character_data() -> None

Remove the character data from the element

remove_from_file method descriptor

remove_from_file(file: ArxmlFile) -> None

remove this element from a file. Does not affect parent elements. When an element is no longer part of any file it is deleted.

remove_sub_element method descriptor

remove_sub_element() -> None

Remove the given sub-element from this element

Removing the element invalidates it, and causes all of the removed elements children to be removed as well.

remove_sub_element_kind method descriptor

remove_sub_element_kind() -> None

Remove a sub-element with the given element name

If multiple sub-elements with the same name exist, only the first one is removed.

serialize method descriptor

serialize() -> str

Serialize the element to a string in XML format

set_attribute method descriptor

set_attribute(attrname_str, value) -> None

set the given attribute to the provided value. If the attribute is valid for this element it will be created or modified as needed.

sort method descriptor

sort() -> None

sort this element and all of its sub elements

ElementContentIterator

Iterates over all content in an element

Content items an be sub elements or character data

ElementType

Type of an Element in the specification

attributes_spec property

attributes_spec: List[AttributeSpec]

chardata_spec property

chardata_spec: CharacterDataType

content_mode property

content_mode: ContentMode

is_named property

is_named: bool

is_ordered property

is_ordered: bool

is_ref property

is_ref: bool

splittable property

splittable: List[AutosarVersion]

std_restriction property

std_restriction: str

sub_elements_spec property

sub_elements_spec: List[SubElementSpec]

find_attribute_spec method descriptor

find_attribute_spec(attrname_str) -> AttributeSpec

find the specification for the given attribute name

find_sub_element method descriptor

find_sub_element(
    target_name: ElementName, version_obj
) -> ElementType

find the ElementType of the named sub element in the specification of this ElementType

reference_dest_value method descriptor

reference_dest_value(target: ElementType) -> EnumItem

helper to determine the correct value for the DEST attribute when setting a reference

splittable_in method descriptor

splittable_in(version: AutosarVersion) -> bool

is this element splittable in a particular AutosarVersion

ElementsDfsIterator

ElementsIterator

Iterator over all sub elements of an element

IdentifiablesIterator

Iterator of all identifiable elements in the model. It provides the tuple (path, Element) for each entry.

IncompatibleAttributeError

Information about an attribute that is incompatible with a given target version

allowed_versions property

allowed_versions: List[AutosarVersion]

attribute property

attribute: AttributeName

element property

element: Element

IncompatibleAttributeValueError

Information about an attribute value that is incompatible with a given target version

allowed_versions property

allowed_versions: List[AutosarVersion]

attribute property

attribute: AttributeName

attribute_value property

attribute_value: str

element property

element: Element

IncompatibleElementError

Information about an element that is incompatible with a given target version

allowed_versions property

allowed_versions: List[AutosarVersion]

element property

element: Element

SubElementSpec

Specification of a sub element

allowed_versions property

allowed_versions: List[AutosarVersion]

list of versions in which this sub element is compatible

element_name property

element_name: str

name of the sub element

element_type property

element_type: ElementType

element type of the sub element

ValidSubElementInfo

Details about a particular sub element

element_name property

element_name: str

is_allowed property

is_allowed: bool

is_named property

is_named: bool

check_buffer builtin

check_buffer()

Check if the given buffer contains valid Autosar data

The function returns true if the buffer starts with a valid arxml header (after skipping whitespace and comments). This function does not check anything after the header.

check_file builtin

check_file(filename: str)

Check if the file contains arxml data. Returns true if an arxml file header is found and does not parse anything after it.