MCPcopy
hub / github.com/psf/requests / prepare_auth

Method prepare_auth

src/requests/models.py:668–695  ·  view source on GitHub ↗

Prepares the given HTTP auth data.

(
        self,
        auth: _t.AuthType,
        url: _t.UriType = "",
    )

Source from the content-addressed store, hash-verified

666 self.headers["Content-Length"] = "0"
667
668 def prepare_auth(
669 self,
670 auth: _t.AuthType,
671 url: _t.UriType = "",
672 ) -> None:
673 """Prepares the given HTTP auth data."""
674
675 # If no Auth is explicitly provided, extract it from the URL first.
676 if auth is None:
677 url_auth = get_auth_from_url(cast(str, self.url))
678 auth = url_auth if any(url_auth) else None
679
680 if auth:
681 if isinstance(auth, tuple) and len(auth) == 2: # type: ignore[arg-type] # pyright widens tuple from Callable in AuthType
682 # special-case basic HTTP auth
683 auth_handler = HTTPBasicAuth(*auth) # type: ignore[arg-type] # pyright widens tuple from Callable in AuthType
684 else:
685 # TODO: can be fixed by flipping the conditionals
686 auth_handler = cast("Callable[..., PreparedRequest]", auth)
687
688 # Allow auth to make its changes.
689 r = auth_handler(self)
690
691 # Update self to reflect the auth changes.
692 self.__dict__.update(r.__dict__)
693
694 # Recompute Content-Length
695 self.prepare_content_length(self.body)
696
697 def prepare_cookies(
698 self, cookies: RequestsCookieJar | CookieJar | dict[str, str] | None

Callers 2

prepareMethod · 0.95
rebuild_authMethod · 0.80

Calls 4

get_auth_from_urlFunction · 0.85
HTTPBasicAuthClass · 0.85
updateMethod · 0.80

Tested by

no test coverage detected