PK!ã&x12_utils/__init__.py__version__ = "0.3.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!x12_utils/x12_validator.pyimport logging from 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() # Capture error logging output of pyx12 # The pyx12 module uses a logger named pyx12, # which we get here. If pyx12 changes this in # a future version, it will break this code. # The line of code defining the logger is at # https://github.com/azoner/pyx12/blob/2e3529e31a167a53ebcd9da348cece9f284b6710/pyx12/scripts/x12valid.py#L78 logger_output: StringIO = StringIO() pyx12_logger = logging.getLogger('pyx12') handler = logging.StreamHandler(logger_output) pyx12_logger.addHandler(handler) pyx12_logger.setLevel(logging.ERROR) # 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() error_val = logger_output.getvalue().splitlines() xml_val = xml.getvalue() return { "html": html_val, "997": nn7_val, "xml": xml_val, "errors": error_val, "ok": ok, } PK!HڽTUx12_utils-0.3.0.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!H%# "x12_utils-0.3.0.dist-info/METADATAPN0+R R%(R@-p76Y {l^7Xkg^9>e2%J8jN~0z%TVxBd#d8 ԔБ\.Wɕј ڕs-,+謣+ѹ6֫d]e#)Efqe: xm`>d0= ).jLB|؀p]my}oʭ5UZǔjJrES%l,4t'ܹ~SH`kϕPK!H0- x12_utils-0.3.0.dist-info/RECORD}ιr@>ϲ⺀qEE \r>}&rۆuiNeWcu*֤e*kRމ~PK!ã&x12_utils/__init__.pyPK!fIx12_utils/x12_generator.pyPK!x12_utils/x12_validator.pyPK!HڽTU x12_utils-0.3.0.dist-info/WHEELPK!H%# "Gx12_utils-0.3.0.dist-info/METADATAPK!H0- x12_utils-0.3.0.dist-info/RECORDPK