Skip to content

Commit f814a6c

Browse files
committed
Exclude query parameters from file names is casda.download_file
1 parent f99e1ba commit f814a6c

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

astroquery/casda/core.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
# 1. standard library imports
44
from io import BytesIO
5-
from urllib.parse import unquote
5+
import os
6+
from urllib.parse import unquote, urlparse
67
import time
78
from xml.etree import ElementTree
89
from datetime import datetime, timezone
@@ -239,9 +240,15 @@ def download_files(self, urls, savedir=''):
239240
# for each url in list, download file and checksum
240241
filenames = []
241242
for url in urls:
242-
fn = self._request('GET', url, save=True, savedir=savedir, timeout=self.TIMEOUT, cache=False)
243-
if fn:
244-
filenames.append(fn)
243+
parseResult = urlparse(url)
244+
local_filename = os.path.basename(parseResult.path)
245+
if os.name == 'nt':
246+
# Windows doesn't allow special characters in filenames like
247+
# ":" so replace them with an underscore
248+
local_filename = local_filename.replace(':', '_')
249+
local_filepath = os.path.join(savedir or self.cache_location or '.', local_filename)
250+
self._download_file(url, local_filepath, timeout=self.TIMEOUT, cache=False)
251+
filenames.append(local_filepath)
245252

246253
return filenames
247254

astroquery/casda/tests/test_casda.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,17 @@ def test_stage_data(patch_get):
280280
urls = casda.stage_data(table, verbose=True)
281281
assert urls == ['http://casda.csiro.au/download/web/111-000-111-000/askap_img.fits.checksum',
282282
'http://casda.csiro.au/download/web/111-000-111-000/askap_img.fits']
283+
284+
285+
def test_download_file(patch_get):
286+
urls = ['https://ingest.pawsey.org/bucket_name/path/askap_img.fits?security=stuff',
287+
'http://casda.csiro.au/download/web/111-000-111-000/askap_img.fits.checksum']
288+
casda = Casda('user', 'password')
289+
290+
# skip the actual downloading of the file
291+
download_mock = MagicMock()
292+
casda._download_file = download_mock
293+
294+
filenames = casda.download_files(urls)
295+
assert filenames[0].endswith('askap_img.fits')
296+
assert filenames[1].endswith('askap_img.fits.checksum')

0 commit comments

Comments
 (0)