Skip to content

Commit

Permalink
Move webkit.http to webkit.httpheaders
Browse files Browse the repository at this point in the history
flake8 got a new warning about a module name shadowing a builtin module: gforcada/flake8-builtins#121

Probably would have been safe enough to ignore it. But I don't think
moving it is that hard anyway. Hopefully I didn't miss anything!
  • Loading branch information
toofar committed Apr 8, 2024
1 parent 4a12ae7 commit 98421e3
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions qutebrowser/browser/qtnetworkdownloads.py
Expand Up @@ -19,7 +19,7 @@
from qutebrowser.utils import message, usertypes, log, urlutils, utils, debug, objreg, qtlog
from qutebrowser.misc import quitter
from qutebrowser.browser import downloads
from qutebrowser.browser.webkit import http
from qutebrowser.browser.webkit import httpheaders
from qutebrowser.browser.webkit.network import networkmanager


Expand Down Expand Up @@ -533,7 +533,7 @@ def fetch(self, reply, *, target=None, auto_remove=False,
try:
suggested_filename = target.suggested_filename()
except downloads.NoFilenameError:
_, suggested_filename = http.parse_content_disposition(reply)
_, suggested_filename = httpheaders.parse_content_disposition(reply)
log.downloads.debug("fetch: {} -> {}".format(reply.url(),
suggested_filename))
download = DownloadItem(reply, manager=self)
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions qutebrowser/browser/webkit/webpage.py
Expand Up @@ -18,7 +18,7 @@

from qutebrowser.config import websettings, config
from qutebrowser.browser import pdfjs, shared, downloads, greasemonkey
from qutebrowser.browser.webkit import http
from qutebrowser.browser.webkit import httpheaders
from qutebrowser.browser.webkit.network import networkmanager
from qutebrowser.utils import message, usertypes, log, jinja, objreg
from qutebrowser.qt import sip
Expand Down Expand Up @@ -263,14 +263,14 @@ def on_unsupported_content(self, reply):
At some point we might want to implement the MIME Sniffing standard
here: https://mimesniff.spec.whatwg.org/
"""
inline, suggested_filename = http.parse_content_disposition(reply)
inline, suggested_filename = httpheaders.parse_content_disposition(reply)
download_manager = objreg.get('qtnetwork-download-manager')
if not inline:
# Content-Disposition: attachment -> force download
download_manager.fetch(reply,
suggested_filename=suggested_filename)
return
mimetype, _rest = http.parse_content_type(reply)
mimetype, _rest = httpheaders.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
Expand Down
4 changes: 2 additions & 2 deletions scripts/dev/check_coverage.py
Expand Up @@ -73,8 +73,8 @@ class MsgType(enum.Enum):
'qutebrowser/browser/history.py'),
('tests/unit/browser/test_pdfjs.py',
'qutebrowser/browser/pdfjs.py'),
('tests/unit/browser/webkit/http/test_http.py',
'qutebrowser/browser/webkit/http.py'),
('tests/unit/browser/webkit/http/test_httpheaders.py',
'qutebrowser/browser/webkit/httpheaders.py'),
# ('tests/unit/browser/webkit/test_webkitelem.py',
# 'qutebrowser/browser/webkit/webkitelem.py'),
# ('tests/unit/browser/webkit/test_webkitelem.py',
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/browser/webkit/http/test_content_disposition.py
Expand Up @@ -6,7 +6,7 @@

import pytest

from qutebrowser.browser.webkit import http
from qutebrowser.browser.webkit import httpheaders


DEFAULT_NAME = 'qutebrowser-download'
Expand All @@ -30,7 +30,7 @@ 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)
cd_inline, cd_filename = httpheaders.parse_content_disposition(reply)
assert cd_filename is not None
assert cd_filename == filename
assert cd_inline == expected_inline
Expand All @@ -40,15 +40,15 @@ def check_ignored(self, header):
reply = self.stubs.FakeNetworkReply(
headers={'Content-Disposition': header})
with self.caplog.at_level(logging.ERROR, 'network'):
cd_inline, cd_filename = http.parse_content_disposition(reply)
cd_inline, cd_filename = httpheaders.parse_content_disposition(reply)
assert cd_filename == DEFAULT_NAME
assert cd_inline

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)
cd_inline, cd_filename = httpheaders.parse_content_disposition(reply)
assert cd_filename == DEFAULT_NAME
assert not cd_inline

Expand Down Expand Up @@ -164,7 +164,7 @@ def test_attonly(self, stubs):
"""
reply = stubs.FakeNetworkReply(
headers={'Content-Disposition': 'attachment'})
cd_inline, cd_filename = http.parse_content_disposition(reply)
cd_inline, cd_filename = httpheaders.parse_content_disposition(reply)
assert not cd_inline
assert cd_filename == DEFAULT_NAME

Expand Down
Expand Up @@ -2,7 +2,7 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later

"""Tests for qutebrowser.browser.webkit.http."""
"""Tests for qutebrowser.browser.webkit.httpheaders."""

import logging

Expand All @@ -11,7 +11,7 @@
from hypothesis import strategies
from qutebrowser.qt.core import QUrl

from qutebrowser.browser.webkit import http
from qutebrowser.browser.webkit import httpheaders


@pytest.mark.parametrize('url, expected', [
Expand All @@ -24,7 +24,7 @@
])
def test_no_content_disposition(stubs, url, expected):
reply = stubs.FakeNetworkReply(url=QUrl(url))
inline, filename = http.parse_content_disposition(reply)
inline, filename = httpheaders.parse_content_disposition(reply)
assert inline
assert filename == expected

Expand All @@ -40,8 +40,8 @@ def test_no_content_disposition(stubs, url, expected):
# dropping QtWebKit.
])
def test_parse_content_disposition_invalid(value):
with pytest.raises(http.ContentDispositionError):
http.ContentDisposition.parse(value)
with pytest.raises(httpheaders.ContentDispositionError):
httpheaders.ContentDisposition.parse(value)


@pytest.mark.parametrize('template', [
Expand All @@ -58,16 +58,16 @@ def test_parse_content_disposition_hypothesis(caplog, template, stubs, s):
header = template.format(s)
reply = stubs.FakeNetworkReply(headers={'Content-Disposition': header})
with caplog.at_level(logging.ERROR, 'network'):
http.parse_content_disposition(reply)
httpheaders.parse_content_disposition(reply)


@hypothesis.given(strategies.binary())
def test_content_disposition_directly_hypothesis(s):
"""Test rfc6266 parsing directly with binary data."""
try:
cd = http.ContentDisposition.parse(s)
cd = httpheaders.ContentDisposition.parse(s)
cd.filename()
except http.ContentDispositionError:
except httpheaders.ContentDispositionError:
pass


Expand All @@ -83,12 +83,12 @@ def test_parse_content_type(stubs, content_type, expected_mimetype,
reply = stubs.FakeNetworkReply()
else:
reply = stubs.FakeNetworkReply(headers={'Content-Type': content_type})
mimetype, rest = http.parse_content_type(reply)
mimetype, rest = httpheaders.parse_content_type(reply)
assert mimetype == expected_mimetype
assert rest == expected_rest


@hypothesis.given(strategies.text())
def test_parse_content_type_hypothesis(stubs, s):
reply = stubs.FakeNetworkReply(headers={'Content-Type': s})
http.parse_content_type(reply)
httpheaders.parse_content_type(reply)

0 comments on commit 98421e3

Please sign in to comment.