Beispiel #1
0
 def test_additional(self, stubs):
     """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)
     assert mimetype == 'image/example'
     assert rest == ' encoding=UTF-8'
Beispiel #2
0
 def test_additional(self, stubs):
     """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)
     assert mimetype == 'image/example'
     assert rest == ' encoding=UTF-8'
Beispiel #3
0
 def test_mimetype(self, stubs):
     """Test with simple Content-Type header."""
     reply = stubs.FakeNetworkReply(
         headers={'Content-Type': 'image/example'})
     mimetype, rest = http.parse_content_type(reply)
     assert mimetype == 'image/example'
     assert rest is None
Beispiel #4
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)
        download_manager = objreg.get('download-manager', scope='window',
                                      window=self._win_id)
        if not inline:
            # Content-Disposition: attachment -> force download
            download_manager.fetch(reply,
                                   suggested_filename=suggested_filename)
            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.
            download_manager.fetch(reply,
                                   suggested_filename=suggested_filename)
Beispiel #5
0
 def test_mimetype(self, stubs):
     """Test with simple Content-Type header."""
     reply = stubs.FakeNetworkReply(
         headers={'Content-Type': 'image/example'})
     mimetype, rest = http.parse_content_type(reply)
     assert mimetype == 'image/example'
     assert rest is None
Beispiel #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)
        download_manager = objreg.get('download-manager',
                                      scope='window',
                                      window=self._win_id)
        if not inline:
            # Content-Disposition: attachment -> force download
            download_manager.fetch(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.
            download_manager.fetch(reply)
Beispiel #7
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)
Beispiel #8
0
 def test_empty(self, stubs):
     """Test with empty Content-Type header."""
     reply = stubs.FakeNetworkReply(headers={'Content-Type': ''})
     mimetype, rest = http.parse_content_type(reply)
     assert mimetype == ''
     assert rest is None
Beispiel #9
0
 def test_not_existing(self, stubs):
     """Test without any Content-Type header."""
     reply = stubs.FakeNetworkReply()
     mimetype, rest = http.parse_content_type(reply)
     assert mimetype is None
     assert rest is None
Beispiel #10
0
 def test_empty(self, stubs):
     """Test with empty Content-Type header."""
     reply = stubs.FakeNetworkReply(headers={'Content-Type': ''})
     mimetype, rest = http.parse_content_type(reply)
     assert mimetype == ''
     assert rest is None
Beispiel #11
0
 def test_not_existing(self, stubs):
     """Test without any Content-Type header."""
     reply = stubs.FakeNetworkReply()
     mimetype, rest = http.parse_content_type(reply)
     assert mimetype is None
     assert rest is None
def test_parse_content_type(stubs, s):
    reply = stubs.FakeNetworkReply(headers={"Content-Type": s})
    http.parse_content_type(reply)
Beispiel #13
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)
Beispiel #14
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)
def test_parse_content_type(stubs, s):
    reply = stubs.FakeNetworkReply(headers={'Content-Type': s})
    http.parse_content_type(reply)