fixed bug caused when instantiating selectors with responses containing empty bodies

This commit is contained in:
Pablo Hoffman 2009-10-21 16:37:30 -02:00
parent 53ae45ad3d
commit 7baff2914a
2 changed files with 8 additions and 2 deletions

View File

@ -24,7 +24,7 @@ def body_as_utf8(response):
def xmlDoc_from_html(response):
"""Return libxml2 doc for HTMLs"""
utf8body = body_as_utf8(response)
utf8body = body_as_utf8(response) or ' '
try:
lxdoc = libxml2.htmlReadDoc(utf8body, response.url, 'utf-8', \
html_parser_options)
@ -35,7 +35,7 @@ def xmlDoc_from_html(response):
def xmlDoc_from_xml(response):
"""Return libxml2 doc for XMLs"""
utf8body = body_as_utf8(response)
utf8body = body_as_utf8(response) or ' '
try:
lxdoc = libxml2.readDoc(utf8body, response.url, 'utf-8', \
xml_parser_options)

View File

@ -241,6 +241,12 @@ class XPathSelectorTestCase(unittest.TestCase):
u'\n ',
u'\n pff\n'])
@libxml2debug
def test_empty_bodies(self):
r1 = TextResponse('http://www.example.com', body='')
hxs = HtmlXPathSelector(r1) # shouldn't raise error
xxs = XmlXPathSelector(r1) # shouldn't raise error
@libxml2debug
def test_weakref_slots(self):
"""Check that classes are using slots and are weak-referenceable"""