code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def _ip_address(request): """Return the IpAddress object for the remote address from the environment.""" remote_inet = type_coerce(request.remote_addr, INET) try: ip_address = request.db.query(IpAddress).filter_by(ip_address=remote_inet).one() except NoResultFound: ip_address = IpAddress...
Return the IpAddress object for the remote address from the environment.
_ip_address
python
pypi/warehouse
warehouse/utils/wsgi.py
https://github.com/pypi/warehouse/blob/master/warehouse/utils/wsgi.py
Apache-2.0
def orm_session_from_obj(obj) -> Session: """ Returns the session from the ORM object. Adds guard, but it should never happen. The guard helps with type hinting, as the object_session function returns Optional[Session] type. """ session = object_session(obj) if not session: rais...
Returns the session from the ORM object. Adds guard, but it should never happen. The guard helps with type hinting, as the object_session function returns Optional[Session] type.
orm_session_from_obj
python
pypi/warehouse
warehouse/utils/db/orm.py
https://github.com/pypi/warehouse/blob/master/warehouse/utils/db/orm.py
Apache-2.0
def print_query(query) -> None: """ Prints the query with the parameters embedded into the query. Useful for development/debugging purposes. """ logging.debug( str( query.compile( dialect=postgresql.dialect(), compile_kwargs={"literal_binds": True...
Prints the query with the parameters embedded into the query. Useful for development/debugging purposes.
print_query
python
pypi/warehouse
warehouse/utils/db/query_printer.py
https://github.com/pypi/warehouse/blob/master/warehouse/utils/db/query_printer.py
Apache-2.0
def request( method: str, url: URL | str, *, params: QueryParamTypes | None = None, content: RequestContent | None = None, data: RequestData | None = None, files: RequestFiles | None = None, json: typing.Any | None = None, headers: HeaderTypes | None = None, cookies: CookieTypes ...
Sends an HTTP request. **Parameters:** * **method** - HTTP method for the new `Request` object: `GET`, `OPTIONS`, `HEAD`, `POST`, `PUT`, `PATCH`, or `DELETE`. * **url** - URL for the new `Request` object. * **params** - *(optional)* Query parameters to include in the URL, as a string, dic...
request
python
encode/httpx
httpx/_api.py
https://github.com/encode/httpx/blob/master/httpx/_api.py
BSD-3-Clause
def stream( method: str, url: URL | str, *, params: QueryParamTypes | None = None, content: RequestContent | None = None, data: RequestData | None = None, files: RequestFiles | None = None, json: typing.Any | None = None, headers: HeaderTypes | None = None, cookies: CookieTypes |...
Alternative to `httpx.request()` that streams the response body instead of loading it into memory at once. **Parameters**: See `httpx.request`. See also: [Streaming Responses][0] [0]: /quickstart#streaming-responses
stream
python
encode/httpx
httpx/_api.py
https://github.com/encode/httpx/blob/master/httpx/_api.py
BSD-3-Clause
def get( url: URL | str, *, params: QueryParamTypes | None = None, headers: HeaderTypes | None = None, cookies: CookieTypes | None = None, auth: AuthTypes | None = None, proxy: ProxyTypes | None = None, follow_redirects: bool = False, verify: ssl.SSLContext | str | bool = True, t...
Sends a `GET` request. **Parameters**: See `httpx.request`. Note that the `data`, `files`, `json` and `content` parameters are not available on this function, as `GET` requests should not include a request body.
get
python
encode/httpx
httpx/_api.py
https://github.com/encode/httpx/blob/master/httpx/_api.py
BSD-3-Clause
def options( url: URL | str, *, params: QueryParamTypes | None = None, headers: HeaderTypes | None = None, cookies: CookieTypes | None = None, auth: AuthTypes | None = None, proxy: ProxyTypes | None = None, follow_redirects: bool = False, verify: ssl.SSLContext | str | bool = True, ...
Sends an `OPTIONS` request. **Parameters**: See `httpx.request`. Note that the `data`, `files`, `json` and `content` parameters are not available on this function, as `OPTIONS` requests should not include a request body.
options
python
encode/httpx
httpx/_api.py
https://github.com/encode/httpx/blob/master/httpx/_api.py
BSD-3-Clause
def head( url: URL | str, *, params: QueryParamTypes | None = None, headers: HeaderTypes | None = None, cookies: CookieTypes | None = None, auth: AuthTypes | None = None, proxy: ProxyTypes | None = None, follow_redirects: bool = False, verify: ssl.SSLContext | str | bool = True, ...
Sends a `HEAD` request. **Parameters**: See `httpx.request`. Note that the `data`, `files`, `json` and `content` parameters are not available on this function, as `HEAD` requests should not include a request body.
head
python
encode/httpx
httpx/_api.py
https://github.com/encode/httpx/blob/master/httpx/_api.py
BSD-3-Clause
def post( url: URL | str, *, content: RequestContent | None = None, data: RequestData | None = None, files: RequestFiles | None = None, json: typing.Any | None = None, params: QueryParamTypes | None = None, headers: HeaderTypes | None = None, cookies: CookieTypes | None = None, a...
Sends a `POST` request. **Parameters**: See `httpx.request`.
post
python
encode/httpx
httpx/_api.py
https://github.com/encode/httpx/blob/master/httpx/_api.py
BSD-3-Clause
def put( url: URL | str, *, content: RequestContent | None = None, data: RequestData | None = None, files: RequestFiles | None = None, json: typing.Any | None = None, params: QueryParamTypes | None = None, headers: HeaderTypes | None = None, cookies: CookieTypes | None = None, au...
Sends a `PUT` request. **Parameters**: See `httpx.request`.
put
python
encode/httpx
httpx/_api.py
https://github.com/encode/httpx/blob/master/httpx/_api.py
BSD-3-Clause
def patch( url: URL | str, *, content: RequestContent | None = None, data: RequestData | None = None, files: RequestFiles | None = None, json: typing.Any | None = None, params: QueryParamTypes | None = None, headers: HeaderTypes | None = None, cookies: CookieTypes | None = None, ...
Sends a `PATCH` request. **Parameters**: See `httpx.request`.
patch
python
encode/httpx
httpx/_api.py
https://github.com/encode/httpx/blob/master/httpx/_api.py
BSD-3-Clause
def delete( url: URL | str, *, params: QueryParamTypes | None = None, headers: HeaderTypes | None = None, cookies: CookieTypes | None = None, auth: AuthTypes | None = None, proxy: ProxyTypes | None = None, follow_redirects: bool = False, timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG...
Sends a `DELETE` request. **Parameters**: See `httpx.request`. Note that the `data`, `files`, `json` and `content` parameters are not available on this function, as `DELETE` requests should not include a request body.
delete
python
encode/httpx
httpx/_api.py
https://github.com/encode/httpx/blob/master/httpx/_api.py
BSD-3-Clause
def _parse_challenge( self, request: Request, response: Response, auth_header: str ) -> _DigestAuthChallenge: """ Returns a challenge from a Digest WWW-Authenticate header. These take the form of: `Digest realm="realm@host.com",qop="auth,auth-int",nonce="abc",opaque="xyz"` ...
Returns a challenge from a Digest WWW-Authenticate header. These take the form of: `Digest realm="realm@host.com",qop="auth,auth-int",nonce="abc",opaque="xyz"`
_parse_challenge
python
encode/httpx
httpx/_auth.py
https://github.com/encode/httpx/blob/master/httpx/_auth.py
BSD-3-Clause
def _is_https_redirect(url: URL, location: URL) -> bool: """ Return 'True' if 'location' is a HTTPS upgrade of 'url' """ if url.host != location.host: return False return ( url.scheme == "http" and _port_or_default(url) == 80 and location.scheme == "https" an...
Return 'True' if 'location' is a HTTPS upgrade of 'url'
_is_https_redirect
python
encode/httpx
httpx/_client.py
https://github.com/encode/httpx/blob/master/httpx/_client.py
BSD-3-Clause
def _same_origin(url: URL, other: URL) -> bool: """ Return 'True' if the given URLs share the same origin. """ return ( url.scheme == other.scheme and url.host == other.host and _port_or_default(url) == _port_or_default(other) )
Return 'True' if the given URLs share the same origin.
_same_origin
python
encode/httpx
httpx/_client.py
https://github.com/encode/httpx/blob/master/httpx/_client.py
BSD-3-Clause
def build_request( self, method: str, url: URL | str, *, content: RequestContent | None = None, data: RequestData | None = None, files: RequestFiles | None = None, json: typing.Any | None = None, params: QueryParamTypes | None = None, heade...
Build and return a request instance. * The `params`, `headers` and `cookies` arguments are merged with any values set on the client. * The `url` argument is merged with any `base_url` set on the client. See also: [Request instances][0] [0]: /advanced/clients/#request-...
build_request
python
encode/httpx
httpx/_client.py
https://github.com/encode/httpx/blob/master/httpx/_client.py
BSD-3-Clause
def _merge_cookies(self, cookies: CookieTypes | None = None) -> CookieTypes | None: """ Merge a cookies argument together with any cookies on the client, to create the cookies used for the outgoing request. """ if cookies or self.cookies: merged_cookies = Cookies(self...
Merge a cookies argument together with any cookies on the client, to create the cookies used for the outgoing request.
_merge_cookies
python
encode/httpx
httpx/_client.py
https://github.com/encode/httpx/blob/master/httpx/_client.py
BSD-3-Clause
def _merge_headers(self, headers: HeaderTypes | None = None) -> HeaderTypes | None: """ Merge a headers argument together with any headers on the client, to create the headers used for the outgoing request. """ merged_headers = Headers(self.headers) merged_headers.update(...
Merge a headers argument together with any headers on the client, to create the headers used for the outgoing request.
_merge_headers
python
encode/httpx
httpx/_client.py
https://github.com/encode/httpx/blob/master/httpx/_client.py
BSD-3-Clause
def _merge_queryparams( self, params: QueryParamTypes | None = None ) -> QueryParamTypes | None: """ Merge a queryparams argument together with any queryparams on the client, to create the queryparams used for the outgoing request. """ if params or self.params: ...
Merge a queryparams argument together with any queryparams on the client, to create the queryparams used for the outgoing request.
_merge_queryparams
python
encode/httpx
httpx/_client.py
https://github.com/encode/httpx/blob/master/httpx/_client.py
BSD-3-Clause
def _build_redirect_request(self, request: Request, response: Response) -> Request: """ Given a request and a redirect response, return a new request that should be used to effect the redirect. """ method = self._redirect_method(request, response) url = self._redirect_url...
Given a request and a redirect response, return a new request that should be used to effect the redirect.
_build_redirect_request
python
encode/httpx
httpx/_client.py
https://github.com/encode/httpx/blob/master/httpx/_client.py
BSD-3-Clause
def _redirect_method(self, request: Request, response: Response) -> str: """ When being redirected we may want to change the method of the request based on certain specs or browser behavior. """ method = request.method # https://tools.ietf.org/html/rfc7231#section-6.4.4 ...
When being redirected we may want to change the method of the request based on certain specs or browser behavior.
_redirect_method
python
encode/httpx
httpx/_client.py
https://github.com/encode/httpx/blob/master/httpx/_client.py
BSD-3-Clause
def _redirect_url(self, request: Request, response: Response) -> URL: """ Return the URL for the redirect to follow. """ location = response.headers["Location"] try: url = URL(location) except InvalidURL as exc: raise RemoteProtocolError( ...
Return the URL for the redirect to follow.
_redirect_url
python
encode/httpx
httpx/_client.py
https://github.com/encode/httpx/blob/master/httpx/_client.py
BSD-3-Clause
def _redirect_headers(self, request: Request, url: URL, method: str) -> Headers: """ Return the headers that should be used for the redirect request. """ headers = Headers(request.headers) if not _same_origin(url, request.url): if not _is_https_redirect(request.url, ...
Return the headers that should be used for the redirect request.
_redirect_headers
python
encode/httpx
httpx/_client.py
https://github.com/encode/httpx/blob/master/httpx/_client.py
BSD-3-Clause
def _redirect_stream( self, request: Request, method: str ) -> SyncByteStream | AsyncByteStream | None: """ Return the body that should be used for the redirect request. """ if method != request.method and method == "GET": return None return request.strea...
Return the body that should be used for the redirect request.
_redirect_stream
python
encode/httpx
httpx/_client.py
https://github.com/encode/httpx/blob/master/httpx/_client.py
BSD-3-Clause
def _transport_for_url(self, url: URL) -> BaseTransport: """ Returns the transport instance that should be used for a given URL. This will either be the standard connection pool, or a proxy. """ for pattern, transport in self._mounts.items(): if pattern.matches(url): ...
Returns the transport instance that should be used for a given URL. This will either be the standard connection pool, or a proxy.
_transport_for_url
python
encode/httpx
httpx/_client.py
https://github.com/encode/httpx/blob/master/httpx/_client.py
BSD-3-Clause
def request( self, method: str, url: URL | str, *, content: RequestContent | None = None, data: RequestData | None = None, files: RequestFiles | None = None, json: typing.Any | None = None, params: QueryParamTypes | None = None, headers: He...
Build and send a request. Equivalent to: ```python request = client.build_request(...) response = client.send(request, ...) ``` See `Client.build_request()`, `Client.send()` and [Merging of configuration][0] for how the various parameters are m...
request
python
encode/httpx
httpx/_client.py
https://github.com/encode/httpx/blob/master/httpx/_client.py
BSD-3-Clause
def stream( self, method: str, url: URL | str, *, content: RequestContent | None = None, data: RequestData | None = None, files: RequestFiles | None = None, json: typing.Any | None = None, params: QueryParamTypes | None = None, headers: Hea...
Alternative to `httpx.request()` that streams the response body instead of loading it into memory at once. **Parameters**: See `httpx.request`. See also: [Streaming Responses][0] [0]: /quickstart#streaming-responses
stream
python
encode/httpx
httpx/_client.py
https://github.com/encode/httpx/blob/master/httpx/_client.py
BSD-3-Clause
def send( self, request: Request, *, stream: bool = False, auth: AuthTypes | UseClientDefault | None = USE_CLIENT_DEFAULT, follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT, ) -> Response: """ Send a request. The request is sent a...
Send a request. The request is sent as-is, unmodified. Typically you'll want to build one with `Client.build_request()` so that any client-level configuration is merged into the request, but passing an explicit `httpx.Request()` is supported as well. See also: [Reques...
send
python
encode/httpx
httpx/_client.py
https://github.com/encode/httpx/blob/master/httpx/_client.py
BSD-3-Clause
def _send_single_request(self, request: Request) -> Response: """ Sends a single request, without handling any redirections. """ transport = self._transport_for_url(request.url) start = time.perf_counter() if not isinstance(request.stream, SyncByteStream): ra...
Sends a single request, without handling any redirections.
_send_single_request
python
encode/httpx
httpx/_client.py
https://github.com/encode/httpx/blob/master/httpx/_client.py
BSD-3-Clause
def get( self, url: URL | str, *, params: QueryParamTypes | None = None, headers: HeaderTypes | None = None, cookies: CookieTypes | None = None, auth: AuthTypes | UseClientDefault | None = USE_CLIENT_DEFAULT, follow_redirects: bool | UseClientDefault = USE...
Send a `GET` request. **Parameters**: See `httpx.request`.
get
python
encode/httpx
httpx/_client.py
https://github.com/encode/httpx/blob/master/httpx/_client.py
BSD-3-Clause
def options( self, url: URL | str, *, params: QueryParamTypes | None = None, headers: HeaderTypes | None = None, cookies: CookieTypes | None = None, auth: AuthTypes | UseClientDefault = USE_CLIENT_DEFAULT, follow_redirects: bool | UseClientDefault = USE_CL...
Send an `OPTIONS` request. **Parameters**: See `httpx.request`.
options
python
encode/httpx
httpx/_client.py
https://github.com/encode/httpx/blob/master/httpx/_client.py
BSD-3-Clause
def head( self, url: URL | str, *, params: QueryParamTypes | None = None, headers: HeaderTypes | None = None, cookies: CookieTypes | None = None, auth: AuthTypes | UseClientDefault = USE_CLIENT_DEFAULT, follow_redirects: bool | UseClientDefault = USE_CLIEN...
Send a `HEAD` request. **Parameters**: See `httpx.request`.
head
python
encode/httpx
httpx/_client.py
https://github.com/encode/httpx/blob/master/httpx/_client.py
BSD-3-Clause
def post( self, url: URL | str, *, content: RequestContent | None = None, data: RequestData | None = None, files: RequestFiles | None = None, json: typing.Any | None = None, params: QueryParamTypes | None = None, headers: HeaderTypes | None = None,...
Send a `POST` request. **Parameters**: See `httpx.request`.
post
python
encode/httpx
httpx/_client.py
https://github.com/encode/httpx/blob/master/httpx/_client.py
BSD-3-Clause
def put( self, url: URL | str, *, content: RequestContent | None = None, data: RequestData | None = None, files: RequestFiles | None = None, json: typing.Any | None = None, params: QueryParamTypes | None = None, headers: HeaderTypes | None = None, ...
Send a `PUT` request. **Parameters**: See `httpx.request`.
put
python
encode/httpx
httpx/_client.py
https://github.com/encode/httpx/blob/master/httpx/_client.py
BSD-3-Clause
def patch( self, url: URL | str, *, content: RequestContent | None = None, data: RequestData | None = None, files: RequestFiles | None = None, json: typing.Any | None = None, params: QueryParamTypes | None = None, headers: HeaderTypes | None = None...
Send a `PATCH` request. **Parameters**: See `httpx.request`.
patch
python
encode/httpx
httpx/_client.py
https://github.com/encode/httpx/blob/master/httpx/_client.py
BSD-3-Clause
def delete( self, url: URL | str, *, params: QueryParamTypes | None = None, headers: HeaderTypes | None = None, cookies: CookieTypes | None = None, auth: AuthTypes | UseClientDefault = USE_CLIENT_DEFAULT, follow_redirects: bool | UseClientDefault = USE_CLI...
Send a `DELETE` request. **Parameters**: See `httpx.request`.
delete
python
encode/httpx
httpx/_client.py
https://github.com/encode/httpx/blob/master/httpx/_client.py
BSD-3-Clause
async def request( self, method: str, url: URL | str, *, content: RequestContent | None = None, data: RequestData | None = None, files: RequestFiles | None = None, json: typing.Any | None = None, params: QueryParamTypes | None = None, heade...
Build and send a request. Equivalent to: ```python request = client.build_request(...) response = await client.send(request, ...) ``` See `AsyncClient.build_request()`, `AsyncClient.send()` and [Merging of configuration][0] for how the various paramete...
request
python
encode/httpx
httpx/_client.py
https://github.com/encode/httpx/blob/master/httpx/_client.py
BSD-3-Clause
async def send( self, request: Request, *, stream: bool = False, auth: AuthTypes | UseClientDefault | None = USE_CLIENT_DEFAULT, follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT, ) -> Response: """ Send a request. The request is ...
Send a request. The request is sent as-is, unmodified. Typically you'll want to build one with `AsyncClient.build_request()` so that any client-level configuration is merged into the request, but passing an explicit `httpx.Request()` is supported as well. See also: [R...
send
python
encode/httpx
httpx/_client.py
https://github.com/encode/httpx/blob/master/httpx/_client.py
BSD-3-Clause
def encode_request( content: RequestContent | None = None, data: RequestData | None = None, files: RequestFiles | None = None, json: Any | None = None, boundary: bytes | None = None, ) -> tuple[dict[str, str], SyncByteStream | AsyncByteStream]: """ Handles encoding the given `content`, `data...
Handles encoding the given `content`, `data`, `files`, and `json`, returning a two-tuple of (<headers>, <stream>).
encode_request
python
encode/httpx
httpx/_content.py
https://github.com/encode/httpx/blob/master/httpx/_content.py
BSD-3-Clause
def encode_response( content: ResponseContent | None = None, text: str | None = None, html: str | None = None, json: Any | None = None, ) -> tuple[dict[str, str], SyncByteStream | AsyncByteStream]: """ Handles encoding the given `content`, returning a two-tuple of (<headers>, <stream>). ...
Handles encoding the given `content`, returning a two-tuple of (<headers>, <stream>).
encode_response
python
encode/httpx
httpx/_content.py
https://github.com/encode/httpx/blob/master/httpx/_content.py
BSD-3-Clause
def __init__(self, children: typing.Sequence[ContentDecoder]) -> None: """ 'children' should be a sequence of decoders in the order in which each was applied. """ # Note that we reverse the order for decoding. self.children = list(reversed(children))
'children' should be a sequence of decoders in the order in which each was applied.
__init__
python
encode/httpx
httpx/_decoders.py
https://github.com/encode/httpx/blob/master/httpx/_decoders.py
BSD-3-Clause
def request_context( request: Request | None = None, ) -> typing.Iterator[None]: """ A context manager that can be used to attach the given request context to any `RequestError` exceptions that are raised within the block. """ try: yield except RequestError as exc: if request...
A context manager that can be used to attach the given request context to any `RequestError` exceptions that are raised within the block.
request_context
python
encode/httpx
httpx/_exceptions.py
https://github.com/encode/httpx/blob/master/httpx/_exceptions.py
BSD-3-Clause
def main( url: str, method: str, params: list[tuple[str, str]], content: str, data: list[tuple[str, str]], files: list[tuple[str, click.File]], json: str, headers: list[tuple[str, str]], cookies: list[tuple[str, str]], auth: tuple[str, str] | None, proxy: str, timeout: fl...
An HTTP command line client. Sends a request and displays the response.
main
python
encode/httpx
httpx/_main.py
https://github.com/encode/httpx/blob/master/httpx/_main.py
BSD-3-Clause
def _is_known_encoding(encoding: str) -> bool: """ Return `True` if `encoding` is a known codec. """ try: codecs.lookup(encoding) except LookupError: return False return True
Return `True` if `encoding` is a known codec.
_is_known_encoding
python
encode/httpx
httpx/_models.py
https://github.com/encode/httpx/blob/master/httpx/_models.py
BSD-3-Clause
def __getitem__(self, key: str) -> str: """ Return a single header value. If there are multiple headers with the same key, then we concatenate them with commas. See: https://tools.ietf.org/html/rfc7230#section-3.2.2 """ normalized_key = key.lower().encode(self.encoding) ...
Return a single header value. If there are multiple headers with the same key, then we concatenate them with commas. See: https://tools.ietf.org/html/rfc7230#section-3.2.2
__getitem__
python
encode/httpx
httpx/_models.py
https://github.com/encode/httpx/blob/master/httpx/_models.py
BSD-3-Clause
def read(self) -> bytes: """ Read and return the request content. """ if not hasattr(self, "_content"): assert isinstance(self.stream, typing.Iterable) self._content = b"".join(self.stream) if not isinstance(self.stream, ByteStream): # ...
Read and return the request content.
read
python
encode/httpx
httpx/_models.py
https://github.com/encode/httpx/blob/master/httpx/_models.py
BSD-3-Clause
def elapsed(self) -> datetime.timedelta: """ Returns the time taken for the complete request/response cycle to complete. """ if not hasattr(self, "_elapsed"): raise RuntimeError( "'.elapsed' may only be accessed after the response " "ha...
Returns the time taken for the complete request/response cycle to complete.
elapsed
python
encode/httpx
httpx/_models.py
https://github.com/encode/httpx/blob/master/httpx/_models.py
BSD-3-Clause
def request(self) -> Request: """ Returns the request instance associated to the current response. """ if self._request is None: raise RuntimeError( "The request instance has not been set on this response." ) return self._request
Returns the request instance associated to the current response.
request
python
encode/httpx
httpx/_models.py
https://github.com/encode/httpx/blob/master/httpx/_models.py
BSD-3-Clause
def encoding(self) -> str | None: """ Return an encoding to use for decoding the byte content into text. The priority for determining this is given by... * `.encoding = <>` has been set explicitly. * The encoding as specified by the charset parameter in the Content-Type header. ...
Return an encoding to use for decoding the byte content into text. The priority for determining this is given by... * `.encoding = <>` has been set explicitly. * The encoding as specified by the charset parameter in the Content-Type header. * The encoding as determined by `defa...
encoding
python
encode/httpx
httpx/_models.py
https://github.com/encode/httpx/blob/master/httpx/_models.py
BSD-3-Clause
def encoding(self, value: str) -> None: """ Set the encoding to use for decoding the byte content into text. If the `text` attribute has been accessed, attempting to set the encoding will throw a ValueError. """ if hasattr(self, "_text"): raise ValueError( ...
Set the encoding to use for decoding the byte content into text. If the `text` attribute has been accessed, attempting to set the encoding will throw a ValueError.
encoding
python
encode/httpx
httpx/_models.py
https://github.com/encode/httpx/blob/master/httpx/_models.py
BSD-3-Clause
def charset_encoding(self) -> str | None: """ Return the encoding, as specified by the Content-Type header. """ content_type = self.headers.get("Content-Type") if content_type is None: return None return _parse_content_type_charset(content_type)
Return the encoding, as specified by the Content-Type header.
charset_encoding
python
encode/httpx
httpx/_models.py
https://github.com/encode/httpx/blob/master/httpx/_models.py
BSD-3-Clause
def _get_content_decoder(self) -> ContentDecoder: """ Returns a decoder instance which can be used to decode the raw byte content, depending on the Content-Encoding used in the response. """ if not hasattr(self, "_decoder"): decoders: list[ContentDecoder] = [] ...
Returns a decoder instance which can be used to decode the raw byte content, depending on the Content-Encoding used in the response.
_get_content_decoder
python
encode/httpx
httpx/_models.py
https://github.com/encode/httpx/blob/master/httpx/_models.py
BSD-3-Clause
def has_redirect_location(self) -> bool: """ Returns True for 3xx responses with a properly formed URL redirection, `False` otherwise. """ return ( self.status_code in ( # 301 (Cacheable redirect. Method may change to GET.) ...
Returns True for 3xx responses with a properly formed URL redirection, `False` otherwise.
has_redirect_location
python
encode/httpx
httpx/_models.py
https://github.com/encode/httpx/blob/master/httpx/_models.py
BSD-3-Clause
def raise_for_status(self) -> Response: """ Raise the `HTTPStatusError` if one occurred. """ request = self._request if request is None: raise RuntimeError( "Cannot call `raise_for_status` as the request " "instance has not been set on ...
Raise the `HTTPStatusError` if one occurred.
raise_for_status
python
encode/httpx
httpx/_models.py
https://github.com/encode/httpx/blob/master/httpx/_models.py
BSD-3-Clause
def links(self) -> dict[str | None, dict[str, str]]: """ Returns the parsed header links of the response, if any """ header = self.headers.get("link") if header is None: return {} return { (link.get("rel") or link.get("url")): link for...
Returns the parsed header links of the response, if any
links
python
encode/httpx
httpx/_models.py
https://github.com/encode/httpx/blob/master/httpx/_models.py
BSD-3-Clause
def read(self) -> bytes: """ Read and return the response content. """ if not hasattr(self, "_content"): self._content = b"".join(self.iter_bytes()) return self._content
Read and return the response content.
read
python
encode/httpx
httpx/_models.py
https://github.com/encode/httpx/blob/master/httpx/_models.py
BSD-3-Clause
def iter_bytes(self, chunk_size: int | None = None) -> typing.Iterator[bytes]: """ A byte-iterator over the decoded response content. This allows us to handle gzip, deflate, brotli, and zstd encoded responses. """ if hasattr(self, "_content"): chunk_size = len(self._c...
A byte-iterator over the decoded response content. This allows us to handle gzip, deflate, brotli, and zstd encoded responses.
iter_bytes
python
encode/httpx
httpx/_models.py
https://github.com/encode/httpx/blob/master/httpx/_models.py
BSD-3-Clause
def iter_text(self, chunk_size: int | None = None) -> typing.Iterator[str]: """ A str-iterator over the decoded response content that handles both gzip, deflate, etc but also detects the content's string encoding. """ decoder = TextDecoder(encoding=self.encoding or "utf-8...
A str-iterator over the decoded response content that handles both gzip, deflate, etc but also detects the content's string encoding.
iter_text
python
encode/httpx
httpx/_models.py
https://github.com/encode/httpx/blob/master/httpx/_models.py
BSD-3-Clause
def iter_raw(self, chunk_size: int | None = None) -> typing.Iterator[bytes]: """ A byte-iterator over the raw response content. """ if self.is_stream_consumed: raise StreamConsumed() if self.is_closed: raise StreamClosed() if not isinstance(self.st...
A byte-iterator over the raw response content.
iter_raw
python
encode/httpx
httpx/_models.py
https://github.com/encode/httpx/blob/master/httpx/_models.py
BSD-3-Clause
def close(self) -> None: """ Close the response and release the connection. Automatically called if the response body is read to completion. """ if not isinstance(self.stream, SyncByteStream): raise RuntimeError("Attempted to call a sync close on an async stream.") ...
Close the response and release the connection. Automatically called if the response body is read to completion.
close
python
encode/httpx
httpx/_models.py
https://github.com/encode/httpx/blob/master/httpx/_models.py
BSD-3-Clause
def extract_cookies(self, response: Response) -> None: """ Loads any cookies based on the response `Set-Cookie` headers. """ urllib_response = self._CookieCompatResponse(response) urllib_request = self._CookieCompatRequest(response.request) self.jar.extract_cookies(urlli...
Loads any cookies based on the response `Set-Cookie` headers.
extract_cookies
python
encode/httpx
httpx/_models.py
https://github.com/encode/httpx/blob/master/httpx/_models.py
BSD-3-Clause
def _format_form_param(name: str, value: str) -> bytes: """ Encode a name/value pair within a multipart form. """ def replacer(match: typing.Match[str]) -> str: return _HTML5_FORM_ENCODING_REPLACEMENTS[match.group(0)] value = _HTML5_FORM_ENCODING_RE.sub(replacer, value) return f'{name}...
Encode a name/value pair within a multipart form.
_format_form_param
python
encode/httpx
httpx/_multipart.py
https://github.com/encode/httpx/blob/master/httpx/_multipart.py
BSD-3-Clause
def _guess_content_type(filename: str | None) -> str | None: """ Guesses the mimetype based on a filename. Defaults to `application/octet-stream`. Returns `None` if `filename` is `None` or empty. """ if filename: return mimetypes.guess_type(filename)[0] or "application/octet-stream" ret...
Guesses the mimetype based on a filename. Defaults to `application/octet-stream`. Returns `None` if `filename` is `None` or empty.
_guess_content_type
python
encode/httpx
httpx/_multipart.py
https://github.com/encode/httpx/blob/master/httpx/_multipart.py
BSD-3-Clause
def get_content_length(self) -> int | None: """ Return the length of the multipart encoded content, or `None` if any of the files have a length that cannot be determined upfront. """ boundary_length = len(self.boundary) length = 0 for field in self.fields: ...
Return the length of the multipart encoded content, or `None` if any of the files have a length that cannot be determined upfront.
get_content_length
python
encode/httpx
httpx/_multipart.py
https://github.com/encode/httpx/blob/master/httpx/_multipart.py
BSD-3-Clause
def close(self) -> None: """ Subclasses can override this method to release any network resources after a request/response cycle is complete. """
Subclasses can override this method to release any network resources after a request/response cycle is complete.
close
python
encode/httpx
httpx/_types.py
https://github.com/encode/httpx/blob/master/httpx/_types.py
BSD-3-Clause
def validate_path(path: str, has_scheme: bool, has_authority: bool) -> None: """ Path validation rules that depend on if the URL contains a scheme or authority component. See https://datatracker.ietf.org/doc/html/rfc3986.html#section-3.3 """ if has_authority: # If a URI contains an auth...
Path validation rules that depend on if the URL contains a scheme or authority component. See https://datatracker.ietf.org/doc/html/rfc3986.html#section-3.3
validate_path
python
encode/httpx
httpx/_urlparse.py
https://github.com/encode/httpx/blob/master/httpx/_urlparse.py
BSD-3-Clause
def normalize_path(path: str) -> str: """ Drop "." and ".." segments from a URL path. For example: normalize_path("/path/./to/somewhere/..") == "/path/to" """ # Fast return when no '.' characters in the path. if "." not in path: return path components = path.split("/") ...
Drop "." and ".." segments from a URL path. For example: normalize_path("/path/./to/somewhere/..") == "/path/to"
normalize_path
python
encode/httpx
httpx/_urlparse.py
https://github.com/encode/httpx/blob/master/httpx/_urlparse.py
BSD-3-Clause
def percent_encoded(string: str, safe: str) -> str: """ Use percent-encoding to quote a string. """ NON_ESCAPED_CHARS = UNRESERVED_CHARACTERS + safe # Fast path for strings that don't need escaping. if not string.rstrip(NON_ESCAPED_CHARS): return string return "".join( [cha...
Use percent-encoding to quote a string.
percent_encoded
python
encode/httpx
httpx/_urlparse.py
https://github.com/encode/httpx/blob/master/httpx/_urlparse.py
BSD-3-Clause
def raw_path(self) -> bytes: """ The complete URL path and query string as raw bytes. Used as the target when constructing HTTP requests. For example: GET /users?search=some%20text HTTP/1.1 Host: www.example.org Connection: close """ path = self....
The complete URL path and query string as raw bytes. Used as the target when constructing HTTP requests. For example: GET /users?search=some%20text HTTP/1.1 Host: www.example.org Connection: close
raw_path
python
encode/httpx
httpx/_urls.py
https://github.com/encode/httpx/blob/master/httpx/_urls.py
BSD-3-Clause
def is_absolute_url(self) -> bool: """ Return `True` for absolute URLs such as 'http://example.com/path', and `False` for relative URLs such as '/path'. """ # We don't use `.is_absolute` from `rfc3986` because it treats # URLs with a fragment portion as not absolute. ...
Return `True` for absolute URLs such as 'http://example.com/path', and `False` for relative URLs such as '/path'.
is_absolute_url
python
encode/httpx
httpx/_urls.py
https://github.com/encode/httpx/blob/master/httpx/_urls.py
BSD-3-Clause
def join(self, url: URL | str) -> URL: """ Return an absolute URL, using this URL as the base. Eg. url = httpx.URL("https://www.example.com/test") url = url.join("/new/path") assert url == "https://www.example.com/new/path" """ from urllib.parse import u...
Return an absolute URL, using this URL as the base. Eg. url = httpx.URL("https://www.example.com/test") url = url.join("/new/path") assert url == "https://www.example.com/new/path"
join
python
encode/httpx
httpx/_urls.py
https://github.com/encode/httpx/blob/master/httpx/_urls.py
BSD-3-Clause
def multi_items(self) -> list[tuple[str, str]]: """ Return all items in the query params. Allow duplicate keys to occur. Usage: q = httpx.QueryParams("a=123&a=456&b=789") assert list(q.multi_items()) == [("a", "123"), ("a", "456"), ("b", "789")] """ multi_items:...
Return all items in the query params. Allow duplicate keys to occur. Usage: q = httpx.QueryParams("a=123&a=456&b=789") assert list(q.multi_items()) == [("a", "123"), ("a", "456"), ("b", "789")]
multi_items
python
encode/httpx
httpx/_urls.py
https://github.com/encode/httpx/blob/master/httpx/_urls.py
BSD-3-Clause
def get(self, key: typing.Any, default: typing.Any = None) -> typing.Any: """ Get a value from the query param for a given key. If the key occurs more than once, then only the first value is returned. Usage: q = httpx.QueryParams("a=123&a=456&b=789") assert q.get("a") =...
Get a value from the query param for a given key. If the key occurs more than once, then only the first value is returned. Usage: q = httpx.QueryParams("a=123&a=456&b=789") assert q.get("a") == "123"
get
python
encode/httpx
httpx/_urls.py
https://github.com/encode/httpx/blob/master/httpx/_urls.py
BSD-3-Clause
def set(self, key: str, value: typing.Any = None) -> QueryParams: """ Return a new QueryParams instance, setting the value of a key. Usage: q = httpx.QueryParams("a=123") q = q.set("a", "456") assert q == httpx.QueryParams("a=456") """ q = QueryParams() ...
Return a new QueryParams instance, setting the value of a key. Usage: q = httpx.QueryParams("a=123") q = q.set("a", "456") assert q == httpx.QueryParams("a=456")
set
python
encode/httpx
httpx/_urls.py
https://github.com/encode/httpx/blob/master/httpx/_urls.py
BSD-3-Clause
def add(self, key: str, value: typing.Any = None) -> QueryParams: """ Return a new QueryParams instance, setting or appending the value of a key. Usage: q = httpx.QueryParams("a=123") q = q.add("a", "456") assert q == httpx.QueryParams("a=123&a=456") """ ...
Return a new QueryParams instance, setting or appending the value of a key. Usage: q = httpx.QueryParams("a=123") q = q.add("a", "456") assert q == httpx.QueryParams("a=123&a=456")
add
python
encode/httpx
httpx/_urls.py
https://github.com/encode/httpx/blob/master/httpx/_urls.py
BSD-3-Clause
def remove(self, key: str) -> QueryParams: """ Return a new QueryParams instance, removing the value of a key. Usage: q = httpx.QueryParams("a=123") q = q.remove("a") assert q == httpx.QueryParams("") """ q = QueryParams() q._dict = dict(self._di...
Return a new QueryParams instance, removing the value of a key. Usage: q = httpx.QueryParams("a=123") q = q.remove("a") assert q == httpx.QueryParams("")
remove
python
encode/httpx
httpx/_urls.py
https://github.com/encode/httpx/blob/master/httpx/_urls.py
BSD-3-Clause
def merge(self, params: QueryParamTypes | None = None) -> QueryParams: """ Return a new QueryParams instance, updated with. Usage: q = httpx.QueryParams("a=123") q = q.merge({"b": "456"}) assert q == httpx.QueryParams("a=123&b=456") q = httpx.QueryParams("a=123...
Return a new QueryParams instance, updated with. Usage: q = httpx.QueryParams("a=123") q = q.merge({"b": "456"}) assert q == httpx.QueryParams("a=123&b=456") q = httpx.QueryParams("a=123") q = q.merge({"a": "456", "b": "789"}) assert q == httpx.QueryPa...
merge
python
encode/httpx
httpx/_urls.py
https://github.com/encode/httpx/blob/master/httpx/_urls.py
BSD-3-Clause
def get_environment_proxies() -> dict[str, str | None]: """Gets proxy information from the environment""" # urllib.request.getproxies() falls back on System # Registry and Config for proxies on Windows and macOS. # We don't want to propagate non-HTTP proxies into # our configuration such as 'TRAVIS...
Gets proxy information from the environment
get_environment_proxies
python
encode/httpx
httpx/_utils.py
https://github.com/encode/httpx/blob/master/httpx/_utils.py
BSD-3-Clause
def peek_filelike_length(stream: typing.Any) -> int | None: """ Given a file-like stream object, return its length in number of bytes without reading it into memory. """ try: # Is it an actual file? fd = stream.fileno() # Yup, seems to be an actual file. length = os.f...
Given a file-like stream object, return its length in number of bytes without reading it into memory.
peek_filelike_length
python
encode/httpx
httpx/_utils.py
https://github.com/encode/httpx/blob/master/httpx/_utils.py
BSD-3-Clause
def priority(self) -> tuple[int, int, int]: """ The priority allows URLPattern instances to be sortable, so that we can match from most specific to least specific. """ # URLs with a port should take priority over URLs without a port. port_priority = 0 if self.port is not ...
The priority allows URLPattern instances to be sortable, so that we can match from most specific to least specific.
priority
python
encode/httpx
httpx/_utils.py
https://github.com/encode/httpx/blob/master/httpx/_utils.py
BSD-3-Clause
def handle_request(self, request: Request) -> Response: """ Send a single HTTP request and return a response. Developers shouldn't typically ever need to call into this API directly, since the Client class provides all the higher level user-facing API niceties. In order...
Send a single HTTP request and return a response. Developers shouldn't typically ever need to call into this API directly, since the Client class provides all the higher level user-facing API niceties. In order to properly release any network resources, the response st...
handle_request
python
encode/httpx
httpx/_transports/base.py
https://github.com/encode/httpx/blob/master/httpx/_transports/base.py
BSD-3-Clause
async def test_asgi_raw_path_should_not_include_querystring_portion(): """ See https://github.com/encode/httpx/issues/2810 """ transport = httpx.ASGITransport(app=echo_raw_path) async with httpx.AsyncClient(transport=transport) as client: url = httpx.URL("http://www.example.org/path?query") ...
See https://github.com/encode/httpx/issues/2810
test_asgi_raw_path_should_not_include_querystring_portion
python
encode/httpx
tests/test_asgi.py
https://github.com/encode/httpx/blob/master/tests/test_asgi.py
BSD-3-Clause
def test_deflate(): """ Deflate encoding may use either 'zlib' or 'deflate' in the wild. https://stackoverflow.com/questions/1838699/how-can-i-decompress-a-gzip-stream-with-zlib#answer-22311297 """ body = b"test 123" compressor = zlib.compressobj(9, zlib.DEFLATED, -zlib.MAX_WBITS) compresse...
Deflate encoding may use either 'zlib' or 'deflate' in the wild. https://stackoverflow.com/questions/1838699/how-can-i-decompress-a-gzip-stream-with-zlib#answer-22311297
test_deflate
python
encode/httpx
tests/test_decoders.py
https://github.com/encode/httpx/blob/master/tests/test_decoders.py
BSD-3-Clause
def test_httpcore_all_exceptions_mapped() -> None: """ All exception classes exposed by HTTPCore are properly mapped to an HTTPX-specific exception class. """ expected_mapped_httpcore_exceptions = { value.__name__ for _, value in vars(httpcore).items() if isinstance(value, ty...
All exception classes exposed by HTTPCore are properly mapped to an HTTPX-specific exception class.
test_httpcore_all_exceptions_mapped
python
encode/httpx
tests/test_exceptions.py
https://github.com/encode/httpx/blob/master/tests/test_exceptions.py
BSD-3-Clause
def test_httpcore_exception_mapping(server: TestServer) -> None: """ HTTPCore exception mapping works as expected. """ impossible_port = 123456 with pytest.raises(httpx.ConnectError): httpx.get(server.url.copy_with(port=impossible_port)) with pytest.raises(httpx.ReadTimeout): ht...
HTTPCore exception mapping works as expected.
test_httpcore_exception_mapping
python
encode/httpx
tests/test_exceptions.py
https://github.com/encode/httpx/blob/master/tests/test_exceptions.py
BSD-3-Clause
def test_multipart_headers_include_content_type() -> None: """ Content-Type from 4th tuple parameter (headers) should override the 3rd parameter (content_type) """ file_name = "test.txt" file_content = io.BytesIO(b"<file content>") file_content_type = "text/plain" file_headers = {"Conten...
Content-Type from 4th tuple parameter (headers) should override the 3rd parameter (content_type)
test_multipart_headers_include_content_type
python
encode/httpx
tests/test_multipart.py
https://github.com/encode/httpx/blob/master/tests/test_multipart.py
BSD-3-Clause
def test_multipart_encode_non_seekable_filelike() -> None: """ Test that special readable but non-seekable filelike objects are supported. In this case uploads with use 'Transfer-Encoding: chunked', instead of a 'Content-Length' header. """ class IteratorIO(io.IOBase): def __init__(self...
Test that special readable but non-seekable filelike objects are supported. In this case uploads with use 'Transfer-Encoding: chunked', instead of a 'Content-Length' header.
test_multipart_encode_non_seekable_filelike
python
encode/httpx
tests/test_multipart.py
https://github.com/encode/httpx/blob/master/tests/test_multipart.py
BSD-3-Clause
def test_wsgi_server_port(url: str, expected_server_port: str) -> None: """ SERVER_PORT is populated correctly from the requested URL. """ hello_world_app = application_factory([b"Hello, World!"]) server_port: str | None = None def app(environ, start_response): nonlocal server_port ...
SERVER_PORT is populated correctly from the requested URL.
test_wsgi_server_port
python
encode/httpx
tests/test_wsgi.py
https://github.com/encode/httpx/blob/master/tests/test_wsgi.py
BSD-3-Clause
async def test_cancellation_during_stream(): """ If any BaseException is raised during streaming the response, then the stream should be closed. This includes: * `asyncio.CancelledError` (A subclass of BaseException from Python 3.8 onwards.) * `trio.Cancelled` * `KeyboardInterrupt` * `...
If any BaseException is raised during streaming the response, then the stream should be closed. This includes: * `asyncio.CancelledError` (A subclass of BaseException from Python 3.8 onwards.) * `trio.Cancelled` * `KeyboardInterrupt` * `SystemExit` See https://github.com/encode/httpx...
test_cancellation_during_stream
python
encode/httpx
tests/client/test_async_client.py
https://github.com/encode/httpx/blob/master/tests/client/test_async_client.py
BSD-3-Clause
async def test_basic_auth_with_stream() -> None: """ See: https://github.com/encode/httpx/pull/1312 """ url = "https://example.org/" auth = ("user", "password123") app = App() async with httpx.AsyncClient( transport=httpx.MockTransport(app), auth=auth ) as client: async ...
See: https://github.com/encode/httpx/pull/1312
test_basic_auth_with_stream
python
encode/httpx
tests/client/test_auth.py
https://github.com/encode/httpx/blob/master/tests/client/test_auth.py
BSD-3-Clause
def test_netrc_auth_credentials_exist() -> None: """ When netrc auth is being used and a request is made to a host that is in the netrc file, then the relevant credentials should be applied. """ netrc_file = str(FIXTURES_DIR / ".netrc") url = "http://netrcexample.org" app = App() auth = ...
When netrc auth is being used and a request is made to a host that is in the netrc file, then the relevant credentials should be applied.
test_netrc_auth_credentials_exist
python
encode/httpx
tests/client/test_auth.py
https://github.com/encode/httpx/blob/master/tests/client/test_auth.py
BSD-3-Clause
def test_netrc_auth_credentials_do_not_exist() -> None: """ When netrc auth is being used and a request is made to a host that is not in the netrc file, then no credentials should be applied. """ netrc_file = str(FIXTURES_DIR / ".netrc") url = "http://example.org" app = App() auth = http...
When netrc auth is being used and a request is made to a host that is not in the netrc file, then no credentials should be applied.
test_netrc_auth_credentials_do_not_exist
python
encode/httpx
tests/client/test_auth.py
https://github.com/encode/httpx/blob/master/tests/client/test_auth.py
BSD-3-Clause
def test_netrc_auth_nopassword_parse_error() -> None: # pragma: no cover """ Python has different netrc parsing behaviours with different versions. For Python < 3.11 a netrc file with no password is invalid. In this case we want to allow the parse error to be raised. """ netrc_file = str(FIXTUR...
Python has different netrc parsing behaviours with different versions. For Python < 3.11 a netrc file with no password is invalid. In this case we want to allow the parse error to be raised.
test_netrc_auth_nopassword_parse_error
python
encode/httpx
tests/client/test_auth.py
https://github.com/encode/httpx/blob/master/tests/client/test_auth.py
BSD-3-Clause
async def test_async_auth_history() -> None: """ Test that intermediate requests sent as part of an authentication flow are recorded in the response history. """ url = "https://example.org/" auth = RepeatAuth(repeat=2) app = App(auth_header="abc") async with httpx.AsyncClient(transport=...
Test that intermediate requests sent as part of an authentication flow are recorded in the response history.
test_async_auth_history
python
encode/httpx
tests/client/test_auth.py
https://github.com/encode/httpx/blob/master/tests/client/test_auth.py
BSD-3-Clause
async def test_async_auth_reads_response_body() -> None: """ Test that we can read the response body in an auth flow if `requires_response_body` is set. """ url = "https://example.org/" auth = ResponseBodyAuth("xyz") app = App() async with httpx.AsyncClient(transport=httpx.MockTransport...
Test that we can read the response body in an auth flow if `requires_response_body` is set.
test_async_auth_reads_response_body
python
encode/httpx
tests/client/test_auth.py
https://github.com/encode/httpx/blob/master/tests/client/test_auth.py
BSD-3-Clause
def test_sync_auth() -> None: """ Test that we can use an auth implementation specific to the sync case. """ url = "https://example.org/" auth = SyncOrAsyncAuth() app = App() with httpx.Client(transport=httpx.MockTransport(app)) as client: response = client.get(url, auth=auth) ...
Test that we can use an auth implementation specific to the sync case.
test_sync_auth
python
encode/httpx
tests/client/test_auth.py
https://github.com/encode/httpx/blob/master/tests/client/test_auth.py
BSD-3-Clause
def test_set_per_request_cookie_is_deprecated() -> None: """ Sending a request including a per-request cookie is deprecated. """ url = "http://example.org/echo_cookies" cookies = {"example-name": "example-value"} client = httpx.Client(transport=httpx.MockTransport(get_and_set_cookies)) with...
Sending a request including a per-request cookie is deprecated.
test_set_per_request_cookie_is_deprecated
python
encode/httpx
tests/client/test_cookies.py
https://github.com/encode/httpx/blob/master/tests/client/test_cookies.py
BSD-3-Clause
def test_set_cookie_with_cookiejar() -> None: """ Send a request including a cookie, using a `CookieJar` instance. """ url = "http://example.org/echo_cookies" cookies = CookieJar() cookie = Cookie( version=0, name="example-name", value="example-value", port=None,...
Send a request including a cookie, using a `CookieJar` instance.
test_set_cookie_with_cookiejar
python
encode/httpx
tests/client/test_cookies.py
https://github.com/encode/httpx/blob/master/tests/client/test_cookies.py
BSD-3-Clause
def test_set_cookie_with_cookies_model() -> None: """ Send a request including a cookie, using a `Cookies` instance. """ url = "http://example.org/echo_cookies" cookies = httpx.Cookies() cookies["example-name"] = "example-value" client = httpx.Client(transport=httpx.MockTransport(get_and_s...
Send a request including a cookie, using a `Cookies` instance.
test_set_cookie_with_cookies_model
python
encode/httpx
tests/client/test_cookies.py
https://github.com/encode/httpx/blob/master/tests/client/test_cookies.py
BSD-3-Clause
def test_cookie_persistence() -> None: """ Ensure that Client instances persist cookies between requests. """ client = httpx.Client(transport=httpx.MockTransport(get_and_set_cookies)) response = client.get("http://example.org/echo_cookies") assert response.status_code == 200 assert response...
Ensure that Client instances persist cookies between requests.
test_cookie_persistence
python
encode/httpx
tests/client/test_cookies.py
https://github.com/encode/httpx/blob/master/tests/client/test_cookies.py
BSD-3-Clause