Skip to content

Commit 0e83d35

Browse files
committed
add in check for mal-configured files
1 parent 510223d commit 0e83d35

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

neo/rawio/spikegadgetsrawio.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,19 @@ def _parse_header(self):
111111
# parse file until "</Configuration>"
112112
header_size = None
113113
with open(self.filename, mode="rb") as f:
114+
# see https://github.com/NeuralEnsemble/python-neo/issues/1757 for bug with while loop
115+
# instead we seek the end of the file so we know when we are at the end
116+
# then readline returns an empty string at EOF so we confirm empty string + EOF location
117+
f.seek(0,2)
118+
end_of_file = f.tell()
119+
f.seek(0)
114120
while True:
115121
line = f.readline()
116122
if b"</Configuration>" in line:
117123
header_size = f.tell()
118124
break
125+
if line == "" and f.tell() == end_of_file:
126+
break
119127

120128
if header_size is None:
121129
ValueError("SpikeGadgets: the xml header does not contain '</Configuration>'")

0 commit comments

Comments
 (0)