added new test case for xpathselector_iternodes

--HG--
extra : convert_revision : svn%3Ab85faa78-f9eb-468e-a121-7cced6da292c%4062
This commit is contained in:
Pablo Hoffman 2008-07-14 13:31:00 +00:00
parent 28b5bb3240
commit 49175d1990
2 changed files with 7 additions and 0 deletions

View File

@ -34,6 +34,11 @@ class UtilsXmlTestCase(unittest.TestCase):
self.assertEqual([x.x("@id").extract() for x in xpathselector_iternodes(response, 'product')],
[['34017532'], ['34017557'], ['34017563'], ['34018057'], ['34018313'], ['34018599']])
def test_iterator_text(self):
body = u"""<?xml version="1.0" encoding="UTF-8"?><products><product>one</product><product>two</product></products>"""
self.assertEqual([x.x("text()").extract() for x in xpathselector_iternodes(body, 'product')],
[[u'one'], [u'two']])
if __name__ == "__main__":
unittest.main()

View File

@ -19,6 +19,8 @@ def xpathselector_iternodes(obj, nodename):
text = obj.body.to_unicode()
elif isinstance(obj, str):
text = obj.decode('utf-8')
else:
text = obj
r = re.compile(r"<%s[\s>].*?</%s>" % (nodename, nodename), re.DOTALL)
for match in r.finditer(text):