• Iustin Pop's avatar
    Fix the SafeEncoding behaviour · d392fa34
    Iustin Pop authored
    Currently we have bad behaviour in SafeEncode:
      - binary strings are actually not handled correctly (ahem)
      - the encoding is not stable, due to use of string_escape
    For this reason, we replace the use of string_escape with part of the
    code of string escape (PyString_Repr in Objects/stringobject.c); we
    don't escape backslashes or single quotes, since that is that makes it
    nonstable. Furthermore, we only use the encode('ascii', ...) for unicode
    The patch also adds unittests for the function that test basic
    Signed-off-by: default avatarIustin Pop <iustin@google.com>
    Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>