mirror of https://github.com/scrapy/scrapy.git
PY3 response bodies as bytes
This commit is contained in:
parent
45d441d444
commit
17b5e9fb86
|
|
@ -9,7 +9,7 @@ from cssselect.parser import SelectorSyntaxError
|
|||
from cssselect.xpath import ExpressionError
|
||||
|
||||
|
||||
HTMLBODY = '''
|
||||
HTMLBODY = b'''
|
||||
<html>
|
||||
<body>
|
||||
<div>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ from scrapy.http import TextResponse, HtmlResponse
|
|||
class LxmlDocumentTest(unittest.TestCase):
|
||||
|
||||
def test_caching(self):
|
||||
r1 = HtmlResponse('http://www.example.com', body='<html><head></head><body></body></html>')
|
||||
r1 = HtmlResponse('http://www.example.com', body=b'<html><head></head><body></body></html>')
|
||||
r2 = r1.copy()
|
||||
|
||||
doc1 = LxmlDocument(r1)
|
||||
|
|
@ -19,7 +19,7 @@ class LxmlDocumentTest(unittest.TestCase):
|
|||
|
||||
def test_null_char(self):
|
||||
# make sure bodies with null char ('\x00') don't raise a TypeError exception
|
||||
body = 'test problematic \x00 body'
|
||||
body = b'test problematic \x00 body'
|
||||
response = TextResponse('http://example.com/catalog/product/blabla-123',
|
||||
headers={'Content-Type': 'text/plain; charset=utf-8'},
|
||||
body=body)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class XmliterTestCase(unittest.TestCase):
|
|||
xmliter = staticmethod(xmliter)
|
||||
|
||||
def test_xmliter(self):
|
||||
body = """<?xml version="1.0" encoding="UTF-8"?>\
|
||||
body = b"""<?xml version="1.0" encoding="UTF-8"?>\
|
||||
<products xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="someschmea.xsd">\
|
||||
<product id="001">\
|
||||
<type>Type 1</type>\
|
||||
|
|
@ -40,7 +40,7 @@ class XmliterTestCase(unittest.TestCase):
|
|||
[[u'one'], [u'two']])
|
||||
|
||||
def test_xmliter_namespaces(self):
|
||||
body = """\
|
||||
body = b"""\
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">
|
||||
<channel>
|
||||
|
|
@ -83,7 +83,7 @@ class XmliterTestCase(unittest.TestCase):
|
|||
self.assertRaises(StopIteration, next, iter)
|
||||
|
||||
def test_xmliter_encoding(self):
|
||||
body = '<?xml version="1.0" encoding="ISO-8859-9"?>\n<xml>\n <item>Some Turkish Characters \xd6\xc7\xde\xdd\xd0\xdc \xfc\xf0\xfd\xfe\xe7\xf6</item>\n</xml>\n\n'
|
||||
body = b'<?xml version="1.0" encoding="ISO-8859-9"?>\n<xml>\n <item>Some Turkish Characters \xd6\xc7\xde\xdd\xd0\xdc \xfc\xf0\xfd\xfe\xe7\xf6</item>\n</xml>\n\n'
|
||||
response = XmlResponse('http://www.example.com', body=body)
|
||||
self.assertEqual(
|
||||
self.xmliter(response, 'item').next().extract(),
|
||||
|
|
@ -95,7 +95,7 @@ class LxmlXmliterTestCase(XmliterTestCase):
|
|||
xmliter = staticmethod(xmliter_lxml)
|
||||
|
||||
def test_xmliter_iterate_namespace(self):
|
||||
body = """\
|
||||
body = b"""\
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<rss version="2.0" xmlns="http://base.google.com/ns/1.0">
|
||||
<channel>
|
||||
|
|
@ -124,7 +124,7 @@ class LxmlXmliterTestCase(XmliterTestCase):
|
|||
self.assertEqual(node.xpath('text()').extract(), ['http://www.mydummycompany.com/images/item2.jpg'])
|
||||
|
||||
def test_xmliter_namespaces_prefix(self):
|
||||
body = """\
|
||||
body = b"""\
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<root>
|
||||
<h:table xmlns:h="http://www.w3.org/TR/html4/">
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class RequestSerializationTest(unittest.TestCase):
|
|||
callback='parse_item',
|
||||
errback='handle_error',
|
||||
method="POST",
|
||||
body="some body",
|
||||
body=b"some body",
|
||||
headers={'content-encoding': 'text/html; charset=latin-1'},
|
||||
cookies={'currency': u'руб'},
|
||||
encoding='latin-1',
|
||||
|
|
|
|||
Loading…
Reference in New Issue