Exemplo n.º 1
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]
     chunk = to_bytes(chunk)
     if not binary_is_text(chunk):
         return self.from_mimetype('application/octet-stream')
     elif b"<html>" in chunk.lower():
         return self.from_mimetype('text/html')
     elif b"<?xml" in chunk.lower():
         return self.from_mimetype('text/xml')
     else:
         return self.from_mimetype('text')
Exemplo n.º 2
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]
     chunk = to_bytes(chunk)
     if not binary_is_text(chunk):
         return self.from_mimetype('application/octet-stream')
     elif b"<html>" in chunk.lower():
         return self.from_mimetype('text/html')
     elif b"<?xml" in chunk.lower():
         return self.from_mimetype('text/xml')
     else:
         return self.from_mimetype('text')
Exemplo n.º 3
0
 def test_real_binary_bytes(self):
     assert not binary_is_text(b"\x02\xa3")
Exemplo n.º 4
0
 def test_one_with_encoding(self):
     assert binary_is_text(b"<div>Price \xa3</div>")
Exemplo n.º 5
0
 def test_utf_16_strings_contain_null_bytes(self):
     assert binary_is_text(u"hello".encode('utf-16'))
Exemplo n.º 6
0
 def test_binaryistext(self):
     assert binary_is_text(b"hello")
Exemplo n.º 7
0
 def test_real_binary_bytes(self):
     assert not binary_is_text(b"\x02\xa3")
Exemplo n.º 8
0
 def test_one_with_encoding(self):
     assert binary_is_text(b"<div>Price \xa3</div>")
Exemplo n.º 9
0
 def test_utf_16_strings_contain_null_bytes(self):
     assert binary_is_text(u"hello".encode('utf-16'))
Exemplo n.º 10
0
 def test_binaryistext(self):
     assert binary_is_text(b"hello")