PK!x12_utils/__init__.py__version__ = "0.1.0" PK!fx12_utils/x12_generator.pyfrom typing import List, IO, Tuple, Union def x12_generate( src: List[Tuple[str, Union[List[str], None]]], output_file: Union[IO[str], None] = None, element_separator: str = "*", segment_separator: str = "~", sub_element_separator: str = ":", ): """ Generates edi based on input in list format :param src: edi information in the format ["Segment Identifier" ("Element 1", "Element 2", ...)] :param element_separator: Separator for elements; default is "*" :param segment_separator: Separator for segments; default is "~" :param sub_element_separator: Separator for sub-elements; default is ":" :returns: String containing syntactically valid edi (not necessarily structurally valid) """ output = "" total_lines = 0 for e in src: car = e[0] cdr = e[1] if cdr is None: continue while len(cdr) is not 0 and cdr[-1] is "": # Don't leave trailing element separators cdr = cdr[:-1] if len(cdr) is 0: continue line = ( car + element_separator + element_separator.join(cdr) + segment_separator + "\n" ) output += line total_lines += 1 return output PK!u!~x12_utils/x12_validator.pyfrom pyx12 import params as x12n_params, x12n_document # type: ignore from io import StringIO from contextlib import redirect_stderr, redirect_stdout from typing import Any, Dict, IO, Union def x12_validate( src: Union[str, IO[str]], params: Union[Any, None] = None, generate_html: bool = False, generate_997: bool = False, generate_xml: bool = False, ) -> Dict[str, Union[str, bool, list]]: """ Validate x12 EDI string or contents of file descriptor. """ src_fd: IO[str] if isinstance(src, str): src_fd = StringIO(src) else: src_fd = src pyx12_params = params if not isinstance(pyx12_params, type(x12n_params)): pyx12_params = x12n_params.params(None) nn7: StringIO = StringIO() html: StringIO = StringIO() xml: StringIO = StringIO() stderr: StringIO = StringIO() with redirect_stderr(stderr): # Capture errors from pyx12 ok = x12n_document.x12n_document( param=pyx12_params, src_file=src_fd, fd_997=nn7 if generate_997 else None, fd_html=html if generate_html else None, fd_xmldoc=xml if generate_xml else None, map_path=None, ) # Get string values html_val = html.getvalue() nn7_val = nn7.getvalue() stderr_val = stderr.getvalue().splitlines() xml_val = xml.getvalue() return { "html": html_val, "997": nn7_val, "xml": xml_val, "errors": stderr_val, "ok": ok, } PK!HڽTUx12_utils-0.2.1.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!Ha"x12_utils-0.2.1.dist-info/METADATAP[O0~8 ID"& 5W8lGut{[o7}iN5z^'l`,GZT6'8޶h+ȩ(}$Op:랩.#_F#\ĕ54ޥ 4->ʝ5iGU$619՝XNT)|˖_ZrmP`>d0=CqQif:X# M+=ÿ$N[.+?/'/;2L39< w> 6X&o]?JPK!Hl{- x12_utils-0.2.1.dist-info/RECORD}Ϲr@g(R hhvԕçORq,G[I;GCNT{?muJ:#{^",, |p5R]Nh`6[u˼yA"$`WcpvX9SIdz g/dˆRITv(gx D: D,pѸ