|
7 | 7 | import pdb
|
8 | 8 | import json
|
9 | 9 |
|
10 |
| -from wfdb.io import record |
| 10 | +from wfdb.io import record, _url |
11 | 11 |
|
12 | 12 |
|
13 | 13 | # The PhysioNet index url
|
@@ -133,7 +133,8 @@ def _stream_header(file_name, pn_dir):
|
133 | 133 | url = posixpath.join(config.db_index_url, pn_dir, file_name)
|
134 | 134 |
|
135 | 135 | # Get the content of the remote file
|
136 |
| - content = _get_url(url) |
| 136 | + with _url.openurl(url, 'rb') as f: |
| 137 | + content = f.read() |
137 | 138 |
|
138 | 139 | # Get each line as a string
|
139 | 140 | filelines = content.decode('iso-8859-1').splitlines()
|
@@ -225,7 +226,8 @@ def _stream_annotation(file_name, pn_dir):
|
225 | 226 | url = posixpath.join(config.db_index_url, pn_dir, file_name)
|
226 | 227 |
|
227 | 228 | # Get the content
|
228 |
| - content = _get_url(url) |
| 229 | + with _url.openurl(url, 'rb') as f: |
| 230 | + content = f.read() |
229 | 231 |
|
230 | 232 | # Convert to numpy array
|
231 | 233 | ann_data = np.fromstring(content, dtype=np.dtype('<u1'))
|
@@ -258,7 +260,8 @@ def get_dbs():
|
258 | 260 | ]
|
259 | 261 |
|
260 | 262 | """
|
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() |
262 | 265 | dbs = json.loads(content)
|
263 | 266 | dbs = [[d['slug'], d['title']] for d in dbs]
|
264 | 267 | dbs.sort()
|
@@ -301,7 +304,8 @@ def get_record_list(db_dir, records='all'):
|
301 | 304 | # Check for a RECORDS file
|
302 | 305 | if records == 'all':
|
303 | 306 | 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() |
305 | 309 | except FileNotFoundError:
|
306 | 310 | raise ValueError('The database %s has no WFDB files to download' % db_url)
|
307 | 311 |
|
@@ -343,7 +347,8 @@ def get_annotators(db_dir, annotators):
|
343 | 347 | if annotators is not None:
|
344 | 348 | # Check for an ANNOTATORS file
|
345 | 349 | 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() |
347 | 352 | except FileNotFoundError:
|
348 | 353 | if annotators == 'all':
|
349 | 354 | return
|
@@ -484,7 +489,8 @@ def dl_full_file(url, save_file_name):
|
484 | 489 | N/A
|
485 | 490 |
|
486 | 491 | """
|
487 |
| - content = _get_url(url) |
| 492 | + with _url.openurl(url, 'rb') as readfile: |
| 493 | + content = readfile.read() |
488 | 494 | with open(save_file_name, 'wb') as writefile:
|
489 | 495 | writefile.write(content)
|
490 | 496 |
|
|
0 commit comments