Skip to content

Commit d95af13

Browse files
author
Benjamin Moody
committed
Use openurl in place of _get_url.
1 parent 9c5fdba commit d95af13

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

wfdb/io/download.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pdb
88
import json
99

10-
from wfdb.io import record
10+
from wfdb.io import record, _url
1111

1212

1313
# The PhysioNet index url
@@ -133,7 +133,8 @@ def _stream_header(file_name, pn_dir):
133133
url = posixpath.join(config.db_index_url, pn_dir, file_name)
134134

135135
# Get the content of the remote file
136-
content = _get_url(url)
136+
with _url.openurl(url, 'rb') as f:
137+
content = f.read()
137138

138139
# Get each line as a string
139140
filelines = content.decode('iso-8859-1').splitlines()
@@ -225,7 +226,8 @@ def _stream_annotation(file_name, pn_dir):
225226
url = posixpath.join(config.db_index_url, pn_dir, file_name)
226227

227228
# Get the content
228-
content = _get_url(url)
229+
with _url.openurl(url, 'rb') as f:
230+
content = f.read()
229231

230232
# Convert to numpy array
231233
ann_data = np.fromstring(content, dtype=np.dtype('<u1'))
@@ -258,7 +260,8 @@ def get_dbs():
258260
]
259261
260262
"""
261-
content = _get_url('https://physionet.org/rest/database-list/')
263+
with _url.openurl('https://physionet.org/rest/database-list/', 'rb') as f:
264+
content = f.read()
262265
dbs = json.loads(content)
263266
dbs = [[d['slug'], d['title']] for d in dbs]
264267
dbs.sort()
@@ -301,7 +304,8 @@ def get_record_list(db_dir, records='all'):
301304
# Check for a RECORDS file
302305
if records == 'all':
303306
try:
304-
content = _get_url(posixpath.join(db_url, 'RECORDS'))
307+
with _url.openurl(posixpath.join(db_url, 'RECORDS'), 'rb') as f:
308+
content = f.read()
305309
except FileNotFoundError:
306310
raise ValueError('The database %s has no WFDB files to download' % db_url)
307311

@@ -343,7 +347,8 @@ def get_annotators(db_dir, annotators):
343347
if annotators is not None:
344348
# Check for an ANNOTATORS file
345349
try:
346-
content = _get_url(posixpath.join(db_url, 'ANNOTATORS'))
350+
with _url.openurl(posixpath.join(db_url, 'ANNOTATORS'), 'rb') as f:
351+
content = f.read()
347352
except FileNotFoundError:
348353
if annotators == 'all':
349354
return
@@ -484,7 +489,8 @@ def dl_full_file(url, save_file_name):
484489
N/A
485490
486491
"""
487-
content = _get_url(url)
492+
with _url.openurl(url, 'rb') as readfile:
493+
content = readfile.read()
488494
with open(save_file_name, 'wb') as writefile:
489495
writefile.write(content)
490496

0 commit comments

Comments
 (0)