From f8b536ca066c75c2d71b166adc618b11a82dfae0 Mon Sep 17 00:00:00 2001 From: oefe Date: Sat, 27 Aug 2022 17:08:29 +0200 Subject: [PATCH 1/2] Fix missing `mode` property on file wrapper Without this property, uploads using `requests` fails to set the Content-Length header, and falls back to chunked encoding, which many hosts (e.g. S3) don't support. --- CHANGELOG.md | 1 + CONTRIBUTORS.md | 1 + rich/progress.py | 4 ++++ tests/test_progress.py | 1 + 4 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b723ded..484c7d31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fix NO_COLOR support on legacy Windows https://github.com/Textualize/rich/pull/2458 +- Fix missing `mode` property on file wrapper breaking uploads via `requests` ## [12.5.2] - 2022-07-18 diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 61125989..7890ec10 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -28,6 +28,7 @@ The following people have contributed to the development of Rich: - [Paul McGuire](https://github.com/ptmcg) - [Antony Milne](https://github.com/AntonyMilneQB) - [Michael Milton](https://github.com/multimeric) +- [Martina Oefelein](https://github.com/oefe) - [Nathan Page](https://github.com/nathanrpage97) - [Avi Perl](https://github.com/avi-perl) - [Laurent Peuch](https://github.com/psycojoker) diff --git a/rich/progress.py b/rich/progress.py index 679731a1..9873e1a5 100644 --- a/rich/progress.py +++ b/rich/progress.py @@ -216,6 +216,10 @@ class _Reader(RawIOBase, BinaryIO): def isatty(self) -> bool: return self.handle.isatty() + @property + def mode(self) -> str: + return self.handle.mode + @property def name(self) -> str: return self.handle.name diff --git a/tests/test_progress.py b/tests/test_progress.py index 792ee636..a3a28766 100644 --- a/tests/test_progress.py +++ b/tests/test_progress.py @@ -614,6 +614,7 @@ def test_wrap_file() -> None: with open(filename, "rb") as file: with rich.progress.wrap_file(file, total=total) as f: assert f.read() == b"Hello, World!" + assert f.mode == "rb" assert f.name == filename assert f.closed assert not f.handle.closed From b51a3033f702dfb05886c70a7d454047a2d56ebc Mon Sep 17 00:00:00 2001 From: oefe Date: Sat, 27 Aug 2022 17:31:17 +0200 Subject: [PATCH 2/2] Add link to PR --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 484c7d31..2d14fff1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fix NO_COLOR support on legacy Windows https://github.com/Textualize/rich/pull/2458 -- Fix missing `mode` property on file wrapper breaking uploads via `requests` +- Fix missing `mode` property on file wrapper breaking uploads via `requests` https://github.com/Textualize/rich/pull/2495 ## [12.5.2] - 2022-07-18