def rpr(s):
 if (s is None):
  return 'None'
 seen_unicode = False
 results = []
 for cc in s:
  ccn = ord(cc)
  if ((ccn >= 32) and (ccn < 127)):
   if (cc == "'"):
    results.append('\\')
    results.append(cc)
   elif (cc == '\\'):
    results.append('\\')
    results.append(cc)
   else:
    results.append(cc)
  else:
   seen_unicode = True
   if (ccn <= 65535):
    results.append('\\u')
    results.append(('%04x' % ccn))
   else:
    results.append('\\U')
    results.append(('%08x' % ccn))
 result = (("'" + ''.join(results)) + "'")
 if seen_unicode:
  return (('u(' + result) + ')')
 else:
  return result

def rpr ( s ) : if ( s is None ) : return 'None' seen_unicode = False results = [ ] for cc in s : ccn = ord ( cc ) if ( ( ccn >= 32 ) and ( ccn < 127 ) ) : if ( cc == "'" ) : results . append ( '\\' ) results . append ( cc ) elif ( cc == '\\' ) : results . append ( '\\' ) results . append ( cc ) else : results . append ( cc ) else : seen_unicode = True if ( ccn <= 65535 ) : results . append ( '\\u' ) results . append ( ( '%04x' % ccn ) ) else : results . append ( '\\U' ) results . append ( ( '%08x' % ccn ) ) result = ( ( "'" + '' . join ( results ) ) + "'" ) if seen_unicode : return ( ( 'u(' + result ) + ')' ) else : return result
create a representation of a unicode string that can be used in both python 2 and python 3k .