From: Ben Darnell Date: Sun, 14 Feb 2016 02:49:33 +0000 (-0500) Subject: Update docs for re_unescape X-Git-Tag: v4.4.0b1~49 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8157a19a256848ea60278afe1fff382a6525ae61;p=thirdparty%2Ftornado.git Update docs for re_unescape --- diff --git a/tornado/util.py b/tornado/util.py index 71f13611b..4283d4e86 100644 --- a/tornado/util.py +++ b/tornado/util.py @@ -181,6 +181,7 @@ def errno_from_exception(e): _alphanum = frozenset( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") + def _re_unescape_replacement(match): group = match.group(1) if group[0] in _alphanum: @@ -189,10 +190,16 @@ def _re_unescape_replacement(match): _re_unescape_pattern = re.compile(r'\\(.)', re.DOTALL) + def re_unescape(s): - ''' - unescape a string escaped by ``re.escape()`` - ''' + """Unescape a string escaped by `re.escape`. + + May raise ``ValueError`` for regular expressions which could not + have been produced by `re.escape` (for example, strings containing + ``\d`` cannot be unescaped). + + .. versionadded:: 4.4 + """ return _re_unescape_pattern.sub(_re_unescape_replacement, s) diff --git a/tornado/web.py b/tornado/web.py index 1226f448c..8826c62b0 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -3032,7 +3032,7 @@ class URLSpec(object): unescaped_fragment = re_unescape(fragment) except ValueError as exc: raise ValueError(exc.args[0] + '; invalid url: %r' % pattern) - pieces.append(re_unescape(fragment)) + pieces.append(unescaped_fragment) return (''.join(pieces), self.regex.groups)