'Saves *enc* as the default encoding, after verifying that
it is valid.  You can also include :error to specify error
handling - eg \'cp437:replace\'
Raises an exception on invalid encoding or error'

def set_encoding(self, enc):

    enc = enc.split(':', 1)
    if (len(enc) > 1):
        (enc, errors) = enc
    else:
        enc = enc[0]
        errors = None
    try:
        codecs.lookup(enc)
    except LookupError:
        raise self.Error(("No    known    encoding    '%s'" % (enc,)))
    try:
        if (errors is not None):
            codecs.lookup_error(errors)
    except LookupError:
        raise self.Error(("No    known    codec    error    handler    '%s'" % (errors,)))
    self.encoding = (enc, errors)
