Skip to content

Commit 7b6b15f

Browse files
author
Benjamin Moody
committed
edf2mit, wav2mit: use openurl in place of requests.get.
Note that this will handle errors (e.g. a file that does not exist) and raise an exception, rather than writing the error document to the output file.
1 parent 6ff2f00 commit 7b6b15f

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

wfdb/io/record.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from wfdb.io import _header
1616
from wfdb.io import _signal
17+
from wfdb.io import _url
1718
from wfdb.io import download
1819
from wfdb.io import annotation
1920

@@ -1466,8 +1467,8 @@ def edf2mit(record_name, pn_dir=None, delete_file=True, record_only=True,
14661467
file_url = posixpath.join(download.PN_INDEX_URL, pn_dir, record_name)
14671468
# Currently must download file for MNE to read it though can give the
14681469
# user the option to delete it immediately afterwards
1469-
r = requests.get(file_url, allow_redirects=False)
1470-
open(record_name, 'wb').write(r.content)
1470+
with _url.openurl(file_url, 'rb') as f:
1471+
open(record_name, 'wb').write(f.read())
14711472

14721473
# Open the desired file
14731474
edf_file = open(record_name, mode='rb')
@@ -2380,8 +2381,8 @@ def wav2mit(record_name, pn_dir=None, delete_file=True, record_only=False):
23802381
file_url = posixpath.join(download.PN_INDEX_URL, pn_dir, record_name)
23812382
# Currently must download file to read it though can give the
23822383
# user the option to delete it immediately afterwards
2383-
r = requests.get(file_url, allow_redirects=False)
2384-
open(record_name, 'wb').write(r.content)
2384+
with _url.openurl(file_url, 'rb') as f:
2385+
open(record_name, 'wb').write(f.read())
23852386

23862387
wave_file = open(record_name, mode='rb')
23872388
record_name_out = record_name.split(os.sep)[-1].replace('-','_').replace('.wav','')

0 commit comments

Comments
 (0)