Prepares the given HTTP auth data.
(
self,
auth: _t.AuthType,
url: _t.UriType = "",
)
| 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 |
no test coverage detected