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

Method stream

impit-python/src/client.rs:323–366  ·  view source on GitHub ↗
(
        &self,
        py: Python<'python>,
        method: &str,
        url: String,
        content: Option<Vec<u8>>,
        data: Option<RequestBody>,
        headers: Option<HashMap<String, St

Source from the content-addressed store, hash-verified

321
322 #[pyo3(signature = (method, url, content=None, data=None, headers=None, timeout=Some(Right(USE_CLIENT_DEFAULT_SENTINEL)), force_http3=false))]
323 pub fn stream<'python>(
324 &self,
325 py: Python<'python>,
326 method: &str,
327 url: String,
328 content: Option<Vec<u8>>,
329 data: Option<RequestBody>,
330 headers: Option<HashMap<String, String>>,
331 timeout: Option<Either<f64, &str>>,
332 force_http3: Option<bool>,
333 ) -> Result<Bound<'python, PyAny>, PyErr> {
334 let response = self.request(
335 py,
336 method,
337 url,
338 content,
339 data,
340 headers,
341 timeout,
342 force_http3,
343 Some(true),
344 )?;
345
346 let fun: Py<PyAny> = PyModule::from_code(
347 py,
348 c_str!(
349 "def wrap_with_context_manager(response):
350 class SyncContextManager:
351 def __enter__(self):
352 self.response = response
353 return self.response
354 def __exit__(self, exc_type, exc_value, traceback):
355 self.response.close()
356 return SyncContextManager()"
357 ),
358 c_str!(""),
359 c_str!(""),
360 )?
361 .getattr("wrap_with_context_manager")?
362 .into();
363
364 let wrapped_response = fun.call1(py, (response,))?;
365 Ok(wrapped_response.into_bound(py))
366 }
367
368 #[pyo3(signature = (method, url, content=None, data=None, headers=None, timeout=Some(Right(USE_CLIENT_DEFAULT_SENTINEL)), force_http3=false, stream=false))]
369 pub fn request(

Callers 15

test_readMethod · 0.95
test_iter_bytesMethod · 0.95
test_read_after_closeMethod · 0.95
test_two_read_callsMethod · 0.95
test_readMethod · 0.45
test_iter_bytesMethod · 0.45

Calls 1

requestMethod · 0.45

Tested by 15

test_readMethod · 0.76
test_iter_bytesMethod · 0.76
test_read_after_closeMethod · 0.76
test_two_read_callsMethod · 0.76
test_readMethod · 0.36
test_iter_bytesMethod · 0.36
test_read_after_closeMethod · 0.36