本文整理汇总了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()
示例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)
示例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)
示例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()
示例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')))
示例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 ) )
示例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)
示例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)
示例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
示例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)
示例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)
示例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")
示例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 = {}
示例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)
示例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)