[issue39365] Support (SEEK_END/SEEK_CUR) relative seeking in StringIO

2020-01-20 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

This is a duplicate of issue25190.

--
components: +Library (Lib)
nosy: +serhiy.storchaka
resolution:  -> duplicate
stage:  -> resolved
status: open -> closed
superseder:  -> Define StringIO seek offset as code point offset
type: behavior -> enhancement
versions: +Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39365] Support (SEEK_END/SEEK_CUR) relative seeking in StringIO

2020-01-19 Thread random832


random832  added the comment:

That documentation isn't specific to StringIO, and in any case, the limitation 
in question isn't documented. The actual implementation is at 
https://github.com/python/cpython/blob/HEAD/Modules/_io/stringio.c#L484

But if examples would help, they're simple to come up with:

>>> f = io.StringIO('t\xe9st')
>>> f.seek(-1, io.SEEK_END)
Traceback (most recent call last):
  File "", line 1, in 
OSError: Can't do nonzero cur-relative seeks
>>> f.seek(2, io.SEEK_CUR)
Traceback (most recent call last):
  File "", line 1, in 
OSError: Can't do nonzero cur-relative seeks
# demonstration that SEEK_SET works treating all characters as one unit
>>> f.seek(2, io.SEEK_SET)
2
>>> f.read()
'st'

As far as I know this is the case in all currently maintained versions of 
Python 3, since the C-based unicode StringIO implementation was added in 2008.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39365] Support (SEEK_END/SEEK_CUR) relative seeking in StringIO

2020-01-19 Thread sanket


sanket  added the comment:

can you provide more details? Python version and code/steps to reproduce. 
That'd be more helpful as it seems the methods are already implemented in 
latest version https://docs.python.org/3/library/io.html#io.TextIOBase.seek

--
nosy: +sanketplus

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39365] Support (SEEK_END/SEEK_CUR) relative seeking in StringIO

2020-01-16 Thread random832


New submission from random832 :

Currently this fails with a (misleading in the case of SEEK_END) "Can't do 
nonzero cur-relative seeks" error, but there's no conceptual reason it 
shouldn't be possible.

The offset should simply be taken as a character offset, without any pretense 
that the "file" represents bytes in some Unicode encoding. This is already done 
for SEEK_START and tell, and has not caused any problems.

--
components: IO
messages: 360158
nosy: random832
priority: normal
severity: normal
status: open
title: Support (SEEK_END/SEEK_CUR) relative seeking in StringIO
type: behavior

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com