def _decode(reader, filename, **kwargs):
    """Successively try different methods to open ``filename`` with
    ``reader``."""

    try:  # First check if the reader is an open ``read`` method.
        return reader(**kwargs)
    except TypeError:
        pass

    try:  # Next possibility is that the reader just needs a string reference
        return reader(filename, **kwargs)
    except TypeError:
        pass

    try:  # Finally, check if we can open the string reference to read.
        with open(filename, 'r') as fileobj:
            return reader(fileobj, **kwargs)
    except UnicodeDecodeError:
        with open(filename, 'rb') as fileobj:
            return reader(fileobj, **kwargs)