##// END OF EJS Templates
re2: feed unicode string to re2 module when necessary...
marmoute -
r47598:112826b5 stable
parent child Browse files
Show More
@@ -2157,6 +2157,7 b' def fscasesensitive(path):'
2157 return True
2157 return True
2158
2158
2159
2159
2160 _re2_input = lambda x: x
2160 try:
2161 try:
2161 import re2 # pytype: disable=import-error
2162 import re2 # pytype: disable=import-error
2162
2163
@@ -2168,11 +2169,21 b' except ImportError:'
2168 class _re(object):
2169 class _re(object):
2169 def _checkre2(self):
2170 def _checkre2(self):
2170 global _re2
2171 global _re2
2172 global _re2_input
2171 try:
2173 try:
2172 # check if match works, see issue3964
2174 # check if match works, see issue3964
2173 _re2 = bool(re2.match(br'\[([^\[]+)\]', b'[ui]'))
2175 check_pattern = br'\[([^\[]+)\]'
2176 check_input = b'[ui]'
2177 _re2 = bool(re2.match(check_pattern, check_input))
2174 except ImportError:
2178 except ImportError:
2175 _re2 = False
2179 _re2 = False
2180 except TypeError:
2181 # the `pyre-2` project provides a re2 module that accept bytes
2182 # the `fb-re2` project provides a re2 module that acccept sysstr
2183 check_pattern = pycompat.sysstr(check_pattern)
2184 check_input = pycompat.sysstr(check_input)
2185 _re2 = bool(re2.match(check_pattern, check_input))
2186 _re2_input = pycompat.sysstr
2176
2187
2177 def compile(self, pat, flags=0):
2188 def compile(self, pat, flags=0):
2178 """Compile a regular expression, using re2 if possible
2189 """Compile a regular expression, using re2 if possible
@@ -2188,7 +2199,7 b' class _re(object):'
2188 if flags & remod.MULTILINE:
2199 if flags & remod.MULTILINE:
2189 pat = b'(?m)' + pat
2200 pat = b'(?m)' + pat
2190 try:
2201 try:
2191 return re2.compile(pat)
2202 return re2.compile(_re2_input(pat))
2192 except re2.error:
2203 except re2.error:
2193 pass
2204 pass
2194 return remod.compile(pat, flags)
2205 return remod.compile(pat, flags)
General Comments 0
You need to be logged in to leave comments. Login now