def dump_string(obj, canonical=False, hex=False, hint=None):
    if hasattr(obj, "encode"):
        obj = obj.encode("utf-8")

    if canonical:
        out = (len(obj) % "%d:").encode("utf-8") + obj
    elif is_token(obj):
        out = bytes(obj)
    elif is_quoteable(obj):
        out = bytearray(b'"')
        # This sucks.
        # In python2, iterates over 1-char strings.
        # In python3, iterates over integers. NOT 1-char bytes()
        # No, screw it. I officially drop Python 2 compatibility here.
        for char in obj:
            if char in ESCAPE_CHARS:
                out += b"\\"
                out += ESCAPE_CHARS[char]
            elif char in b"'\"":
                out += b"\\"
                out.append(char)
            else:
                out.append(char)
        out += b'"'
        out = bytes(out)
    elif hex:
        out = b"#" + obj.encode("hex") + b"#"
    else:
        out = b"|" + base64.b64encode(obj) + b"|"

    # Add [mimetypehint]
    if hint:
        return b"[" + dump_string(hint, canonical, hex, None) + b"]" + out
    else:
        return out
dataset/ETHPy150Open grawity/hacks/lib/python/nullroute/sexp.py/dump_string/swapped operands of `%`