@@ -527,7 +527,8 @@ def main(options):
527527 elif options .out_format == "tlv" :
528528 # We may apply this encoding to all the other outputs. However, the TLV
529529 # is the only one which generates binary data.
530- options .output .reconfigure (encoding = 'charmap' , newline = '' )
530+ if __name__ == '__main__' :
531+ options .output .reconfigure (encoding = 'charmap' , newline = '' )
531532 formattlv (options .output , str_result )
532533 elif options .out_format == "pds" :
533534 options .output .write (str_result )
@@ -538,14 +539,20 @@ def main(options):
538539# This function is only an help for third-party tools that import pds_compress
539540# as a python module (also note it is necessary to add .py extention to this in
540541# order to import it).
541- def compress_string (str_in , extra_options = "" ):
542+ def compress_string (str_in , extra_options = "" , format = "pds" ):
542543 global g_defs , g_result , g_ret_value
543544 g_defs = {}
544545 g_result = []
545546 g_ret_value = 0
547+ if format == "tlv" :
548+ extra_options += " --out=tlv"
546549 options = parse_cmdline ([ "-" ] + extra_options .split ())
547550 options .input = io .StringIO (str_in )
548- options .output = io .StringIO ()
551+ if format == "tlv" :
552+ options .output = io .StringIO (newline = '' )
553+ else :
554+ options .output = io .StringIO ()
555+
549556 main (options )
550557 return options .output .getvalue ()
551558
0 commit comments