[plugin] binary sys.stdout/err on win32

John Arbash Meinel john at arbash-meinel.com
Sun Jun 18 16:55:39 BST 2006


I just created a very simple plugin which sets sys.stdout and stderr to
binary for win32.

This is the sum total of the code:

import sys

if sys.platform in ('win32', 'cygwin'):
    try:
        import msvcrt, os
    except ImportError:
        pass
    else:
        msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
        msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY)

I'm not sure if cygwin has msvcrt, or if sys.stdout is already in
binary, but I thought I would cover it, just in case.

It isn't as difficult as I thought it would be. But now we need to
decide if we always want binary mode or not. I think commands like diff
and bundle definitely want binary mode set.

The windows command console will do the right thing when seeing a plain
\r. The only thing I know of that doesn't handle it well is notepad, in
the case that you redirected the output to a file.

I would like to hear Alexander's position on this, as someone who works
within windows all the time. For myself, I always use Vim on all
platforms, and it copes without any problems.

I'm tempted to just put this code in bzr mainline, and just live with
it. I'm not sure exactly where it should go in the stack, I'm guessing
either in the 'bzr' front end, or in bzrlib.commands.main().

The other possibility would be to just use the encoding_type that I've
already specified for other stuff. And if the encoding_type == 'exact'
set sys.stdout to binary mode. Otherwise if we are translating
filenames, it seems like we could translate line-endings at the same time.

Any thoughts?

John
=:->

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060618/75089da8/attachment.pgp 


More information about the bazaar mailing list