Details
Details
- Reviewers
durin42 - Group Reviewers
hg-reviewers - Commits
- rHG25c543944bc0: py3: add b'' to regular expressions which are raw strings
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
durin42 |
hg-reviewers |
Lint Skipped |
Unit Tests Skipped |
Path | Packages | |||
---|---|---|---|---|
M | hgext/mq.py (2 lines) | |||
M | mercurial/dispatch.py (4 lines) | |||
M | mercurial/util.py (2 lines) |
def matchpatch(l): | def matchpatch(l): | ||||
l = l.split('#', 1)[0] | l = l.split('#', 1)[0] | ||||
return l.strip() == patch | return l.strip() == patch | ||||
for index, l in enumerate(self.fullseries): | for index, l in enumerate(self.fullseries): | ||||
if matchpatch(l): | if matchpatch(l): | ||||
return index | return index | ||||
return None | return None | ||||
guard_re = re.compile(r'\s?#([-+][^-+# \t\r\n\f][^# \t\r\n\f]*)') | guard_re = re.compile(br'\s?#([-+][^-+# \t\r\n\f][^# \t\r\n\f]*)') | ||||
def parseseries(self): | def parseseries(self): | ||||
self.series = [] | self.series = [] | ||||
self.seriesguards = [] | self.seriesguards = [] | ||||
for l in self.fullseries: | for l in self.fullseries: | ||||
h = l.find('#') | h = l.find('#') | ||||
if h == -1: | if h == -1: | ||||
patch = l | patch = l |
replacemap['$$'] = '$' | replacemap['$$'] = '$' | ||||
replacemap['$@'] = ' '.join(args) | replacemap['$@'] = ' '.join(args) | ||||
# Typical Unix shells interpolate "$@" (with quotes) as all the positional | # Typical Unix shells interpolate "$@" (with quotes) as all the positional | ||||
# parameters, separated out into words. Emulate the same behavior here by | # parameters, separated out into words. Emulate the same behavior here by | ||||
# quoting the arguments individually. POSIX shells will then typically | # quoting the arguments individually. POSIX shells will then typically | ||||
# tokenize each argument into exactly one word. | # tokenize each argument into exactly one word. | ||||
replacemap['"$@"'] = ' '.join(util.shellquote(arg) for arg in args) | replacemap['"$@"'] = ' '.join(util.shellquote(arg) for arg in args) | ||||
# escape '\$' for regex | # escape '\$' for regex | ||||
regex = '|'.join(replacemap.keys()).replace('$', r'\$') | regex = '|'.join(replacemap.keys()).replace('$', br'\$') | ||||
r = re.compile(regex) | r = re.compile(regex) | ||||
return r.sub(lambda x: replacemap[x.group()], cmd) | return r.sub(lambda x: replacemap[x.group()], cmd) | ||||
class cmdalias(object): | class cmdalias(object): | ||||
def __init__(self, name, definition, cmdtable, source): | def __init__(self, name, definition, cmdtable, source): | ||||
self.name = self.cmd = name | self.name = self.cmd = name | ||||
self.cmdname = '' | self.cmdname = '' | ||||
self.definition = definition | self.definition = definition | ||||
return m.group() | return m.group() | ||||
elif int(m.groups()[0]) <= len(args): | elif int(m.groups()[0]) <= len(args): | ||||
return m.group() | return m.group() | ||||
else: | else: | ||||
ui.debug("No argument found for substitution " | ui.debug("No argument found for substitution " | ||||
"of %i variable in alias '%s' definition." | "of %i variable in alias '%s' definition." | ||||
% (int(m.groups()[0]), self.name)) | % (int(m.groups()[0]), self.name)) | ||||
return '' | return '' | ||||
cmd = re.sub(r'\$(\d+|\$)', _checkvar, self.definition[1:]) | cmd = re.sub(br'\$(\d+|\$)', _checkvar, self.definition[1:]) | ||||
cmd = aliasinterpolate(self.name, args, cmd) | cmd = aliasinterpolate(self.name, args, cmd) | ||||
return ui.system(cmd, environ=env, | return ui.system(cmd, environ=env, | ||||
blockedtag='alias_%s' % self.name) | blockedtag='alias_%s' % self.name) | ||||
self.fn = fn | self.fn = fn | ||||
return | return | ||||
try: | try: | ||||
args = pycompat.shlexsplit(self.definition) | args = pycompat.shlexsplit(self.definition) |
patterns = '|'.join(mapping.keys()) | patterns = '|'.join(mapping.keys()) | ||||
if escape_prefix: | if escape_prefix: | ||||
patterns += '|' + prefix | patterns += '|' + prefix | ||||
if len(prefix) > 1: | if len(prefix) > 1: | ||||
prefix_char = prefix[1:] | prefix_char = prefix[1:] | ||||
else: | else: | ||||
prefix_char = prefix | prefix_char = prefix | ||||
mapping[prefix_char] = prefix_char | mapping[prefix_char] = prefix_char | ||||
r = remod.compile(r'%s(%s)' % (prefix, patterns)) | r = remod.compile(br'%s(%s)' % (prefix, patterns)) | ||||
return r.sub(lambda x: fn(mapping[x.group()[1:]]), s) | return r.sub(lambda x: fn(mapping[x.group()[1:]]), s) | ||||
def getport(port): | def getport(port): | ||||
"""Return the port for a given network service. | """Return the port for a given network service. | ||||
If port is an integer, it's returned as is. If it's a string, it's | If port is an integer, it's returned as is. If it's a string, it's | ||||
looked up using socket.getservbyname(). If there's no matching | looked up using socket.getservbyname(). If there's no matching | ||||
service, error.Abort is raised. | service, error.Abort is raised. |