示例#1
0
 def test_additional(self):
     """Test with Content-Type header with additional informations."""
     reply = stubs.FakeNetworkReply(
         headers={'Content-Type': 'image/example; encoding=UTF-8'})
     mimetype, rest = http.parse_content_type(reply)
     self.assertEqual(mimetype, 'image/example')
     self.assertEqual(rest, ' encoding=UTF-8')
示例#2
0
 def test_mimetype(self):
     """Test with simple Content-Type header."""
     reply = stubs.FakeNetworkReply(
         headers={'Content-Type': 'image/example'})
     mimetype, rest = http.parse_content_type(reply)
     self.assertEqual(mimetype, 'image/example')
     self.assertIsNone(rest)
示例#3
0
 def test_additional(self):
     """Test with Content-Type header with additional informations."""
     reply = stubs.FakeNetworkReply(
         headers={'Content-Type': 'image/example; encoding=UTF-8'})
     mimetype, rest = http.parse_content_type(reply)
     self.assertEqual(mimetype, 'image/example')
     self.assertEqual(rest, ' encoding=UTF-8')
示例#4
0
 def test_mimetype(self):
     """Test with simple Content-Type header."""
     reply = stubs.FakeNetworkReply(
         headers={'Content-Type': 'image/example'})
     mimetype, rest = http.parse_content_type(reply)
     self.assertEqual(mimetype, 'image/example')
     self.assertIsNone(rest)
示例#5
0
    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)
        if not inline:
            # Content-Disposition: attachment -> force download
            self.start_download.emit(reply)
            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.
            self.start_download.emit(reply)
示例#6
0
    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)
        if not inline:
            # Content-Disposition: attachment -> force download
            self.start_download.emit(reply)
            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.
            self.start_download.emit(reply)
示例#7
0
 def test_empty(self):
     """Test with empty Content-Type header."""
     reply = stubs.FakeNetworkReply(headers={'Content-Type': ''})
     mimetype, rest = http.parse_content_type(reply)
     self.assertEqual(mimetype, '')
     self.assertIsNone(rest)
示例#8
0
 def test_not_existing(self):
     """Test without any Content-Type header."""
     reply = stubs.FakeNetworkReply()
     mimetype, rest = http.parse_content_type(reply)
     self.assertIsNone(mimetype)
     self.assertIsNone(rest)
示例#9
0
 def test_empty(self):
     """Test with empty Content-Type header."""
     reply = stubs.FakeNetworkReply(headers={'Content-Type': ''})
     mimetype, rest = http.parse_content_type(reply)
     self.assertEqual(mimetype, '')
     self.assertIsNone(rest)
示例#10
0
 def test_not_existing(self):
     """Test without any Content-Type header."""
     reply = stubs.FakeNetworkReply()
     mimetype, rest = http.parse_content_type(reply)
     self.assertIsNone(mimetype)
     self.assertIsNone(rest)