From adff3177a4b9bd6ee0e351c7706cb644a9df8e7f Mon Sep 17 00:00:00 2001 From: Gregory Szorc Date: Mon, 17 Jan 2022 12:56:59 -0800 Subject: [PATCH] rust: implement iterator protocol for Zstd[De]CompressionWriter This should have been done in commit 13172073018884d68167f8d3e25416d84113a7bc. --- rust-ext/src/compression_writer.rs | 20 ++++++++++++++++++++ rust-ext/src/decompression_writer.rs | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/rust-ext/src/compression_writer.rs b/rust-ext/src/compression_writer.rs index 0bac253d..7064a213 100644 --- a/rust-ext/src/compression_writer.rs +++ b/rust-ext/src/compression_writer.rs @@ -11,6 +11,7 @@ use { exceptions::{PyNotImplementedError, PyOSError, PyValueError}, prelude::*, types::PyBytes, + PyIterProtocol, }, std::sync::Arc, }; @@ -304,3 +305,22 @@ impl ZstdCompressionWriter { self.bytes_compressed } } + +#[pyproto] +impl PyIterProtocol for ZstdCompressionWriter { + fn __iter__(slf: PyRef) -> PyResult<()> { + let py = slf.py(); + let io = py.import("io")?; + let exc = io.getattr("UnsupportedOperation")?; + + Err(PyErr::from_instance(exc)) + } + + fn __next__(slf: PyRef) -> PyResult> { + let py = slf.py(); + let io = py.import("io")?; + let exc = io.getattr("UnsupportedOperation")?; + + Err(PyErr::from_instance(exc)) + } +} diff --git a/rust-ext/src/decompression_writer.rs b/rust-ext/src/decompression_writer.rs index 6400ce30..9eace104 100644 --- a/rust-ext/src/decompression_writer.rs +++ b/rust-ext/src/decompression_writer.rs @@ -11,6 +11,7 @@ use { exceptions::{PyOSError, PyValueError}, prelude::*, types::PyBytes, + PyIterProtocol, }, std::sync::Arc, }; @@ -276,3 +277,22 @@ impl ZstdDecompressionWriter { } } } + +#[pyproto] +impl PyIterProtocol for ZstdDecompressionWriter { + fn __iter__(slf: PyRef) -> PyResult<()> { + let py = slf.py(); + let io = py.import("io")?; + let exc = io.getattr("UnsupportedOperation")?; + + Err(PyErr::from_instance(exc)) + } + + fn __next__(slf: PyRef) -> PyResult> { + let py = slf.py(); + let io = py.import("io")?; + let exc = io.getattr("UnsupportedOperation")?; + + Err(PyErr::from_instance(exc)) + } +}