Extract variables to link more clearly the comment to the operation
@@ -53,8 +53,8 @@ def unescape(value):
"""
Inverse of escape.
"""
- re_esc = re.compile(
+ pattern = ESCAPE_FMT.replace('%02X', '(?P<code>[0-9A-Fa-f]{2})')
# the pattern must be bytes to operate on bytes
- ESCAPE_FMT.replace('%02X', '(?P<code>[0-9A-Fa-f]{2})').encode('ascii')
- )
+ pattern_bytes = pattern.encode('ascii')
+ re_esc = re.compile(pattern_bytes)
return re_esc.sub(_unescape_code, value.encode('ascii')).decode('utf-8')
