MCPcopy Create free account
hub / github.com/apify/impit / read

Method read

impit-python/src/response.rs:468–507  ·  view source on GitHub ↗
(&mut self, py: Python<'_>)

Source from the content-addressed store, hash-verified

466 }
467
468 fn read(&mut self, py: Python<'_>) -> PyResult<Vec<u8>> {
469 match self.inner_state {
470 InnerResponseState::Read => self
471 .content
472 .as_ref()
473 .cloned()
474 .ok_or_else(|| ImpitPyError(impit::errors::ImpitError::ResponseNotRead).into()),
475 InnerResponseState::Streaming | InnerResponseState::StreamingClosed => {
476 if self.is_stream_consumed {
477 Err(ImpitPyError(impit::errors::ImpitError::StreamConsumed).into())
478 } else {
479 Err(ImpitPyError(impit::errors::ImpitError::StreamClosed).into())
480 }
481 }
482 InnerResponseState::Unread => {
483 let response = self
484 .inner
485 .take()
486 .ok_or(ImpitPyError(impit::errors::ImpitError::StreamClosed))?;
487
488 let runtime = pyo3_async_runtimes::tokio::get_runtime();
489 let content = py.detach(|| {
490 runtime.block_on(async {
491 response
492 .bytes()
493 .await
494 .map(|b| b.to_vec())
495 .map_err(|_| ImpitPyError(impit::errors::ImpitError::NetworkError))
496 })
497 })?;
498
499 self.content = Some(content.clone());
500 self.inner_state = InnerResponseState::Read;
501 self.is_stream_consumed = true;
502 self.is_closed = true;
503
504 Ok(content)
505 }
506 }
507 }
508}
509
510impl ImpitPyResponse {

Callers 15

#serializeBodyMethod · 0.80
basics.test.tsFile · 0.80
test_readMethod · 0.80
test_read_after_closeMethod · 0.80
test_two_read_callsMethod · 0.80
test_readMethod · 0.80
test_read_after_closeMethod · 0.80
test_two_read_callsMethod · 0.80
test_read_after_closeMethod · 0.80
test_two_read_callsMethod · 0.80
contentMethod · 0.80
textMethod · 0.80

Calls 3

ImpitPyErrorClass · 0.85
bytesMethod · 0.80
cloneMethod · 0.80

Tested by 8

test_readMethod · 0.64
test_read_after_closeMethod · 0.64
test_two_read_callsMethod · 0.64
test_readMethod · 0.64
test_read_after_closeMethod · 0.64
test_two_read_callsMethod · 0.64
test_read_after_closeMethod · 0.64
test_two_read_callsMethod · 0.64