Amaury Forgeot d'Arc added the comment:

> But that will still be within the TextIOWrapper itself, right?

Yes. And I just noticed that the _io module (the C version) will also buffer 
encoded bytes, up to f._CHUNK_SIZE.

On the other hand, TextIOWrapper is broken for buffering codecs, encode() is 
never called with final=True

    >>> import io
    >>> buffer = io.BytesIO()      # <-- not really buffered, right?
    >>> output = io.TextIOWrapper(buffer, encoding='idna')
    >>> output.write("www.somesite.com")
    16
    >>> print(buffer.getvalue())
    b''                            # <-- ok, _CHUNK_SIZE buffering
    >>> output.flush()
    >>> print(buffer.getvalue())
    b'www.somesite.'               # <-- the last word is missing!
    >>> output.close()
    >>> print(buffer.getvalue())
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ValueError: I/O operation on closed file.


And it's even worse with python 2.7::

    >>> import io as io
    >>> buffer = io.BytesIO()
    >>> output = io.TextIOWrapper(buffer, encoding='idna')
    >>> output.write("www.somesite.com")
    Traceback (most recent call last):
      File "<stdin>", line 3, in <module>
    TypeError: must be unicode, not str

----------

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

Reply via email to