def file_handle(fnh, mode="rU"):
    """
    Takes either a file path or an open file handle, checks validity and returns an open
    file handle or raises an appropriate Exception.

    :type fnh: str
    :param fnh: It is the full path to a file, or open file handle

    :type mode: str
    :param mode: The way in which this file will be used, for example to read or write or
                 both. By default, file will be opened in rU mode.

    :return: Returns an opened file for appropriate usage.
    """
    handle = None
    if isinstance(fnh, file):
        if fnh.closed:
            raise ValueError("Input file is closed.")
        handle = fnh
    elif isinstance(fnh, str):
        handle = open(fnh, mode)

    return handle