Create a representation of a Unicode string that can be used in both
    Python 2 and Python 3k, allowing for use of the u() function

def rpr(s):
    """Create a representation of a Unicode string that can be used in both
    Python 2 and Python 3k, allowing for use of the u() function"""
    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 == "'":  # escape single quote
                results.append('\\')
                results.append(cc)
            elif cc == "\\":  # escape backslash
                results.append('\\')
                results.append(cc)
            else:
                results.append(cc)
        else:
            seen_unicode = True
            if ccn <= 0xFFFF:
                results.append('\\u')
                results.append("%04x" % ccn)
            else:  # pragma no cover
                results.append('\\U')
                results.append("%08x" % ccn)
    result = "'" + "".join(results) + "'"
    if seen_unicode:
        return "u(" + result + ")"
    else:
        return result