New submission from Martin Panter:

This follows from Issue 12922. When no newline translation is being done, it 
would be useful to define the seek() offset as the code point offset into the 
underlying string, allowing stuff like:

s = StringIO()
print("line", file=s)  # Some inflexible API with an unwanted newline
s.seek(-1, SEEK_CUR)  # Undo the trailing newline
s.truncate()

In general, relative seeks are not allowed for text streams, and absolute 
offsets have arbitrary values. But when no encoding is actually going on, these 
restrictions are annoying.

I guess the biggest problem is what to do when newline translation is enabled. 
But I think this is a rarely-used feature of StringIO. I suggest to say that 
offsets in that case remain arbitrary, and let the code do whatever it happens 
to do (probably jumping to the wrong character, chopping CRLFs in half, etc, as 
long as it won’t crash).

----------
components: IO
messages: 251149
nosy: martin.panter
priority: normal
severity: normal
status: open
title: Define StringIO seek offset as code point offset
type: enhancement
versions: Python 3.6

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25190>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to