(path)
return extracted_path
Replace nonexistent paths that look like they refer to a member of a zip
    archive with the location of an extracted copy of the target, or else
    just return the provided path unchanged.
Replace nonexistent paths that look like they refer to a member of a zip
    archive with the location of an extracted copy of the target, or else
    just return the provided path unchanged.
Replace nonexistent paths that look like they refer to a member of a zip archive with the location of an extracted copy of the target or else just return the provided path unchanged .
def extract_zipped_paths(path):
    """Replace nonexistent paths that look like they refer to a member of a zip
    archive with the location of an extracted copy of the target, or else
    just return the provided path unchanged.
    """
    if os.path.exists(path):
        # this is already a valid path, no need to do anything further
        return path

    # find the first valid part of the provided path and treat that as a zip archive
    # assume the rest of the path is the name of a member in the archive
    archive, member = os.path.split(path)
    while archive and not os.path.exists(archive):
        archive, prefix = os.path.split(archive)
        member = '/'.join([prefix, member])

    if not zipfile.is_zipfile(archive):
        return path

    zip_file = zipfile.ZipFile(archive)
    if member not in zip_file.namelist():
        return path

    # we have a valid zip archive and a valid member of that archive
    tmp = tempfile.gettempdir()
    extracted_path = os.path.join(tmp, *member.split('/'))
    if not os.path.exists(extracted_path):
        extracted_path = zip_file.extract(member, path=tmp)

    return extracted_path
def extract_zipped_paths ( path ) : if os . path . exists ( path ) : # this is already a valid path, no need to do anything further return path # find the first valid part of the provided path and treat that as a zip archive # assume the rest of the path is the name of a member in the archive archive , member = os . path . split ( path ) while archive and not os . path . exists ( archive ) : archive , prefix = os . path . split ( archive ) member = '/' . join ( [ prefix , member ] ) if not zipfile . is_zipfile ( archive ) : return path zip_file = zipfile . ZipFile ( archive ) if member not in zip_file . namelist ( ) : return path # we have a valid zip archive and a valid member of that archive tmp = tempfile . gettempdir ( ) extracted_path = os . path . join ( tmp , * member . split ( '/' ) ) if not os . path . exists ( extracted_path ) : extracted_path = zip_file . extract ( member , path = tmp ) return extracted_path