From e55693c966394f6f17a8035589512f5bd85e0883 Mon Sep 17 00:00:00 2001 From: Scott Black Date: Thu, 29 Apr 2021 16:46:33 -0600 Subject: [PATCH] update for windows path compatibility --- hsclient/hydroshare.py | 19 +++++++++---------- setup.py | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/hsclient/hydroshare.py b/hsclient/hydroshare.py index 557d39f..d00c55c 100644 --- a/hsclient/hydroshare.py +++ b/hsclient/hydroshare.py @@ -7,8 +7,7 @@ from datetime import datetime from posixpath import basename, dirname, join as urljoin, splitext from typing import Dict, List, Union -from urllib.parse import urlparse -from urllib.request import pathname2url, url2pathname +from urllib.parse import urlparse, quote, unquote from zipfile import ZipFile import pandas @@ -111,12 +110,12 @@ def _files(self): if not file.path == self.metadata_path: if not str(file.path).endswith('/'): # checking for folders, shouldn't have to do this file_checksum_path = file.path.split(self._resource_path, 1)[1].strip("/") - file_path = url2pathname( + file_path = unquote( file_checksum_path.split( "data/contents/", )[1] ) - f = File(file_path, url2pathname(file.path), self._checksums[file_checksum_path]) + f = File(file_path, unquote(file.path), self._checksums[file_checksum_path]) self._parsed_files.append(f) return self._parsed_files @@ -127,7 +126,7 @@ def _aggregations(self): for file in self._map.describes.files: if is_aggregation(str(file)): self._parsed_aggregations.append( - Aggregation(url2pathname(file.path), self._hs_session, self._checksums) + Aggregation(unquote(file.path), self._hs_session, self._checksums) ) return self._parsed_aggregations @@ -156,7 +155,7 @@ def _retrieve_and_parse(self, path): def _retrieve_checksums(self, path): file_str = self._hs_session.retrieve_string(path) data = { - pathname2url(path): checksum + quote(path): checksum for checksum, path in (line.split(" ") for line in file_str.split("\n") if line) } return data @@ -174,7 +173,7 @@ def _download(self, save_path: str = "", unzip_to: str = None) -> str: with zipfile.ZipFile(downloaded_zip, 'r') as zip_ref: zip_ref.extractall(unzip_to) - os.remove(downloaded_zip) + os.remove(downloaded_zip) return unzip_to return downloaded_zip @@ -576,8 +575,8 @@ def file_upload(self, *files: str, destination_path: str = "") -> None: self._upload(files[0], destination_path=destination_path) else: with tempfile.TemporaryDirectory() as tmpdir: - zipped_file = urljoin(tmpdir, 'files.zip') - with ZipFile(urljoin(tmpdir, zipped_file), 'w') as zipped: + zipped_file = os.path.join(tmpdir, 'files.zip') + with ZipFile(zipped_file, 'w') as zipped: for file in files: zipped.write(file, basename(file)) self._upload(zipped_file, destination_path=destination_path) @@ -679,7 +678,7 @@ def retrieve_file(self, path, save_path=""): cd = file.headers['content-disposition'] filename = cd.split("filename=")[1].strip('"') - downloaded_file = urljoin(save_path, filename) + downloaded_file = os.path.join(save_path, filename) with open(downloaded_file, 'wb') as f: f.write(file.content) return downloaded_file diff --git a/setup.py b/setup.py index ba4684c..d914c4e 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name='hsclient', - version='0.1.5', + version='0.1.6', packages=find_packages(include=['hsclient', 'hsclient.*'], exclude=("tests",)), install_requires=[