Show More
@@ -2172,6 +2172,7 b' def fscasesensitive(path):' | |||
|
2172 | 2172 | return True |
|
2173 | 2173 | |
|
2174 | 2174 | |
|
2175 | _re2_input = lambda x: x | |
|
2175 | 2176 | try: |
|
2176 | 2177 | import re2 # pytype: disable=import-error |
|
2177 | 2178 | |
@@ -2183,11 +2184,21 b' except ImportError:' | |||
|
2183 | 2184 | class _re(object): |
|
2184 | 2185 | def _checkre2(self): |
|
2185 | 2186 | global _re2 |
|
2187 | global _re2_input | |
|
2186 | 2188 | try: |
|
2187 | 2189 | # check if match works, see issue3964 |
|
2188 |
|
|
|
2190 | check_pattern = br'\[([^\[]+)\]' | |
|
2191 | check_input = b'[ui]' | |
|
2192 | _re2 = bool(re2.match(check_pattern, check_input)) | |
|
2189 | 2193 | except ImportError: |
|
2190 | 2194 | _re2 = False |
|
2195 | except TypeError: | |
|
2196 | # the `pyre-2` project provides a re2 module that accept bytes | |
|
2197 | # the `fb-re2` project provides a re2 module that acccept sysstr | |
|
2198 | check_pattern = pycompat.sysstr(check_pattern) | |
|
2199 | check_input = pycompat.sysstr(check_input) | |
|
2200 | _re2 = bool(re2.match(check_pattern, check_input)) | |
|
2201 | _re2_input = pycompat.sysstr | |
|
2191 | 2202 | |
|
2192 | 2203 | def compile(self, pat, flags=0): |
|
2193 | 2204 | """Compile a regular expression, using re2 if possible |
@@ -2203,7 +2214,7 b' class _re(object):' | |||
|
2203 | 2214 | if flags & remod.MULTILINE: |
|
2204 | 2215 | pat = b'(?m)' + pat |
|
2205 | 2216 | try: |
|
2206 | return re2.compile(pat) | |
|
2217 | return re2.compile(_re2_input(pat)) | |
|
2207 | 2218 | except re2.error: |
|
2208 | 2219 | pass |
|
2209 | 2220 | return remod.compile(pat, flags) |
General Comments 0
You need to be logged in to leave comments.
Login now