當前位置: 首頁>>代碼示例>>Python>>正文


Python zipfile.ZIP_LZMA屬性代碼示例

本文整理匯總了Python中zipfile.ZIP_LZMA屬性的典型用法代碼示例。如果您正苦於以下問題:Python zipfile.ZIP_LZMA屬性的具體用法?Python zipfile.ZIP_LZMA怎麽用?Python zipfile.ZIP_LZMA使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在zipfile的用法示例。


在下文中一共展示了zipfile.ZIP_LZMA屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import zipfile [as 別名]
# 或者: from zipfile import ZIP_LZMA [as 別名]
def __init__(self, ressourcefile, format = zipfile.ZIP_LZMA):
        self.zip = zipfile.ZipFile(ressourcefile, "r", format) 
開發者ID:Berserker66,項目名稱:omnitool,代碼行數:4,代碼來源:resources.py

示例2: output_to_zip

# 需要導入模塊: import zipfile [as 別名]
# 或者: from zipfile import ZIP_LZMA [as 別名]
def output_to_zip(filename: str, error: Optional[str], results: Dict, zip_type: str = "lzma"):
    """
    Output the results to a zip
    The file in the zip is named slither_results.json
    Note: the json file will not have indentation, as a result the resulting json file will be smaller
    :param zip_type:
    :param filename:
    :param error:
    :param results:
    :return:
    """
    json_result = {
        "success": error is None,
        "error": error,
        "results": results
    }
    if os.path.isfile(filename):
        logger.info(yellow(f'{filename} exists already, the overwrite is prevented'))
    else:
        with ZipFile(filename, "w", compression=ZIP_TYPES_ACCEPTED.get(zip_type, zipfile.ZIP_LZMA)) as file_desc:
            file_desc.writestr("slither_results.json", json.dumps(json_result).encode('utf8'))


# endregion
###################################################################################
###################################################################################
# region Json generation
###################################################################################
################################################################################### 
開發者ID:crytic,項目名稱:slither,代碼行數:31,代碼來源:output.py

示例3: save_to_zip

# 需要導入模塊: import zipfile [as 別名]
# 或者: from zipfile import ZIP_LZMA [as 別名]
def save_to_zip(files: List[Export], zip_filename: str, zip_type: str = "lzma"):
    """
    Save projects to a zip
    """
    logger.info(f"Export {zip_filename}")
    with zipfile.ZipFile(
        zip_filename, "w", compression=ZIP_TYPES_ACCEPTED.get(zip_type, zipfile.ZIP_LZMA)
    ) as file_desc:
        for f in files:
            file_desc.writestr(str(f.filename), f.content) 
開發者ID:crytic,項目名稱:slither,代碼行數:12,代碼來源:export.py

示例4: __init__

# 需要導入模塊: import zipfile [as 別名]
# 或者: from zipfile import ZIP_LZMA [as 別名]
def __init__(self, path, mode, archive=None):
        assert mode == 'r' or mode == 'w'
        assert archive in (None, 'zip', 'zip:none', 'zip:deflate', 'zip:bzip2', 'zip:lzma', 'tar', 'tar:none', 'tar:gzip', 'tar:bzip2', 'tar:lzma')
        self.archive = path
        self.mode = mode
        if not os.path.isdir(self.archive[:self.archive.rindex('/')]):
            os.mkdir(self.archive[:self.archive.rindex('/')])
        try:
            if not os.path.isdir('/tmp/shapeworld'):
                os.makedirs('/tmp/shapeworld')
            self.temp_directory = os.path.join('/tmp/shapeworld', 'temp-' + str(time.time()))
            os.mkdir(self.temp_directory)
        except PermissionError:
            self.temp_directory = os.path.join(self.archive[:self.archive.rindex('/')], 'temp-' + str(time.time()))
            os.mkdir(self.temp_directory)
        if archive is None:
            self.archive_type = None
            if not os.path.isdir(self.archive):
                os.mkdir(self.archive)
        elif archive[:3] == 'zip':
            self.archive_type = 'zip'
            if len(archive) == 3:
                compression = zipfile.ZIP_DEFLATED
            elif archive[4:] == 'none':
                compression = zipfile.ZIP_STORED
            elif archive[4:] == 'deflate':
                compression = zipfile.ZIP_DEFLATED
            elif archive[4:] == 'bzip2':
                compression = zipfile.ZIP_BZIP2
            elif archive[4:] == 'lzma':
                compression = zipfile.ZIP_LZMA
            if not self.archive.endswith('.zip'):
                self.archive += '.zip'
            self.archive = zipfile.ZipFile(self.archive, mode, compression)
        elif archive[:3] == 'tar':
            self.archive_type = 'tar'
            if len(archive) == 3:
                mode += ':gz'
                extension = '.gz'
            elif archive[4:] == 'none':
                extension = ''
            elif archive[4:] == 'gzip':
                mode += ':gz'
                extension = '.gz'
            elif archive[4:] == 'bzip2':
                mode += ':bz2'
                extension = '.bz2'
            elif archive[4:] == 'lzma':
                mode += ':xz'
                extension = '.lzma'
            if not self.archive.endswith('.tar' + extension):
                self.archive += '.tar' + extension
            self.archive = tarfile.open(self.archive, mode) 
開發者ID:AlexKuhnle,項目名稱:ShapeWorld,代碼行數:55,代碼來源:util.py


注:本文中的zipfile.ZIP_LZMA屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。