Serhiy Storchaka added the comment:
May be. Looking at the code, both Python and C implementations of TextIOWrapper
look incorrect.
Python implementation:
def truncate(self, pos=None):
self.flush()
if pos is None:
pos = self.tell()
return self.buffer.truncate(pos)
If pos is not specified, self.tell() is used as truncating position for
underlying binary file. But self.tell() is not an offset in bytes, as seen from
UTF-7 example. This is complex cookie that includes starting position in binary
file, a number of bytes that should be read and feed to the decoder, and other
decoder flags. Needed at least unpack the cookie returned by self.tell(), and
raise an exception if it doesn't ambiguously point to binary file position.
C implementation is equivalent to:
def truncate(self, pos=None):
self.flush()
return self.buffer.truncate(pos)
It just ignores decoder buffer.
----------
stage: -> needs patch
type: -> behavior
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue26158>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com