(text)
return (result.encode('ascii')  # Make it bytes to allow decode.
          .decode('unicode_escape')
          # Make it bytes again to return the proper type.
          .encode('raw_unicode_escape'))
Unescape a text string with C-style escape sequences to UTF-8 bytes.
Unescape a text string with C-style escape sequences to UTF-8 bytes.
Unescape a text string with C - style escape sequences to UTF - 8 bytes .
def CUnescape(text):
  """Unescape a text string with C-style escape sequences to UTF-8 bytes."""

  def ReplaceHex(m):
    # Only replace the match if the number of leading back slashes is odd. i.e.
    # the slash itself is not escaped.
    if len(m.group(1)) & 1:
      return m.group(1) + 'x0' + m.group(2)
    return m.group(0)

  # This is required because the 'string_escape' encoding doesn't
  # allow single-digit hex escapes (like '\xf').
  result = _CUNESCAPE_HEX.sub(ReplaceHex, text)

  if str is bytes:  # PY2
    return result.decode('string_escape')
  result = ''.join(_cescape_highbit_to_str[ord(c)] for c in result)
  return (result.encode('ascii')  # Make it bytes to allow decode.
          .decode('unicode_escape')
          # Make it bytes again to return the proper type.
          .encode('raw_unicode_escape'))
def CUnescape ( text ) : def ReplaceHex ( m ) : # Only replace the match if the number of leading back slashes is odd. i.e. # the slash itself is not escaped. if len ( m . group ( 1 ) ) & 1 : return m . group ( 1 ) + 'x0' + m . group ( 2 ) return m . group ( 0 ) # This is required because the 'string_escape' encoding doesn't # allow single-digit hex escapes (like '\xf'). result = _CUNESCAPE_HEX . sub ( ReplaceHex , text ) if str is bytes : # PY2 return result . decode ( 'string_escape' ) result = '' . join ( _cescape_highbit_to_str [ ord ( c ) ] for c in result ) return ( result . encode ( 'ascii' ) # Make it bytes to allow decode. . decode ( 'unicode_escape' ) # Make it bytes again to return the proper type. . encode ( 'raw_unicode_escape' ) )