[issue26730] SpooledTemporaryFile doesn't correctly preserve data for text (non-binary) SpooledTemporaryFile objects when Unicode characters are written
Serhiy Storchaka
report at bugs.python.org
Tue Apr 19 01:05:44 EDT 2016
Serhiy Storchaka added the comment:
> This still depends on StringIO.tell() corresponding to the number of code points, which is undocumented (we already disable newline translation in the StringIO). See also Issue 25190.
And doesn't work with Python implementation of StringIO. More general solution needs the code like:
pos = file.tell()
tail = file.read()
file.seek(0)
head = file.read()
if tail:
head = head[:-len(tail)]
newfile.write(head)
pos = newfile.tell() # TextIOWrapper position is opaque
newfile.write(tail)
newfile.seek(pos, 0)
Yet one bad thing with using independent StringIO instead of TextIOWrapper, is that saved tell() position becomes not valid after rollover(). I'm going to write few tests for cases when file position points not at the end of the stream.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26730>
_______________________________________
More information about the Python-bugs-list
mailing list