Skip to content

Commit 481b67c

Browse files
committed
Fixing py2 compatibility of #6987 backport as suggested in the PR
1 parent 5b8190f commit 481b67c

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

‎astropy/utils/data.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,8 @@ def download_file(remote_url, cache=False, show_progress=True, timeout=None):
10551055
# Check if URL is Astropy data server, which has alias, and cache it.
10561056
if (url_key.startswith(conf.dataurl) and
10571057
conf.dataurl not in _dataurls_to_alias):
1058-
with urllib.request.urlopen(conf.dataurl, timeout=timeout) as remote:
1058+
with contextlib.closing(urllib.request.urlopen(
1059+
conf.dataurl, timeout=timeout)) as remote:
10591060
_dataurls_to_alias[conf.dataurl] = [conf.dataurl, remote.geturl()]
10601061

10611062
try:

‎astropy/utils/tests/test_data.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ def test_download_nocache():
6060

6161
@remote_data('astropy')
6262
def test_download_parallel():
63-
import shelve
6463
from ..data import (download_file, download_files_in_parallel,
65-
_get_download_cache_locs, get_cached_urls)
64+
_get_download_cache_locs, get_cached_urls,
65+
_open_shelve)
6666

6767
main_url = 'http://data.astropy.org/intersphinx/README'
6868
mirror_url = 'http://www.astropy.org/astropy-data/intersphinx/README'
@@ -73,7 +73,7 @@ def test_download_parallel():
7373
# Now test that download_file looks in mirror's cache before download.
7474
# https://github.com/astropy/astropy/issues/6982
7575
dldir, urlmapfn = _get_download_cache_locs()
76-
with shelve.open(urlmapfn) as url2hash:
76+
with _open_shelve(urlmapfn, True) as url2hash:
7777
del url2hash[main_url]
7878
# NOTE: Cannot disable internet in a remote_data test, so comparing hash
7979
# should be good enough?

0 commit comments

Comments
 (0)