Skip to content

Commit 17b5e9f

Browse files
nyovkmike
authored andcommitted
PY3 response bodies as bytes
1 parent 45d441d commit 17b5e9f

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

tests/test_selector_csstranslator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from cssselect.xpath import ExpressionError
1010

1111

12-
HTMLBODY = '''
12+
HTMLBODY = b'''
1313
<html>
1414
<body>
1515
<div>

tests/test_selector_lxmldocument.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
class LxmlDocumentTest(unittest.TestCase):
77

88
def test_caching(self):
9-
r1 = HtmlResponse('http://www.example.com/', body='<html><head></head><body></body></html>')
9+
r1 = HtmlResponse('http://www.example.com/', body=b'<html><head></head><body></body></html>')
1010
r2 = r1.copy()
1111

1212
doc1 = LxmlDocument(r1)
@@ -19,7 +19,7 @@ def test_caching(self):
1919

2020
def test_null_char(self):
2121
# make sure bodies with null char ('\x00') don't raise a TypeError exception
22-
body = 'test problematic \x00 body'
22+
body = b'test problematic \x00 body'
2323
response = TextResponse('http://example.com/catalog/product/blabla-123',
2424
headers={'Content-Type': 'text/plain; charset=utf-8'},
2525
body=body)

tests/test_utils_iterators.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class XmliterTestCase(unittest.TestCase):
1313
xmliter = staticmethod(xmliter)
1414

1515
def test_xmliter(self):
16-
body = """<?xml version="1.0" encoding="UTF-8"?>\
16+
body = b"""<?xml version="1.0" encoding="UTF-8"?>\
1717
<products xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="someschmea.xsd">\
1818
<product id="001">\
1919
<type>Type 1</type>\
@@ -40,7 +40,7 @@ def test_xmliter_text(self):
4040
[[u'one'], [u'two']])
4141

4242
def test_xmliter_namespaces(self):
43-
body = """\
43+
body = b"""\
4444
<?xml version="1.0" encoding="UTF-8"?>
4545
<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">
4646
<channel>
@@ -83,7 +83,7 @@ def test_xmliter_exception(self):
8383
self.assertRaises(StopIteration, next, iter)
8484

8585
def test_xmliter_encoding(self):
86-
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'
86+
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'
8787
response = XmlResponse('http://www.example.com', body=body)
8888
self.assertEqual(
8989
self.xmliter(response, 'item').next().extract(),
@@ -95,7 +95,7 @@ class LxmlXmliterTestCase(XmliterTestCase):
9595
xmliter = staticmethod(xmliter_lxml)
9696

9797
def test_xmliter_iterate_namespace(self):
98-
body = """\
98+
body = b"""\
9999
<?xml version="1.0" encoding="UTF-8"?>
100100
<rss version="2.0" xmlns="http://base.google.com/ns/1.0">
101101
<channel>
@@ -124,7 +124,7 @@ def test_xmliter_iterate_namespace(self):
124124
self.assertEqual(node.xpath('text()').extract(), ['http://www.mydummycompany.com/images/item2.jpg'])
125125

126126
def test_xmliter_namespaces_prefix(self):
127-
body = """\
127+
body = b"""\
128128
<?xml version="1.0" encoding="UTF-8"?>
129129
<root>
130130
<h:table xmlns:h="http://www.w3.org/TR/html4/">

tests/test_utils_reqser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def test_all_attributes(self):
2020
callback='parse_item',
2121
errback='handle_error',
2222
method="POST",
23-
body="some body",
23+
body=b"some body",
2424
headers={'content-encoding': 'text/html; charset=latin-1'},
2525
cookies={'currency': u'руб'},
2626
encoding='latin-1',

0 commit comments

Comments
 (0)