def escape_unicode(string):
 returnValue = StringIO()
 for character in string:
  code = ord(character)
  if (code > 127):
   hexCode = hex(code)
   returnValue.write(((('%' + hexCode[2:4]) + '%') + hexCode[4:6]))
  else:
   returnValue.write(character)
 return returnValue.getvalue()

def escape_unicode ( string ) : returnValue = StringIO ( ) for character in string : code = ord ( character ) if ( code > 127 ) : hexCode = hex ( code ) returnValue . write ( ( ( ( '%' + hexCode [ 2 : 4 ] ) + '%' ) + hexCode [ 4 : 6 ] ) ) else : returnValue . write ( character ) return returnValue . getvalue ( )
converts a unicode string into us-ascii .