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


Python utils.SafeUnzip类代码示例

本文整理汇总了Python中olympia.files.utils.SafeUnzip的典型用法代码示例。如果您正苦于以下问题:Python SafeUnzip类的具体用法?Python SafeUnzip怎么用?Python SafeUnzip使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: rezip_file

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
开发者ID:Natim,项目名称:addons-server,代码行数:32,代码来源:utils.py

示例2: test_invalid_zip_encoding

    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.')
开发者ID:tsl143,项目名称:addons-server,代码行数:8,代码来源:test_helpers.py

示例3: get_localepicker

    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 ''
开发者ID:darktrojan,项目名称:addons-server,代码行数:16,代码来源:models.py

示例4: test_is_broken

 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()
开发者ID:Alien426,项目名称:addons-server,代码行数:5,代码来源:test_helpers.py

示例5: test_is_secure

 def test_is_secure(self):
     zip_file = SafeUnzip(self.xpi_path('signed'))
     zip_file.is_valid()
     assert zip_file.is_signed()
开发者ID:Alien426,项目名称:addons-server,代码行数:4,代码来源:test_helpers.py

示例6: test_not_secure

 def test_not_secure(self):
     zip_file = SafeUnzip(self.xpi_path('extension'))
     zip_file.is_valid()
     assert not zip_file.is_signed()
开发者ID:Alien426,项目名称:addons-server,代码行数:4,代码来源:test_helpers.py

示例7: test_extract_path

 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')
开发者ID:Alien426,项目名称:addons-server,代码行数:4,代码来源:test_helpers.py

示例8: test_unzip_not_fatal

 def test_unzip_not_fatal(self):
     zip_file = SafeUnzip(self.xpi_path('search.xml'))
     assert not zip_file.is_valid(fatal=False)
开发者ID:Alien426,项目名称:addons-server,代码行数:3,代码来源:test_helpers.py


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