Skip to content

Commit 524870d

Browse files
committed
added support for newline types other than unix style
1 parent e170edf commit 524870d

File tree

6 files changed

+1666
-13
lines changed

6 files changed

+1666
-13
lines changed

stl/stl.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,20 @@ def _load_binary(cls, fh, header, check_size=False):
136136

137137
@classmethod
138138
def _ascii_reader(cls, fh, header):
139-
if b'\n' in header:
140-
recoverable = [True]
139+
recoverable = [True]
140+
line_separator = b'\n'
141+
142+
if b'\r\n' in header:
143+
line_separator = b'\r\n'
144+
elif b'\n' in header:
145+
pass
146+
elif b'\r' in header:
147+
line_separator = b'\r'
141148
else:
142149
recoverable = [False]
143150
header += b(fh.read(BUFFER_SIZE))
144151

145-
lines = b(header).split(b('\n'))
152+
lines = b(header).split(line_separator)
146153

147154
def get(prefix=''):
148155
prefix = b(prefix).lower()
@@ -156,7 +163,7 @@ def get(prefix=''):
156163
recoverable[0] = False
157164

158165
# Read more lines and make sure we prepend any old data
159-
lines[:] = b(fh.read(BUFFER_SIZE)).split(b('\n'))
166+
lines[:] = b(fh.read(BUFFER_SIZE)).split(line_separator)
160167
raw_line += lines.pop(0)
161168

162169
raw_line = raw_line.strip()

0 commit comments

Comments
 (0)