Show More
@@ -5,6 +5,9 b'' | |||||
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
|
8 | # See https://github.com/google/pytype/issues/860 | |||
|
9 | # pytype: skip-file | |||
|
10 | ||||
8 | from __future__ import absolute_import |
|
11 | from __future__ import absolute_import | |
9 |
|
12 | |||
10 | from ..i18n import _ |
|
13 | from ..i18n import _ |
@@ -2177,6 +2177,7 b' def fscasesensitive(path):' | |||||
2177 | return True |
|
2177 | return True | |
2178 |
|
2178 | |||
2179 |
|
2179 | |||
|
2180 | _re2_input = lambda x: x | |||
2180 | try: |
|
2181 | try: | |
2181 | import re2 # pytype: disable=import-error |
|
2182 | import re2 # pytype: disable=import-error | |
2182 |
|
2183 | |||
@@ -2188,11 +2189,21 b' except ImportError:' | |||||
2188 | class _re(object): |
|
2189 | class _re(object): | |
2189 | def _checkre2(self): |
|
2190 | def _checkre2(self): | |
2190 | global _re2 |
|
2191 | global _re2 | |
|
2192 | global _re2_input | |||
2191 | try: |
|
2193 | try: | |
2192 | # check if match works, see issue3964 |
|
2194 | # check if match works, see issue3964 | |
2193 |
|
|
2195 | check_pattern = br'\[([^\[]+)\]' | |
|
2196 | check_input = b'[ui]' | |||
|
2197 | _re2 = bool(re2.match(check_pattern, check_input)) | |||
2194 | except ImportError: |
|
2198 | except ImportError: | |
2195 | _re2 = False |
|
2199 | _re2 = False | |
|
2200 | except TypeError: | |||
|
2201 | # the `pyre-2` project provides a re2 module that accept bytes | |||
|
2202 | # the `fb-re2` project provides a re2 module that acccept sysstr | |||
|
2203 | check_pattern = pycompat.sysstr(check_pattern) | |||
|
2204 | check_input = pycompat.sysstr(check_input) | |||
|
2205 | _re2 = bool(re2.match(check_pattern, check_input)) | |||
|
2206 | _re2_input = pycompat.sysstr | |||
2196 |
|
2207 | |||
2197 | def compile(self, pat, flags=0): |
|
2208 | def compile(self, pat, flags=0): | |
2198 | """Compile a regular expression, using re2 if possible |
|
2209 | """Compile a regular expression, using re2 if possible | |
@@ -2208,7 +2219,7 b' class _re(object):' | |||||
2208 | if flags & remod.MULTILINE: |
|
2219 | if flags & remod.MULTILINE: | |
2209 | pat = b'(?m)' + pat |
|
2220 | pat = b'(?m)' + pat | |
2210 | try: |
|
2221 | try: | |
2211 | return re2.compile(pat) |
|
2222 | return re2.compile(_re2_input(pat)) | |
2212 | except re2.error: |
|
2223 | except re2.error: | |
2213 | pass |
|
2224 | pass | |
2214 | return remod.compile(pat, flags) |
|
2225 | return remod.compile(pat, flags) |
General Comments 0
You need to be logged in to leave comments.
Login now