##// END OF EJS Templates
util: move compilere to a class...
Siddharth Agarwal -
r21908:cad9dadc default
parent child Browse files
Show More
@@ -716,29 +716,33 b' try:'
716 716 except ImportError:
717 717 _re2 = False
718 718
719 def compilere(pat, flags=0):
720 '''Compile a regular expression, using re2 if possible
719 class _re(object):
720 def compile(self, pat, flags=0):
721 '''Compile a regular expression, using re2 if possible
721 722
722 For best performance, use only re2-compatible regexp features. The
723 only flags from the re module that are re2-compatible are
724 IGNORECASE and MULTILINE.'''
725 global _re2
726 if _re2 is None:
727 try:
728 # check if match works, see issue3964
729 _re2 = bool(re2.match(r'\[([^\[]+)\]', '[ui]'))
730 except ImportError:
731 _re2 = False
732 if _re2 and (flags & ~(remod.IGNORECASE | remod.MULTILINE)) == 0:
733 if flags & remod.IGNORECASE:
734 pat = '(?i)' + pat
735 if flags & remod.MULTILINE:
736 pat = '(?m)' + pat
737 try:
738 return re2.compile(pat)
739 except re2.error:
740 pass
741 return remod.compile(pat, flags)
723 For best performance, use only re2-compatible regexp features. The
724 only flags from the re module that are re2-compatible are
725 IGNORECASE and MULTILINE.'''
726 global _re2
727 if _re2 is None:
728 try:
729 # check if match works, see issue3964
730 _re2 = bool(re2.match(r'\[([^\[]+)\]', '[ui]'))
731 except ImportError:
732 _re2 = False
733 if _re2 and (flags & ~(remod.IGNORECASE | remod.MULTILINE)) == 0:
734 if flags & remod.IGNORECASE:
735 pat = '(?i)' + pat
736 if flags & remod.MULTILINE:
737 pat = '(?m)' + pat
738 try:
739 return re2.compile(pat)
740 except re2.error:
741 pass
742 return remod.compile(pat, flags)
743
744 re = _re()
745 compilere = re.compile
742 746
743 747 _fspathcache = {}
744 748 def fspath(name, root):
General Comments 0
You need to be logged in to leave comments. Login now