def _to_bytes(value, encoding='<STR_LIT:ascii>'):
result = (value.encode(encoding)<EOL>if isinstance(value, six.text_type) else value)<EOL>if isinstance(result, six.binary_type):<EOL><INDENT>return result<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>'.format(value))<EOL><DEDENT>
Converts a string value to bytes, if necessary.

    Unfortunately, ``six.b`` is insufficient for this task since in
    Python2 it does not modify ``unicode`` objects.

    Args:
        value: The string/bytes value to be converted.
        encoding: The encoding to use to convert unicode to bytes. Defaults
                  to "ascii", which will not allow any characters from ordinals
                  larger than 127. Other useful values are "latin-1", which
                  which will only allows byte ordinals (up to 255) and "utf-8",
                  which will encode any unicode that needs to be.

    Returns:
        The original value converted to bytes (if unicode) or as passed in
        if it started out as bytes.

    Raises:
        ValueError if the value could not be converted to bytes.