Skip to content

Commit 8ff4493

Browse files
committed
using posixpath for URL creation
1 parent 772a8bb commit 8ff4493

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

wfdb/downloads.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import numpy as np
22
import re
33
import os
4+
import posixpath
45
import sys
56
import requests
67
from IPython.display import display
@@ -9,7 +10,7 @@
910
def streamheader(recordname, pbdir):
1011

1112
# Full url of header location
12-
url = os.path.join(dbindexurl, pbdir, recordname+'.hea')
13+
url = posixpath.join(dbindexurl, pbdir, recordname+'.hea')
1314
r = requests.get(url)
1415

1516
# Raise HTTPError if invalid url
@@ -44,7 +45,7 @@ def streamheader(recordname, pbdir):
4445
def streamdat(filename, pbdir, fmt, bytecount, startbyte, datatypes):
4546

4647
# Full url of dat file
47-
url = os.path.join(dbindexurl, pbdir, filename)
48+
url = posixpath.join(dbindexurl, pbdir, filename)
4849

4950
# Specify the byte range
5051
endbyte = startbyte + bytecount-1
@@ -72,7 +73,7 @@ def streamdat(filename, pbdir, fmt, bytecount, startbyte, datatypes):
7273
def streamannotation(filename, pbdir):
7374

7475
# Full url of annotation file
75-
url = os.path.join(dbindexurl, pbdir, filename)
76+
url = posixpath.join(dbindexurl, pbdir, filename)
7677

7778
# Get the content
7879
r = requests.get(url)
@@ -94,7 +95,7 @@ def getdblist():
9495
Usage:
9596
dblist = getdblist()
9697
"""
97-
url = os.path.join(dbindexurl, 'DBS')
98+
url = posixpath.join(dbindexurl, 'DBS')
9899
r = requests.get(url)
99100

100101
dblist = r.content.decode('ascii').splitlines()
@@ -109,7 +110,7 @@ def getdblist():
109110
def getrecordlist(dburl, records):
110111
# Check for a RECORDS file
111112
if records == 'all':
112-
r = requests.get(os.path.join(dburl, 'RECORDS'))
113+
r = requests.get(posixpath.join(dburl, 'RECORDS'))
113114
if r.status_code == 404:
114115
sys.exit('The database '+dburl+' has no WFDB files to download')
115116

@@ -125,7 +126,7 @@ def getannotators(dburl, annotators):
125126

126127
if annotators is not None:
127128
# Check for an ANNOTATORS file
128-
r = requests.get(os.path.join(dburl, 'ANNOTATORS'))
129+
r = requests.get(posixpath.join(dburl, 'ANNOTATORS'))
129130
if r.status_code == 404:
130131
if annotators == 'all':
131132
return
@@ -175,7 +176,7 @@ def dlpbfile(inputs):
175176
basefile, subdir, pbdb, dlbasedir, keepsubdirs, overwrite = inputs
176177

177178
# Full url of file
178-
url = os.path.join(dbindexurl, pbdb, subdir, basefile)
179+
url = posixpath.join(dbindexurl, pbdb, subdir, basefile)
179180

180181
# Get the request header
181182
rh = requests.head(url, headers={'Accept-Encoding': 'identity'})

wfdb/records.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import numpy as np
99
import re
1010
import os
11+
import posixpath
1112
import sys
1213
from collections import OrderedDict
1314
from calendar import monthrange
@@ -1185,7 +1186,7 @@ def dldatabase(pbdb, dlbasedir, records = 'all', annotators = 'all' , keepsubdir
11851186
"""
11861187

11871188
# Full url physiobank database
1188-
dburl = os.path.join(downloads.dbindexurl, pbdb)
1189+
dburl = posixpath.join(downloads.dbindexurl, pbdb)
11891190
# Check if the database is valid
11901191
r = requests.get(dburl)
11911192
r.raise_for_status()
@@ -1208,13 +1209,13 @@ def dldatabase(pbdb, dlbasedir, records = 'all', annotators = 'all' , keepsubdir
12081209
# If MIT format, have to figure out all associated files
12091210
allfiles.append(rec+'.hea')
12101211
dirname, baserecname = os.path.split(rec)
1211-
record = rdheader(baserecname, pbdir = os.path.join(pbdb, dirname))
1212+
record = rdheader(baserecname, pbdir = posixpath.join(pbdb, dirname))
12121213

12131214
# Single segment record
12141215
if type(record) == Record:
12151216
# Add all dat files of the segment
12161217
for file in record.filename:
1217-
allfiles.append(os.path.join(dirname, file))
1218+
allfiles.append(posixpath.join(dirname, file))
12181219

12191220
# Multi segment record
12201221
else:
@@ -1223,19 +1224,19 @@ def dldatabase(pbdb, dlbasedir, records = 'all', annotators = 'all' , keepsubdir
12231224
if seg == '~':
12241225
continue
12251226
# Add the header
1226-
allfiles.append(os.path.join(dirname, seg+'.hea'))
1227+
allfiles.append(posixpath.join(dirname, seg+'.hea'))
12271228
# Layout specifier has no dat files
12281229
if seg.endswith('_layout'):
12291230
continue
12301231
# Add all dat files of the segment
1231-
recseg = rdheader(seg, pbdir = os.path.join(pbdb, dirname))
1232+
recseg = rdheader(seg, pbdir = posixpath.join(pbdb, dirname))
12321233
for file in recseg.filename:
1233-
allfiles.append(os.path.join(dirname, file))
1234+
allfiles.append(posixpath.join(dirname, file))
12341235
# check whether the record has any requested annotation files
12351236
if annotators is not None:
12361237
for a in annotators:
12371238
annfile = rec+'.'+a
1238-
url = os.path.join(downloads.dbindexurl, pbdb, annfile)
1239+
url = posixpath.join(downloads.dbindexurl, pbdb, annfile)
12391240
rh = requests.head(url)
12401241

12411242
if rh.status_code != 404:
@@ -1282,7 +1283,7 @@ def dldatabasefiles(pbdb, dlbasedir, files, keepsubdirs = True, overwrite = Fals
12821283
"""
12831284

12841285
# Full url physiobank database
1285-
dburl = os.path.join(downloads.dbindexurl, pbdb)
1286+
dburl = posixpath.join(downloads.dbindexurl, pbdb)
12861287
# Check if the database is valid
12871288
r = requests.get(dburl)
12881289
r.raise_for_status()

0 commit comments

Comments
 (0)