• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python http.parse_content_disposition函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: fetch

    def fetch(self, reply, fileobj=None, filename=None, auto_remove=False,
              suggested_filename=None):
        """Download a QNetworkReply to disk.

        Args:
            reply: The QNetworkReply to download.
            fileobj: The file object to write the answer to.
            filename: A path to write the data to.
            auto_remove: Whether to remove the download even if
                         ui -> remove-finished-downloads is set to false.

        Return:
            The created DownloadItem.
        """
        if fileobj is not None and filename is not None:
            raise TypeError("Only one of fileobj/filename may be given!")
        if not suggested_filename:
            if filename is not None:
                suggested_filename = os.path.basename(filename)
            elif fileobj is not None and getattr(fileobj, 'name', None):
                suggested_filename = fileobj.name
            else:
                _, suggested_filename = http.parse_content_disposition(reply)
        log.downloads.debug("fetch: {} -> {}".format(reply.url(),
                                                     suggested_filename))
        download = DownloadItem(reply, self._win_id, self)
        download.cancelled.connect(
            functools.partial(self.remove_item, download))
        if config.get('ui', 'remove-finished-downloads') or auto_remove:
            download.finished.connect(
                functools.partial(self.remove_item, download))
        download.data_changed.connect(
            functools.partial(self.on_data_changed, download))
        download.error.connect(self.on_error)
        download.redirected.connect(
            functools.partial(self.on_redirect, download))
        download.basename = suggested_filename
        idx = len(self.downloads) + 1
        download.index = idx
        self.beginInsertRows(QModelIndex(), idx, idx)
        self.downloads.append(download)
        self.endInsertRows()

        if filename is not None:
            download.set_filename(filename)
        elif fileobj is not None:
            download.set_fileobj(fileobj)
            download.autoclose = False
        else:
            q = self._prepare_question()
            q.default = _path_suggestion(suggested_filename)
            q.answered.connect(download.set_filename)
            q.cancelled.connect(download.cancel)
            download.cancelled.connect(q.abort)
            download.error.connect(q.abort)
            message_bridge = objreg.get('message-bridge', scope='window',
                                        window=self._win_id)
            message_bridge.ask(q, blocking=False)

        return download
开发者ID:xetch,项目名称:qutebrowser,代码行数:60,代码来源:downloads.py


示例2: check_unnamed

 def check_unnamed(self, header):
     """Check if the passed header results in an unnamed attachment."""
     reply = self.stubs.FakeNetworkReply(
         headers={'Content-Disposition': header})
     cd_inline, cd_filename = http.parse_content_disposition(reply)
     assert cd_filename == DEFAULT_NAME
     assert not cd_inline
开发者ID:shawa,项目名称:qutebrowser,代码行数:7,代码来源:test_content_disposition.py


示例3: on_unsupported_content

    def on_unsupported_content(self, reply):
        """Handle an unsupportedContent signal.

        Most likely this will mean we need to download the reply, but we
        correct for some common errors the server do.

        At some point we might want to implement the MIME Sniffing standard
        here: http://mimesniff.spec.whatwg.org/
        """
        inline, suggested_filename = http.parse_content_disposition(reply)
        download_manager = objreg.get('download-manager', scope='window',
                                      window=self._win_id)
        if not inline:
            # Content-Disposition: attachment -> force download
            download_manager.fetch(reply,
                                   suggested_filename=suggested_filename)
            return
        mimetype, _rest = http.parse_content_type(reply)
        if mimetype == 'image/jpg':
            # Some servers (e.g. the LinkedIn CDN) send a non-standard
            # image/jpg (instead of image/jpeg, defined in RFC 1341 section
            # 7.5). If this is the case, we force displaying with a corrected
            # mimetype.
            if reply.isFinished():
                self.display_content(reply, 'image/jpeg')
            else:
                reply.finished.connect(functools.partial(
                    self.display_content, reply, 'image/jpeg'))
        else:
            # Unknown mimetype, so download anyways.
            download_manager.fetch(reply,
                                   suggested_filename=suggested_filename)
开发者ID:jagajaga,项目名称:qutebrowser,代码行数:32,代码来源:webpage.py


示例4: _check_ignored

 def _check_ignored(self, header):
     """Check if the passed header is ignored."""
     reply = stubs.FakeNetworkReply(headers={'Content-Disposition': header})
     with self.assertLogs(log.rfc6266, logging.ERROR):
         cd_inline, cd_filename = http.parse_content_disposition(reply)
     self.assertEqual(cd_filename, DEFAULT_NAME)
     self.assertTrue(cd_inline)
开发者ID:JIVS,项目名称:qutebrowser,代码行数:7,代码来源:test_content_disposition.py


示例5: _check_filename

 def _check_filename(self, header, filename):
     """Check if the passed header has the given filename."""
     reply = stubs.FakeNetworkReply(headers={'Content-Disposition': header})
     cd_inline, cd_filename = http.parse_content_disposition(reply)
     self.assertIsNotNone(cd_filename)
     self.assertEqual(cd_filename, filename)
     self.assertFalse(cd_inline)
开发者ID:JIVS,项目名称:qutebrowser,代码行数:7,代码来源:test_content_disposition.py


示例6: check_filename

 def check_filename(self, header, filename, expected_inline=False):
     """Check if the passed header has the given filename."""
     reply = self.stubs.FakeNetworkReply(
         headers={'Content-Disposition': header})
     cd_inline, cd_filename = http.parse_content_disposition(reply)
     assert cd_filename is not None
     assert cd_filename == filename
     assert cd_inline == expected_inline
开发者ID:shawa,项目名称:qutebrowser,代码行数:8,代码来源:test_content_disposition.py


示例7: check_ignored

 def check_ignored(self, header):
     """Check if the passed header is ignored."""
     reply = self.stubs.FakeNetworkReply(
         headers={'Content-Disposition': header})
     with self.caplog.at_level(logging.ERROR, 'rfc6266'):
         # with self.assertLogs(log.rfc6266, logging.ERROR):
         cd_inline, cd_filename = http.parse_content_disposition(reply)
     assert cd_filename == DEFAULT_NAME
     assert cd_inline
开发者ID:shawa,项目名称:qutebrowser,代码行数:9,代码来源:test_content_disposition.py


示例8: test_attonly

    def test_attonly(self, stubs):
        """'attachment' only.

        UA should offer to download the resource.
        """
        reply = stubs.FakeNetworkReply(
            headers={'Content-Disposition': 'attachment'})
        cd_inline, cd_filename = http.parse_content_disposition(reply)
        assert not cd_inline
        assert cd_filename == DEFAULT_NAME
开发者ID:shawa,项目名称:qutebrowser,代码行数:10,代码来源:test_content_disposition.py


示例9: fetch

    def fetch(self, reply, *, fileobj=None, filename=None, auto_remove=False,
              suggested_filename=None, prompt_download_directory=None):
        """Download a QNetworkReply to disk.

        Args:
            reply: The QNetworkReply to download.
            fileobj: The file object to write the answer to.
            filename: A path to write the data to.
            auto_remove: Whether to remove the download even if
                         ui -> remove-finished-downloads is set to -1.

        Return:
            The created DownloadItem.
        """
        if fileobj is not None and filename is not None:
            raise TypeError("Only one of fileobj/filename may be given!")
        if not suggested_filename:
            if filename is not None:
                suggested_filename = os.path.basename(filename)
            elif fileobj is not None and getattr(fileobj, 'name', None):
                suggested_filename = fileobj.name
            else:
                _, suggested_filename = http.parse_content_disposition(reply)
        log.downloads.debug("fetch: {} -> {}".format(reply.url(),
                                                     suggested_filename))
        download = DownloadItem(reply, self._win_id, self)
        download.cancelled.connect(
            functools.partial(self.remove_item, download))

        delay = config.get('ui', 'remove-finished-downloads')
        if delay > -1:
            download.finished.connect(
                functools.partial(self.remove_item_delayed, download, delay))
        elif auto_remove:
            download.finished.connect(
                functools.partial(self.remove_item, download))

        download.data_changed.connect(
            functools.partial(self.on_data_changed, download))
        download.error.connect(self.on_error)
        download.redirected.connect(
            functools.partial(self.on_redirect, download))
        download.basename = suggested_filename
        idx = len(self.downloads) + 1
        download.index = idx
        self.beginInsertRows(QModelIndex(), idx, idx)
        self.downloads.append(download)
        self.endInsertRows()

        if not self._update_timer.isActive():
            self._update_timer.start()

        if fileobj is not None:
            download.set_fileobj(fileobj)
            download.autoclose = False
            return download

        if filename is not None:
            download.set_filename(filename)
            return download

        # Neither filename nor fileobj were given, prepare a question
        filename, q = ask_for_filename(
            suggested_filename, self._win_id, parent=self,
            prompt_download_directory=prompt_download_directory,
        )

        # User doesn't want to be asked, so just use the download_dir
        if filename is not None:
            download.set_filename(filename)
            return download

        # Ask the user for a filename
        self._postprocess_question(q)
        q.answered.connect(download.set_filename)
        q.cancelled.connect(download.cancel)
        download.cancelled.connect(q.abort)
        download.error.connect(q.abort)
        q.ask()

        return download
开发者ID:a2batic,项目名称:qutebrowser,代码行数:81,代码来源:downloads.py


示例10: test_none

 def test_none(self, stubs, url):
     """Test with no filename at all."""
     reply = stubs.FakeNetworkReply(url=QUrl(url))
     inline, filename = http.parse_content_disposition(reply)
     assert inline
     assert filename == 'qutebrowser-download'
开发者ID:AdaJass,项目名称:qutebrowser,代码行数:6,代码来源:test_http.py


示例11: test_url

 def test_url(self, stubs, url):
     """Test with a filename in the URL."""
     reply = stubs.FakeNetworkReply(url=QUrl(url))
     inline, filename = http.parse_content_disposition(reply)
     assert inline
     assert filename == 'path'
开发者ID:AdaJass,项目名称:qutebrowser,代码行数:6,代码来源:test_http.py


示例12: test_parse_content_disposition

def test_parse_content_disposition(template, stubs, s):
    """Test parsing headers based on templates which hypothesis completes."""
    header = template.format(s)
    reply = stubs.FakeNetworkReply(headers={"Content-Disposition": header})
    http.parse_content_disposition(reply)
开发者ID:b80905,项目名称:qutebrowser,代码行数:5,代码来源:test_http_hypothesis.py


示例13: _check_unnamed

 def _check_unnamed(self, header):
     """Check if the passed header results in an unnamed attachment."""
     reply = stubs.FakeNetworkReply(headers={'Content-Disposition': header})
     cd_inline, cd_filename = http.parse_content_disposition(reply)
     self.assertEqual(cd_filename, DEFAULT_NAME)
     self.assertFalse(cd_inline)
开发者ID:JIVS,项目名称:qutebrowser,代码行数:6,代码来源:test_content_disposition.py


示例14: test_parse_content_disposition

def test_parse_content_disposition(caplog, template, stubs, s):
    """Test parsing headers based on templates which hypothesis completes."""
    header = template.format(s)
    reply = stubs.FakeNetworkReply(headers={'Content-Disposition': header})
    with caplog.atLevel(logging.ERROR, 'rfc6266'):
        http.parse_content_disposition(reply)
开发者ID:ProtractorNinja,项目名称:qutebrowser,代码行数:6,代码来源:test_http_hypothesis.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python webelem.get_child_frames函数代码示例发布时间:2022-05-26
下一篇:
Python quora.Quora类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap