B `Vg @sfddlZddlZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z ddlm Z ddlmZmZmZmZmZmZmZmZmZmZddlmZddlZddlmZmZmZm Z ddl!m"Z"d d l#m$Z$d d l%m&Z&d d l'm(Z(m)Z)m*Z*m+Z+m,Z,d d l-m.Z.d dl/m0Z0d dl1m2Z2m3Z3d dl4m5Z5m6Z6d dl7m8Z8m9Z9m:Z:m;Z;mZ>d dl?m@Z@dZAerd dlBmCZCd dlDmEZEd dlFmGZGejHddddGdddZIejJejKdZLdeLdZMdNd Od!d"d#ePeQd$d%DZRd&ZSd'jNeReSd(ZTd)jNeMeTd*ZUeVd+ZWeVeUZXGd,d-d-eeYefe*ZZGd.d/d/eZZ[dS)0N) parsedate) SimpleCookie)MappingProxyType) TYPE_CHECKINGAnyDictIteratorMappingMutableMappingOptionalTupleUnioncast) parse_qsl) CIMultiDictCIMultiDictProxy MultiDictMultiDictProxy)URL)hdrs)AbstractStreamWriter)DEBUG ChainMapProxy HeadersMixinreifysentinel)RawRequestMessage) HttpVersion)BodyPartReaderMultipartReader)EmptyStreamReader StreamReader)DEFAULT_JSON_DECODER JSONDecoder LooseHeaders RawHeadersStrOrURL)HTTPRequestEntityTooLarge)StreamResponse) BaseRequest FileFieldRequest) Application)RequestHandler)UrlMappingMatchInfoT)Z auto_attribsfrozenslotsc@s8eZdZUeed<eed<ejed<eed<ded<dS)r+namefilenamefile content_typezCIMultiDictProxy[str]headersN)__name__ __module__ __qualname__str__annotations__ioBufferedReaderr>r>n/private/var/folders/7j/8686xlfs15q3tgljmghtvg0r0000gn/T/pip-target-isidps9b/lib/python/aiohttp/web_request.pyr+9s  r+z!#$%&'*+.^_`|~-[z]+z[{}]ccs|]}t|VqdS)N)chr).0cr>r>r? HsrE) !#z \\[\t !-~]z"(?:{quoted_pair}|{qdtext})*")ZqdtextZ quoted_pairz0({token})=({token}|{quoted_string})(:\d{{1,4}})?)tokenZ quoted_stringz \\([\t !-~])c@sleZdZejejejejejhZ e j e ddddddddd d d d d ddddgBZ dddddde ededejeeeeefeeeeeedd ddZeeeeeedeeeeeeddddZedddd Zeddd!d"Zeeejdd#d$Z eedd%d&Z!e"e dd'd(Z#e"e$dd)d*Z%e"ejdd+d,Z&eed-d.d/Z'eedd0d1d2Z(edd-d3d4Z)edd5d6Z*e+edd7d8Z,e"e-dd9d:Z.e"e/e0eefd;fddd?Z2e"edd@dAZ3e"e4ddBdCZ5e"eddDdEZ6e"eeddFdGZ7e"e$ddHdIZ8e"eddJdKZ9e"eddLdMZ:e"eddNdOZ;e"dPddQdRZe"e?ddXdYZ@eAeeeeBjBdZd[d\ZCe"eeBjBdd]d^ZDe"eeBjBdd_d`ZEe"eeBjBddadbZFe"e-ddcddZGe"e0eefddedfZHe"eIddgdhZJe"eddidjZKee-ddkdlZLee-ddmdnZMe"e-ddodpZNdddqdrZOePddsdtZQeddudvZReSdweTedxdydzZUeVdd{d|ZWd}dd~dZXdeeedddZYedddZZe[e-dddZ\e-dddZ]e^ddddZ_e`ddddZadS)r*_message _protocol_payload_writer_payload_headers_method_version_rel_url_post _read_bytes_state_cache_task_client_max_size_loop_transport_sslcontext_transport_peernameiN)client_max_sizestateschemehostremoter.zasyncio.Task[None]) messagepayloadprotocolpayload_writertaskloopr]r^r_r`rareturnc Cs|dkr i}||_||_||_||_|j|_|j|_|j|_ |j |_ d|_ d|_ ||_i|_||_||_||_|jj} | dk st| d|_| d|_| dk r| |jd<| dk r| |jd<| dk r| |jd<dS)NZ sslcontextZpeernamer_r`ra)rLrMrNrOr6rPmethodrQversionrRurlrSrTrUrVrWrXrYrZ transportAssertionErrorget_extra_infor[r\) selfrbrcrdrerfrgr]r^r_r`rarlr>r>r?__init__s6     zBaseRequest.__init__)rirel_urlr6r_r`ra)rirqr6r_r`rarhc Cs|jrtdi}|tk r"||d<|tk rFt|}||d<t||d<|tk rxtt||d<tdd|D|d<|j j f|} i} |tk r|| d <|tk r|| d <|tk r|| d <|j | |j |j |j|j|jf|j|jd | S) aClone itself with replacement some attributes. Creates and returns a new instance of Request object. If no parameters are given, an exact copy is returned. If a parameter is not passed, it will reuse the one from the current request object. z.Cannot clone request after reading its contentrirkpathr6css&|]\}}|d|dfVqdS)zutf-8N)encode)rCkvr>r>r?rEsz$BaseRequest.clone.. raw_headersr_r`ra)r]r^)rU RuntimeErrorrrr:rrtupleitemsrL_replace __class__rOrMrNrXrZrYrVcopy) rorirqr6r_r`radctnew_urlrbkwargsr>r>r?clones>  zBaseRequest.clone)rhcCs|jS)N)rX)ror>r>r?rfszBaseRequest.taskcCs|jS)N)rM)ror>r>r?rdszBaseRequest.protocolcCs|jdkrdS|jjS)N)rMrl)ror>r>r?rls zBaseRequest.transportcCs|jS)N)rN)ror>r>r?writerszBaseRequest.writercCstjdtdd|jS)NzRequest.message is deprecated) stacklevel)warningswarnDeprecationWarningrL)ror>r>r?rbszBaseRequest.messagecCs|jS)N)rS)ror>r>r?rqszBaseRequest.rel_urlcCstjdtdd|jS)Nz#request.loop property is deprecated)r)rrrrZ)ror>r>r?rgs zBaseRequest.loop)keyrhcCs |j|S)N)rV)rorr>r>r? __getitem__szBaseRequest.__getitem__)rvaluerhcCs||j|<dS)N)rV)rorrr>r>r? __setitem__szBaseRequest.__setitem__cCs |j|=dS)N)rV)rorr>r>r? __delitem__szBaseRequest.__delitem__cCs t|jS)N)lenrV)ror>r>r?__len__szBaseRequest.__len__cCs t|jS)N)iterrV)ror>r>r?__iter__szBaseRequest.__iter__cCs |jdkS)z5A bool indicating if the request is handled with SSL.https)r_)ror>r>r?secure szBaseRequest.secure.c Csfg}xV|jjtjdD]>}t|}d}d}i}|t|xd|kr^|krXnnt ||}|dk r|r| d|}n\| \}} } | ddkrt d| dd } | r| | 7} | ||<|t|d7}d }qH||dkrd}i}|t||d7}qH||d kr2d}|d7}qH||d krJ|d7}qH| d|}qHWqWt|S) aA tuple containing all parsed Forwarded header(s). Makes an effort to parse Forwarded headers as specified by RFC 7239: - It adds one (immutable) dictionary per Forwarded 'field-value', ie per proxy. The element corresponds to the data in the Forwarded field-value added by the first proxy encountered by the client. Each subsequent item corresponds to those added by later proxies. - It checks that every value has valid syntax in general as specified in section 4: either a 'token' or a 'quoted-string'. - It un-escapes found escape sequences. - It does NOT validate 'by' and 'for' contents as specified in section 6. - It does NOT validate 'host' contents (Host ABNF). - It does NOT validate 'proto' contents for valid URI scheme names. Returns a tuple containing one or more immutable dicts r>rFN,"z\1rT;z )rLr6ZgetallrZ FORWARDEDrappendtypesr_FORWARDED_PAIR_REmatchfindgroups_QUOTED_PAIR_REPLACE_REsublowergrouprx) roelemsZ field_valuelengthposZneed_separatorelemrr2rportr>r>r? forwarded%s@      zBaseRequest.forwardedcCs|jr dSdSdS)aA string representing the scheme of the request. Hostname is resolved in this order: - overridden value by .clone(scheme=new_scheme) call. - type of connection to peer: HTTPS if socket is SSL, HTTP otherwise. 'http' or 'https'. rhttpN)r[)ror>r>r?r_bs zBaseRequest.schemecCs|jS)zyRead only property for getting HTTP method. The value is upper-cased str like 'GET', 'POST', 'PUT' etc. )rQ)ror>r>r?rirszBaseRequest.methodcCs|jS)zxRead only property for getting HTTP version of request. Returns aiohttp.protocol.HttpVersion instance. )rR)ror>r>r?rjzszBaseRequest.versioncCs(|jjtj}|dk r|StSdS)zHostname of the request. Hostname is resolved in this order: - overridden value by .clone(host=new_host) call. - HOST HTTP header - socket.getfqdn() value N)rLr6getrZHOSTsocketgetfqdn)ror`r>r>r?r`s zBaseRequest.hostcCs$t|jttfr|jdS|jSdS)zRemote IP of client initiated HTTP request. The IP is resolved in this order: - overridden value by .clone(remote=new_remote) call. - peername of opened socket rN) isinstancer\listrx)ror>r>r?ras  zBaseRequest.remotecCstj|j|jd}||jS)N)r_r`)rbuildr_r`joinrS)rorkr>r>r?rkszBaseRequest.urlcCs|jjS)z_The URL including *PATH INFO* without the host or scheme. E.g., ``/app/blog`` )rSrr)ror>r>r?rrszBaseRequest.pathcCs t|jS)zXThe URL including PATH_INFO and the query string. E.g, /app/blog?id=10 )r:rS)ror>r>r?path_qsszBaseRequest.path_qscCs|jjS)zThe URL including raw *PATH INFO* without the host or scheme. Warning, the path is unquoted and may contains non valid URL characters E.g., ``/my%2Fpath%7Cwith%21some%25strange%24characters`` )rLrr)ror>r>r?raw_pathszBaseRequest.raw_pathzMultiDictProxy[str]cCs|jjS)z7A multidict with all the variables in the query string.)rSquery)ror>r>r?rszBaseRequest.querycCs|jjS)z:The query string in the URL. E.g., id=10 )rS query_string)ror>r>r?rszBaseRequest.query_stringzCIMultiDictProxy[str]cCs|jS)z4A case-insensitive multidict proxy with all headers.)rP)ror>r>r?r6szBaseRequest.headerscCs|jjS)z$A sequence of pairs for all headers.)rLrv)ror>r>r?rvszBaseRequest.raw_headers) _date_strrhcCs8|dk r4t|}|dk r4tj|dddtjjiSdS)z/Process a date string, return a datetime objectNtzinfo)rdatetimetimezoneutc)r timetupler>r>r? _http_dates zBaseRequest._http_datecCs||jtjS)zyThe value of If-Modified-Since HTTP header, or None. This header is represented as a `datetime` object. )rr6rrZIF_MODIFIED_SINCE)ror>r>r?if_modified_sinceszBaseRequest.if_modified_sincecCs||jtjS)z{The value of If-Unmodified-Since HTTP header, or None. This header is represented as a `datetime` object. )rr6rrZIF_UNMODIFIED_SINCE)ror>r>r?if_unmodified_sinceszBaseRequest.if_unmodified_sincecCs||jtjS)zpThe value of If-Range HTTP header, or None. This header is represented as a `datetime` object. )rr6rrZIF_RANGE)ror>r>r?if_rangeszBaseRequest.if_rangecCs |jj S)zIs keepalive enabled by client?)rLZ should_close)ror>r>r? keep_aliveszBaseRequest.keep_alivecCs.|jtjd}t|}tdd|DS)zMReturn request cookies. A read-only dictionary-like object. rAcSsi|]\}}|j|qSr>)r)rCrvalr>r>r? sz'BaseRequest.cookies..)r6rrZCOOKIErrry)rorawparsedr>r>r?cookiesszBaseRequest.cookiescCs|jtj}d\}}|dk ryd}t||d\}}Wntk rVtdYnX|rdt|nd}|rtt|nd}|dkr|dk r| }d}|dk r|dk r|d7}||krtd||krdkrnntdt ||dS) zMThe content of Range HTTP header. Return a slice instance. )NNNz^bytes=(\d*)-(\d*)$rzrange not in acceptable formatrzstart cannot be after endz"No start or end of range specified) rPrrRANGErefindall IndexError ValueErrorintslice)rorngstartendpatternr>r>r? http_ranges(zBaseRequest.http_rangecCs|jS)zReturn raw payload stream.)rO)ror>r>r?content)szBaseRequest.contentcCstjdtdd|j S)z@Return True if request's HTTP BODY can be read, False otherwise.z$Deprecated, use .can_read_body #2005r)r)rrrrOat_eof)ror>r>r?has_body.s zBaseRequest.has_bodycCs |j S)z@Return True if request's HTTP BODY can be read, False otherwise.)rOr)ror>r>r? can_read_body6szBaseRequest.can_read_bodycCst|jtk S)z6Return True if request has HTTP BODY, False otherwise.)typerOr!)ror>r>r? body_exists;szBaseRequest.body_existscs$x|js|jIdHqWdS)zKRelease request. Eat unread part of HTTP BODY if present. N)rOrreadany)ror>r>r?release@s zBaseRequest.releasecsl|jdkrft}xJ|jIdH}|||jrRt|}||jkrRt|j|d|sPqWt||_|jS)z_Read request body if present. Returns bytes object with full request content. N)max_size actual_size) rU bytearrayrOrextendrYrr(bytes)robodychunkZ body_sizer>r>r?readHs     zBaseRequest.readcs"|IdH}|jpd}||S)z1Return BODY as text using encoding from .charset.Nzutf-8)rcharsetdecode)roZ bytes_bodyencodingr>r>r?text]s zBaseRequest.text)loads)rrhcs|IdH}||S)zReturn BODY as JSON.N)r)rorrr>r>r?jsoncszBaseRequest.jsoncst|j|jS)z3Return async iterator to process BODY as multipart.)r rPrO)ror>r>r? multiparthszBaseRequest.multipartz,MultiDictProxy[Union[str, bytes, FileField]]cs|jdk r|jS|j|jkr.tt|_|jS|j}|dkrNtt|_|jSt}|dkr2|IdH}|j}|IdH}x|dk r.d}|j t j }t |tr|jdk st|jrt}|jddIdH} xd| r@|| } || |t| 7}d|kr|kr,nn t||d|jddIdH} qW|d|dkrZd}t|j|jttj|||j } ||j| n|jd d IdH} |dks| d r|j!d d } ||j| | n||j| |t| 7}d|kr|krnn t||dnt"d|IdH}qWn>|IdH} | rp|j#pPd } |$t%| &| d | dt||_|jS)zReturn POST parameters.N)rAz!application/x-www-form-urlencodedzmultipart/form-datazmultipart/form-datari)size)rrzapplication/octet-streamT)rztext/zutf-8)defaultz8To decode nested multipart you need to use custom reader)keep_blank_valuesr)'rTrQ POST_METHODSrrr5rrYnextr6rr CONTENT_TYPErrr2rmr3tempfile TemporaryFileZ read_chunkrwriterr(seekr+rr<r=addr startswith get_charsetrrrrrstrip)ror5outrrfieldrZfield_cttmprffrrdatar>r>r?postls~                    zBaseRequest.post)r2rrhcCs0|j}|dkr|S|j}|dkr$|S|||S)z"Extra info from protocol transportN)rMrlrn)ror2rrdrlr>r>r?rnszBaseRequest.get_extra_infocCs(|jddd}d|jj|j|S)Nasciibackslashreplacez <{} {} {} >)rrrsrformatr{r7rQ)roZascii_encodable_pathr>r>r?__repr__szBaseRequest.__repr__)otherrhcCst|t|kS)N)id)rorr>r>r?__eq__szBaseRequest.__eq__cCsdS)NTr>)ror>r>r?__bool__szBaseRequest.__bool__)responserhcsdS)Nr>)rorr>r>r? _prepare_hookszBaseRequest._prepare_hook)excrhcCs|j|dS)N)rOZ set_exception)rorr>r>r?_cancelszBaseRequest._cancel)N)br7r8r9rZ METH_PATCHZ METH_POSTZMETH_PUTZ METH_TRACEZ METH_DELETErrATTRS frozensetrr"rasyncioZAbstractEventLooprr rr:rrprr'r%rpropertyrfrd Transportrlrrrbrrqrgrrrrrrboolrr r rr_rirrjr`rarkrrrrrrr6r&rv staticmethodrrrrrrrrrrrrrrrrrr#r$rr rrrnrobjectrrr)r BaseExceptionrr>r>r>r?r*as 6&0 <  #_ r*c seZdZejedgBZeeddfdd ZerHe eddfdd Z e e e e e e d e e e e e e dd fd d Zed dddZeddddZeedddZeddddZZS)r, _match_infoN)argsrrhcstj||d|_dS)N)superrpr)rorr)r{r>r?rpszRequest.__init__)r2rrhcs8||jkr&tjd|jj|tddt||dS)Nz-Setting custom {}.{} attribute is discouragedr)r) rrrrr{r7rr __setattr__)ror2r)r{r>r?rs  zRequest.__setattr__)rirqr6r_r`ra)rirqr6r_r`rarhc s.tj||||||d}tt|}|j|_|S)N)rirqr6r_r`ra)rrrr,r) rorirqr6r_r`raretZnew_ret)r{r>r?rs  z Request.cloner/)rhcCs|j}|dk st|S)zResult of route resolving.N)rrm)ro match_infor>r>r?rs zRequest.match_infor-cCs|j}|dk st|jS)zApplication instance.N)rrmZ current_app)rorr>r>r?app"s z Request.appcCsH|j}|dk st|j}|j}||}tt|d|d}t|S)Nr)rrmZappsrindexrreversedr)rorlstridxZsublistr>r>r? config_dict)s  zRequest.config_dict)rrhcs:|j}|dkrdSx"|jD]}|j||IdHqWdS)N)rZ_appsZon_response_preparesend)rorrrr>r>r?r3s  zRequest._prepare_hook)r7r8r9r*rrrrprr:rrr'r%rrrr rrrr)r __classcell__r>r>)r{r?r,s$    r,)\r rr<rrstringrrr email.utilsr http.cookiesrrtypingrrrrr r r r r r urllib.parserattrZ multidictrrrrZyarlrrArabcrZhelpersrrrrrZ http_parserrZ http_writerrrrr Zstreamsr!r"Ztypedefsr#r$r%r&r'Zweb_exceptionsr(Z web_responser)__all__Zweb_appr-Z web_protocolr.Zweb_urldispatcherr/sr+digits ascii_lettersZ_TCHARZ_TOKENrrrxrangeZ_QDTEXTZ _QUOTED_PAIRZ_QUOTED_STRINGZ_FORWARDED_PAIRcompilerrr:r*r,r>r>r>r?sd   0             $