a c)@sJddlZddlZddlmZddlZddlmZmZddl m Z m Z m Z m Z mZmZddlmZddlmZmZmZddlmZmZmZmZzddlmZWneydZYn0ejrdd lm Z hd Z!e"ej#e"e"fd d d Z$Gddde%Z&Gdddej'e"ej(fZ)ej*dddZ+eej*dddZ,Gddde)Z-dS)N)cookies)AwaitableOrContextManager AwaitableOrContextManagerWrapper)URLAddressFormDataHeaders QueryParamsState) HTTPException) FormParserMultiPartExceptionMultiPartParser)MessageReceiveScopeSend)parse_options_header)Router>zaccept-languageacceptz user-agentzaccept-encodingz cache-control) cookie_stringreturncCsdi}|dD]P}d|vr,|dd\}}n d|}}||}}|sP|rt|||<q|S)a This function parses a ``Cookie`` HTTP header into a dict of key/value pairs. It attempts to mimic browser cookie parsing behavior: browsers and web servers frequently disregard the spec (RFC 6265) when setting and reading cookies, so we attempt to suit the common scenarios here. This function has been adapted from Django 3.1.0. Note: we are explicitly _NOT_ using `SimpleCookie.load` because it is based on an outdated spec and will fail on lots of input we want to support ;=)splitstrip http_cookies_unquote)r cookie_dictchunkkeyvalr$_/workspaces/shunt/resources/test-fastapi/venv/lib/python3.9/site-packages/starlette/requests.py cookie_parser s  r&c@s eZdZdS)ClientDisconnectN)__name__ __module__ __qualname__r$r$r$r%r';sr'c@seZdZdZd)eejeddddZe ej dddZ ej e d d d Z ed d d ZejZejZeej d ddZeed ddZeed ddZeed ddZeed ddZeeje ej fd ddZeeje e fd ddZeejed ddZ eeje ej fd ddZ!eej d d d!Z"eej d d"d#Z#ee$d d$d%Z%e ej e d&d'd(Z&dS)*HTTPConnectionz A base class for incoming HTTP connections, that is used to provide any functionality that is common to both `Request` and `WebSocket`. N)scopereceivercCs|ddvsJ||_dS)Ntype)httpZ websocketr,)selfr,r-r$r$r%__init__EszHTTPConnection.__init__)r"rcCs |j|SNr0)r1r"r$r$r% __getitem__IszHTTPConnection.__getitem__rcCs t|jSr3)iterr,r1r$r$r%__iter__LszHTTPConnection.__iter__cCs t|jSr3)lenr,r7r$r$r%__len__OszHTTPConnection.__len__cCs |jdS)Nappr0r7r$r$r%r;XszHTTPConnection.appcCst|dst|jd|_|jS)N_urlr0)hasattrrr,r<r7r$r$r%url\s zHTTPConnection.urlcCsNt|dsHt|j}d|d<d|d<|d|dd|d<t|d |_|jS) N _base_url/path query_stringZ app_root_path root_pathrr0)r=dictr,getrr?)r1Zbase_url_scoper$r$r%base_urlbs    zHTTPConnection.base_urlcCst|dst|jd|_|jS)N_headersr0)r=rr,rHr7r$r$r%headersns zHTTPConnection.headerscCs t|dst|jd|_|jS)N _query_paramsrC)r=r r,rJr7r$r$r% query_paramsts zHTTPConnection.query_paramscCs|jdiS)N path_params)r,rFr7r$r$r%rLzszHTTPConnection.path_paramscCs2t|ds,i}|jd}|r&t|}||_|jS)N_cookiescookie)r=rIrFr&rM)r1r cookie_headerr$r$r%r~s  zHTTPConnection.cookiescCs |jd}|durt|SdS)Nclient)r,rFr)r1 host_portr$r$r%rPs zHTTPConnection.clientcCsd|jvsJd|jdS)Nsessionz=SessionMiddleware must be installed to access request.sessionr0r7r$r$r%rRs zHTTPConnection.sessioncCsd|jvsJd|jdS)NauthzAAuthenticationMiddleware must be installed to access request.authr0r7r$r$r%rSs zHTTPConnection.authcCsd|jvsJd|jdS)NuserzAAuthenticationMiddleware must be installed to access request.userr0r7r$r$r%rTs zHTTPConnection.usercCs.t|ds(|jdit|jd|_|jS)N_statestate)r=r, setdefaultr rUr7r$r$r%rVs zHTTPConnection.state)namerLrcKs*|jd}|j|fi|}|j|jdS)Nrouter)rG)r,Z url_path_forZmake_absolute_urlrG)r1rXrLrYZurl_pathr$r$r%url_fors zHTTPConnection.url_for)N)'r(r)r*__doc__rtypingOptionalrr2strAnyr4Iteratorr8intr:object__eq____hash__propertyr;rr>rGrrIr rKDictrLrrrPrRrSrTr rVrZr$r$r$r%r+?s@   r+r5cs tddS)Nz+Receive channel has not been made available RuntimeErrorr$r$r$r% empty_receivesri)messagercs tddS)Nz(Send channel has not been made availablerg)rjr$r$r% empty_sendsrkcs"eZdZUejeed<eefe e e dfdd Z e edddZe e ddd Zejed fdd d Zedd dZejdddZdddejeefejeefedddZdddejeefejeefeedddZd dddZedddZed dddZ Z!S)Request_form)r,r-sendcs>t||ddksJ||_||_d|_d|_d|_dS)Nr.r/F)superr2_receive_send_stream_consumed_is_disconnectedrm)r1r,r-rn __class__r$r%r2s zRequest.__init__r5cCs |jdS)Nmethodr0r7r$r$r%rvszRequest.methodcCs|jSr3)rpr7r$r$r%r-szRequest.receiveNcCst|dr|jVdVdS|jr*tdd|_|IdH}|ddkrp|dd}|r`|V|dd sqq0|dd kr0d|_tq0dVdS) N_bodyrBzStream consumedTr.z http.requestbodyZ more_bodyFhttp.disconnect)r=rwrrrhrprFrsr')r1rjrxr$r$r%streams$     zRequest.streamcsBt|ds0Y|ddkr\d|_|jS)Nr.ryT)rsanyioZ CancelScopecancelrprF)r1rjcsr$r$r%is_disconnected&s ,zRequest.is_disconnected)rArcshd|jdivrdg}tD]0}|j|D]}||d|dfq*q|d||dIdHdS)Nzhttp.response.push extensionszlatin-1)r.rArI)r,rFSERVER_PUSH_HEADERS_TO_COPYrIgetlistr{encoderq)r1rAZ raw_headersrXvaluer$r$r%send_push_promise4s zRequest.send_push_promise)"r(r)r*r\r]r__annotations__rirkrrrr2rer^rvr-AsyncGeneratorbytesrzrxr_rUnionrafloatrrrrboolrr __classcell__r$r$rtr%rls:      $   rl).rr\r/rrrZstarlette._utilsrrZstarlette.datastructuresrrrrr r Zstarlette.exceptionsr Zstarlette.formparsersr r rZstarlette.typesrrrrZmultipart.multipartr ImportError TYPE_CHECKINGZstarlette.routingrrr^rfr& Exceptionr'Mappingr_r+NoReturnrirkrlr$r$r$r%s*       w