[issue33361] readline() + seek() on io.EncodedFile breaks next readline()

2018-05-21 Thread Diego Argueta
Diego Argueta added the comment: Update: Tested this on Python 3.5.4, 3.4.8, and 3.7.0b3 on OSX 10.13.4. They also exhibit the bug. Updating the ticket accordingly. -- versions: +Python 3.4, Python 3.5, Python 3.7 ___

[issue33361] readline() + seek() on io.EncodedFile breaks next readline()

2018-04-27 Thread Elena Oat
Elena Oat added the comment: I've modified a little your example and it's clearly that the readline moves the cursor. ``` from __future__ import print_function import codecs import io def run(stream): offset = stream.tell() try: stream.seek(0)

[issue33361] readline() + seek() on io.EncodedFile breaks next readline()

2018-04-27 Thread Elena Oat
Elena Oat added the comment: For you specific example I get also a weird result. Tried this in Python 2.7.10 and Python 3.6.0. -- ___ Python tracker

[issue33361] readline() + seek() on io.EncodedFile breaks next readline()

2018-04-27 Thread Elena Oat
Elena Oat added the comment: I've tried this with Python 3.6.0 on OSX 10.13.4 -- ___ Python tracker ___

[issue33361] readline() + seek() on io.EncodedFile breaks next readline()

2018-04-26 Thread Diego Argueta
Diego Argueta added the comment: Update: If I run your exact code it still breaks for me: ``` Got header: 'abc\n' Skipping the header. 'def\n' Line 2: 'ghi\n' Line 3: 'abc\n' Line 4: 'def\n' Line 5: 'ghi\n' ``` I'm running Python 2.7.14 and 3.6.5 on OSX 10.13.4.

[issue33361] readline() + seek() on io.EncodedFile breaks next readline()

2018-04-26 Thread Diego Argueta
Diego Argueta added the comment: That's because the stream isn't transcoding, since UTF-8 is ASCII-compatible. Try using something not ASCII-compatible as the codec e.g. 'ibm500' and it'll give incorrect results. ``` b =

[issue33361] readline() + seek() on io.EncodedFile breaks next readline()

2018-04-26 Thread Elena Oat
Elena Oat added the comment: I cannot replicate this when the stream is: In: stream_ex = io.BytesIO(u"abc\ndef\nghi\n".encode("utf-8")) In: f = codecs.EncodedFile(stream_ex, 'utf-8') In: run(f) Out: Got header: b'abc\n' Skipping the header: b'abc\n' Line 2: b'def\n' Line

[issue33361] readline() + seek() on io.EncodedFile breaks next readline()

2018-04-25 Thread Diego Argueta
New submission from Diego Argueta : It appears that calling readline() on a codecs.EncodedFile stream breaks seeking and causes subsequent attempts to iterate over the lines or call readline() to backtrack and return already consumed lines. A minimal example: ```