Skip to content

Commit 801f8e7

Browse files
committed
updated for test coverage
1 parent 722f4a4 commit 801f8e7

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

llsd/base.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -411,16 +411,12 @@ def _reset(self, something):
411411
# BytesIO is significant, advise caller to pass a stream instead.
412412
self._stream = io.BytesIO(something)
413413
elif isinstance(something, io.IOBase):
414-
# 'something' is a proper IO stream
414+
# 'something' is a proper IO stream - must be seekable for parsing
415415
if something.seekable():
416-
# Seekable stream, use directly
417416
self._stream = something
418-
elif something.readable():
419-
# Readable but not seekable, wrap in BufferedReader
420-
self._stream = io.BufferedReader(something)
421417
else:
422418
raise LLSDParseError(
423-
"Cannot parse LLSD from non-readable stream."
419+
"Cannot parse LLSD from non-seekable stream."
424420
)
425421
else:
426422
# Invalid input type - raise a clear error

tests/llsd_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,4 +2022,14 @@ def test_parse_int_raises_error(self):
20222022
llsd.parse(42)
20232023
self.assertIn('int', str(context.exception))
20242024

2025+
def test_parse_non_seekable_stream_raises_error(self):
2026+
'''
2027+
Parsing a non-seekable stream should raise LLSDParseError.
2028+
'''
2029+
stream = io.BytesIO()
2030+
stream.seekable = lambda: False
2031+
with self.assertRaises(llsd.LLSDParseError) as context:
2032+
llsd.parse(stream)
2033+
self.assertIn('non-seekable', str(context.exception))
2034+
20252035

0 commit comments

Comments
 (0)