def __tester_replace_in_file(): txt_test = 'test.txt' text = 'First Row\nSecond Row\n' u_file.write(txt_test, text) u_file.replace_in_file(txt_test, [('o', 'a')]) text_test = u_file.read(txt_test) text_true = 'First Raw\nSecand Raw\n' p0 = text_test == text_true u_tester.run(p0)
def hex_to_file(path_hex, path_text): """ ============================================================================ Description: Convert Hex-File into Text-File. ============================================================================ Arguments: ---------------------------------------------------------------------------- 1. path_hex : str (Path to Hex-File). 2. path_text : str (Path to Text-File). ============================================================================ """ str_hex = u_file.read(path_hex) text = hex_to_str(str_hex) u_file.write(text, path_text)
def file_to_hex(path_text, path_hex): """ ============================================================================ Description: Convert Text-File into Hex-File. ============================================================================ Arguments: ---------------------------------------------------------------------------- 1. path_text : str (Path to Text-File). 2. path_hex : str (Path to Hex-File). ============================================================================ """ text = u_file.read(path_text) str_hex = str_to_hex(text) u_file.write(str_hex, path_hex)
def decode_py(path_csv, path_py): """ ======================================================================= Description: Decode Text-File with Hex-Encoding into Python-File. ======================================================================= Arguments: ----------------------------------------------------------------------- 1. path_txt : str (Path to encoded Text-File). 2. path_py : str (Path to Python-File to Decode). ======================================================================= """ csv_hex = u_file.read(path_csv) text_hex = csv_hex.replace(',', '').replace('\n', '') text_py = bytearray.fromhex(text_hex).decode('utf-8') u_file.write(text_py, path_py)
def encode_py(path_py, path_csv): """ ======================================================================= Description: Encode Python-File into Csv-File with Hex-Encoding. ======================================================================= Arguments: ----------------------------------------------------------------------- 1. path_py : str (Path to Python-File to Encode). 2. path_csv : str (Path to encoded Csv-File). ======================================================================= """ text_py = u_file.read(path_py) text_hex = bytearray(text_py.encode('utf-8')).hex() csv_hex = str() for i, ch in enumerate(text_hex): csv_hex += ch if not i: continue if not (i + 1) % 10: csv_hex += ',' if not (i + 1) % 100: csv_hex += '\n' u_file.write(csv_hex, path_csv)