[Bug 5240] New: (py3) sys.stdout.buffer isn't guaranteed available

mercurial-bugs at selenic.com mercurial-bugs at selenic.com
Fri May 20 01:32:01 UTC 2016


https://bz.mercurial-scm.org/show_bug.cgi?id=5240

            Bug ID: 5240
           Summary: (py3) sys.stdout.buffer isn't guaranteed available
           Product: Mercurial
           Version: unspecified
          Hardware: PC
                OS: Windows
            Status: UNCONFIRMED
          Severity: feature
          Priority: wish
         Component: Mercurial
          Assignee: bugzilla at selenic.com
          Reporter: timeless at gmail.com
                CC: mercurial-devel at selenic.com

https://docs.python.org/3/library/sys.html#sys.stdout

> Note: To write or read binary data from/to the standard streams, use the underlying binary buffer object. For example, to write bytes to stdout, use sys.stdout.buffer.write(b'abc').
> However, if you are writing a library (and do not control in which context its code will be executed), be aware that the standard streams may be replaced with file-like objects like io.StringIO which do not support the buffer attribute.

We're going to need to write our own magic wrapper which inserts buffer when
it's missing.

I think that when I use a debugger (like pudb3), sys.stdout.buffer is missing.

https://docs.python.org/3/library/sys.html#sys.displayhook

Has the following:
       if hasattr(sys.stdout, 'buffer'):
            sys.stdout.buffer.write(bytes)
        else:
            text = bytes.decode(sys.stdout.encoding, 'strict')
            sys.stdout.write(text)

This is going to be needed for anything that tries to do i/o.
(including tests/run-tests.py, contrib/check-code.py, and mercurial/ui.py,
mercurial/hgweb/wsgicgi.py

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Mercurial-devel mailing list