xj-BddlmZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z ddl mZmZmZddlmZmZej(rdd lmZgd ZGd d ZGd deZGddeZGddeZGddeZGddej8Zy)) annotationsN) b64encode)parse_http_list) ProtocolError)CookiesRequestResponse)to_bytesto_str)_Hash)Auth BasicAuth DigestAuth FunctionAuth NetRCAuthc0eZdZdZdZdZddZddZddZy) 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 `/mnt/ssd/data/Dropbox/adrian/sandbox/mcp-query/venv/lib/python3.12/site-packages/httpx2/_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_flowUs  % %--/ ! !~~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(rrrrs$ ""0.r/rc eZdZdZddZddZy)rz 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__ss  r/c#2K|j|ywr2r3rs rrzFunctionAuth.auth_flowvsjj!!sN)r5z#typing.Callable[[Request], Request]r*Noner))r+r,r-r.r6rrr/rrrms "r/rc(eZdZdZddZddZddZy) rzy Allows the 'auth' argument to be passed as a (username, password) pair, and uses HTTP Basic authentication. c2|j|||_yr2)_build_auth_header _auth_headerrusernamepasswords rr6zBasicAuth.__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?rNr*r8r)r>rNr?rNr*strr+r,r-r.r6rr;rr/rrrzs 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)rfilerTs rr6zNetRCAuth.__init__s  ;;t,r/c#K|jj|jj}||ds|y|j |d|d|j d<|yw)Nr)r>r?rA)rUauthenticatorsurlhostr;rB)rr auth_infos rrzNetRCAuth.auth_flowsj$$33GKK4D4DE  IaLM04/F/FPYZ[P\gpqrgs/F/tGOOO ,MsA'A)cdjt|t|f}t|j}d|SrDrFrIs rr;zNetRCAuth._build_auth_headerrLr/r2)rVz str | Noner*r8r)rOrQrr/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 rr6zDigestAuth.__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)NrAizwww-authenticatezdigest rr) rer;rB status_codeget_listlower startswith_parse_challengerfcookiesrset_cookie_header)rrr$ auth_headers rrzDigestAuth.auth_flows   /3/F/FwPTPdPd/eGOOO , =   3 &*.digestsT?,,.557 7r/rEs%08xrz-sessrh)r>rvrwurir$rxryauthrznccnoncezDigest )rbytesr*r)rarxupperrGrcrvrdrZraw_pathmethodr~rf_get_client_noncerwrkendswith _resolve_qoprzry_get_header_value)rr challengersA1pathA2HA2nc_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) rPr~timectimeosurandomhashlibsha1r)r nonce_countrwss rrzDigestAuth._get_client_noncesp   # # % 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_value's6#% !*=+>+>+@!A B A~u1u$ */7H*HNaH HOOE6%=A AL  B r/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 authrh)rer}NotImplementedErrorr)rrzrqopsrs rrzDigestAuth._resolve_qop5sV ;xx$ d? K= %&VW W*3'1ABGW55r/NrMr))rr r$r rprPr*r)rr rrr*rP)rintrwrr*r)rzdict[str, bytes]r*rP)rz bytes | Nonerr r*r)r+r,r-rmd5rsha256sha512ra__annotations__r6rrmr;rrrrr/rrrsp{{KK||LL>>>> O!K  6C6,?\9  6r/rc@eZdZUded<ded<ded<ded<ded<y ) rrrvrwrPrxrryrzN)r+r,r-rrr/rrrCs L LN  r/r) __future__rrrrrtypingbase64rurllib.requestr _exceptionsr_modelsrr r _utilsr r TYPE_CHECKINGr __all__rrrrr NamedTuplerrr/rrs" *&//$  KTTn "4 "  &  8W6W6t6,,r/