def encode_count_name(count_name):
    """Encode a name to printable ASCII characters so it can be safely
    used as an attribute name for the datastore."""
    encoded = []
    append = encoded.append
    for ch in map(ord, count_name):
        if ch == 92:
            append('\\\\')
        elif 33 <= ch <= 126:
            append(chr(ch))
        else:
            append('\\u%04x' % ch)
    return ''.join(encoded)