def test_isbinarytext(self):

        # basic tests
        assert not isbinarytext("hello")

        # utf-16 strings contain null bytes
        assert not isbinarytext(u"hello".encode('utf-16')) 

        # one with encoding
        assert not isbinarytext("<div>Price \xa3</div>")

        # finally some real binary bytes
        assert isbinarytext("\x02\xa3")
Beispiel #2
0
    def test_isbinarytext(self):

        # basic tests
        assert not isbinarytext("hello")

        # utf-16 strings contain null bytes
        assert not isbinarytext(u"hello".encode('utf-16'))

        # one with encoding
        assert not isbinarytext("<div>Price \xa3</div>")

        # finally some real binary bytes
        assert isbinarytext("\x02\xa3")
Beispiel #3
0
 def from_body(self, body):
     """Try to guess the appropriate response based on the body content.
     This method is a bit magic and could be improved in the future, but
     it's not meant to be used except for special cases where response types
     cannot be guess using more straightforward methods."""
     chunk = body[:5000]
     if isbinarytext(chunk):
         return self.from_mimetype('application/octet-stream')
     elif "<html>" in chunk.lower():
         return self.from_mimetype('text/html')
     elif "<?xml" in chunk.lower():
         return self.from_mimetype('text/xml')
     else:
         return self.from_mimetype('text')
Beispiel #4
0
 def from_body(self, body):
     """Try to guess the appropriate response based on the body content.
     This method is a bit magic and could be improved in the future, but
     it's not meant to be used except for special cases where response types
     cannot be guess using more straightforward methods."""
     chunk = body[:5000]
     if isbinarytext(chunk):
         return self.from_mimetype('application/octet-stream')
     elif "<html>" in chunk.lower():
         return self.from_mimetype('text/html')
     elif "<?xml" in chunk.lower():
         return self.from_mimetype('text/xml')
     else:
         return self.from_mimetype('text')
Beispiel #5
0
 def test_real_binary_bytes(self):
     assert isbinarytext(b"\x02\xa3")
Beispiel #6
0
 def test_one_with_encoding(self):
     assert not isbinarytext(b"<div>Price \xa3</div>")
Beispiel #7
0
 def test_utf_16_strings_contain_null_bytes(self):
     assert not isbinarytext(u"hello".encode('utf-16'))
Beispiel #8
0
 def test_isbinarytext(self):
     assert not isbinarytext(b"hello")
Beispiel #9
0
 def test_real_binary_bytes(self):
     assert isbinarytext(b"\x02\xa3")
Beispiel #10
0
 def test_one_with_encoding(self):
     assert not isbinarytext(b"<div>Price \xa3</div>")
Beispiel #11
0
 def test_utf_16_strings_contain_null_bytes(self):
     assert not isbinarytext(u"hello".encode('utf-16'))
Beispiel #12
0
 def test_isbinarytext(self):
     assert not isbinarytext(b"hello")