equal
deleted
inserted
replaced
660 import re2 |
660 import re2 |
661 _re2 = None |
661 _re2 = None |
662 except ImportError: |
662 except ImportError: |
663 _re2 = False |
663 _re2 = False |
664 |
664 |
665 def compilere(pat): |
665 def compilere(pat, flags=0): |
666 '''Compile a regular expression, using re2 if possible |
666 '''Compile a regular expression, using re2 if possible |
667 |
667 |
668 For best performance, use only re2-compatible regexp features.''' |
668 For best performance, use only re2-compatible regexp features. The |
|
669 only flags from the re module that are re2-compatible are |
|
670 IGNORECASE and MULTILINE.''' |
669 global _re2 |
671 global _re2 |
670 if _re2 is None: |
672 if _re2 is None: |
671 try: |
673 try: |
672 re2.compile |
674 re2.compile |
673 _re2 = True |
675 _re2 = True |
674 except ImportError: |
676 except ImportError: |
675 _re2 = False |
677 _re2 = False |
676 if _re2: |
678 if _re2 and (flags & ~(re.IGNORECASE | re.MULTILINE)) == 0: |
|
679 if flags & re.IGNORECASE: |
|
680 pat = '(?i)' + pat |
|
681 if flags & re.MULTILINE: |
|
682 pat = '(?m)' + pat |
677 try: |
683 try: |
678 return re2.compile(pat) |
684 return re2.compile(pat) |
679 except re2.error: |
685 except re2.error: |
680 pass |
686 pass |
681 return re.compile(pat) |
687 return re.compile(pat, flags) |
682 |
688 |
683 _fspathcache = {} |
689 _fspathcache = {} |
684 def fspath(name, root): |
690 def fspath(name, root): |
685 '''Get name in the case stored in the filesystem |
691 '''Get name in the case stored in the filesystem |
686 |
692 |