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


Python ZipFile.__init__方法代码示例

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


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

示例1: __init__

# 需要导入模块: from zipfile import ZipFile [as 别名]
# 或者: from zipfile.ZipFile import __init__ [as 别名]
    def __init__(self, apk, outdir=None, outname=None):
        ZipFile.__init__(self, apk)

        with open(apk, 'rb') as f:
            sha1obj = hashlib.sha1()
            sha1obj.update(f.read())
            self.sha1 = sha1obj.hexdigest()

        self.outdir = outdir if outdir != None else os.path.join(os.path.dirname(self.filename))
        self.outname = outname if outname else 'tencent_%s.dex' % (self.sha1) 

        if not os.path.exists(self.outdir):
            os.makedirs(self.outdir)

        self.__total = 0
        self.sections = defaultdict(dict)
        self.classes_dex = StringStream( self.read('classes.dex') )
        self.new_classes_dex = FileStream(os.path.join(self.outdir, self.outname))
        self.new_classes_dex.write_bytes(self.classes_dex.get_data())

        add_attr = lambda pos, attr : (self.classes_dex.set_position(pos), setattr(self, attr, self.classes_dex.read_int()))

        add_attr(56, 'string_ids_size')
        add_attr(60, 'string_ids_off')
        add_attr(68, 'type_ids_off')
        add_attr(84, 'field_ids_off')
        add_attr(92, 'method_ids_off')
        add_attr(76, 'proto_ids_off')
        add_attr(100, 'class_defs_off')
        add_attr(48, 'link_off')
        add_attr(32, 'file_size')
        add_attr(104, 'data_size')
        add_attr(108, 'data_off')

        self.__read_encode_sections()
开发者ID:fireall,项目名称:unpacker,代码行数:37,代码来源:Tencent.py

示例2: __init__

# 需要导入模块: from zipfile import ZipFile [as 别名]
# 或者: from zipfile.ZipFile import __init__ [as 别名]
 def __init__(self, *args, **kwargs):
     """
     Validates the zip file
     """
     try:
         ZipFile.__init__(self, *args, **kwargs)
     except BadZipfile:
         print _("Manifest zip is invalid.")
         sys.exit(1)
开发者ID:MichaelMraka,项目名称:subscription-manager,代码行数:11,代码来源:manifest_commands.py

示例3: __init__

# 需要导入模块: from zipfile import ZipFile [as 别名]
# 或者: from zipfile.ZipFile import __init__ [as 别名]
    def __init__(self, zip_string):
        buffer = StringIO()
        if zip_string:
            if is_zipfile(zip_string):
                fp = open(zip_string, "rb")
                while 1:
                    data = fp.read(1024 * 8)
                    if not data:
                        break
                    buffer.write(data)
                fp.close()
            else:
                buffer.write(zip_string)

        ZipFile.__init__(self, buffer, 'a', compression=ZIP_DEFLATED)
开发者ID:BackupTheBerlios,项目名称:osocgen-svn,代码行数:17,代码来源:zipextended.py

示例4: __init__

# 需要导入模块: from zipfile import ZipFile [as 别名]
# 或者: from zipfile.ZipFile import __init__ [as 别名]
    def __init__(self,
                 file,
                 strict=False,
                 mode='r',
                 compression=ZIP_STORED,
                 allowZip64=True):
        """Open IPA file. Primary difference from ZipFile is that allowZip64
        is set to True by default because many IPA files are larger than 2
        GiB in file size."""
        ZipFile.__init__(self,
                         file,
                         mode=mode,
                         compression=compression,
                         allowZip64=allowZip64)

        filenames = self.namelist()

        self._logger.debug('Files within the archive.\n{0}'.format(filenames))

        matched = len([x for x in [re.match(self.info_plist_regex, y)
                                   for y in filenames]
                       if x]) == 1

        self._logger.debug('IPA file passes test phase one: {0}'.format(
            _yn(matched)))
        if strict:
            is_ipa = 'iTunesMetadata.plist' in filenames and matched
            self._logger.debug('IPA file passes test phase two: {0}'.format(
                _yn(is_ipa)))
        else:
            is_ipa = matched

        if not is_ipa:
            self._logger.debug(
                'IPA file failed {0}/2 test phases, IPA file is invalid.'.
                format(_tests_fails(matched, is_ipa)))

            self._logger.debug('IPA file test phase report: {0}'.format(
                _tests_report(matched, is_ipa)))

            self._raise_ipa_error('Not an IPA')

        self._logger.debug(
            'IPA file passes all test phases, IPA file is valid.')

        self._get_app_info()
开发者ID:Tatsh,项目名称:libipa,代码行数:48,代码来源:__init__.py

示例5: __init__

# 需要导入模块: from zipfile import ZipFile [as 别名]
# 或者: from zipfile.ZipFile import __init__ [as 别名]
    def __init__(self, file, mode='r'):
        basename = os.path.basename(file)
        self.parsed_filename = WHEEL_INFO_RE.match(basename)
        if not basename.endswith('.whl') or self.parsed_filename is None:
            raise WheelError("Bad wheel filename {!r}".format(basename))

        ZipFile.__init__(self, file, mode, compression=ZIP_DEFLATED, allowZip64=True)

        self.dist_info_path = '{}.dist-info'.format(self.parsed_filename.group('namever'))
        self.record_path = self.dist_info_path + '/RECORD'
        self._file_hashes = OrderedDict()
        self._file_sizes = {}
        if mode == 'r':
            # Ignore RECORD and any embedded wheel signatures
            self._file_hashes[self.record_path] = None, None
            self._file_hashes[self.record_path + '.jws'] = None, None
            self._file_hashes[self.record_path + '.p7s'] = None, None

            # Fill in the expected hashes by reading them from RECORD
            try:
                record = self.open(self.record_path)
            except KeyError:
                raise WheelError('Missing {} file'.format(self.record_path))

            with record:
                for line in record:
                    line = line.decode('utf-8')
                    path, hash_sum, size = line.rsplit(u',', 2)
                    if hash_sum:
                        algorithm, hash_sum = hash_sum.split(u'=')
                        try:
                            hashlib.new(algorithm)
                        except ValueError:
                            raise WheelError('Unsupported hash algorithm: {}'.format(algorithm))

                        if algorithm.lower() in {'md5', 'sha1'}:
                            raise WheelError(
                                'Weak hash algorithm ({}) is not permitted by PEP 427'
                                .format(algorithm))

                        self._file_hashes[path] = (
                            algorithm, urlsafe_b64decode(hash_sum.encode('ascii')))
开发者ID:Black-Thunder01,项目名称:PythonAPI,代码行数:44,代码来源:wheelfile.py

示例6: __init__

# 需要导入模块: from zipfile import ZipFile [as 别名]
# 或者: from zipfile.ZipFile import __init__ [as 别名]
    def __init__(self, apk, outdir=None, outname=None):
        ZipFile.__init__(self, apk)

        f = open(apk, 'rb')
        sha1obj = hashlib.sha1()
        sha1obj.update(f.read())
        self.sha1 = sha1obj.hexdigest()
        f.close()

        self.outdir = outdir if outdir != None else os.path.join(os.path.dirname(self.filename))
        self.outname = outname if outname else 'apkprotect_%s.dex' % (self.sha1) 

        if not os.path.exists(self.outdir):
            os.makedirs(self.outdir)

        self.classes_dex = StringStream( self.read('classes.dex') )
        self.libAPKProtect_so = StringStream( self.read('lib/armeabi/libAPKProtect.so') )
        self.sections = []

        self.new_classes_dex = FileStream( os.path.join( self.outdir, self.outname ) )
开发者ID:fireall,项目名称:unpacker,代码行数:22,代码来源:APKProtect.py

示例7: __init__

# 需要导入模块: from zipfile import ZipFile [as 别名]
# 或者: from zipfile.ZipFile import __init__ [as 别名]
 def __init__(self, file):
     ZipFile.__init__(self, file, mode='w', allowZip64=True)
开发者ID:dCache,项目名称:SmallFiles,代码行数:4,代码来源:pack-files.py

示例8: __init__

# 需要导入模块: from zipfile import ZipFile [as 别名]
# 或者: from zipfile.ZipFile import __init__ [as 别名]
 def __init__(self, file, mode="r", compression=ZIP_STORED, allowZip64=False):
     ZipFile.__init__(self, file, mode, compression, allowZip64)
开发者ID:crawley,项目名称:mytardis,代码行数:4,代码来源:download.py

示例9: __init__

# 需要导入模块: from zipfile import ZipFile [as 别名]
# 或者: from zipfile.ZipFile import __init__ [as 别名]
 def __init__(self, name, folder):
     ZipFile.__init__(self, name, 'w')
     self.folder = folder
开发者ID:bitzl,项目名称:latex-grid-system,代码行数:5,代码来源:fabfile.py

示例10: __init__

# 需要导入模块: from zipfile import ZipFile [as 别名]
# 或者: from zipfile.ZipFile import __init__ [as 别名]
 def __init__(self, *args, **kwargs):
     ZipFile.__init__(self, *args, **kwargs)
     # each piece of content will be created with the same date_time
     # attribute (set to now)
     now = time.localtime(time.time())
     self.zip_info_factory = functools.partial(ZipInfo, date_time=now)
开发者ID:yougov,项目名称:openpack,代码行数:8,代码来源:zippack.py

示例11: __init__

# 需要导入模块: from zipfile import ZipFile [as 别名]
# 或者: from zipfile.ZipFile import __init__ [as 别名]
 def __init__(self, dest_path, mode="r"):
     ZipFile.__init__(self, dest_path, mode, ZIP_DEFLATED, True)
开发者ID:amitsaroj001,项目名称:tvb-framework,代码行数:4,代码来源:files_helper.py

示例12: __init__

# 需要导入模块: from zipfile import ZipFile [as 别名]
# 或者: from zipfile.ZipFile import __init__ [as 别名]
 def __init__(self, file, mode="r", compression=ZIP_STORED, allowZip64=False):
     if not isinstance(file, basestring):
         return _ZipFile.__init__(self, file, mode, compression, allowZip64)
     else:
         raise NotImplemented("Paths not supported by SafeZipFile")
开发者ID:pretaweb,项目名称:pretaweb.plominolib,代码行数:7,代码来源:__init__.py

示例13: __init__

# 需要导入模块: from zipfile import ZipFile [as 别名]
# 或者: from zipfile.ZipFile import __init__ [as 别名]
 def __init__(self, *args, **kwargs):
     ZipFile.__init__(self, *args, **kwargs)
     self.mapping = {}
开发者ID:inthecloud247,项目名称:virgo,代码行数:5,代码来源:lua2zip.py

示例14: __init__

# 需要导入模块: from zipfile import ZipFile [as 别名]
# 或者: from zipfile.ZipFile import __init__ [as 别名]
 def __init__(self, fname, mode='r'):
     ZipFile.__init__(
         self, as_posix(fname), mode=mode, compression=ZIP_DEFLATED, allowZip64=True)
开发者ID:clld,项目名称:clldutils,代码行数:5,代码来源:ziparchive.py

示例15: __init__

# 需要导入模块: from zipfile import ZipFile [as 别名]
# 或者: from zipfile.ZipFile import __init__ [as 别名]
 def __init__(self, zfile, method=None):
     self.zfile = zfile
     zfile.seek(0,0)
     ZipFile.__init__(self, zfile, "a", method or ZIP_STORED)
开发者ID:joepie91,项目名称:mintrayr,代码行数:6,代码来源:build.py


注:本文中的zipfile.ZipFile.__init__方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。