當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。