This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients Zero, benjamin.peterson, docs@python, eryksun, fornax, pitrou, serhiy.storchaka, steve.dower, stutzbach, vstinner
Date 2016-01-19.20:00:14
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1453233614.3.0.663923262079.issue26158@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2016-01-19 20:00:14serhiy.storchakasetrecipients: + serhiy.storchaka, pitrou, vstinner, benjamin.peterson, stutzbach, Zero, docs@python, eryksun, steve.dower, fornax
2016-01-19 20:00:14serhiy.storchakasetmessageid: <1453233614.3.0.663923262079.issue26158@psf.upfronthosting.co.za>
2016-01-19 20:00:14serhiy.storchakalinkissue26158 messages
2016-01-19 20:00:14serhiy.storchakacreate