@@ -1309,35 +1309,17 @@ def _ensure_directory(path):
13091309 if not os .path .isdir (dirname ):
13101310 os .makedirs (dirname )
13111311
1312- def _unpack_zipfile (filename , extract_dir ):
1312+ def _unpack_zipfile (filename , extract_dir , ** kwargs ):
13131313 """Unpack zip `filename` to `extract_dir`
13141314 """
13151315 import zipfile # late import for breaking circular dependency
13161316
13171317 if not zipfile .is_zipfile (filename ):
13181318 raise ReadError ("%s is not a zip file" % filename )
13191319
1320- zip = zipfile .ZipFile (filename )
1321- try :
1322- for info in zip .infolist ():
1323- name = info .filename
1324-
1325- # don't extract absolute paths or ones with .. in them
1326- if name .startswith ('/' ) or '..' in name :
1327- continue
1320+ with zipfile .ZipFile (filename ) as zf :
1321+ zf .extractall (extract_dir )
13281322
1329- targetpath = os .path .join (extract_dir , * name .split ('/' ))
1330- if not targetpath :
1331- continue
1332-
1333- _ensure_directory (targetpath )
1334- if not name .endswith ('/' ):
1335- # file
1336- with zip .open (name , 'r' ) as source , \
1337- open (targetpath , 'wb' ) as target :
1338- copyfileobj (source , target )
1339- finally :
1340- zip .close ()
13411323
13421324def _unpack_tarfile (filename , extract_dir , * , filter = None ):
13431325 """Unpack tar/tar.gz/tar.bz2/tar.xz/tar.zst `filename` to `extract_dir`
@@ -1668,3 +1650,4 @@ def __getattr__(name):
16681650 )
16691651 return RuntimeError
16701652 raise AttributeError (f"module { __name__ !r} has no attribute { name !r} " )
1653+
0 commit comments