|
35 | 35 | import zipfile |
36 | 36 | import binascii |
37 | 37 | import platform |
38 | | -import mimetypes |
39 | 38 | try: |
40 | 39 | from backports import tempfile |
41 | 40 | except ImportError: |
@@ -480,49 +479,6 @@ def decode_unicode_escape(value): |
480 | 479 | outextlist.append('zlib') |
481 | 480 | outextlistwd.append('.zlib') |
482 | 481 |
|
483 | | -tarfile_mimetype = "application/tar" |
484 | | -tarfile_tar_mimetype = tarfile_mimetype |
485 | | -zipfile_mimetype = "application/zip" |
486 | | -zipfile_zip_mimetype = zipfile_mimetype |
487 | | -rarfile_mimetype = "application/rar" |
488 | | -rarfile_rar_mimetype = rarfile_mimetype |
489 | | -archivefile_mimetype = "application/x-"+__file_format_dict__['format_lower']+"" |
490 | | -mimetypes.add_type(archivefile_mimetype, __file_format_extension__, strict=True) |
491 | | -archivefile_cat_mimetype = archivefile_mimetype |
492 | | -archivefile_gzip_mimetype = "application/x-" + \ |
493 | | - __file_format_dict__['format_lower']+"+gzip" |
494 | | -archivefile_gz_mimetype = archivefile_gzip_mimetype |
495 | | -mimetypes.add_type(archivefile_gz_mimetype, __file_format_extension__+".gz", strict=True) |
496 | | -archivefile_bzip2_mimetype = "application/x-" + \ |
497 | | - __file_format_dict__['format_lower']+"+bzip2" |
498 | | -archivefile_bz2_mimetype = archivefile_bzip2_mimetype |
499 | | -mimetypes.add_type(archivefile_bz2_mimetype, __file_format_extension__+".bz2", strict=True) |
500 | | -archivefile_lz4_mimetype = "application/x-" + \ |
501 | | - __file_format_dict__['format_lower']+"+lz4" |
502 | | -mimetypes.add_type(archivefile_lz4_mimetype, __file_format_extension__+".lz4", strict=True) |
503 | | -archivefile_lzop_mimetype = "application/x-" + \ |
504 | | - __file_format_dict__['format_lower']+"+lzop" |
505 | | -mimetypes.add_type(archivefile_lzop_mimetype, __file_format_extension__+".lzop", strict=True) |
506 | | -archivefile_lzo_mimetype = archivefile_lzop_mimetype |
507 | | -mimetypes.add_type(archivefile_lzo_mimetype, __file_format_extension__+".lzo", strict=True) |
508 | | -archivefile_zstandard_mimetype = "application/x-" + \ |
509 | | - __file_format_dict__['format_lower']+"+zstandard" |
510 | | -archivefile_zstd_mimetype = archivefile_zstandard_mimetype |
511 | | -mimetypes.add_type(archivefile_zstd_mimetype, __file_format_extension__+".zst", strict=True) |
512 | | -archivefile_lzma_mimetype = "application/x-" + \ |
513 | | - __file_format_dict__['format_lower']+"+lzma" |
514 | | -mimetypes.add_type(archivefile_lzma_mimetype, __file_format_extension__+".lzma", strict=True) |
515 | | -archivefile_xz_mimetype = "application/x-" + \ |
516 | | - __file_format_dict__['format_lower']+"+xz" |
517 | | -mimetypes.add_type(archivefile_xz_mimetype, __file_format_extension__+".xz", strict=True) |
518 | | -archivefile_zlib_mimetype = "application/x-" + \ |
519 | | - __file_format_dict__['format_lower']+"+zlib" |
520 | | -mimetypes.add_type(archivefile_zlib_mimetype, __file_format_extension__+".zz", strict=True) |
521 | | -mimetypes.add_type(archivefile_zlib_mimetype, __file_format_extension__+".zl", strict=True) |
522 | | -mimetypes.add_type(archivefile_zlib_mimetype, __file_format_extension__+".zlib", strict=True) |
523 | | -archivefile_zz_mimetype = archivefile_zlib_mimetype |
524 | | -archivefile_zl_mimetype = archivefile_zlib_mimetype |
525 | | -archivefile_extensions = [__file_format_extension__, __file_format_extension__+".gz", __file_format_extension__+".bz2", __file_format_extension__+".zst", __file_format_extension__+".lz4", __file_format_extension__ + ".lzo", __file_format_extension__+".lzop", __file_format_extension__+".lzma", __file_format_extension__+".xz", __file_format_extension__+".zz", __file_format_extension__+".zl", __file_format_extension__+".zlib"] |
526 | 482 |
|
527 | 483 | if __name__ == "__main__": |
528 | 484 | import subprocess |
@@ -4217,36 +4173,6 @@ def CheckCompressionTypeFromBytes(instring, formatspecs=__file_format_multi_dict |
4217 | 4173 | return CheckCompressionType(instringsfile, formatspecs, closefp) |
4218 | 4174 |
|
4219 | 4175 |
|
4220 | | - |
4221 | | -def GetCompressionMimeType(infile, formatspecs=__file_format_multi_dict__): |
4222 | | - compresscheck = CheckCompressionType(fp, formatspecs, False) |
4223 | | - if(IsNestedDict(formatspecs) and compresscheck in formatspecs): |
4224 | | - formatspecs = formatspecs[compresscheck] |
4225 | | - if(compresscheck == "gzip" or compresscheck == "gz"): |
4226 | | - return archivefile_gzip_mimetype |
4227 | | - elif(compresscheck == "zlib" or (compresscheck == "zz" or compresscheck == "zl" or compresscheck == "zlib")): |
4228 | | - return archivefile_zlib_mimetype |
4229 | | - elif(compresscheck == "bzip2" or compresscheck == "bz2"): |
4230 | | - return archivefile_bzip2_mimetype |
4231 | | - elif(compresscheck == "zstd" or compresscheck == "zstandard"): |
4232 | | - return archivefile_zstandard_mimetype |
4233 | | - elif(compresscheck == "lz4"): |
4234 | | - return archivefile_lz4_mimetype |
4235 | | - elif(compresscheck == "lzo" or compresscheck == "lzop"): |
4236 | | - return archivefile_lzop_mimetype |
4237 | | - elif(compresscheck == "lzma"): |
4238 | | - return archivefile_lzma_mimetype |
4239 | | - elif(compresscheck == "xz"): |
4240 | | - return archivefile_xz_mimetype |
4241 | | - elif(compresscheck == formatspecs['format_magic']): |
4242 | | - return archivefile_cat_mimetype |
4243 | | - else: |
4244 | | - return False |
4245 | | - if(not compresscheck): |
4246 | | - return False |
4247 | | - return False |
4248 | | - |
4249 | | - |
4250 | 4176 | def UncompressArchiveFile(fp, formatspecs=__file_format_multi_dict__): |
4251 | 4177 | if(not hasattr(fp, "read")): |
4252 | 4178 | return False |
@@ -5006,11 +4932,6 @@ def PackArchiveFile(infiles, outfile, dirlistfromtxt=False, fmttype="auto", comp |
5006 | 4932 | return True |
5007 | 4933 |
|
5008 | 4934 |
|
5009 | | -if(hasattr(shutil, "register_archive_format")): |
5010 | | - def PackArchiveFileFunc(archive_name, source_dir, **kwargs): |
5011 | | - return PackArchiveFile(source_dir, archive_name, False, "auto", "auto", True, None, compressionlistalt, False, "crc32", [], __file_format_dict__['format_delimiter'], False, False) |
5012 | | - |
5013 | | - |
5014 | 4935 | def PackArchiveFileFromDirList(infiles, outfile, dirlistfromtxt=False, fmttype="auto", compression="auto", compresswholefile=True, compressionlevel=None, compressionuselist=compressionlistalt, followlink=False, checksumtype=["crc32", "crc32", "crc32"], extradata=[], formatspecs=__file_format_dict__, verbose=False, returnfp=False): |
5015 | 4936 | return PackArchiveFile(infiles, outfile, dirlistfromtxt, fmttype, compression, compresswholefile, compressionlevel, compressionuselist, followlink, checksumtype, extradata, formatspecs, verbose, returnfp) |
5016 | 4937 |
|
@@ -9580,11 +9501,6 @@ def UnPackArchiveFile(infile, outdir=None, followlink=False, seekstart=0, seeken |
9580 | 9501 | return True |
9581 | 9502 |
|
9582 | 9503 |
|
9583 | | -if(hasattr(shutil, "register_unpack_format")): |
9584 | | - def UnPackArchiveFileFunc(archive_name, extract_dir=None, **kwargs): |
9585 | | - return UnPackArchiveFile(archive_name, extract_dir, False, 0, 0, False, __file_format_dict__['format_delimiter'], False, False) |
9586 | | - |
9587 | | - |
9588 | 9504 | def UnPackArchiveFileString(catstr, outdir=None, followlink=False, seekstart=0, seekend=0, skipchecksum=False, formatspecs=__file_format_multi_dict__, verbose=False, returnfp=False): |
9589 | 9505 | fp = BytesIO(catstr) |
9590 | 9506 | listcatfiles = UnPackArchiveFile( |
@@ -10795,19 +10711,3 @@ def upload_file_to_internet_compress_string(ifp, url, compression="auto", compre |
10795 | 10711 | upload_file_to_internet_file(fp, outfile) |
10796 | 10712 | return True |
10797 | 10713 |
|
10798 | | - |
10799 | | -try: |
10800 | | - if(hasattr(shutil, "register_archive_format")): |
10801 | | - # Register the packing format |
10802 | | - shutil.register_archive_format( |
10803 | | - __file_format_name__, PackArchiveFileFunc, description='Pack concatenated files') |
10804 | | -except shutil.RegistryError: |
10805 | | - pass |
10806 | | - |
10807 | | -try: |
10808 | | - if(hasattr(shutil, "register_unpack_format")): |
10809 | | - # Register the unpacking format |
10810 | | - shutil.register_unpack_format(__file_format_name__, archivefile_extensions, |
10811 | | - UnPackArchiveFileFunc, description='UnPack concatenated files') |
10812 | | -except shutil.RegistryError: |
10813 | | - pass |
0 commit comments