import codecs


def try_encoding(encoding, data):
    """ Return decoded data, or None if decoding failed or the codec isn't
    usable on this machine. """
    try:
        return codecs.decode(data, encoding, "strict")
    except (UnicodeDecodeError, LookupError):
        return None