Show More
@@ -662,10 +662,12 b' try:' | |||||
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: | |
@@ -673,12 +675,16 b' def compilere(pat):' | |||||
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): |
General Comments 0
You need to be logged in to leave comments.
Login now