_alphanum = frozenset(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
+
def _re_unescape_replacement(match):
group = match.group(1)
if group[0] in _alphanum:
_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)
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)