Skip to content

Commit cdea434

Browse files
committed
dont use local path separator for uri
1 parent a30249a commit cdea434

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

wfdb/io/record.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,31 +1829,35 @@ def rdheader(record_name, pn_dir=None, rd_segments=False):
18291829
"""
18301830
dir_name, base_record_name = os.path.split(record_name)
18311831
dir_name = os.path.abspath(dir_name)
1832+
file_name = f"{base_record_name}.hea"
1833+
1834+
# If this is a cloud path, use posixpath to construct the path
1835+
if any(dir_name.startswith(proto) for proto in CLOUD_PROTOCOLS):
1836+
with fsspec.open(
1837+
posixpath.join(dir_name, file_name),
1838+
mode="rb"
1839+
) as f:
1840+
header_content = f.read()
18321841

1833-
# If this is a cloud path we leave it as is
1834-
if (pn_dir is not None) and any(
1835-
pn_dir.startswith(proto) for proto in CLOUD_PROTOCOLS
1836-
):
1837-
pass
18381842
# If it isn't a cloud path, construct the download path using the database version
1839-
elif (pn_dir is not None) and ("." not in pn_dir):
1840-
dir_list = pn_dir.split("/")
1841-
pn_dir = posixpath.join(
1842-
dir_list[0], download.get_version(dir_list[0]), *dir_list[1:]
1843-
)
1843+
elif (pn_dir is not None):
1844+
if ("." not in pn_dir):
1845+
dir_list = pn_dir.split("/")
1846+
pn_dir = posixpath.join(
1847+
dir_list[0], download.get_version(dir_list[0]), *dir_list[1:]
1848+
)
18441849

1845-
# Read the local or remote header file.
1846-
file_name = f"{base_record_name}.hea"
1847-
if pn_dir is None:
1850+
header_content = download._stream_header(file_name, pn_dir)
1851+
1852+
# If it isn't a cloud path or a PhysioNet path, we treat as a local file
1853+
else:
18481854
with fsspec.open(
18491855
os.path.join(dir_name, file_name),
18501856
"r",
18511857
encoding="ascii",
18521858
errors="ignore",
18531859
) as f:
18541860
header_content = f.read()
1855-
else:
1856-
header_content = download._stream_header(file_name, pn_dir)
18571861

18581862
# Separate comment and non-comment lines
18591863
header_lines, comment_lines = header.parse_header_content(header_content)

0 commit comments

Comments
 (0)