當前位置: 首頁>>代碼示例>>Python>>正文


Python downloader.FileDownloader類代碼示例

本文整理匯總了Python中pyupdater.client.downloader.FileDownloader的典型用法代碼示例。如果您正苦於以下問題:Python FileDownloader類的具體用法?Python FileDownloader怎麽用?Python FileDownloader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了FileDownloader類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_cb

 def test_cb(self):
     def cb(status):
         pass
     fd = FileDownloader(FILENAME, URLS, hexdigest=FILE_HASH,
                         progress_hooks=[cb], verify=True)
     binary_data = fd.download_verify_return()
     assert binary_data is not None
開發者ID:awesome-python,項目名稱:PyUpdater,代碼行數:7,代碼來源:test_downloader.py

示例2: _download_verify_patches

    def _download_verify_patches(self):
        # Downloads & verifies all patches
        log.debug('Downloading patches')
        downloaded = 0
        total = len(self.patch_data)
        for p in self.patch_data:
            # Initialize downloader
            fd = FileDownloader(p['patch_name'], p['patch_urls'],
                                p['patch_hash'], self.verify)

            # Attempt to download resource
            data = fd.download_verify_return()
            if data is not None:
                self.patch_binary_data.append(data)
                downloaded += 1
                status = {'total': total,
                          'downloaed': downloaded,
                          'status': 'downloading'}
                self._call_progress_hooks(status)
            else:
                # Since patches are applied sequentially
                # we cannot continue successfully
                status = {'total': total,
                          'downloaded': downloaded,
                          'status': 'failed to download all patches'}
                self._call_progress_hooks(status)
                return False
        status = {'total': total,
                  'downloaed': downloaded,
                  'status': 'finished'}
        self._call_progress_hooks(status)
        return True
開發者ID:dlernstrom,項目名稱:PyUpdater,代碼行數:32,代碼來源:patcher.py

示例3: test_basic_auth

 def test_basic_auth(self):
     headers = {'basic_auth': 'user:pass'}
     fd = FileDownloader('test', ['test'], urllb3_headers=headers)
     http = fd._get_http_pool(secure=True)
     sc = http.request('GET',
                       'https://httpbin.org/basic-auth/user/pass').status
     assert sc == 200
開發者ID:JMSwag,項目名稱:PyUpdater,代碼行數:7,代碼來源:test_downloader.py

示例4: test_bad_content_length

    def test_bad_content_length(self):
        class FakeHeaders(object):
            headers = {}

        fd = FileDownloader(FILENAME, URLS, hexdigest=FILE_HASH, verify=True)
        data = FakeHeaders()
        assert fd._get_content_length(data) is None
開發者ID:JMSwag,項目名稱:PyUpdater,代碼行數:7,代碼來源:test_downloader.py

示例5: _full_update

    def _full_update(self):
        log.debug('Starting full update')
        file_hash = self._get_file_hash_from_manifest()

        with dsdev_utils.paths.ChDir(self.update_folder):
            log.debug('Downloading update...')
            fd = FileDownloader(self.filename, self.update_urls,
                                hexdigest=file_hash, verify=self.verify,
                                progress_hooks=self.progress_hooks)
            result = fd.download_verify_write()
            if result:
                log.debug('Download Complete')
                return True
            else:  # pragma: no cover
                log.debug('Failed To Download Latest Version')
                return False
開發者ID:smazoyer,項目名稱:PyUpdater,代碼行數:16,代碼來源:updates.py

示例6: _download_verify_patches

    def _download_verify_patches(self):
        # Downloads & verifies all patches
        log.debug('Downloading patches')
        downloaded = 0
        percent = 0
        total = len(self.patch_data)

        temp_dir = tempfile.gettempdir()

        for p in self.patch_data:
            # Don't write temp files to cwd
            with ChDir(temp_dir):
                fd = FileDownloader(p['patch_name'], p['patch_urls'],
                                    hexdigest=p['patch_hash'], verify=self.verify,
                                    max_download_retries=self.max_download_retries,
                                    urllb3_headers=self.urllib3_headers)

                # Attempt to download resource
                data = fd.download_verify_return()

            percent = int((float(downloaded + 1) / float(total)) * 100)
            percent = '{0:.1f}'.format(percent)
            if data is not None:
                self.patch_binary_data.append(data)
                downloaded += 1
                status = {'total': total,
                          'downloaded': downloaded,
                          'percent_complete': percent,
                          'status': 'downloading'}
                self._call_progress_hooks(status)
            else:
                # Since patches are applied sequentially
                # we cannot continue successfully
                status = {'total': total,
                          'downloaded': downloaded,
                          'percent_complete': percent,
                          'status': 'failed to download all patches'}
                self._call_progress_hooks(status)
                return False

        status = {'total': total,
                  'downloaded': downloaded,
                  'percent_complete': percent,
                  'status': 'finished'}
        self._call_progress_hooks(status)

        return True
開發者ID:JMSwag,項目名稱:PyUpdater,代碼行數:47,代碼來源:patcher.py

示例7: _download_manifest

 def _download_manifest(self):
     log.info('Downloading online version file')
     try:
         fd = FileDownloader(self.version_file, self.update_urls,
                             verify=self.verify)
         data = fd.download_verify_return()
         try:
             decompressed_data = gzip_decompress(data)
         except IOError:
             log.error('Failed to decompress gzip file')
             # Will be caught down below. Just logging the error
             raise
         log.info('Version file download successful')
         # Writing version file to application data directory
         self._write_manifest_2_filesystem(decompressed_data)
         return decompressed_data
     except Exception as err:
         log.error('Version file download failed')
         log.debug(str(err), exc_info=True)
         return None
開發者ID:timeyyy,項目名稱:PyUpdater,代碼行數:20,代碼來源:__init__.py

示例8: _full_update

    def _full_update(self, name):
        log.info('Starting full update')
        latest = get_highest_version(name, self.platform, self.easy_data)

        filename = get_filename(name, latest, self.platform, self.easy_data)

        hash_key = '{}*{}*{}*{}*{}'.format(self.updates_key, name,
                                           latest, self.platform,
                                           'file_hash')
        file_hash = self.easy_data.get(hash_key)

        with jms_utils.paths.ChDir(self.update_folder):
            log.info('Downloading update...')
            fd = FileDownloader(filename, self.update_urls,
                                file_hash, self.verify, self.progress_hooks)
            result = fd.download_verify_write()
            if result:
                log.info('Download Complete')
                return True
            else:  # pragma: no cover
                log.error('Failed To Download Latest Version')
                return False
開發者ID:timeyyy,項目名稱:PyUpdater,代碼行數:22,代碼來源:updates.py

示例9: test_good_conent_length

 def test_good_conent_length(self):
     fd = FileDownloader(FILENAME, URLS, hexdigest=FILE_HASH, verify=True)
     fd.download_verify_return()
     assert fd.content_length == 2387
開發者ID:awesome-python,項目名稱:PyUpdater,代碼行數:4,代碼來源:test_downloader.py

示例10: test_bad_url

 def test_bad_url(self):
     fd = FileDownloader(FILENAME, ['bad url'], hexdigest='bad hash',
                         verify=True)
     binary_data = fd.download_verify_return()
     assert binary_data is None
開發者ID:awesome-python,項目名稱:PyUpdater,代碼行數:5,代碼來源:test_downloader.py

示例11: test_url_with_spaces

 def test_url_with_spaces(self):
     fd = FileDownloader(FILENAME_WITH_SPACES, URLS,
                         hexdigest=FILE_HASH, verify=True)
     binary_data = fd.download_verify_return()
     assert binary_data is not None
開發者ID:awesome-python,項目名稱:PyUpdater,代碼行數:5,代碼來源:test_downloader.py

示例12: test_return_fail

 def test_return_fail(self):
     fd = FileDownloader(FILENAME, URLS,
                         'JKFEIFJILEFJ983NKFNKL', verify=True)
     binary_data = fd.download_verify_return()
     assert binary_data is None
開發者ID:awesome-python,項目名稱:PyUpdater,代碼行數:5,代碼來源:test_downloader.py

示例13: test_return

 def test_return(self):
     fd = FileDownloader(FILENAME, URLS, FILE_HASH, verify=True)
     binary_data = fd.download_verify_return()
     assert binary_data is not None
開發者ID:awesome-python,項目名稱:PyUpdater,代碼行數:4,代碼來源:test_downloader.py

示例14: test_good_conent_length

 def test_good_conent_length(self):
     fd = FileDownloader(FILENAME, URL, FILE_HASH, verify=False)
     fd.download_verify_return()
     assert fd.content_length == 60000
開發者ID:Encryptabit,項目名稱:PyUpdater,代碼行數:4,代碼來源:test_downloader.py

示例15: test_bad_content_length

 def test_bad_content_length(self):
     class FakeHeaders(object):
         headers = {}
     fd = FileDownloader(FILENAME, URL, FILE_HASH, verify=False)
     data = FakeHeaders()
     assert fd._get_content_length(data) == 100001
開發者ID:Encryptabit,項目名稱:PyUpdater,代碼行數:6,代碼來源:test_downloader.py


注:本文中的pyupdater.client.downloader.FileDownloader類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。