def file_handle(fnh, mode="<STR_LIT>"):
handle = None<EOL>if isinstance(fnh, file):<EOL><INDENT>if fnh.closed:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>handle = fnh<EOL><DEDENT>elif isinstance(fnh, str):<EOL><INDENT>handle = open(fnh, mode)<EOL><DEDENT>return handle<EOL>
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.