wceZjddlZddlZddlZddlZddlmZddlmZddlm Z ddl m Z ddl mZddlmZmZmZmZmZmZmZmZmZmZmZddlZddlZdd lmZmZdd l m!Z!dd l"m#Z#dd l m$Z$m%Z%m&Z&m'Z'm(Z(dd l)m*Z*m+Z+ddl,m-Z-m.Z.ddl/m0Z0ddl1m2Z2ddl3m4Z4ddl5m6Z6ddl7m8Z8m9Z9dZ:erddl;me'dde&iiddddej~d Z@GddeAZBGddeAZCejddd Gd!d"ZEeee'eEfe.fZFGd#de!ZGy)$N)deque)suppress)escape) HTTPStatus)Logger) TYPE_CHECKINGAny AwaitableCallableDequeOptionalSequenceTupleTypeUnioncast)AbstractAccessLoggerAbstractStreamWriter) BaseProtocol) ceil_timeout)HttpProcessingErrorHttpRequestParser HttpVersion10RawRequestMessage StreamWriter) access_logger server_logger) EMPTY_PAYLOAD StreamReader) tcp_keepalive) HTTPException) AccessLogger) BaseRequest)ResponseStreamResponse)RequestHandlerRequestPayloadErrorPayloadAccessError)Serverr'zasyncio.Task[None]UNKNOWN/TFceZdZdZy)r(zPayload parsing error.N__name__ __module__ __qualname____doc__6/usr/lib/python3/dist-packages/aiohttp/web_protocol.pyr(r(Ns r4r(ceZdZdZy)r)z-Payload was accessed after response was sent.Nr.r3r4r5r)r)Rs7r4r)) auto_attribsfrozenslotsc,eZdZUeed<eed<eed<y)_ErrInfostatusexcmessageN)r/r0r1int__annotations__ BaseExceptionstrr3r4r5r;r;Vs K  Lr4r;c!leZdZdZdZdZddeeeejddddd d dd d d dde jde de dedeededede dededede dede de f fdZdefd Zede fd!ZdFd"ee dd#fd$Zd%e j2dd#ffd& Zd'eedd#ffd( Zd)edd#fd*ZdGd+Zd,e dd#fd-Z!d.e dd#fd/Z"dGd0Z#dGd1Z$d2e%d3e&d4e dd#fd5Z'd6ed7edd#fd8Z(d6ed7edd#fd9Z)dGd:Z*d2e%d;e dZ/d2e%d?e&d;e de fd@Z0 dHd2e%dAed'eedBeede&f dCZ1dDe2de+e%ge,e&ffdEZ3xZ4S)Ir'ajHTTP protocol implementation. RequestHandler handles incoming HTTP request. It reads request line, request headers and request payload and calls handle_request() method. By default it always returns with 404 response. RequestHandler handles errors in incoming request, like bad status line, bad headers or incomplete payload. If any error occurs, connection gets closed. keepalive_timeout -- number of seconds before closing keep-alive connection tcp_keepalive -- TCP keep-alive is on, default is on debug -- enable debug mode logger -- custom logger object access_log_class -- custom class for access_logger access_log -- custom logging object access_log_format -- access log format string loop -- Optional event loop max_line_size -- Optional maximum header line size max_field_size -- Optional maximum header field size max_headers -- Optional maximum header size timeout_ceil_threshold -- Optional value to specify threshold to ceil() timeout values r)_request_count _keepalive_manager_request_handler_request_factory_tcp_keepalive_keepalive_time_keepalive_handle_keepalive_timeout_lingering_time _messages _message_tail_waiter _task_handler_upgrade_payload_parser_request_parser_reading_pausedloggerdebug access_logr_close _force_close_current_request_timeout_ceil_thresholdgR@TFiig$@i)keepalive_timeoutr!rVaccess_log_classrXaccess_log_formatrW max_line_size max_headersmax_field_sizelingering_time read_bufsizeauto_decompresstimeout_ceil_thresholdmanagerr*loopr^r!rVr_rXr`rWrarbrcrdrerfrgc dt||d|_d|_d|_||_|j |_|j|_ ||_ d|_ d|_ ||_ t| |_t!|_d|_d|_d|_d|_d|_t/|||| | | t0||_d|_ t||_||_| |_||_|r||||_ nd|_ d|_!d|_"y#t6t8f$rYMwxYw)NrFgr4)rarcrbpayload_exceptionrfr])#super__init__rDrEr[rFrequest_handlerrGrequest_factoryrHrIrJrKrLfloatrMrrNrOrPrQrRrSrr(rTr\ TypeError ValueErrorrVrWrXrrYrZ)selfrhrir^r!rVr_rXr`rWrarbrcrdrerfrg __class__s r5rmzRequestHandler.__init__sJ( 7;*1 ;B;R;R;B;R;R+";?"3$^4*/' 7; ;? $( connected disconnected)formatrtr/ transportrss r5__repr__zRequestHandler.__repr__s; NN # #>>5K  ;I  r4c|jSN)rLr{s r5r^z RequestHandler.keepalive_timeouts&&&r4timeoutNc8Kd|_|j|jj|jr|jjt t j t j5t|4d{|j-|jjt j |j.|jjs|jd{dddd{ddd|j|jj|j"|jjd|_ yy77s7e#1d{7swYuxYw#1swYyxYww)zDo worker process exit preparations. We need to clean up everything and stop accepting requests. It is especially important for keep-alive connections. TN)rZrKcancelrPrasyncioCancelledError TimeoutErrorrr[_cancelrQdonerzclose)rsrs r5shutdownzRequestHandler.shutdownsJ !  ! ! -  " " ) ) + << LL   !g,,g.B.B C -#G, - -((4))11'2H2H2JK%%1$:L:L:Q:Q:S,,,,  - - -    )    % % ' >> % NN "!DN & - -  - - - - - -szAFE3FA/E9E5E9 FE7FAF3F5E97F9F ?FF FFFrzc6t||ttj|}|j r t ||jj|j|_ |jJ|jj||yr~) rlconnection_maderr TransportrIr!_loop create_taskstartrQrF)rsrzreal_transportrts r5rzRequestHandler.connection_madest  *g//;    . )!ZZ33DJJLA}}((( %%dN;r4r=c|jy|jj||t|||jj}d|_d|_d|_d|_d|_|j|jj|j(| td}|jj||j|jj|r&|j|jjd|_|j"|jj!d|_yy)NTzConnection lost)rFconnection_lostrlhandler_cancellationrZrHrGrTrKrr[ConnectionResetErrorrrPrQrSfeed_eof)rsr=rrts r5rzRequestHandler.connection_lost%s% ==  %%dC0 $ $}}AA   $ $#  ! ! -  " " ) ) +  ,{*+<=  ! ! ) )# . << # LL   ! D$6$6$B    % % '!    +  ) ) +#'D  ,r4parserc|jJ||_|jr-|jj|jd|_yy)Nr4)rSrO feed_data)rsrs r5 set_parserzRequestHandler.set_parserIsL##+++%     * *4+=+= >!$D  r4cyr~r3r{s r5 eof_receivedzRequestHandler.eof_receivedSs r4datac |js |jry|j|js|jJ |jj |\}}}|xsdD]7\}}|xjdz c_ |jj||f9|j}|r#|!|js|jd||_|r |r||_yyy|j$|jr|r|xj |z c_y|r2|jj |\} }| r|j#yyy#t $r.}td||jtfg}d}d}Yd}~d}~wwxYw)Ni)r<r=r>Fr4r3r)rZrYrSrRrTrrr;r>rrDrNappendrPr set_resultrOr) rsrmessagesupgradedtailr=msgpayloadwaitereofs r5 data_receivedzRequestHandler.data_receivedVsv        ' ''3 33 +/+?+?+I+I$+O((D!)B 6 W##q(#%%sGn5 6\\FF.v{{}!!$'$DMD%)"!x ! ! )dmm   $ & ,,66t> % NN "!DN &r4requestresponsetimec|j9|jj|||jj|z yyr~)rlogrr)rsrrrs r5 log_accesszRequestHandler.log_accesss=    )    " "7Hdjjoo6G$6N O *r4argskwcV|jr|jj|i|yyr~)rWrVrsrrs r5 log_debugzRequestHandler.log_debugs' :: DKK  t *r * r4c<|jj|i|yr~)rV exceptionrs r5 log_exceptionzRequestHandler.log_exceptions t*r*r4cF|js |jsy|j|jz}|jr.|j j |kDr|jy|j j|j|j|_ yr~) rZrErJrLrPrrr call_laterKEEPALIVE_RESCHEDULE_DELAY_process_keepaliverK)rsnexts r5rz!RequestHandler._process_keepalives   DOO ##d&=&== <<zz 4'  ""&!6!6  + +  # #" r4 start_timerncK|jJ ||_||d{}d|_ t|ddrtjdt |j |||d{}||fS7R#d|_wxYw7#t$r+}|}|j |||d{7}Yd}~||fSd}~wtj$rtj$rN}|jd||j|d}|j |||d{7}Yd}~||fSd}~wt$r<}|j|d|}|j |||d{7}Yd}~||fSd}~wwxYww)N__http_exception__Fzlreturning HTTPException object is deprecated (#2415) and will be removed, please raise the exception insteadzRequest handler timed out.exc_infoi)rGr[getattrwarningswarnDeprecationWarningfinish_responser"rrrr handle_error Exception)rsrrrnrespresetr=s r5_handle_requestzRequestHandler._handle_requests $$000 J -(/%,W55(,%t159 9' ..wjIIEU{76(,%.J- JD..wjIIIE,U{+%%  ## J NN7#N F$$Wc2D..wjIIIE U{ J$$Wc37D..wjIIIEU{ JsE4A:A8A:B=E4/B0E48A:: BBE4 E1B7)B,*B7/E47)E1 ;D)DD)!E4) E15)E,E!E,$E4,E11E4cK|j}|j}|J|j}|J|j}d}|jJ|j J|j s|js2 |j|_ |jd{ d|_ |jj\}}|j}|xjdz c_t||} t!|t"r|j%|} t&}n |j } |j |||| |} |jj)|j+| || } | d{\}} ~ | r|j/d |j0||j/dn|j s|j2rc|j4sW|j|jj}||_|j8<|j;||z|j<|_nnt?|j@|_|jCs)|jD}|j s|r|j/d||j}||z}tGtjHtj5|jCsj||kretK||z 4d{|jMd{dddd{|j}|jCs||kreddd|jCs-|j s!|j/d|jO|jQtS|j0||j/dny|j sm|j2r`|j4sT|S|jj}||_|j8&|j;||z|j<|_nn|j s|j s/d|_|j0|j0jOyyy7#tj$r Yd|_ [wxYw#d|_ wxYw7;#tjt,f$r|j/dY|j0||j/d|j r|j2rd|j4sX||jj}||_|j8|j;||z|j<|_68wxYw777r#1d{7swYxYw#1swYbxYw#tj$r|j/dY|j0||j/d|j r|j2re|j4sY||jj}||_|j8|j;||z|j<|_-/tT$r:}|jVr|jYd | |j[Yd}~d}~wt\$r.}|jYd | |j[Yd}~Hd}~wwxYw#|j0||j/dw|j sr|j2rb|j4sV|S|jj}||_|j8%|j;||z|j<|_wwwYHwxYww) a_Process incoming request. It reads request line, request headers and request payload, then calls handle_request() method. Subclass has to override handle_request(). start() handles various exceptions in request or response handling. Connection is being closed always unless keep_alive(True) specified. Nrz&Ignored premature client disconnectionz'Ignored premature client disconnection.z(Ignored premature client disconnection 2z'Start lingering close timer for %s sec.zUncompleted request.z'Ignored premature client disconnection zUnhandled runtime exceptionrzUnhandled exception)/rrQrFrLrHrGrZrN create_futurerPrrpopleftrrequests_countr isinstancer;_make_error_handlerERRORrrConnectionErrorrrzrErYrJrKcall_atrboolris_eofrMrrrreadanyr set_exceptionr) RuntimeErrorrWrrr)rsrihandlerrhr^rr>rrwriterrnrtaskrnowrdend_tr=s r5rzRequestHandler.startszz$$"""--""" 33$$000$$000##>>(#'#5#5#7DL,,&&$(DL#~~557 GWIIKE  " "a ' "!$-F'8,"&":":7"C"&"7"7++GWdFGTGE zz--((%I(,*KD% NN#MNR>>)d.>NN#LM**t{{,8"&**//"3C36D0#55=9=$'*;$;T=T=T:" 6g#'t"7~~'%)%9%9N,,E~#iik #n 4%g&:&:G>+D4E4E'=> %%&8&:;>>)d.>NN#LM**t{{,8"&**//"3C36D0#55=9=$'*;$;T=T=T:" 6}##B  !%D ~~)$$&*!y'--#'DL$(DL,#-..@NN#KL^>>)d.>NN#LM**t{{,8"&**//"3C36D0#55=9=$'*;$;T=T=T:" 6}4!<$;!<!<!<!<22)) HI>>)d.>NN#LM**t{{,8"&**//"3C36D0#55=9=$'*;$;T=T=T:" 6+  #::&&'Ds&S  "" #""#83"G  "" #>>)d.>NN#LM**t{{,8"&**//"3C36D0#55=9=$'*;$;T=T=T:" 6 >9+sA0^ 3$Q=Q:Q=B^ <,V&)R,.R)/R,6V& B^ *BV&>(V&U:'V*V>U=?V VV)V9AV&B%^ ><^ :Q==RR^ RR R&&^ )R,,*U7V&,^ ^ -^ (^ 6U77V&:V=VVV V  V VV#V&&$[$ [' -^ :^ -^ (^ -[$5/Z*$['* [$6#[['[$$[''B^^ ^^ rcK|jZ|jjdd|_|jr,|jj |jd|_ |j } ||d{|jd{|j|||y#t $r(| tdtdj|wxYw7d7N#t$r|j|||YywxYww)aPrepare the response and write_eof, then log access. This has to be called within the context of any exception so the access logger can get exception information. Returns True if the client disconnects prematurely. NFr4z+Missing return statement on request handlerz7Web-handler should return a response instance, got {!r}T) rT set_upgradedrRrOrprepareAttributeErrorrry write_eofrr)rsrrr prepare_meths r5rzRequestHandler.finish_responseZs    +  - -e 4!DM!!$$..t/A/AB%(" <c~|jd||jjdkDr tdd}|tj k(rdj tj }tj j}d}|jr,tt5tj}dddd|jjd d vr)|rt|}d |d }d j ||}d}n |r|}|dz|z}t!|||} | j#| S#1swY|xYw)zHandle errors. Returns HTTP response with specific status code. Logs additional information. It always closes current connection. zError handling requestrrzMResponse is sent already, cannot send another response with the error messagez text/plainz{0.value} {0.phrase}Nz text/htmlAcceptz

Traceback:

z
zV{title}

{title}

{msg} )titlerz )r<text content_type)rr output_sizerrINTERNAL_SERVER_ERRORry descriptionrWrr traceback format_excheadersget html_escaper%r) rsrr<r=r>ctrrtbrs r5rzRequestHandler.handle_errors< 3cB >> % % )!)   Z55 5*11*2R2RSE22>>CBzzi(0"--/B0goo11(B??$RB6rd&AC0&u#&.  !C&.3.vG"E  -00s #D33D<err_infoc0dtdtffd }|S)NrrucpKj|jjjSwr~)rr<r=r>)rrrss r5rz3RequestHandler._make_error_handler..handlers1$$(,,8H8H s36)r$r&)rsrrs`` r5rz"RequestHandler._make_error_handlers ; >  r4)g.@)ruN)rNN)5r/r0r1r2r __slots__rr#r LOG_FORMATrAbstractEventLooprprrrrrBr?rmr|propertyr^r r BaseTransportrrArr rrbytesrrrrr$r&rrrrr r rrrrrr;r __classcell__)rts@r5r'r'`s %N"#ID$("&7C*!-!8!8! " $! $()%H"H"'' H" ! H"  H"H"34H"H"H"H"H"H"H"H" !H""#H"$!&%H"T # '5''"huo""> <)>)> <4 <"(8M#:"(t"(H%%% %%%D%N*d*t*""P"P.<PDIP P +s+#+$++3+c+d+ &%%%";->1J"JK % ~t# $ %Nw'r#"#*8#FK# #P'+!% 111m $ 1 # 1  1f  ;->!:: ;r4)Hrasyncio.streamsrr collectionsr contextlibrhtmlrrhttprloggingrtypingrr r r r r rrrrrattryarlabcrr base_protocolrhelpersrrrrrrrrrstreamsrr tcp_helpersr!web_exceptionsr"web_logr# web_requestr$ web_responser%r&__all__ web_serverr*_RequestFactory_RequestHandlerURLrrr(r)sr;_MsgTyper'r3r4r5rsO&     ;'!.0&)!$2 I"  K=)N*CCD    DHHSM !)!88T$d34 ((23\A BZ \Z r4