Skip to content

Commit 216222f

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

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

wfdb/io/_coreio.py

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from wfdb.io import _url
66
from wfdb.io.download import config
7+
from wfdb.io.record import CLOUD_PROTOCOLS
78

89

910
def _open_file(
@@ -59,6 +60,12 @@ def _open_file(
5960
newline=newline,
6061
)
6162
else:
63+
# check to make sure a cloud path isn't being passed under pn_dir
64+
if any(pn_dir.startswith(proto) for proto in CLOUD_PROTOCOLS):
65+
raise ValueError(
66+
"Cloud paths should be passed under record_name, not under pn_dir"
67+
)
68+
6269
url = posixpath.join(config.db_index_url, pn_dir, file_name)
6370
return _url.openurl(
6471
url,

wfdb/io/_signal.py

+13
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import numpy as np
88

99
from wfdb.io import download, _coreio, util
10+
from wfdb.io.record import CLOUD_PROTOCOLS
1011

1112

1213
MAX_I32 = 2147483647
@@ -1698,6 +1699,12 @@ def _rd_dat_file(file_name, dir_name, pn_dir, fmt, start_byte, n_samp):
16981699

16991700
# Stream dat file from PhysioNet
17001701
else:
1702+
# check to make sure a cloud path isn't being passed under pn_dir
1703+
if any(pn_dir.startswith(proto) for proto in CLOUD_PROTOCOLS):
1704+
raise ValueError(
1705+
"Cloud paths should be passed under record_name, not under pn_dir"
1706+
)
1707+
17011708
dtype_in = np.dtype(DATA_LOAD_TYPES[fmt])
17021709
sig_data = download._stream_dat(
17031710
file_name, pn_dir, byte_count, start_byte, dtype_in
@@ -2613,6 +2620,12 @@ def _infer_sig_len(
26132620

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

wfdb/io/record.py

+17-5
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

0 commit comments

Comments
 (0)