Skip to content

Commit

Permalink
Response: add attrib text_plain
Browse files Browse the repository at this point in the history
  • Loading branch information
deedy5 committed Jul 23, 2024
1 parent ac26941 commit 71130c7
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/response.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use encoding_rs::Encoding;
use html2text::from_read;
use html2text::{from_read, from_read_with_decorator, render::text_renderer::TrivialDecorator};
use pyo3::exceptions;
use pyo3::prelude::*;
use pyo3::types::{PyBytes, PyDict, PyString};
Expand Down Expand Up @@ -71,4 +71,11 @@ impl Response {
let text = from_read(raw_bytes, usize::MAX);
Ok(text)
}

#[getter]
fn text_plain(&mut self, py: Python) -> PyResult<String> {
let raw_bytes = self.content.bind(py).as_bytes();
let text = from_read_with_decorator(raw_bytes, usize::MAX, TrivialDecorator::new());
Ok(text)
}
}

0 comments on commit 71130c7

Please sign in to comment.