Patchwork [1,of,9] util: rename 're' to 'remod'

login
register
mail settings
Submitter Siddharth Agarwal
Date July 15, 2014, 11:15 p.m.
Message ID <ed42268099cf2d549203.1405466123@dev1738.prn1.facebook.com>
Download mbox | patch
Permalink /patch/5173/
State Accepted
Commit 7e5dfa00e3c28777bbee425a514cd5a0a3dcc27e
Headers show

Comments

Siddharth Agarwal - July 15, 2014, 11:15 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1405460119 25200
#      Tue Jul 15 14:35:19 2014 -0700
# Node ID ed42268099cf2d5492034ed55003326708b76a98
# Parent  cf599f8a2da8fc0f0221b0daa3494802eb94af16
util: rename 're' to 'remod'

Upcoming patches will introduce a binding called 're'.

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -15,7 +15,8 @@ 
 
 from i18n import _
 import error, osutil, encoding
-import errno, re, shutil, sys, tempfile, traceback
+import errno, shutil, sys, tempfile, traceback
+import re as remod
 import os, time, datetime, calendar, textwrap, signal, collections
 import imp, socket, urllib
 
@@ -728,16 +729,16 @@ 
             _re2 = bool(re2.match(r'\[([^\[]+)\]', '[ui]'))
         except ImportError:
             _re2 = False
-    if _re2 and (flags & ~(re.IGNORECASE | re.MULTILINE)) == 0:
-        if flags & re.IGNORECASE:
+    if _re2 and (flags & ~(remod.IGNORECASE | remod.MULTILINE)) == 0:
+        if flags & remod.IGNORECASE:
             pat = '(?i)' + pat
-        if flags & re.MULTILINE:
+        if flags & remod.MULTILINE:
             pat = '(?m)' + pat
         try:
             return re2.compile(pat)
         except re2.error:
             pass
-    return re.compile(pat, flags)
+    return remod.compile(pat, flags)
 
 _fspathcache = {}
 def fspath(name, root):
@@ -761,7 +762,7 @@ 
         seps = seps + os.altsep
     # Protect backslashes. This gets silly very quickly.
     seps.replace('\\','\\\\')
-    pattern = re.compile(r'([^%s]+)|([%s]+)' % (seps, seps))
+    pattern = remod.compile(r'([^%s]+)|([%s]+)' % (seps, seps))
     dir = os.path.normpath(root)
     result = []
     for part, sep in pattern.findall(name):
@@ -1565,7 +1566,7 @@ 
         else:
             prefix_char = prefix
         mapping[prefix_char] = prefix_char
-    r = re.compile(r'%s(%s)' % (prefix, patterns))
+    r = remod.compile(r'%s(%s)' % (prefix, patterns))
     return r.sub(lambda x: fn(mapping[x.group()[1:]]), s)
 
 def getport(port):
@@ -1680,7 +1681,7 @@ 
 
     _safechars = "!~*'()+"
     _safepchars = "/!~*'()+:\\"
-    _matchscheme = re.compile(r'^[a-zA-Z0-9+.\-]+:').match
+    _matchscheme = remod.compile(r'^[a-zA-Z0-9+.\-]+:').match
 
     def __init__(self, path, parsequery=True, parsefragment=True):
         # We slowly chomp away at path until we have only the path left