make selector re() method use re.UNICODE flag to compile regexes

This commit is contained in:
Pablo Hoffman 2012-04-01 00:41:03 -03:00
parent 27018fced7
commit e9184def35
2 changed files with 8 additions and 1 deletions

View File

@ -174,6 +174,13 @@ class XPathSelectorTestCase(unittest.TestCase):
self.assertEqual(x.select("//ul/li").re("Age: (\d+)"),
["10", "20"])
@libxml2debug
def test_selector_re_intl(self):
body = """<div>Evento: cumplea\xc3\xb1os</div>"""
response = HtmlResponse(url="http://example.com", body=body, encoding='utf-8')
x = self.hxs_cls(response)
self.assertEqual(x.select("//div").re("Evento: (\w+)"), [u'cumplea\xf1os'])
@libxml2debug
def test_selector_over_text(self):
hxs = self.hxs_cls(text='<root>lala</root>')

View File

@ -75,7 +75,7 @@ def extract_regex(regex, text, encoding='utf-8'):
"""
if isinstance(regex, basestring):
regex = re.compile(regex)
regex = re.compile(regex, re.UNICODE)
try:
strings = [regex.search(text).group('extract')] # named group