diff --git a/changelog/3838.bugfix.1.rst b/changelog/3838.bugfix.1.rst new file mode 100644 index 00000000000..a6446ad19d9 --- /dev/null +++ b/changelog/3838.bugfix.1.rst @@ -0,0 +1 @@ +Add support for passing paths of type `pathlib.Path` in `sunpy.net.jsoc.JSOCClient.fetch`. diff --git a/changelog/3838.bugfix.rst b/changelog/3838.bugfix.rst new file mode 100644 index 00000000000..d7dd877e621 --- /dev/null +++ b/changelog/3838.bugfix.rst @@ -0,0 +1 @@ +Add explicit support for dealing with download urls for files, under 'as-is' protocol in `sunpy.net.jsoc.JSOCClient.get_request`. diff --git a/sunpy/net/jsoc/jsoc.py b/sunpy/net/jsoc/jsoc.py index a7b7e38e251..558cf5aef28 100644 --- a/sunpy/net/jsoc/jsoc.py +++ b/sunpy/net/jsoc/jsoc.py @@ -4,6 +4,7 @@ import urllib import warnings from collections.abc import Sequence +from pathlib import Path import drms import numpy as np @@ -560,7 +561,10 @@ def get_request(self, requests, path=None, overwrite=False, progress=True, if path is None: default_dir = config.get("downloads", "download_dir") path = os.path.join(default_dir, '{file}') - elif isinstance(path, str) and '{file}' not in path: + elif isinstance(path, Path): + path = str(path) + + if isinstance(path, str) and '{file}' not in path: path = os.path.join(path, '{file}') paths = [] @@ -584,9 +588,13 @@ def get_request(self, requests, path=None, overwrite=False, progress=True, urls = [] for request in requests: if request.status == 0: - for index, data in request.data.iterrows(): - url_dir = request.request_url + '/' - urls.append(urllib.parse.urljoin(url_dir, data['filename'])) + if request.protocol == 'as-is': + urls.extend(list(request.urls.url)) + else: + for index, data in request.data.iterrows(): + url_dir = request.request_url + '/' + urls.append(urllib.parse.urljoin(url_dir, data['filename'])) + if urls: if progress: print_message = "{0} URLs found for download. Full request totalling {1}MB" diff --git a/sunpy/net/jsoc/tests/test_jsoc.py b/sunpy/net/jsoc/tests/test_jsoc.py index b9ced1002b7..ccda08c7b00 100644 --- a/sunpy/net/jsoc/tests/test_jsoc.py +++ b/sunpy/net/jsoc/tests/test_jsoc.py @@ -318,3 +318,17 @@ def test_results_filenames(): assert len(files) == len(responses) for hmiurl in files: assert os.path.isfile(hmiurl) + + +@pytest.mark.remote_data +def test_results_filenames_as_is(tmp_path): + responses = client.search( + a.Time('2014/1/1T1:00:36', '2014/1/1T01:01:38'), + a.jsoc.Series('hmi.M_45s'), a.jsoc.Notify('jsoc@cadair.com'), + a.jsoc.Protocol('as-is')) + assert len(responses) == 2 + files = client.fetch(responses, path=tmp_path) + assert isinstance(files, Results) + assert len(files) == len(responses) + for hmiurl in files: + assert os.path.isfile(hmiurl)