Scrapy, a fast high-level web crawling & scraping framework for Python.
make selector re() method use re.UNICODE flag to compile regexes
Pablo Hoffmane9184def3573
diff --git a/scrapy/tests/test_selector.py b/scrapy/tests/test_selector.pyindex 5ee0c6625..3b2bbc982 100644--- a/scrapy/tests/test_selector.py+++ b/scrapy/tests/test_selector.py@@ -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'])+@libxml2debugdef test_selector_over_text(self):hxs = self.hxs_cls(text='<root>lala</root>')diff --git a/scrapy/utils/misc.py b/scrapy/utils/misc.pyindex 344d01f62..fe9b6d058 100644--- a/scrapy/utils/misc.py+++ b/scrapy/utils/misc.py@@ -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