Check that `string` is printable ASCII and at most 256 chars.

    Raise a `ValueError` if this check fails. Note that `string` itself doesn't
    have to be ASCII-encoded.

    :type string: str
    :param string: The string to check.

def check_ascii_256(string):
    """Check that `string` is printable ASCII and at most 256 chars.

    Raise a `ValueError` if this check fails. Note that `string` itself doesn't
    have to be ASCII-encoded.

    :type string: str
    :param string: The string to check.
    """
    if string is None:
        return
    if len(string) > 256:
        raise ValueError("Value is longer than 256 characters")
    bad_char = _NON_PRINTABLE_ASCII.search(string)
    if bad_char:
        raise ValueError(u'Character "{}" at position {} is not printable '
                         'ASCII'
                         .format(
                             string[bad_char.start():bad_char.end()],
                             bad_char.start()))