redditwarp.core.authorizer_ASYNC#

class redditwarp.core.authorizer_ASYNC.Authorizer(token_client: TokenObtainmentClient | None = None, token: Token | None = None)[source]#

Bases: object

An object for managing the token.

The Authorizer keeps token information and knows how to renew the token when it expires and how to prepare a requisition.

token_client: TokenObtainmentClient | None#

A token obtainment client used to make the token obtainment requests.

token: Token | None#

Holds the current token information.

renewal_time: float | None#

Time at which the token is expected to expire. See time().

renewal_skew: float#

Number of seconds before the token expiration when the token should be renewed.

expires_in_fallback: int | None#

A fallback value for the token expiration time when not specified by the server.

time_func: Callable[[], float]#

A function that returns the current time. The time() method calls this this function.

authorization_header_name: str#

Name of the Authorization header. Use this attribute to change its capitalization.

has_token_client() bool[source]#
fetch_token_client() TokenObtainmentClient[source]#

Return .token_client. Raise RuntimeError if not set.

set_token_client(value: TokenObtainmentClient | None) None[source]#

Set .token_client.

has_token() bool[source]#
fetch_token() Token[source]#

Return .token. Raise RuntimeError if not set.

set_token(value: Token | None) None[source]#

Set .token.

async renew_token() None[source]#

Renew the token.

Raises:

RuntimeError – No token client (token_client) is set.

time() float[source]#

Return the current internal time. This is used for renewal_time.

should_renew_token() bool[source]#

Return true if the token is expired, about to expire, or is unset.

can_renew_token() bool[source]#

The token can be renewed if a token client (token_client) is available.

async attain_token() Token[source]#
get_header_entry() tuple[str, str][source]#

Return an authorization header entry tuple.

prepare_requisition(requisition: Requisition) None[source]#

Prepare a requisition for authorization using the token.

prepare_headers(headers: MutableMapping[str, str]) None[source]#

Update headers with an authorization entry.

class redditwarp.core.authorizer_ASYNC.Authorized(handler: Handler, authorizer: Authorizer)[source]#

Bases: DelegatingHandler

Used to make requests to endpoints that require authorization.

authorizer: Authorizer#