本文整理汇总了Python中olympia.files.utils.SafeUnzip.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python SafeUnzip.is_valid方法的具体用法?Python SafeUnzip.is_valid怎么用?Python SafeUnzip.is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类olympia.files.utils.SafeUnzip
的用法示例。
在下文中一共展示了SafeUnzip.is_valid方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_invalid_zip_encoding
# 需要导入模块: from olympia.files.utils import SafeUnzip [as 别名]
# 或者: from olympia.files.utils.SafeUnzip import is_valid [as 别名]
def test_invalid_zip_encoding(self):
zip_file = SafeUnzip(self.xpi_path('invalid-cp437-encoding.xpi'))
with pytest.raises(forms.ValidationError) as exc:
zip_file.is_valid()
assert isinstance(exc.value, forms.ValidationError)
assert exc.value.message.endswith(
'Please make sure all filenames are utf-8 or latin1 encoded.')
示例2: rezip_file
# 需要导入模块: from olympia.files.utils import SafeUnzip [as 别名]
# 或者: from olympia.files.utils.SafeUnzip import is_valid [as 别名]
def rezip_file(response, pk):
# An .xpi does not have a directory inside the zip, yet zips from github
# do, so we'll need to rezip the file before passing it through to the
# validator.
loc = os.path.join(user_media_path('addons'), 'temp', uuid.uuid4().hex)
old_filename = '{}_github_webhook.zip'.format(pk)
old_path = os.path.join(loc, old_filename)
with storage.open(old_path, 'wb') as old:
old.write(response.content)
new_filename = '{}_github_webhook.xpi'.format(pk)
new_path = os.path.join(loc, new_filename)
old_zip = SafeUnzip(old_path)
if not old_zip.is_valid():
raise
with storage.open(new_path, 'w') as new:
new_zip = zipfile.ZipFile(new, 'w')
for obj in old_zip.filelist:
# Basically strip off the leading directory.
new_filename = obj.filename.partition('/')[-1]
if not new_filename:
continue
new_zip.writestr(new_filename, old_zip.read(obj.filename))
new_zip.close()
old_zip.close()
return new_path
示例3: get_localepicker
# 需要导入模块: from olympia.files.utils import SafeUnzip [as 别名]
# 或者: from olympia.files.utils.SafeUnzip import is_valid [as 别名]
def get_localepicker(self):
"""
For a file that is part of a language pack, extract
the chrome/localepicker.properties file and return as
a string.
"""
start = time.time()
zip = SafeUnzip(self.file_path)
if not zip.is_valid(fatal=False):
return ''
try:
manifest = zip.extract_path('chrome.manifest')
except KeyError, e:
log.info('No file named: chrome.manifest in file: %s' % self.pk)
return ''
示例4: test_is_broken
# 需要导入模块: from olympia.files.utils import SafeUnzip [as 别名]
# 或者: from olympia.files.utils.SafeUnzip import is_valid [as 别名]
def test_is_broken(self):
zip_file = SafeUnzip(self.xpi_path('signed'))
zip_file.is_valid()
zip_file.info_list[2].filename = 'META-INF/foo.sf'
assert not zip_file.is_signed()
示例5: test_is_secure
# 需要导入模块: from olympia.files.utils import SafeUnzip [as 别名]
# 或者: from olympia.files.utils.SafeUnzip import is_valid [as 别名]
def test_is_secure(self):
zip_file = SafeUnzip(self.xpi_path('signed'))
zip_file.is_valid()
assert zip_file.is_signed()
示例6: test_not_secure
# 需要导入模块: from olympia.files.utils import SafeUnzip [as 别名]
# 或者: from olympia.files.utils.SafeUnzip import is_valid [as 别名]
def test_not_secure(self):
zip_file = SafeUnzip(self.xpi_path('extension'))
zip_file.is_valid()
assert not zip_file.is_signed()
示例7: test_extract_path
# 需要导入模块: from olympia.files.utils import SafeUnzip [as 别名]
# 或者: from olympia.files.utils.SafeUnzip import is_valid [as 别名]
def test_extract_path(self):
zip_file = SafeUnzip(self.xpi_path('langpack-localepicker'))
assert zip_file.is_valid()
assert'locale browser de' in zip_file.extract_path('chrome.manifest')
示例8: test_unzip_not_fatal
# 需要导入模块: from olympia.files.utils import SafeUnzip [as 别名]
# 或者: from olympia.files.utils.SafeUnzip import is_valid [as 别名]
def test_unzip_not_fatal(self):
zip_file = SafeUnzip(self.xpi_path('search.xml'))
assert not zip_file.is_valid(fatal=False)