utils.http: Return [None, None] in parse_content_type.

This commit is contained in:
Florian Bruhin 2014-08-12 21:12:13 +02:00
parent dd2ed78f40
commit cdd7457aee
2 changed files with 7 additions and 8 deletions

View File

@ -33,12 +33,12 @@ class ParseContentTypeTests(unittest.TestCase):
"""Test for parse_content_type."""
# pylint: disable=unpacking-non-sequence
def test_not_existing(self):
"""Test without any Content-Type header."""
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):
"""Test with simple Content-Type header."""

View File

@ -72,12 +72,12 @@ def parse_content_type(reply):
reply: The QNetworkReply to handle.
Return:
A [mimetype, rest] list, or None.
A [mimetype, rest] list, or [None, None] if unset.
Rest can be None.
"""
content_type = reply.header(QNetworkRequest.ContentTypeHeader)
if content_type is None:
return None
return [None, None]
if ';' in content_type:
ret = content_type.split(';', maxsplit=1)
else:
@ -96,10 +96,9 @@ def change_content_type(reply, mapping):
Return:
None (modifies the passed reply).
"""
parsed = parse_content_type(reply)
if parsed is None:
content_type, rest = parse_content_type(reply)
if content_type is None:
return
content_type, rest = parsed # pylint: disable=unpacking-non-sequence
try:
content_type = mapping[content_type]
except KeyError: