diff --git a/mercurial/parser.py b/mercurial/parser.py --- a/mercurial/parser.py +++ b/mercurial/parser.py @@ -122,6 +122,13 @@ def buildargsdict(trees, funcname, keys, args[k] = x[2] return args +def unescapestr(s): + try: + return s.decode("string_escape") + except ValueError as e: + # mangle Python's exception into our format + raise error.ParseError(str(e).lower()) + def _prettyformat(tree, leafnodes, level, lines): if not isinstance(tree, tuple) or tree[0] in leafnodes: lines.append((level, str(tree))) diff --git a/mercurial/templater.py b/mercurial/templater.py --- a/mercurial/templater.py +++ b/mercurial/templater.py @@ -39,13 +39,6 @@ elements = { "end": (0, None, None, None, None), } -def _unescape(s): - try: - return s.decode("string_escape") - except ValueError as e: - # mangle Python's exception into our format - raise error.ParseError(str(e).lower()) - def tokenize(program, start, end): pos = start while pos < end: @@ -113,7 +106,7 @@ def tokenize(program, start, end): continue if program.startswith(quote, pos, end): # interpret as if it were a part of an outer string - data = _unescape(program[s:pos]) + data = parser.unescapestr(program[s:pos]) if token == 'template': data = _parsetemplate(data, 0, len(data))[0] yield (token, data, s) @@ -162,18 +155,18 @@ def _parsetemplate(tmpl, start, stop, qu n = min((tmpl.find(c, pos, stop) for c in sepchars), key=lambda n: (n < 0, n)) if n < 0: - parsed.append(('string', _unescape(tmpl[pos:stop]))) + parsed.append(('string', parser.unescapestr(tmpl[pos:stop]))) pos = stop break c = tmpl[n] bs = (n - pos) - len(tmpl[pos:n].rstrip('\\')) if bs % 2 == 1: # escaped (e.g. '\{', '\\\{', but not '\\{') - parsed.append(('string', _unescape(tmpl[pos:n - 1]) + c)) + parsed.append(('string', parser.unescapestr(tmpl[pos:n - 1]) + c)) pos = n + 1 continue if n > pos: - parsed.append(('string', _unescape(tmpl[pos:n]))) + parsed.append(('string', parser.unescapestr(tmpl[pos:n]))) if c == quote: return parsed, n + 1