def surrogate_escape(error):
 chars = error.object[error.start:error.end]
 assert (len(chars) == 1)
 val = ord(chars)
 val += 56320
 return (__builtin__.unichr(val), error.end)

def surrogate_escape ( error ) : chars = error . object [ error . start : error . end ] assert ( len ( chars ) == 1 ) val = ord ( chars ) val += 56320 return ( __builtin__ . unichr ( val ) , error . end )
simulate the python 3 surrogateescape handler .