Mercurial > hg-stable
comparison mercurial/util.py @ 21908:cad9dadc9d26
util: move compilere to a class
We do this to allow us to use descriptors for other related methods.
For now, util.compilere does the same thing. Upcoming patches will remove it.
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Tue, 15 Jul 2014 14:40:43 -0700 |
parents | 7e5dfa00e3c2 |
children | b6ef4469191d |
comparison
equal
deleted
inserted
replaced
21907:7e5dfa00e3c2 | 21908:cad9dadc9d26 |
---|---|
714 import re2 | 714 import re2 |
715 _re2 = None | 715 _re2 = None |
716 except ImportError: | 716 except ImportError: |
717 _re2 = False | 717 _re2 = False |
718 | 718 |
719 def compilere(pat, flags=0): | 719 class _re(object): |
720 '''Compile a regular expression, using re2 if possible | 720 def compile(self, pat, flags=0): |
721 | 721 '''Compile a regular expression, using re2 if possible |
722 For best performance, use only re2-compatible regexp features. The | 722 |
723 only flags from the re module that are re2-compatible are | 723 For best performance, use only re2-compatible regexp features. The |
724 IGNORECASE and MULTILINE.''' | 724 only flags from the re module that are re2-compatible are |
725 global _re2 | 725 IGNORECASE and MULTILINE.''' |
726 if _re2 is None: | 726 global _re2 |
727 try: | 727 if _re2 is None: |
728 # check if match works, see issue3964 | 728 try: |
729 _re2 = bool(re2.match(r'\[([^\[]+)\]', '[ui]')) | 729 # check if match works, see issue3964 |
730 except ImportError: | 730 _re2 = bool(re2.match(r'\[([^\[]+)\]', '[ui]')) |
731 _re2 = False | 731 except ImportError: |
732 if _re2 and (flags & ~(remod.IGNORECASE | remod.MULTILINE)) == 0: | 732 _re2 = False |
733 if flags & remod.IGNORECASE: | 733 if _re2 and (flags & ~(remod.IGNORECASE | remod.MULTILINE)) == 0: |
734 pat = '(?i)' + pat | 734 if flags & remod.IGNORECASE: |
735 if flags & remod.MULTILINE: | 735 pat = '(?i)' + pat |
736 pat = '(?m)' + pat | 736 if flags & remod.MULTILINE: |
737 try: | 737 pat = '(?m)' + pat |
738 return re2.compile(pat) | 738 try: |
739 except re2.error: | 739 return re2.compile(pat) |
740 pass | 740 except re2.error: |
741 return remod.compile(pat, flags) | 741 pass |
742 return remod.compile(pat, flags) | |
743 | |
744 re = _re() | |
745 compilere = re.compile | |
742 | 746 |
743 _fspathcache = {} | 747 _fspathcache = {} |
744 def fspath(name, root): | 748 def fspath(name, root): |
745 '''Get name in the case stored in the filesystem | 749 '''Get name in the case stored in the filesystem |
746 | 750 |