def APEValue(value, kind):
if kind in (TEXT, EXTERNAL):<EOL><INDENT>if not isinstance(value, text_type):<EOL><INDENT>if PY3:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT><DEDENT>else:<EOL><INDENT>value = value.encode("<STR_LIT:utf-8>")<EOL><DEDENT><DEDENT>if kind == TEXT:<EOL><INDENT>return APETextValue(value, kind)<EOL><DEDENT>elif kind == BINARY:<EOL><INDENT>return APEBinaryValue(value, kind)<EOL><DEDENT>elif kind == EXTERNAL:<EOL><INDENT>return APEExtValue(value, kind)<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>
APEv2 tag value factory.

    Use this if you need to specify the value's type manually.  Binary
    and text data are automatically detected by APEv2.__setitem__.