[PR #71] [MERGED] [python] fix unbuffered binary mode for I/O streams in Windows pypy #664

Open
opened 2026-01-29 20:50:12 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/google/brotli/pull/71
Author: @anthrotype
Created: 4/16/2015
Status: Merged
Merged: 4/16/2015
Merged by: @szabadka

Base: masterHead: pypy_unbuffered


📝 Commits (1)

  • b316cb7 [python] fix unbuffered binary mode for I/O streams in Windows pypy

📊 Changes

1 file changed (+10 additions, -2 deletions)

View changed files

📝 python/bro.py (+10 -2)

📄 Description

Hello,

I tried to build the brotli extension under PyPy and everything seems fine.
I tested the latest Python2.7-compatible release (PyPy version 2.5.1) on OS X, Ubuntu and Windows.
The extension compiles correctly, and both the compatibility and roundtrip tests pass just like with the CPython implementation.

I only found a small issue when running tests under pypy for Windows. It has to do with the "bro.py" script used for the tests. In PyPy, the msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY trick does not seem to produce any effect (unlike under Windows CPython), and so brotli fails because the standard input/output streams are not read/written in binary mode, but in the default text mode (with \n line endings converted to \r\n).

I modified the "bro.py" script to use a different method (os.fdopen) to reopen standard streams in binary mode only when it is run from PyPy on Windows. For some reasons, the latter trick does not work from Windows CPython, so for the latter I still use the msvcrt.setmode method.

Cheers,

Cosimo


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/google/brotli/pull/71 **Author:** [@anthrotype](https://github.com/anthrotype) **Created:** 4/16/2015 **Status:** ✅ Merged **Merged:** 4/16/2015 **Merged by:** [@szabadka](https://github.com/szabadka) **Base:** `master` ← **Head:** `pypy_unbuffered` --- ### 📝 Commits (1) - [`b316cb7`](https://github.com/google/brotli/commit/b316cb747acfb4ec73f7d80b04ea6c78c385a68d) [python] fix unbuffered binary mode for I/O streams in Windows pypy ### 📊 Changes **1 file changed** (+10 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `python/bro.py` (+10 -2) </details> ### 📄 Description Hello, I tried to build the brotli extension under PyPy and everything seems fine. I tested the latest Python2.7-compatible release (PyPy version 2.5.1) on OS X, Ubuntu and Windows. The extension compiles correctly, and both the compatibility and roundtrip tests pass just like with the CPython implementation. I only found a small issue when running tests under pypy for Windows. It has to do with the "bro.py" script used for the tests. In PyPy, the `msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY` trick does not seem to produce any effect (unlike under Windows CPython), and so brotli fails because the standard input/output streams are not read/written in binary mode, but in the default text mode (with `\n` line endings converted to `\r\n`). I modified the "bro.py" script to use a different method (`os.fdopen`) to reopen standard streams in binary mode only when it is run from PyPy on Windows. For some reasons, the latter trick does not work from Windows CPython, so for the latter I still use the `msvcrt.setmode` method. Cheers, Cosimo --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 20:50:12 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/brotli#664