app/grandchallenge/components/backends/utils.py
def safe_extract(*, src: File, dest: Path):
    """
    Safely extracts a zip file into a directory

    Any common prefixes and system files are removed.
    """

    if not dest.exists():
        raise RuntimeError("The destination must exist")

    with src.open("rb") as f:
        with zipfile.ZipFile(f) as zf:
            members = _filter_members(zf.infolist())

            for member in members:
                file_dest = Path(safe_join(dest, member["dest"]))
                # We know that the dest is within the prefix as
                # safe_join is used, and the destination is already
                # created, so ok to create the parents here
                file_dest.parent.mkdir(exist_ok=True, parents=True)

                with zf.open(member["src"], "r") as fs, open(
                    file_dest, "wb"
                ) as fd:
                    while True:
                        chunk = fs.read(1024)
                        if not chunk:
                            break

                        fd.write(chunk)

    Safely extracts a zip file into a directory

    Any common prefixes and system files are removed.
    
Safely extracts a zip file into a directory
Any common prefixes and system files are removed.
Safely extracts a zip file into a directory Any common prefixes and system files are removed .
def safe_extract(*, src: File, dest: Path):
    if not dest.exists():
        raise RuntimeError("The destination must exist")
    with src.open("rb") as f:
        with zipfile.ZipFile(f) as zf:
            members = _filter_members(zf.infolist())
            for member in members:
                file_dest = Path(safe_join(dest, member["dest"]))
                file_dest.parent.mkdir(exist_ok=True, parents=True)
                with zf.open(member["src"], "r") as fs, open(
                    file_dest, "wb"
                ) as fd:
                    while True:
                        chunk = fs.read(1024)
                        if not chunk:
                            break
                        fd.write(chunk)
def safe_extract ( * , src : File , dest : Path ) : if not dest . exists ( ) : raise RuntimeError ( "The destination must exist" ) with src . open ( "rb" ) as f : with zipfile . ZipFile ( f ) as zf : members = _filter_members ( zf . infolist ( ) ) for member in members : file_dest = Path ( safe_join ( dest , member [ "dest" ] ) ) file_dest . parent . mkdir ( exist_ok = True , parents = True ) with zf . open ( member [ "src" ] , "r" ) as fs , open ( file_dest , "wb" ) as fd : while True : chunk = fs . read ( 1024 ) if not chunk : break fd . write ( chunk )
Safely extracts a zip file into a directory
Any common prefixes and system files are removed.
Safely extracts a zip file into a directory Any common prefixes and system files are removed .
"""
    Safely extracts a zip file into a directory

    Any common prefixes and system files are removed.
    """ # We know that the dest is within the prefix as # safe_join is used, and the destination is already # created, so ok to create the parents here
src
File
dest
Path