diff options
author | Cosimo Lupo <cosimo.lupo@daltonmaag.com> | 2015-04-16 12:41:40 +0100 |
---|---|---|
committer | Cosimo Lupo <cosimo.lupo@daltonmaag.com> | 2015-04-16 12:41:40 +0100 |
commit | b316cb747acfb4ec73f7d80b04ea6c78c385a68d (patch) | |
tree | 7ac40ac8c088223676a83c01cb367975efffde21 /python | |
parent | 9e53d522a34bb8eabfda4a50f7e9da1d1e57a98f (diff) | |
download | brotli-b316cb747acfb4ec73f7d80b04ea6c78c385a68d.zip brotli-b316cb747acfb4ec73f7d80b04ea6c78c385a68d.tar.gz brotli-b316cb747acfb4ec73f7d80b04ea6c78c385a68d.tar.bz2 |
[python] fix unbuffered binary mode for I/O streams in Windows pypy
Diffstat (limited to 'python')
-rwxr-xr-x | python/bro.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/python/bro.py b/python/bro.py index 4ed88a6..0e0ab21 100755 --- a/python/bro.py +++ b/python/bro.py @@ -6,6 +6,7 @@ import getopt import sys import os import brotli +import platform __usage__ = """\ Usage: bro [--force] [--decompress] [--input filename] [--output filename] @@ -29,8 +30,15 @@ def get_binary_stdio(stream): if sys.version_info[0] < 3: if sys.platform == 'win32': # set I/O stream binary flag on python2.x (Windows) - import msvcrt - msvcrt.setmode(stdio.fileno(), os.O_BINARY) + runtime = platform.python_implementation() + if runtime == "PyPy": + # the msvcrt trick doesn't work in pypy, so I use fdopen + mode = "rb" if stream == "stdin" else "wb" + stdio = os.fdopen(stdio.fileno(), mode, 0) + else: + # this works with CPython -- untested on other implementations + import msvcrt + msvcrt.setmode(stdio.fileno(), os.O_BINARY) return stdio else: # get 'buffer' attribute to read/write binary data on python3.x |