Skip to content

Commit 7569042

Browse files
committed
add check for cloud path in pn_dir
1 parent e3a83b6 commit 7569042

File tree

5 files changed

+47
-14
lines changed

5 files changed

+47
-14
lines changed

wfdb/io/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
wfdbdesc,
1212
wfdbtime,
1313
SIGNAL_CLASSES,
14+
CLOUD_PROTOCOLS,
1415
)
1516
from wfdb.io._signal import est_res, wr_dat_file
1617
from wfdb.io.annotation import (

wfdb/io/_coreio.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from wfdb.io import _url
66
from wfdb.io.download import config
77

8-
98
def _open_file(
109
pn_dir,
1110
file_name,
@@ -59,6 +58,12 @@ def _open_file(
5958
newline=newline,
6059
)
6160
else:
61+
# check to make sure a cloud path isn't being passed under pn_dir
62+
if any(pn_dir.startswith(proto) for proto in CLOUD_PROTOCOLS):
63+
raise ValueError(
64+
"Cloud paths should be passed under record_name, not under pn_dir"
65+
)
66+
6267
url = posixpath.join(config.db_index_url, pn_dir, file_name)
6368
return _url.openurl(
6469
url,

wfdb/io/_signal.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from wfdb.io import download, _coreio, util
1010

11-
1211
MAX_I32 = 2147483647
1312
MIN_I32 = -2147483648
1413

@@ -1698,6 +1697,12 @@ def _rd_dat_file(file_name, dir_name, pn_dir, fmt, start_byte, n_samp):
16981697

16991698
# Stream dat file from PhysioNet
17001699
else:
1700+
# check to make sure a cloud path isn't being passed under pn_dir
1701+
if any(pn_dir.startswith(proto) for proto in CLOUD_PROTOCOLS):
1702+
raise ValueError(
1703+
"Cloud paths should be passed under record_name, not under pn_dir"
1704+
)
1705+
17011706
dtype_in = np.dtype(DATA_LOAD_TYPES[fmt])
17021707
sig_data = download._stream_dat(
17031708
file_name, pn_dir, byte_count, start_byte, dtype_in
@@ -2613,6 +2618,12 @@ def _infer_sig_len(
26132618

26142619
# If the PhysioNet database path is provided, construct the download path using the database version
26152620
elif pn_dir is not None:
2621+
# check to make sure a cloud path isn't being passed under pn_dir
2622+
if any(pn_dir.startswith(proto) for proto in CLOUD_PROTOCOLS):
2623+
raise ValueError(
2624+
"Cloud paths should be passed under record_name, not under pn_dir"
2625+
)
2626+
26162627
file_size = download._remote_file_size(
26172628
file_name=file_name, pn_dir=pn_dir
26182629
)

wfdb/io/annotation.py

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
from wfdb.io import _header
1212
from wfdb.io import record
1313
from wfdb.io import util
14-
from wfdb.io.record import CLOUD_PROTOCOLS
15-
1614

1715
class Annotation(object):
1816
"""

wfdb/io/record.py

+28-10
Original file line numberDiff line numberDiff line change
@@ -1837,6 +1837,12 @@ def rdheader(record_name, pn_dir=None, rd_segments=False):
18371837

18381838
# If the PhysioNet database path is provided, construct the download path using the database version
18391839
elif pn_dir is not None:
1840+
# check to make sure a cloud path isn't being passed under pn_dir
1841+
if any(pn_dir.startswith(proto) for proto in CLOUD_PROTOCOLS):
1842+
raise ValueError(
1843+
"Cloud paths should be passed under record_name, not under pn_dir"
1844+
)
1845+
18401846
if "." not in pn_dir:
18411847
dir_list = pn_dir.split("/")
18421848
pn_dir = posixpath.join(
@@ -2032,11 +2038,17 @@ def rdrecord(
20322038
dir_name = os.path.abspath(dir_name)
20332039

20342040
# Read the header fields
2035-
if (pn_dir is not None) and ("." not in pn_dir):
2036-
dir_list = pn_dir.split("/")
2037-
pn_dir = posixpath.join(
2038-
dir_list[0], download.get_version(dir_list[0]), *dir_list[1:]
2039-
)
2041+
if pn_dir is not None:
2042+
# check to make sure a cloud path isn't being passed under pn_dir
2043+
if any(pn_dir.startswith(proto) for proto in CLOUD_PROTOCOLS):
2044+
raise ValueError(
2045+
"Cloud paths should be passed under record_name, not under pn_dir"
2046+
)
2047+
if "." not in pn_dir:
2048+
dir_list = pn_dir.split("/")
2049+
pn_dir = posixpath.join(
2050+
dir_list[0], download.get_version(dir_list[0]), *dir_list[1:]
2051+
)
20402052

20412053
record = rdheader(record_name, pn_dir=pn_dir, rd_segments=False)
20422054

@@ -2320,11 +2332,17 @@ def rdsamp(
23202332
channels=[1,3])
23212333
23222334
"""
2323-
if (pn_dir is not None) and ("." not in pn_dir):
2324-
dir_list = pn_dir.split("/")
2325-
pn_dir = posixpath.join(
2326-
dir_list[0], download.get_version(dir_list[0]), *dir_list[1:]
2327-
)
2335+
if pn_dir is not None:
2336+
# check to make sure a cloud path isn't being passed under pn_dir
2337+
if any(pn_dir.startswith(proto) for proto in CLOUD_PROTOCOLS):
2338+
raise ValueError(
2339+
"Cloud paths should be passed under record_name, not under pn_dir"
2340+
)
2341+
if "." not in pn_dir:
2342+
dir_list = pn_dir.split("/")
2343+
pn_dir = posixpath.join(
2344+
dir_list[0], download.get_version(dir_list[0]), *dir_list[1:]
2345+
)
23282346

23292347
record = rdrecord(
23302348
record_name=record_name,

0 commit comments

Comments
 (0)