#NEWLINE# def py_encode_basestring_ascii( s ) : #NEWLINE# #INDENT# if ( isinstance ( s , str ) and ( HAS_UTF8 . search ( s ) is not None ) ) : #NEWLINE# #INDENT# s = s . decode ( 'utf-8' ) #NEWLINE# #UNINDENT# def replace( match ) : #NEWLINE# #INDENT# s = match . group ( 0 ) #NEWLINE# try : #NEWLINE# #INDENT# return ESCAPE_DCT [ s ] #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# n = ord ( s ) #NEWLINE# if ( n < 65536 ) : #NEWLINE# #INDENT# return '\\u{0:04x}' . format ( n ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# n -= 65536 #NEWLINE# s1 = ( 55296 | ( ( n >> 10 ) & 1023 ) ) #NEWLINE# s2 = ( 56320 | ( n & 1023 ) ) #NEWLINE# return '\\u{0:04x}\\u{1:04x}' . format ( s1 , s2 ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return ( ( '"' + str ( ESCAPE_ASCII . sub ( replace , s ) ) ) + '"' )