xL is.FddlmZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z ddl mZmZmZddlmZmZmZej*rdd lmZgd ZGd d ZGd deZGddeZGddeZGddeZGddej:Zy)) annotationsN) b64encode)parse_http_list) ProtocolError)CookiesRequestResponse)to_bytesto_strunquote)_Hash)Auth BasicAuth DigestAuth NetRCAuthc@eZdZdZdZdZddZ ddZ ddZy) ra Base class for all authentication schemes. To implement a custom authentication scheme, subclass `Auth` and override the `.auth_flow()` method. If the authentication scheme does I/O such as disk access or network calls, or uses synchronization primitives such as locks, you should override `.sync_auth_flow()` and/or `.async_auth_flow()` instead of `.auth_flow()` to provide specialized implementations that will be used by `Client` and `AsyncClient` respectively. Fc#K|yw)a Execute the authentication flow. To dispatch a request, `yield` it: ``` yield request ``` The client will `.send()` the response back into the flow generator. You can access it like so: ``` response = yield request ``` A `return` (or reaching the end of the generator) will result in the client returning the last response obtained from the server. You can dispatch as many requests as is necessary. Nselfrequests Q/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/httpx/_auth.py auth_flowzAuth.auth_flow&s , sc#K|jr|j|j|}t|} |}|jr|j |j |}3#t $rYywxYww)z Execute the authentication flow synchronously. By default, this defers to `.auth_flow()`. You should override this method when the authentication scheme does I/O and/or uses concurrency primitives. N)requires_request_bodyreadrnextrequires_response_bodysend StopIterationrrflowresponses rsync_auth_flowzAuth.sync_auth_flow>sx  % % LLN~~g&t*$}H**  ))H- !  s*AA>A/.A>/ A;8A>:A;;A>c*K|jr|jd{|j|}t|} |}|jr|jd{ |j |}<7]7#t $rYywxYww)z Execute the authentication flow asynchronously. By default, this defers to `.auth_flow()`. You should override this method when the authentication scheme does I/O and/or uses concurrency primitives. N)rareadrrrr r!r"s rasync_auth_flowzAuth.async_auth_flowWs  % %--/ ! !~~g&t*$}H**nn&&& ))H-  "'!  sF BBAB(B)B.B?BB B BBBNrr returnz)typing.Generator[Request, Response, None])rr r*z(typing.AsyncGenerator[Request, Response]) __name__ __module__ __qualname____doc__rrrr%r(rrrrsD ""0 22 1r/rc eZdZdZddZddZy) FunctionAuthz Allows the 'auth' argument to be passed as a simple callable function, that takes the request, and returns a new, modified request. c||_yN_func)rfuncs r__init__zFunctionAuth.__init__ws  r/c#2K|j|ywr3r4rs rrzFunctionAuth.auth_flowzsjj!!sN)r6z#typing.Callable[[Request], Request]r*Noner))r+r,r-r.r7rrr/rr1r1qs "r/r1c(eZdZdZddZddZddZy) rzy Allows the 'auth' argument to be passed as a (username, password) pair, and uses HTTP Basic authentication. c2|j|||_yr3)_build_auth_header _auth_headerrusernamepasswords rr7zBasicAuth.__init__s 33HhGr/c#FK|j|jd<|yw)N Authorization)r=headersrs rrzBasicAuth.auth_flows+/+<+<( s!cdjt|t|f}t|j}d|SN:zBasic joinr rdecoderr?r@userpasstokens rr<zBasicAuth._build_auth_header?99hx0(82DEF(#**,wr/Nr? str | bytesr@rOr*r9r)r?rOr@rOr*strr+r,r-r.r7rr<rr/rrr~s H r/rc*eZdZdZdddZddZd dZy) rzT Use a 'netrc' file to lookup basic auth credentials based on the url host. Nc8ddl}|j||_y)Nr)netrc _netrc_info)rfilerUs rr7zNetRCAuth.__init__s  ;;t,r/c#K|jj|jj}||ds|y|j |d|d|j d<|yw)Nr)r?r@rB)rVauthenticatorsurlhostr<rC)rr auth_infos rrzNetRCAuth.auth_flowsl$$33GKK4D4DE  IaLM04/F/F"1 ! 0G0GOOO ,MsA'A)cdjt|t|f}t|j}d|SrErGrJs rr<zNetRCAuth._build_auth_headerrMr/r3)rWz str | Noner*r9r)rPrRrr/rrrs-  r/rc "eZdZUejejej ej ej ej ejejdZde d<d dZ d dZ ddZ ddZ ddZdd Zdd Zy )r)MD5zMD5-SESSSHAzSHA-SESSzSHA-256z SHA-256-SESSzSHA-512z SHA-512-SESSz*dict[str, typing.Callable[[bytes], _Hash]]_ALGORITHM_TO_HASH_FUNCTIONc`t||_t||_d|_d|_y)Nr)r _username _password_last_challenge _nonce_countr>s rr7zDigestAuth.__init__s*!(+!(+<@r/c#8K|jr)|j||j|jd<|}|jdk7sd|jvry|jj dD]#}|j j ds#ny|j||||_d|_|j||j|jd<|jr%t|jj||yw)NrBizwww-authenticatezdigest rr) rfr<rC status_codeget_listlower startswith_parse_challengergcookiesrset_cookie_header)rrr$ auth_headers rrzDigestAuth.auth_flows    /3/F/F--0GOOO ,!=   3 &*.digestsT?,,.557 7r/rFs%08xrz-sessri)r?rvrwurir$rxryauthrznccnoncezDigest )rbytesr*r)rbrxupperrHrdrvrer[raw_pathmethodr~rg_get_client_noncerwrlendswith _resolve_qoprzry_get_header_value)rr challengertA1pathA2HA2nc_valuerHA1rz digest_data format_argsrs @rr<zDigestAuth._build_auth_headers44Y5H5H5N5N5PQ  8YY H I{{## YY--/6 7RjT...''(9(99??K QRj    $ $ & / / 8C&#ABCC w? ; 5K 63LK____tyy56",,335     $-$4$4K ! !(K  (K $*K !411+>>>r/c t|j}||z }|tjjz }|t j dz }t j|jddjS)N) rQr~timectimeosurandomhashlibsha1r)r nonce_countrwss rrzDigestAuth._get_client_nonce/sp   # # % U  TZZ\ "" RZZ]||A((*3B/6688r/cd}d}d}d}t|jD]8\}\}}|dkDr|dz }||vr|n|} || j|t|z }:|S)N)rxrzrz{}="{}"z{}={}rz, ) enumerateitemsformatr ) r header_fieldsNON_QUOTED_FIELDSQUOTED_TEMPLATENON_QUOTED_TEMPLATE header_valueirrtemplates rrzDigestAuth._get_header_value7s6#% !*=+>+>+@!A B A~u1u$  11 (  HOOE6%=A AL Br/c|ytjd|}d|vry|dgk(r tdd|d}t||)Ns, ?rsauth-intz.Digest auth-int support is not yet implementedzUnexpected qop value "z" in digest authri)rer}NotImplementedErrorr)rrzrqopsrs rrzDigestAuth._resolve_qopIsV ;xx$ d? K= %&VW W*3'1ABGW55r/NrNr))rr r$r rqrQr*r)rr rrr*rQ)rintrwrr*r)rzdict[str, bytes]r*rQ)rz bytes | Nonerr r*r)r+r,r-rmd5rsha256sha512rb__annotations__r7rrnr<rrrrr/rrrs{{KK||LL>>>> O!K  >CC*2CADC C>.?.?+?.? .?`9$ 6r/rc@eZdZUded<ded<ded<ded<ded<y ) rrrvrwrQrxrryrzN)r+r,r-rrr/rrrWs L LN  r/r) __future__rrrrrtypingbase64rurllib.requestr _exceptionsr_modelsrr r _utilsr r r TYPE_CHECKINGr__all__rr1rrr NamedTuplerrr/rrs" *&//--  ;XXv "4 "  &