xmu.utils

Functions to assess whether EMu field names are tables, references, etc.

xmu.utils.TAB_SUFFIXES = ('0', '_nesttab', '_nesttab_inner', '_tab')

suffixes that designate tables in EMu

Type:

tuple

xmu.utils.REF_SUFFIXES = ('RefLocal', 'Ref', 'Ref_nesttab', 'Ref_nesttab_inner', 'Ref_tab')

suffixes that designate references in EMu

Type:

tuple

xmu.utils.NESTTAB_SUFFIXES = ('_nesttab',)

suffixes that designate nested tables in EMu

Type:

tuple

xmu.utils.NESTTAB_INNER_SUFFIXES = ('_nesttab_inner',)

suffixes that designate inner nested tables in EMu

Type:

tuple

xmu.utils.TAB_PATTERN = '(0|_nesttab|_nesttab_inner|_tab)$'

pattern that matches table suffixes

Type:

str

xmu.utils.REF_PATTERN = '(RefLocal|Ref|Ref_nesttab|Ref_nesttab_inner|Ref_tab)$'

pattern that matches reference suffixes

Type:

str

xmu.utils.MOD_PATTERN = '\\(\\d*[=\\+\\-]\\)$'

pattern that matches update modifiers

Type:

str

xmu.utils.is_tab(field: str) bool[source]

Checks if a field name is a table

Parameters:

field (str) – field name

Returns:

True if field name is a table, False if not

Return type:

bool

xmu.utils.is_nesttab(field: str) bool[source]

Checks if a field name is a nested table

Parameters:

field (str) – field name

Returns:

True if field name is a nested table, False if not

Return type:

bool

xmu.utils.is_nesttab_inner(field: str) bool[source]

Checks if a field name is an inner nested table

Parameters:

field (str) – field name

Returns:

True if field name is an inner nested table, False if not

Return type:

bool

xmu.utils.is_ref_tab(field: str) bool[source]

Checks if a field name is a reference table

Parameters:

field (str) – field name

Returns:

True if field name is a reference table, False if not

Return type:

bool

xmu.utils.is_ref(field: str) bool[source]

Checks if a field name is a reference

Parameters:

field (str) – field name

Returns:

True if field name is a reference, False if not

Return type:

bool

xmu.utils.has_mod(field: str) bool[source]

Checks if a field name ends with an update modifier

Parameters:

field (str) – field name

Returns:

True if field name ends with an update modifier, False if not

Return type:

bool

xmu.utils.split_field(field: str) tuple[str][source]

Splits field into components

Parameters:

field (str) – field name

Returns:

field, ref, tab, mod

Return type:

tuple[str]

xmu.utils.to_ref(field: str) str[source]

Converts field to reference

Parameters:

field (str) – field name

Returns:

field name with reference signifier

Return type:

tuple

xmu.utils.strip_tab(field: str) str[source]

Strips table suffixes from a field name

Parameters:

field (str) – field name

Returns:

field name without a table suffix

Return type:

str

xmu.utils.strip_mod(field: str) str[source]

Strips update modifier from a field name

Parameters:

field (str) – field name

Returns:

field name without an update modifier

Return type:

str

xmu.utils.get_ref(field: str) str[source]

Gets the reference signifier from a field name

Parameters:

field (str) – field name

Returns:

a reference signifier if present, otherwise an empty string

Return type:

str

xmu.utils.get_tab(field: str) str[source]

Gets the table signifier from a field name

Parameters:

field (str) – field name

Returns:

a table signifier if present, otherwise an empty string

Return type:

str

xmu.utils.get_mod(field: str) str[source]

Gets the update modifier from a field name

Parameters:

field (str) – field name

Returns:

a modifier if found, otherwise an empty string

Return type:

str

xmu.utils.flatten(obj: dict, path: list = None, result: dict = None) dict[source]

Flattens a record to a one-level dict

Parameters:
  • obj (dict) – an EMu record

  • path (list, omit) – the path to the current key. Users should omit when calling.

  • result (dict, optional) – the flattened object. Defaults to empty dict. Users should generally omit when calling.

Returns:

records flattened to one level

Return type:

list