pyx12.map_walker

Walk a tree of x12_map nodes. Find the correct node.

If seg indicates a loop has been entered, returns the first child segment node. If seg indicates a segment has been entered, returns the segment node.

Attributes

Classes

MissingMandatorySeg

A pending 'mandatory missing' error to be flushed once the loop has moved on.

walk_tree

Walks a map_if tree. Tracks loop/segment counting, missing loop/segment.

Functions

pop_to_parent_loop(node)

is_first_seg_match2(child, seg_data)

Find the first segment in loop, verify it matches segment

get_id_list(node_list)

traverse_path(start_node, pop_loops, push_loops)

Debug function - From the start path, pop up then push down to get a path string

apply_walk_errors(errh, errors)

Forward walker SegErrors to an err_handler. Each error with a non-None

Module Contents

pyx12.map_walker.logger[source]
class pyx12.map_walker.MissingMandatorySeg[source]

Bases: NamedTuple

A pending ‘mandatory missing’ error to be flushed once the loop has moved on.

seg_node: Any[source]
seg_data: pyx12.segment.Segment[source]
err_cde: str[source]
err_str: str[source]
seg_count: int[source]
cur_line: int[source]
ls_id: str | None[source]
pyx12.map_walker.pop_to_parent_loop(node)[source]
Parameters:

node (L{node<map_if.x12_node>}) – Loop Node

Returns:

Closest parent loop node

Return type:

L{node<map_if.x12_node>}

pyx12.map_walker.is_first_seg_match2(child, seg_data)[source]

Find the first segment in loop, verify it matches segment

Parameters:
  • child (L{node<map_if.x12_node>}) – child node

  • seg_data (L{segment<segment.Segment>}) – Segment object

Return type:

boolean

pyx12.map_walker.get_id_list(node_list)[source]
Parameters:

node_list (list[Any])

Return type:

list[str]

pyx12.map_walker.traverse_path(start_node, pop_loops, push_loops)[source]

Debug function - From the start path, pop up then push down to get a path string

Parameters:
  • start_node (Any)

  • pop_loops (list[Any])

  • push_loops (list[Any])

Return type:

str

pyx12.map_walker.apply_walk_errors(errh, errors)[source]

Forward walker SegErrors to an err_handler. Each error with a non-None map_node triggers errh.add_seg(…) before errh.seg_error(…); map_node=None preserves the existing cursor (used for usage=’N’ emissions that historically attach to the prior segment).

Errors whose pyx12 code is in errh.suppress_error_codes are filtered out before they reach the err_handler tree.

Parameters:
  • errh (L{error_handler.err_handler}) – Error handler

  • errors ([L{SegError}]) – SegErrors accumulated by walk_errors()

Return type:

None

class pyx12.map_walker.walk_tree(initialCounts=None)[source]

Walks a map_if tree. Tracks loop/segment counting, missing loop/segment.

Parameters:

initialCounts (collections.abc.Mapping[str | pyx12.path.X12Path, int] | None)

mandatory_segs_missing: list[MissingMandatorySeg][source]
counter: pyx12.nodeCounter.NodeCounter[source]
errors_pending: list[pyx12.error_item.SegError][source]
walk_errors(node, seg_data, seg_count, cur_line, ls_id)[source]

Walk the node tree from the starting node to the node matching seg_data. Catch any counting or requirement errors along the way.

Handle required segment/loop missed (not found in seg) Handle found segment = Not used

Parameters:
  • node (L{node<map_if.x12_node>}) – Starting node

  • seg_data (L{segment<segment.Segment>}) – Segment object

  • seg_count (int) – Count of current segment in the ST Loop

  • cur_line (int) – Current line number in the file

  • ls_id (string) – The current LS loop identifier

Returns:

The matching x12 segment node, a list of x12 popped loops, a list of x12 pushed loops from the start segment to the found segment, and the list of accumulated SegErrors found along the way.

Return type:

(L{node<map_if.segment_if>}, [L{node<map_if.loop_if>}], [L{node<map_if.loop_if>}], [L{SegError}])

TODO: check single segment loop repeat

getCountState()[source]
Return type:

Any

setCountState(initialCounts=None)[source]
Parameters:

initialCounts (collections.abc.Mapping[str | pyx12.path.X12Path, int] | None)

Return type:

None

forceWalkCounterToLoopStart(x12_path, child_path)[source]
Parameters:
  • x12_path (str)

  • child_path (str)

Return type:

None