当前位置: 首页>>代码示例>>Python>>正文


Python zipfile.ZIP_BZIP2属性代码示例

本文整理汇总了Python中zipfile.ZIP_BZIP2属性的典型用法代码示例。如果您正苦于以下问题:Python zipfile.ZIP_BZIP2属性的具体用法?Python zipfile.ZIP_BZIP2怎么用?Python zipfile.ZIP_BZIP2使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在模块zipfile的用法示例。

在下文中一共展示了zipfile.ZIP_BZIP2属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: zip_closer_helper

# 需要导入模块: import zipfile [as 别名]
# 或者: from zipfile import ZIP_BZIP2 [as 别名]
def zip_closer_helper(self):
        with zipfile.ZipFile(
            self.config.filename, self.WRITEMODE, compression=zipfile.ZIP_BZIP2
        ) as archive:
            with archive.open(
                self.__class__.__qualname__,
                mode=self.WRITEMODE,
                force_zip64=True,
            ) as zip_fd:
                with io.TextIOWrapper(zip_fd, write_through=True) as fd:
                    yield fd 
开发者ID:intel,项目名称:dffml,代码行数:13,代码来源:file.py


示例2: __init__

# 需要导入模块: import zipfile [as 别名]
# 或者: from zipfile import ZIP_BZIP2 [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_BZIP2属性示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。