utils.http: Return [None, None] in parse_content_type.
This commit is contained in:
parent
dd2ed78f40
commit
cdd7457aee
@ -33,12 +33,12 @@ class ParseContentTypeTests(unittest.TestCase):
|
|||||||
|
|
||||||
"""Test for parse_content_type."""
|
"""Test for parse_content_type."""
|
||||||
|
|
||||||
# pylint: disable=unpacking-non-sequence
|
|
||||||
|
|
||||||
def test_not_existing(self):
|
def test_not_existing(self):
|
||||||
"""Test without any Content-Type header."""
|
"""Test without any Content-Type header."""
|
||||||
reply = FakeNetworkReply()
|
reply = FakeNetworkReply()
|
||||||
self.assertIsNone(httputils.parse_content_type(reply))
|
mimetype, rest = httputils.parse_content_type(reply)
|
||||||
|
self.assertIsNone(mimetype)
|
||||||
|
self.assertIsNone(rest)
|
||||||
|
|
||||||
def test_mimetype(self):
|
def test_mimetype(self):
|
||||||
"""Test with simple Content-Type header."""
|
"""Test with simple Content-Type header."""
|
||||||
|
@ -72,12 +72,12 @@ def parse_content_type(reply):
|
|||||||
reply: The QNetworkReply to handle.
|
reply: The QNetworkReply to handle.
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
A [mimetype, rest] list, or None.
|
A [mimetype, rest] list, or [None, None] if unset.
|
||||||
Rest can be None.
|
Rest can be None.
|
||||||
"""
|
"""
|
||||||
content_type = reply.header(QNetworkRequest.ContentTypeHeader)
|
content_type = reply.header(QNetworkRequest.ContentTypeHeader)
|
||||||
if content_type is None:
|
if content_type is None:
|
||||||
return None
|
return [None, None]
|
||||||
if ';' in content_type:
|
if ';' in content_type:
|
||||||
ret = content_type.split(';', maxsplit=1)
|
ret = content_type.split(';', maxsplit=1)
|
||||||
else:
|
else:
|
||||||
@ -96,10 +96,9 @@ def change_content_type(reply, mapping):
|
|||||||
Return:
|
Return:
|
||||||
None (modifies the passed reply).
|
None (modifies the passed reply).
|
||||||
"""
|
"""
|
||||||
parsed = parse_content_type(reply)
|
content_type, rest = parse_content_type(reply)
|
||||||
if parsed is None:
|
if content_type is None:
|
||||||
return
|
return
|
||||||
content_type, rest = parsed # pylint: disable=unpacking-non-sequence
|
|
||||||
try:
|
try:
|
||||||
content_type = mapping[content_type]
|
content_type = mapping[content_type]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
Loading…
Reference in New Issue
Block a user