From b846b3f26090ab0178fef6c0d607652601b47828 Mon Sep 17 00:00:00 2001 From: Greg Lucas Date: Wed, 13 Nov 2024 06:49:45 -0700 Subject: [PATCH] MNT: Extract all NE resources from the zip file --- lib/cartopy/io/shapereader.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/lib/cartopy/io/shapereader.py b/lib/cartopy/io/shapereader.py index 344465b26..7a00a41db 100644 --- a/lib/cartopy/io/shapereader.py +++ b/lib/cartopy/io/shapereader.py @@ -31,6 +31,7 @@ import itertools from pathlib import Path from urllib.error import HTTPError +from zipfile import ZipFile import shapefile import shapely.geometry as sgeom @@ -349,25 +350,15 @@ def acquire_resource(self, target_path, format_dict): :meth:`zip_file_contents` to the target path. """ - from zipfile import ZipFile - target_dir = Path(target_path).parent target_dir.mkdir(parents=True, exist_ok=True) url = self.url(format_dict) shapefile_online = self._urlopen(url) - - zfh = ZipFile(io.BytesIO(shapefile_online.read()), 'r') - - for member_path in self.zip_file_contents(format_dict): - member = zfh.getinfo(member_path.replace('\\', '/')) - with open(target_path.with_suffix( - Path(member_path).suffix), 'wb') as fh: - fh.write(zfh.open(member).read()) - + with ZipFile(io.BytesIO(shapefile_online.read()), 'r') as zfh: + zfh.extractall(target_dir) shapefile_online.close() - zfh.close() return target_path @@ -456,8 +447,6 @@ def zip_file_contents(self, format_dict): yield str(p).format(extension=ext, **format_dict) def acquire_all_resources(self, format_dict): - from zipfile import ZipFile - # Download archive. url = self.url(format_dict) try: