pyx12.map_if

Interface to a X12N IG Map.

This package re-exports the classes that previously lived in a single map_if.py module so that import pyx12.map_if and from pyx12.map_if import X keep working unchanged.

Attributes

Classes

x12_node

X12 Node Superclass

composite_if

Composite Node Interface

element_if

Element Interface

loop_if

Loop Interface

map_if

Map file interface

segment_if

Segment Interface

Functions

is_syntax_valid(seg_data, syn)

Verifies the segment against the syntax

load_map_file(map_file, param[, map_path])

Create the map object from a file

Package Contents

pyx12.map_if.is_syntax_valid(seg_data, syn)[source]

Verifies the segment against the syntax :param seg_data: data segment instance :type seg_data: L{segment<segment.Segment>} :param syn: list containing the syntax type, and the indices of elements :type syn: list[string] :rtype: tuple(boolean, error string)

Parameters:
Return type:

tuple[bool, str | None]

pyx12.map_if.MAXINT = 2147483647
class pyx12.map_if.x12_node[source]

X12 Node Superclass

id: str | None
name: str | None
usage: str | None
parent: x12_node | None
children: list[x12_node]
path: str
getnodebypath(path)[source]
Parameters:

path (str)

Return type:

x12_node | None

get_child_count()[source]
Return type:

int

get_child_node_by_idx(idx)[source]
Parameters:

idx (int) – zero based

Return type:

x12_node | None

get_child_node_by_ordinal(ordinal)[source]

Get a child element or composite by the X12 ordinal :param ord: one based element/composite index. Corresponds to the map <seq> element :type ord: int

Parameters:

ordinal (int)

Return type:

x12_node | None

get_path()[source]
Returns:

path - XPath style

Return type:

string

x12path
debug_print()[source]
Return type:

None

xml()[source]
Return type:

None

is_first_seg_in_loop()[source]
Return type:

boolean

is_map_root()[source]
Return type:

boolean

is_loop()[source]
Return type:

boolean

is_segment()[source]
Return type:

boolean

is_element()[source]
Return type:

boolean

is_composite()[source]
Return type:

boolean

class pyx12.map_if.composite_if(root, parent, elem)[source]

Bases: pyx12.map_if._base.x12_node

Composite Node Interface

Get the values for this composite :param parent: parent node

Parameters:
root: pyx12.map_if._root.map_if
children: list[pyx12.map_if._element.element_if]
base_name: str
refdes: str | None
data_ele: str | None
seq: int
repeat: int
parent
path = ''
id
usage
name
debug_print()[source]
Return type:

None

xml()[source]

Sends an xml representation of the composite to stdout

Return type:

None

is_valid_errors(comp_data)[source]

Pure validator: returns (ok, errors) without touching an error handler. Composite-level errors leave map_node unset (=None) so a wrapper iterating with cursor tracking attaches them to whatever cursor was last set — matches the historical behavior of the per-composite errh.ele_error calls.

Parameters:

comp_data (pyx12.segment.Composite | None)

Return type:

tuple[bool, list[pyx12.error_item.EleError]]

is_composite()[source]
Return type:

boolean

class pyx12.map_if.element_if(root, parent, elem)[source]

Bases: pyx12.map_if._base.x12_node

Element Interface

Parameters:
root: pyx12.map_if._root.map_if
base_name: str
valid_codes: list[str | None]
external_codes: str | None
rec: re.Pattern[str] | None
refdes: str | None
data_ele: str | None
seq: int
max_use: str | None
res: str | None
children = []
parent
id
usage
name
path
debug_print()[source]
Return type:

None

get_parent()[source]
Returns:

ref to parent class instance

Return type:

pyx12.map_if._base.x12_node | None

abstractmethod is_match()[source]
Returns:

Return type:

boolean

is_valid_errors(elem, type_list=None)[source]

Pure validator: returns (ok, errors) without touching an error handler.

Parameters:
Return type:

tuple[bool, list[pyx12.error_item.EleError]]

get_data_type()[source]
Return type:

str | None

property data_type: str | None
Return type:

str | None

property min_len: int
Return type:

int

property max_len: int
Return type:

int

property data_element_name: str | None
Return type:

str | None

get_seg_count()[source]
Return type:

None

is_element()[source]
Return type:

boolean

get_path()[source]
Returns:

path - XPath style

Return type:

string

get_parent_segment()[source]
Return type:

pyx12.map_if._base.x12_node

pyx12.map_if.load_map_file(map_file, param, map_path=None)[source]

Create the map object from a file

Parameters:
  • map_file (string) – filename (basename) of the map xml file to load

  • map_path (string) – Override directory containing map xml files. If None, uses package resource folder

  • param (pyx12.params.ParamsBase)

Return type:

pyx12.map_if

class pyx12.map_if.loop_if(root, parent, elem)[source]

Bases: pyx12.map_if._base.x12_node

Loop Interface

Parameters:
root: pyx12.map_if._root.map_if
pos_map: dict[int, list[pyx12.map_if._base.x12_node]]
base_name: str
type: str | None
pos: int
repeat: str | None
parent
id
path
name
usage
debug_print()[source]
Return type:

None

get_max_repeat()[source]
Return type:

int

get_parent()[source]
Return type:

pyx12.map_if._base.x12_node | None

get_first_node()[source]
Return type:

pyx12.map_if._base.x12_node | None

get_first_seg()[source]
Return type:

pyx12.map_if._segment.segment_if | None

childIterator()[source]
Return type:

collections.abc.Iterator[pyx12.map_if._base.x12_node]

getnodebypath(spath)[source]
Parameters:

spath (string) – remaining path to match

Returns:

matching node, or None is no match

Return type:

pyx12.map_if._base.x12_node | None

getnodebypath2(path_str)[source]

Try x12 path

Parameters:

path_str (string) – remaining path to match

Returns:

matching node, or None is no match

Return type:

pyx12.map_if._base.x12_node | None

get_child_count()[source]
Return type:

int

get_child_node_by_idx(idx)[source]
Parameters:

idx (int) – zero based

Return type:

pyx12.map_if._base.x12_node | None

get_seg_count()[source]
Returns:

Number of child segments

Return type:

integer

is_loop()[source]
Return type:

boolean

is_match(seg_data)[source]
Returns:

Is the segment a match to this loop?

Return type:

boolean

Parameters:

seg_data (L{segment<segment.Segment>})

get_child_seg_node(seg_data)[source]

Return the child segment matching the segment data

Parameters:

seg_data (pyx12.segment.Segment)

Return type:

pyx12.map_if._segment.segment_if | None

get_child_loop_node(seg_data)[source]

Return the child segment matching the segment data

Parameters:

seg_data (pyx12.segment.Segment)

Return type:

loop_if | None

get_cur_count()[source]
Returns:

current count

Return type:

int

incr_cur_count()[source]
Return type:

None

reset_child_count()[source]

Set cur_count of child nodes to zero

Return type:

None

reset_cur_count()[source]

Set cur_count of node and child nodes to zero

Return type:

None

set_cur_count(ct)[source]
Parameters:

ct (int)

Return type:

None

get_counts_list(ct_list)[source]

Build a list of (path, ct) of the current node and parents Gets the node counts to apply to another map :param ct_list: List to append to :type ct_list: list[(string, int)]

Parameters:

ct_list (list[tuple[str, int]])

Return type:

bool

loop_segment_iterator()[source]
Return type:

collections.abc.Iterator[pyx12.map_if._base.x12_node]

class pyx12.map_if.map_if(eroot, param, base_path=None)[source]

Bases: pyx12.map_if._base.x12_node

Map file interface

Parameters:
pos_map: dict[int, list[pyx12.map_if._base.x12_node]]
cur_path: str
param: pyx12.params.ParamsBase
ext_codes: pyx12.codes.ExternalCodes
data_elements: pyx12.dataele.DataElements
base_name: str
icvn: str | None
children = None
path = '/'
id
name
debug_print()[source]
Return type:

None

get_child_count()[source]
Return type:

int

get_first_node()[source]
Return type:

pyx12.map_if._base.x12_node | None

get_first_seg()[source]
Return type:

pyx12.map_if._segment.segment_if | None

get_path()[source]
Return type:

string

get_child_node_by_idx(idx)[source]
Parameters:

idx (int) – zero based

Return type:

pyx12.map_if._base.x12_node | None

getnodebypath(spath)[source]
Parameters:

spath (string) – Path string; /1000/2000/2000A/NM102-3

Return type:

pyx12.map_if._base.x12_node | None

getnodebypath2(path_str)[source]
Parameters:
  • path (string) – Path string; /1000/2000/2000A/NM102-3

  • path_str (str)

Return type:

pyx12.map_if._base.x12_node | None

is_map_root()[source]
Return type:

boolean

reset_child_count()[source]

Set cur_count of child nodes to zero

Return type:

None

reset_cur_count()[source]

Set cur_count of child nodes to zero

Return type:

None

loop_segment_iterator()[source]
Return type:

collections.abc.Iterator[pyx12.map_if._base.x12_node]

class pyx12.map_if.segment_if(root, parent, elem)[source]

Bases: pyx12.map_if._base.x12_node

Segment Interface

Parameters:
root: pyx12.map_if._root.map_if
children: list[pyx12.map_if._element.element_if | pyx12.map_if._composite.composite_if]
base_name: str
syntax: list[list[Any]]
type: str | None
pos: int
max_use: str | None
repeat: str | None
end_tag: str | None
parent
id
path
name
usage
debug_print()[source]
Return type:

None

get_child_node_by_idx(idx)[source]
Parameters:

idx (int) – zero based

Return type:

pyx12.map_if._element.element_if | pyx12.map_if._composite.composite_if | None

get_child_node_by_ordinal(ord)[source]

Get a child element or composite by the X12 ordinal :param ord: one based element/composite index. Corresponds to the map <seq> element :type ord: int

Parameters:

ord (int)

Return type:

pyx12.map_if._element.element_if | pyx12.map_if._composite.composite_if | None

getnodebypath2(path_str)[source]

Try x12 path

Parameters:

path_str (string) – remaining path to match

Returns:

matching node, or None is no match

Return type:

pyx12.map_if._base.x12_node | None

get_max_repeat()[source]
Return type:

int

get_parent()[source]
Returns:

ref to parent class instance

Return type:

pyx12.x12_node

is_first_seg_in_loop()[source]
Return type:

boolean

is_match(seg)[source]

Is data segment given a match to this segment node? :param seg: data segment instance :return: boolean :rtype: boolean

Parameters:

seg (pyx12.segment.Segment)

Return type:

bool

is_match_qual(seg_data, seg_id, qual_code)[source]

Is segment id and qualifier a match to this segment node and to this particular segment data? :param seg_data: data segment instance :type seg_data: L{segment<segment.Segment>} :param seg_id: data segment ID :param qual_code: an ID qualifier code :return: (True if a match, qual_code, element_index, subelement_index) :rtype: tuple(boolean, string, int, int)

Parameters:
Return type:

tuple[bool, str | None, int | None, int | None]

guess_unique_key_id_element()[source]

Some segments, like REF, DTP, and DTP are duplicated. They are matched using the value of an ID element. Which element to use varies. This function tries to find a good candidate.

Return type:

pyx12.map_if._element.element_if | None

get_unique_key_id_element(id_val)[source]

Some segments, like REF, DTP, and DTP are duplicated. They are matched using the value of an ID element. Which element to use varies. This function tries to find a good candidate, using a key value

Parameters:

id_val (str)

Return type:

pyx12.map_if._element.element_if | None

is_segment()[source]
Return type:

boolean

is_valid_errors(seg_data)[source]

Pure validator parallel to is_valid: returns (ok, errors) without touching an error handler. Seg-level errors (too many elements, too many sub-elements, syntax) leave map_node unset (=None); per-element errors carry map_node from the element validator so a cursor-tracking wrapper can replay add_ele/ele_error in the original order.

Parameters:

seg_data (pyx12.segment.Segment)

Return type:

tuple[bool, list[pyx12.error_item.EleError]]

get_cur_count()[source]
Returns:

current count

Return type:

int

incr_cur_count()[source]
Return type:

None

reset_cur_count()[source]

Set cur_count of node to zero

Return type:

None

set_cur_count(ct)[source]
Parameters:

ct (int)

Return type:

None

get_counts_list(ct_list)[source]

Build a list of (path, ct) of the current node and parents Gets the node counts to apply to another map :param ct_list: List to append to :type ct_list: list[(string, int)]

Parameters:

ct_list (list[tuple[str, int]])

Return type:

bool

loop_segment_iterator()[source]
Return type:

collections.abc.Iterator[pyx12.map_if._base.x12_node]