| 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( |