Mercurial > public > mercurial-scm > hg-stable
diff mercurial/templater.py @ 26231:87c9c562c37a
parser: move unescape helper from templater
revset and fileset have a similar problem, so let's make it a common helper
function.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Thu, 10 Sep 2015 23:25:10 +0900 |
parents | 72aad184f061 |
children | e4609ec959f8 |
line wrap: on
line diff
--- a/mercurial/templater.py Thu Sep 10 16:14:39 2015 -0700 +++ b/mercurial/templater.py Thu Sep 10 23:25:10 2015 +0900 @@ -39,13 +39,6 @@ "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 @@ 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 @@ 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