Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 21907:7e5dfa00e3c2
util: rename 're' to 'remod'
Upcoming patches will introduce a binding called 're'.
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Tue, 15 Jul 2014 14:35:19 -0700 |
parents | 86c2d792a4b7 |
children | cad9dadc9d26 |
comparison
equal
deleted
inserted
replaced
21906:08dcb572a456 | 21907:7e5dfa00e3c2 |
---|---|
13 hide platform-specific details from the core. | 13 hide platform-specific details from the core. |
14 """ | 14 """ |
15 | 15 |
16 from i18n import _ | 16 from i18n import _ |
17 import error, osutil, encoding | 17 import error, osutil, encoding |
18 import errno, re, shutil, sys, tempfile, traceback | 18 import errno, shutil, sys, tempfile, traceback |
19 import re as remod | |
19 import os, time, datetime, calendar, textwrap, signal, collections | 20 import os, time, datetime, calendar, textwrap, signal, collections |
20 import imp, socket, urllib | 21 import imp, socket, urllib |
21 | 22 |
22 if os.name == 'nt': | 23 if os.name == 'nt': |
23 import windows as platform | 24 import windows as platform |
726 try: | 727 try: |
727 # check if match works, see issue3964 | 728 # check if match works, see issue3964 |
728 _re2 = bool(re2.match(r'\[([^\[]+)\]', '[ui]')) | 729 _re2 = bool(re2.match(r'\[([^\[]+)\]', '[ui]')) |
729 except ImportError: | 730 except ImportError: |
730 _re2 = False | 731 _re2 = False |
731 if _re2 and (flags & ~(re.IGNORECASE | re.MULTILINE)) == 0: | 732 if _re2 and (flags & ~(remod.IGNORECASE | remod.MULTILINE)) == 0: |
732 if flags & re.IGNORECASE: | 733 if flags & remod.IGNORECASE: |
733 pat = '(?i)' + pat | 734 pat = '(?i)' + pat |
734 if flags & re.MULTILINE: | 735 if flags & remod.MULTILINE: |
735 pat = '(?m)' + pat | 736 pat = '(?m)' + pat |
736 try: | 737 try: |
737 return re2.compile(pat) | 738 return re2.compile(pat) |
738 except re2.error: | 739 except re2.error: |
739 pass | 740 pass |
740 return re.compile(pat, flags) | 741 return remod.compile(pat, flags) |
741 | 742 |
742 _fspathcache = {} | 743 _fspathcache = {} |
743 def fspath(name, root): | 744 def fspath(name, root): |
744 '''Get name in the case stored in the filesystem | 745 '''Get name in the case stored in the filesystem |
745 | 746 |
759 seps = os.sep | 760 seps = os.sep |
760 if os.altsep: | 761 if os.altsep: |
761 seps = seps + os.altsep | 762 seps = seps + os.altsep |
762 # Protect backslashes. This gets silly very quickly. | 763 # Protect backslashes. This gets silly very quickly. |
763 seps.replace('\\','\\\\') | 764 seps.replace('\\','\\\\') |
764 pattern = re.compile(r'([^%s]+)|([%s]+)' % (seps, seps)) | 765 pattern = remod.compile(r'([^%s]+)|([%s]+)' % (seps, seps)) |
765 dir = os.path.normpath(root) | 766 dir = os.path.normpath(root) |
766 result = [] | 767 result = [] |
767 for part, sep in pattern.findall(name): | 768 for part, sep in pattern.findall(name): |
768 if sep: | 769 if sep: |
769 result.append(sep) | 770 result.append(sep) |
1563 if len(prefix) > 1: | 1564 if len(prefix) > 1: |
1564 prefix_char = prefix[1:] | 1565 prefix_char = prefix[1:] |
1565 else: | 1566 else: |
1566 prefix_char = prefix | 1567 prefix_char = prefix |
1567 mapping[prefix_char] = prefix_char | 1568 mapping[prefix_char] = prefix_char |
1568 r = re.compile(r'%s(%s)' % (prefix, patterns)) | 1569 r = remod.compile(r'%s(%s)' % (prefix, patterns)) |
1569 return r.sub(lambda x: fn(mapping[x.group()[1:]]), s) | 1570 return r.sub(lambda x: fn(mapping[x.group()[1:]]), s) |
1570 | 1571 |
1571 def getport(port): | 1572 def getport(port): |
1572 """Return the port for a given network service. | 1573 """Return the port for a given network service. |
1573 | 1574 |
1678 <url scheme: 'http', host: 'host', path: 'a?b#c'> | 1679 <url scheme: 'http', host: 'host', path: 'a?b#c'> |
1679 """ | 1680 """ |
1680 | 1681 |
1681 _safechars = "!~*'()+" | 1682 _safechars = "!~*'()+" |
1682 _safepchars = "/!~*'()+:\\" | 1683 _safepchars = "/!~*'()+:\\" |
1683 _matchscheme = re.compile(r'^[a-zA-Z0-9+.\-]+:').match | 1684 _matchscheme = remod.compile(r'^[a-zA-Z0-9+.\-]+:').match |
1684 | 1685 |
1685 def __init__(self, path, parsequery=True, parsefragment=True): | 1686 def __init__(self, path, parsequery=True, parsefragment=True): |
1686 # We slowly chomp away at path until we have only the path left | 1687 # We slowly chomp away at path until we have only the path left |
1687 self.scheme = self.user = self.passwd = self.host = None | 1688 self.scheme = self.user = self.passwd = self.host = None |
1688 self.port = self.path = self.query = self.fragment = None | 1689 self.port = self.path = self.query = self.fragment = None |