'\'Magic\' value setter.
This function tries to guess at what kind of value you want to
store. If you pass in a valid UTF-8 or Unicode string, it
treats it as a text value. If you pass in a list, it treats it
as a list of string/Unicode values.  If you pass in a string
that is not valid UTF-8, it assumes it is a binary value.
Python 3: all bytes will be assumed to be a byte value, even
if they are valid utf-8.
If you need to force a specific type of value (e.g. binary
data that also happens to be valid UTF-8, or an external
reference), use the APEValue factory and set the value to the
result of that::
from mutagen.apev2 import APEValue, EXTERNAL
tag[\'Website\'] = APEValue(\'http://example.org\', EXTERNAL)'

def __setitem__(self, key, value):

    if (not is_valid_apev2_key(key)):
        raise KeyError(('%r    is    not    a    valid    APEv2    key' % key))
    if PY2:
        key = key.encode('ascii')
    if (not isinstance(value, _APEValue)):
        if isinstance(value, text_type):
            value = APEValue(value, TEXT)
        elif isinstance(value, list):
            items = []
            for v in value:
                if (not isinstance(v, text_type)):
                    if PY3:
                        raise TypeError('item    in    list    not    str')
                    v = v.decode('utf-8')
                items.append(v)
            value = APEValue(u'\x00'.join(items), TEXT)
        elif PY3:
            value = APEValue(value, BINARY)
        else:
            try:
                value.decode('utf-8')
            except UnicodeError:
                value = APEValue(value, BINARY)
            else:
                value = APEValue(value, TEXT)
    super(APEv2, self).__setitem__(key, value)
