<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def zip_file(fn, mode="r"):
 """ returns either a zipfile.ZipFile instance or an ExplodedZipFile instance, depending on whether fn is the name of a valid zip file, or a directory. """


    if isdir(fn):
        return ExplodedZipFile(fn)
    elif is_zipfile(fn):
        return ZipFile(fn, mode)
    else:
        raise Exception("cannot treat as an archive: %r" % fn)