http: remove change_content_type.
We're probably not going to need it.
This commit is contained in:
parent
dc00f346f4
commit
48e81b34d0
@ -63,47 +63,5 @@ class ParseContentTypeTests(unittest.TestCase):
|
||||
self.assertEqual(rest, ' encoding=UTF-8')
|
||||
|
||||
|
||||
class ChangeContentTypeTests(unittest.TestCase):
|
||||
|
||||
"""Test for change_content_type."""
|
||||
|
||||
def test_not_existing(self):
|
||||
"""Test without any Content-Type header."""
|
||||
reply = FakeNetworkReply()
|
||||
httputils.change_content_type(reply, {'image/example': 'image/jpeg'})
|
||||
|
||||
def test_mimetype(self):
|
||||
"""Test with simple Content-Type header."""
|
||||
reply = FakeNetworkReply(headers={'Content-Type': 'image/example'})
|
||||
httputils.change_content_type(reply, {'image/example': 'image/jpeg'})
|
||||
self.assertEqual(reply.headers['Content-Type'], 'image/jpeg')
|
||||
|
||||
def test_empty(self):
|
||||
"""Test with empty Content-Type header."""
|
||||
reply = FakeNetworkReply(headers={'Content-Type': ''})
|
||||
httputils.change_content_type(reply, {'image/example': 'image/jpeg'})
|
||||
self.assertEqual(reply.headers['Content-Type'], '')
|
||||
|
||||
def test_additional(self):
|
||||
"""Test with Content-Type header with additional informations."""
|
||||
reply = FakeNetworkReply(
|
||||
headers={'Content-Type': 'image/example; encoding=UTF-8'})
|
||||
httputils.change_content_type(reply, {'image/example': 'image/jpeg'})
|
||||
self.assertEqual(reply.headers['Content-Type'],
|
||||
'image/jpeg; encoding=UTF-8')
|
||||
|
||||
def test_wrong_mapping(self):
|
||||
"""Test with a mapping which doesn't match the header."""
|
||||
reply = FakeNetworkReply(headers={'Content-Type': 'image/example'})
|
||||
httputils.change_content_type(reply, {'image/foo': 'image/bar'})
|
||||
self.assertEqual(reply.headers['Content-Type'], 'image/example')
|
||||
|
||||
def test_empty_mapping(self):
|
||||
"""Test with a mapping which is empty."""
|
||||
reply = FakeNetworkReply(headers={'Content-Type': 'image/example'})
|
||||
httputils.change_content_type(reply, {})
|
||||
self.assertEqual(reply.headers['Content-Type'], 'image/example')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
@ -84,27 +84,3 @@ def parse_content_type(reply):
|
||||
ret = [content_type, None]
|
||||
ret[0] = ret[0].strip()
|
||||
return ret
|
||||
|
||||
|
||||
def change_content_type(reply, mapping):
|
||||
"""Change a content-type of a QNetworkReply.
|
||||
|
||||
Args:
|
||||
reply: The QNetworkReply to handle.
|
||||
mapping: A mapping of source to target content types.
|
||||
|
||||
Return:
|
||||
None (modifies the passed reply).
|
||||
"""
|
||||
content_type, rest = parse_content_type(reply)
|
||||
if content_type is None:
|
||||
return
|
||||
try:
|
||||
content_type = mapping[content_type]
|
||||
except KeyError:
|
||||
return
|
||||
if rest is not None:
|
||||
header = ';'.join((content_type, rest))
|
||||
else:
|
||||
header = content_type
|
||||
reply.setHeader(QNetworkRequest.ContentTypeHeader, header)
|
||||
|
Loading…
Reference in New Issue
Block a user