def run_info(self, args): self.show_version() print("\nFormats:") table = texttable.Texttable() table.set_deco(texttable.Texttable.HEADER) table.set_cols_dtype(['t', 't']) table.set_cols_align(["l", "r"]) for f in SupportedMethods.formats: m = ''.join(' {:02x}'.format(x) for x in f['magic']) table.add_row([f['name'], m]) print(table.draw()) print("\nCodecs and hashes:") table = texttable.Texttable() table.set_deco(texttable.Texttable.HEADER) table.set_cols_dtype(['t', 't']) table.set_cols_align(["l", "r"]) for c in SupportedMethods.methods: m = ''.join('{:02x}'.format(x) for x in c['id']) table.add_row([m, c['name']]) table.add_row(['0', 'CRC32']) if is_check_supported(CHECK_SHA256): table.add_row(['0', 'SHA256']) if is_check_supported(CHECK_CRC64): table.add_row(['0', 'CRC64']) print(table.draw())
def test_cli_info(capsys): if lzma.is_check_supported(lzma.CHECK_CRC64): check0 = "\nCHECK_CRC64" else: check0 = "" if lzma.is_check_supported(lzma.CHECK_SHA256): check1 = "\nCHECK_SHA256" else: check1 = "" expected_checks = """Checks: CHECK_NONE CHECK_CRC32{}{}""".format(check0, check1) expected = """py7zr version {} {} Formats: 7z 37 7a bc af 27 1c Codecs: 030101 LZMA 21 LZMA2 03 DELTA 03030103 BCJ 03030205 PPC 03030401 IA64 03030501 ARM 03030701 ARMT 03030805 SPARC {} """.format(py7zr.__version__, py7zr.__copyright__, expected_checks) cli = py7zr.cli.Cli() cli.run(["i"]) out, err = capsys.readouterr() assert expected == out
def run_info(self, args): self.show_version() print("\nFormats:") table = texttable.Texttable() table.set_deco(texttable.Texttable.HEADER) table.set_cols_dtype(["t", "t"]) table.set_cols_align(["l", "r"]) for f in SupportedMethods.formats: m = "".join(" {:02x}".format(x) for x in f["magic"]) table.add_row([f["name"], m]) print(table.draw()) print("\nCodecs and hashes:") table = texttable.Texttable() table.set_deco(texttable.Texttable.HEADER) table.set_cols_dtype(["t", "t"]) table.set_cols_align(["l", "r"]) for c in SupportedMethods.methods: m = "".join("{:02x}".format(x) for x in c["id"]) table.add_row([m, c["name"]]) table.add_row(["0", "CRC32"]) if is_check_supported(CHECK_SHA256): table.add_row(["0", "SHA256"]) if is_check_supported(CHECK_CRC64): table.add_row(["0", "CRC64"]) print(table.draw())
def run_info(self, args): print("py7zr version {} {}".format(py7zr.__version__, py7zr.__copyright__)) print("Formats:") table = texttable.Texttable() table.set_deco(texttable.Texttable.HEADER) table.set_cols_dtype(['t', 't']) table.set_cols_align(["l", "r"]) for f in SupportedMethods.formats: m = ''.join(' {:02x}'.format(x) for x in f['magic']) table.add_row([f['name'], m]) print(table.draw()) print("\nCodecs:") table = texttable.Texttable() table.set_deco(texttable.Texttable.HEADER) table.set_cols_dtype(['t', 't']) table.set_cols_align(["l", "r"]) for c in SupportedMethods.codecs: m = ''.join('{:02x}'.format(x) for x in c['id']) table.add_row([m, c['name']]) print(table.draw()) print("\nChecks:") print("CHECK_NONE") print("CHECK_CRC32") if lzma.is_check_supported(lzma.CHECK_CRC64): print("CHECK_CRC64") if lzma.is_check_supported(lzma.CHECK_SHA256): print("CHECK_SHA256")
def test_cli_info(capsys): expected = py7zr.cli.Cli._get_version() if lzma.is_check_supported(lzma.CHECK_CRC64): check0 = "\n0 CRC64" else: check0 = "" if lzma.is_check_supported(lzma.CHECK_SHA256): check1 = "\n0 SHA256" else: check1 = "" expected_checks = """0 CRC32{}{}""".format(check1, check0) expected += """\n Formats: 7z 37 7a bc af 27 1c Codecs and hashes: 00 COPY 21 LZMA2 03 DELTA 030101 LZMA 03030103 BCJ 03030205 PPC 03030401 IA64 03030501 ARM 03030701 ARMT 03030805 SPARC 040108 DEFLATE 040202 BZip2 04f71101 ZStandard 030401 PPMd 04f71102 Brotli 040109 DEFLATE64 06f10701 7zAES {} """.format( expected_checks ) cli = py7zr.cli.Cli() cli.run(["i"]) out, err = capsys.readouterr() assert out == expected
def lzma_func(): ''' LZMA压缩算法压缩和解压缩 LZMAFile线程不是安全的 ''' # 文件 # 读取:format, filters, 写入:format, check, preset, filters # lzma.open(filename, mode="rb", *, format=None, check=-1, preset=None, filters=None, encoding=None, errors=None, newline=None) f = lzma.open("box.xz") # lzma.compress(data, format=FORMAT_XZ, check=-1, preset=None, filters=None) // 压缩 bytes_com = lzma.compress(b'luzhuo.me') # lzma.decompress(data, format=FORMAT_AUTO, memlimit=None, filters=None) // 解压 bytes_decom = lzma.decompress(bytes_com) # lzma.is_check_supported(check) // 是否支持完整性检查 boolean = lzma.is_check_supported(lzma.CHECK_SHA256) # 压缩对象 check:完整性检查:CHECK_NONE,CHECK_CRC32(32位循环冗余校验),CHECK_CRC64(64位循环冗余校验),CHECK_SHA256(sha256) # preset: 压缩级别[0,9] # class lzma.LZMACompressor(format=FORMAT_XZ, check=-1, preset=None, filters=None) lzmacom = lzma.LZMACompressor() bytes_com = lzmacom.compress(b"luzhuo.me") # 压缩 bytes_com = lzmacom.flush() # 完成压缩 # 解压缩对象 # class lzma.LZMADecompressor(format=FORMAT_AUTO, memlimit=None, filters=None) lzmadecom = lzma.LZMADecompressor() # decompress(data, max_length=-1) bytes_decom = lzmadecom.decompress(bytes_com) # 解压 # 异常 try: pass except lzma.LZMAError: pass # 在压缩或解压或初始化时发生错误
def test_default_check_supported() -> None: assert is_check_supported(DEFAULT_CHECK)
def verify_compression(): import bz2, lzma, zlib assert lzma.is_check_supported(lzma.CHECK_CRC64) assert lzma.is_check_supported(lzma.CHECK_SHA256)
def update_event(self, inp=-1): self.set_output_val(0, lzma.is_check_supported(self.input(0)))
def test_compression(self): import bz2, lzma, zlib self.assertTrue(lzma.is_check_supported(lzma.CHECK_CRC64)) self.assertTrue(lzma.is_check_supported(lzma.CHECK_SHA256))