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

Method new

impit-python/src/async_client.rs:45–131  ·  view source on GitHub ↗
(
        py: Python<'_>,
        browser: Option<String>,
        http3: Option<bool>,
        proxy: Option<String>,
        timeout: Option<Either<f64, &str>>,
        verify: Option<bool>,
       

Source from the content-addressed store, hash-verified

43 #[new]
44 #[pyo3(signature = (browser=None, http3=None, proxy=None, timeout=Some(Right(USE_CLIENT_DEFAULT_SENTINEL)), verify=None, default_encoding=None, follow_redirects=None, max_redirects=Some(20), cookie_jar=None, cookies=None, headers=None, local_address=None))]
45 pub fn new(
46 py: Python<'_>,
47 browser: Option<String>,
48 http3: Option<bool>,
49 proxy: Option<String>,
50 timeout: Option<Either<f64, &str>>,
51 verify: Option<bool>,
52 default_encoding: Option<String>,
53 follow_redirects: Option<bool>,
54 max_redirects: Option<u16>,
55 cookie_jar: Option<crate::Bound<'_, crate::PyAny>>,
56 cookies: Option<crate::Bound<'_, crate::PyAny>>,
57 headers: Option<HashMap<String, String>>,
58 local_address: Option<String>,
59 ) -> PyResult<Self> {
60 let builder = ImpitBuilder::default();
61
62 let builder = match browser {
63 Some(browser) => {
64 builder.with_fingerprint(crate::fingerprint::fingerprint_by_name(&browser)?)
65 }
66 None => builder,
67 };
68
69 let builder = match http3 {
70 Some(true) => builder.with_http3(),
71 _ => builder,
72 };
73
74 let builder = match proxy {
75 Some(proxy) => builder.with_proxy(proxy),
76 None => builder,
77 };
78
79 let builder = match parse_timeout(timeout)? {
80 Some(Some(d)) => builder.with_default_timeout(d),
81 Some(None) => builder.with_default_timeout(Duration::MAX),
82 None => builder,
83 };
84
85 let builder = match verify {
86 Some(false) => builder.with_ignore_tls_errors(true),
87 _ => builder,
88 };
89
90 let builder = match follow_redirects {
91 Some(true) => builder.with_redirect(impit::impit::RedirectBehavior::FollowRedirect(
92 max_redirects.unwrap_or(20).into(),
93 )),
94 _ => builder.with_redirect(impit::impit::RedirectBehavior::ManualRedirect),
95 };
96
97 let builder = match (cookie_jar, cookies) {
98 (Some(_), Some(_)) => {
99 return Err(PyErr::new::<pyo3::exceptions::PyValueError, _>(
100 "Both cookie_jar and cookies cannot be provided at the same time",
101 ));
102 }

Callers

nothing calls this directly

Calls 12

fingerprint_by_nameFunction · 0.85
parse_timeoutFunction · 0.85
with_proxyMethod · 0.80
with_default_timeoutMethod · 0.80
with_redirectMethod · 0.80
with_cookie_storeMethod · 0.80
with_headersMethod · 0.80
with_local_addressMethod · 0.80
with_fingerprintMethod · 0.45
with_http3Method · 0.45
buildMethod · 0.45

Tested by

no test coverage detected