ó
    ö›‘h(@  ã                   ó  • S SK r S SKrS SKrS SKJr  S SKJrJr  S SKJ	r	  S SK
Jr  S SKJr  S SKJr  SS	KJrJr  \ R&                  " \5      r " S
 S\R,                  5      r\" \	5       " S S\R0                  5      5       rg)é    N)Úunquote)ÚinlineCallbacksÚmaybeDeferred)ÚIProtocolNegotiationFactory)ÚProtocolWrapper)Úhttp)Úimplementeré   )ÚHEADER_NAME_REÚparse_x_forwarded_forc                   óî   • \ rS rSrSrSR                  SS5      R                  SS5      R                  SS5      R                  S	S5      rS
 r\S 5       r	S r
S rS rS rS rS rS rS rS rS rSrg)Ú
WebRequesté   z¸
Request that either hands off information to channels, or offloads
to a WebSocket class.

Does some extra processing over the normal Twisted Web request to separate
GET and POST out.
a�  
        <html>
            <head>
                <title>%(title)s</title>
                <style>
                    body { font-family: sans-serif; margin: 0; padding: 0; }
                    h1 { padding: 0.6em 0 0.2em 20px; color: #896868; margin: 0; }
                    p { padding: 0 0 0.3em 20px; margin: 0; }
                    footer { padding: 1em 0 0.3em 20px; color: #999; font-size: 80%%; font-style: italic; }
                </style>
            </head>
            <body>
                <h1>%(title)s</h1>
                <p>%(body)s</p>
                <footer>Daphne</footer>
            </body>
        </html>
    Ú
Ú z    Ú z   z  c                 ót  • S U l         S U l         [        R                  R                  " U /UQ70 UD6  U R
                  R                  R                  U l        S U l        SU l	        U R                  R                  U 5        g ! [         a*    [        R                  [        R                  " 5       5        e f = f)NF)Úclient_addrÚserver_addrr   ÚRequestÚ__init__ÚchannelÚfactoryÚserverÚapplication_queueÚ_response_startedÚprotocol_connectedÚ	ExceptionÚloggerÚerrorÚ	tracebackÚ
format_exc)ÚselfÚargsÚkwargss      ÚXC:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\daphne/http_protocol.pyr   ÚWebRequest.__init__4   s“   € ØˆÔØˆÔð		Ü�L‰L×!Ò! $Ð8¨Ò8°Ò8àŸ,™,×.Ñ.×5Ñ5ˆDŒKØ%)ˆDÔ"Ø%*ˆDÔ"Ø�K‰K×*Ñ*¨4Õ0øÜó 	Ü�L‰Lœ×-Ò-Ó/Ô0Øð	ús   �A2B Â4B7c              #   óØ  #   •  [         R                   " 5       U l        U R                  R                  5        H5  u  p[        R
                  " U5      (       a  M"  U R                  SSS5          g    S nU R                  R                  S5      (       a  U R                  R                  S5      S   n[        U R                  S5      (       a�  [        U R                  S5      (       at  [        U R                  R                  5      U R                  R                  /U l        [        U R                  R                  5      U R                  R                  /U l        U R!                  5       (       a  SOS	U l        U R$                  R&                  (       aw  [)        U R                  U R$                  R&                  U R$                  R*                  U R$                  R,                  U R                  U R"                  5      u  U l        U l         U R.                  R1                  S
5        SU l        SU R6                  ;   a@  U R6                  R9                  SS5      S   U l         U R4                  R1                  S
5        U(       GaÚ  UR;                  5       S:X  GaÅ  U R$                  R<                  R?                  U R@                  RC                  5       5      nU(       d6  U RE                  S5        [F        RI                  S5        U RK                  5         U R4                  Ul&        U R@                  S soPl         [O        U[P        5      (       a  XEl)        OXEl*        URW                  U5        U RX                  S-   U R6                  -   S-   nU R                  R                  5        H%  nXgS   S-   SR[                  US   5      -   S-   -  nM'     US-  nX`R\                  R_                  5       -  nURa                  U5        [F        Rc                  SU R                  5        U R$                  Re                  U 5        U Rf                  Rh                  Rk                  5         g / U l6        U R$                  Rn                  U l7        U R                  R                  5        Hv  u  pSU;   a  M  U Hc  n	UR;                  5       S:X  a!  [q        U	R1                  S
5      5      U l7        M8  U Rl                  Rs                  UR;                  5       U	45        Me     Mx     [F        Rc                  SU RX                  U R                  5        U R\                  Ru                  SS5        [w        U R$                  Rx                  U S	U Rz                  R9                  S5      S   R1                  S
5      U RX                  R1                  S
5      [q        U R.                  R1                  S
5      5      U R.                  U Rn                  U R"                  U R4                  U Rl                  U R                  U R                  S.5      v •U l>        U R|                  b  U R\                  R~                  (       a  g U R$                  R€                  n
 U R\                  R_                  U
5      n[ƒ        U5      U
:  + nSUUS .nU R|                  R…                  U5        U(       d  g MU  ! [2         a    SU l        U R                  SSS5         g f = f! [2         a    U R                  SSS5         g f = f! [†         a>    [F        R‰                  [Š        RŒ                  " 5       5        U R                  SS!S"5         g f = f7f)#Ni�  s   Bad RequestzInvalid header names   Upgrader   ÚhostÚportÚhttpsr   Úasciió   /zInvalid characters in pathó    ó   ?r
   zInvalid query strings	   websocketéô  z!Could not make WebSocket protocoló    s    HTTP/1.1
s   : ó   ,s   
z#Upgraded connection %s to WebSocketó   _s   daphne-root-pathzHTTP %s request for %séÿÿÿÿ)ÚtypeÚhttp_versionÚmethodÚpathÚraw_pathÚ	root_pathÚschemeÚquery_stringÚheadersÚclientr   zhttp.request)r5   ÚbodyÚ	more_bodyó   Internal Server ErrorzDaphne HTTP processing error)GÚtimeÚrequest_startÚrequestHeadersÚgetAllRawHeadersr   Ú	fullmatchÚbasic_errorÚ	hasHeaderÚgetRawHeadersÚhasattrr>   Ústrr)   r*   r   r   ÚisSecureÚclient_schemer   Úproxy_forwarded_address_headerr   Úproxy_forwarded_port_headerÚproxy_forwarded_proto_headerr8   ÚdecodeÚUnicodeDecodeErrorr<   ÚuriÚsplitÚlowerÚ
ws_factoryÚbuildProtocolÚ	transportÚgetPeerÚsetResponseCoder   ÚwarnÚfinishÚ_raw_query_stringÚ
isinstancer   ÚwrappedProtocolÚprotocolÚmakeConnectionr7   ÚjoinÚcontentÚreadÚdataReceivedÚdebugÚprotocol_disconnectedr   Ú_networkProducerÚresumeProducingÚclean_headersr:   r   ÚappendÚseekr   Úcreate_applicationÚclientprotor   ÚclosedÚrequest_buffer_sizeÚlenÚ
put_nowaitr   r    r!   r"   )r#   ÚnameÚ_Úupgrade_headerr`   rX   ÚdataÚhÚvaluesÚvalueÚbuffer_sizeÚchunkr@   Úpayloads                 r&   ÚprocessÚWebRequest.processD   sÛ  é € ðM	Ü!%§¢£ˆDÔð  ×.Ñ.×?Ñ?ÖA‘�Ü%×/Ò/°×5Ó5Ø×$Ñ$ S¨.Ð:OÔPÙñ Bð "ˆNØ×"Ñ"×,Ñ,¨Z×8Ñ8Ø!%×!4Ñ!4×!BÑ!BÀ:Ó!NÈqÑ!Q�ä�t—{‘{ F×+Ñ+´¸¿¹ÀV×0LÑ0Lô %(¨¯©×(8Ñ(8Ó$9¸4¿;¹;×;KÑ;KÐ#L�Ô Ü$'¨¯	©	¯©Ó$7¸¿¹¿¹Ð#H�Ô à,0¯M©M¯O©O¡ÀˆDÔð �{‰{×9×9Ü7LØ×'Ñ'Ø—K‘K×>Ñ>Ø—K‘K×;Ñ;Ø—K‘K×<Ñ<Ø×$Ñ$Ø×&Ñ&ó8Ñ4�Ô  $Ô"4ðØ—	‘	× Ñ  Ô)ð !$ˆDÔØ�t—x‘xÓØ$(§H¡H§N¡N°4¸Ó$;¸AÑ$>�Ô!ðØ×%Ñ%×,Ñ,¨WÔ5÷
  .×"6Ñ"6Ó"8¸LÔ"HàŸ;™;×1Ñ1×?Ñ?Ø—N‘N×*Ñ*Ó,ó�ö  à×(Ñ(¨Ô-Ü—K‘KÐ CÔDØ—K‘K”Mà-1×->Ñ->�Ô*à,0¯N©N¸DÐ)�	œ>Ü˜i¬×9Ñ9à08Õ-à)1Ô&Ø×'Ñ'¨	Ô2à—{‘{ TÑ)¨D¯H©HÑ4Ð7KÑK�Ø×,Ñ,×=Ñ=Ö?�AØ˜a™D 5™L¨4¯9©9°Q°q±T«?Ñ:¸[ÑHÑH’Dñ @à˜Ñ#�ØŸ™×)Ñ)Ó+Ñ+�Ø×%Ñ% dÔ+ä—‘ÐBÀD×DTÑDTÔUØ—‘×1Ñ1°$Ô7à—‘×-Ñ-×=Ñ=Õ?ð
 &(�Ô"Ø!%§¡×!6Ñ!6�”Ø$(×$7Ñ$7×$HÑ$HÖ$J‘L�Dà˜t“|Ù Û!'˜ØŸ:™:›<Ð+>Ó>Ü-4°U·\±\À'Ó5JÓ-K˜DžNà ×.Ñ.×5Ñ5°t·z±z³|ÀUÐ6KÖLó	 "(ñ	 %Kô —‘Ð5°t·{±{ÀD×DTÑDTÔUØ—‘×!Ñ! ! QÔ'ä/<Ø—K‘K×2Ñ2Øà &à(,×(8Ñ(8×(>Ñ(>¸tÓ(DÀRÑ(H×(OÑ(OØ#ó)ð #'§+¡+×"4Ñ"4°WÓ"=Ü '¨¯	©	×(8Ñ(8¸Ó(AÓ BØ$(§I¡IØ%)§^¡^Ø"&×"4Ñ"4Ø(,×(9Ñ(9Ø#'×#5Ñ#5Ø"&×"2Ñ"2Ø"&×"2Ñ"2ñó0ñ *�Ô&ð* ×)Ñ)Ñ1°T·\±\×5H×5Hàà"Ÿk™k×=Ñ=�ØØ ŸL™L×-Ñ-¨kÓ:�EÜ%(¨£Z°+Ò >�Ià .Ø %Ø%.ñ�Gð
 ×*Ñ*×5Ñ5°gÔ>Þ$Øñ øôu &ó Ø �”	Ø× Ñ   nÐ6RÔSÙðûô *ó Ø×$Ñ$ S¨.Ð:PÔQÙðûôx ó 	Ü�L‰Lœ×-Ò-Ó/Ô0Ø×ÑØÐ-Ð/Möð	üs²   ‚]*„A\ Á\ Á.]*Á/F\ È[ È';\ É#[< É>G!\ Ñ]*Ñ H\ Ù%]*Ù&A)\ Û]*Û\ Û$[9Û6\ Û7]*Û8[9Û9\ Û<\Ü\ Ü]*Ü\Ü\ ÜA]'Ý$]*Ý&]'Ý']*c                 óú   • U R                   (       a  U R                  5         [        R                  SU R                  5        [
        R                  R                  X5        U R                  R                  U 5        g)ú#
Cleans up reply channel on close.
zHTTP disconnect for %sN)
r   Úsend_disconnectr   rf   r   r   r   ÚconnectionLostr   rg   )r#   Úreasons     r&   r‚   ÚWebRequest.connectionLostÕ   sR   € ð ×!×!Ø× Ñ Ô"Ü�‰Ð-¨t×/?Ñ/?Ô@Ü�‰×#Ñ# DÔ1Ø�‰×)Ñ)¨$Õ/r.   c                 óú   • U R                   (       a  U R                  5         [        R                  SU R                  5        [
        R                  R                  U 5        U R                  R                  U 5        g)r€   zHTTP close for %sN)
r   r�   r   rf   r   r   r   r\   r   rg   ©r#   s    r&   r\   ÚWebRequest.finishß   sR   € ð ×!×!Ø× Ñ Ô"Ü�‰Ð(¨$×*:Ñ*:Ô;Ü�‰×Ñ˜DÔ!Ø�‰×)Ñ)¨$Õ/r.   c                 óJ  • U R                   (       d  U R                  c  gSU;  a  [        S5      eUS   S:X  Ga  U R                  (       a  [        S5      eSU l        SU;  a  [        S5      eU R	                  US   5        UR                  S	0 5       H   u  p#U R                  R                  X#5        M"     U R                  R                  (       aT  U R                  R                  S
5      (       d4  U R                  SU R                  R                  R                  5       5        [        R                  SUS   U R                  5        gUS   S:X  Ga`  U R                  (       d  [        SUS   -  5      e[         R"                  R%                  XR                  SS5      5        UR                  SS5      (       d×  U R'                  5         [        R                  SU R                  5         U R(                  R+                  S5      n U R                  R1                  SSUU R2                  U R4                  R+                  SS5      U R                  (       a  S[7        U R                  5      -  OSU R9                  5       U R:                  S.5        g[        R                  SU R                  5        g[        SUS   -  5      e! [,         a    [/        U R(                  5      n NÞf = f! [<         a+    [        R?                  [@        RB                  " 5       5         gf = f)z!
Handles a reply from the client
Nr5   zMessage has no type definedúhttp.response.startz&HTTP response has already been startedTÚstatusz<Specifying a status code is required for a Response message.r=   r   s   serverzHTTP %s response started for %súhttp.response.bodyz1HTTP response has not yet been started but got %sr?   r.   r@   FzHTTP response complete for %sr,   r   ÚcompleteÚreplacez%s:%s)r8   rŠ   r7   r>   Ú
time_takenÚsizezHTTP response chunk for %szCannot handle message type %s!)"Úfinishedr   Ú
ValueErrorr   rZ   ÚgetÚresponseHeadersÚaddRawHeaderr   Úserver_namerH   Ú	setHeaderÚencoder   rf   r   r   r   Úwriter\   rS   rQ   rR   ÚreprÚ
log_actionÚcoder7   ÚtupleÚdurationÚ
sentLengthr   r    r!   r"   )r#   ÚmessageÚheaderry   rS   s        r&   Úhandle_replyÚWebRequest.handle_replyë   sŠ  € ð
 �=�=˜DŸL™LÑ0Øà˜Ó ÜÐ:Ó;Ð;à�6‰?Ð3Ô3Ø×%×%Ü Ð!IÓJÐJØ%)ˆDÔ"Ø˜wÓ&Ü ØRóð ð × Ñ  ¨Ñ!2Ô3à!(§¡¨Y¸Ö!;‘�Ø×$Ñ$×1Ñ1°&Ö@ñ "<à�{‰{×&×&¨t×/CÑ/C×/MÑ/MÈh×/WÑ/WØ—‘˜y¨$¯+©+×*AÑ*A×*HÑ*HÓ*JÔKÜ�L‰LØ1°7¸8Ñ3DÀd×FVÑFVõð �V‰_Ð 4Ô4Ø×)×)Ü ØGØ˜f‘oñ&óð ô
 �L‰L×Ñ˜t§[¡[°¸Ó%=Ô>à—;‘;˜{¨E×2Ñ2Ø—‘”Ü—‘Ð<¸d×>NÑ>NÔOð)ØŸ(™(Ÿ/™/¨'Ó2�Cð9Ø—K‘K×*Ñ*ØØ"à$'Ø&*§i¡iØ&*§k¡k×&8Ñ&8¸À)Ó&Lð $(×#3×#3ð !(¬%°×0@Ñ0@Ó*AÒ Aà%)à*.¯-©-«/Ø$(§O¡Oñõô& —‘Ð9¸4×;KÑ;KÕLäÐ=ÀÈÁÑOÓPÐPøô3 *ó )ä˜tŸx™x›.’Cð)ûô( !ó 9Ü—L‘L¤×!5Ò!5Ó!7Ö8ð9ús%   Ç0K ÈB	K- ËK*Ë)K*Ë-2L"Ì!L"c                 ó*   • U R                  SSS5        g)z6
Called by the server when our application tracebacks
r0   rA   zException inside application.N)rG   )r#   Ú	exceptions     r&   Úhandle_exceptionÚWebRequest.handle_exception1  s   € ð 	×Ñ˜Ð6Ð8WÕXr.   c                 ó"  • U R                   R                  (       at  U R                  5       U R                   R                  :”  aK  U R                  (       a&  [        R                  S5        U R                  5         gU R                  SSS5        ggg)z;
Called periodically to see if we should timeout something
z,Application timed out while sending responsei÷  s   Service Unavailablez0Application failed to respond within time limit.N)r   Úhttp_timeoutr�   r   r   Úwarningr\   rG   r†   s    r&   Úcheck_timeoutsÚWebRequest.check_timeouts7  sg   € ð
 �;‰;×#×#¨¯©«¸$¿+¹+×:RÑ:RÓ(RØ×%×%Ü—‘ÐMÔNØ—‘•à× Ñ ØØ*ØFõð )SÐ#r.   c                 ób   • U R                   (       a  U R                  R                  SS05        gg)zG
Sends a http.disconnect message.
Useful only really for long-polling.
r5   zhttp.disconnectN)r8   r   rr   r†   s    r&   r�   ÚWebRequest.send_disconnectI  s*   € ð �9�9Ø×"Ñ"×-Ñ-¨vÐ7HÐ.IÕJð r.   c                 ój   • [        U S5      (       d  g[        R                  " 5       U R                  -
  $ )z2
Returns the time since the start of the request.
rC   r   )rJ   rB   rC   r†   s    r&   r�   ÚWebRequest.durationR  s+   € ô �t˜_×-Ñ-ØÜ�yŠy‹{˜T×/Ñ/Ñ/Ð/r.   c                 óÒ   • U R                  SUS/S.5        U R                  SU R                  [        U5      S-   UR                  S5      -   US.-  R	                  S5      S	.5        g
)z6
Responds with a server-level error page (very basic)
r‰   )s   Content-Types   text/html; charset=utf-8)r5   rŠ   r=   r‹   r   r,   )Útitler?   Úutf8)r5   r?   N)r¡   Úerror_templaterK   rQ   r—   )r#   rŠ   Ústatus_textr?   s       r&   rG   ÚWebRequest.basic_errorZ  sx   € ð 	×Ñà-Ø ØJÐKñô	
ð 	×Ñà,à×'Ñ'ä!$ V£¨sÑ!2°[×5GÑ5GÈÓ5PÑ!PØ $ññ÷
 ‘&˜“.ñ	õ	
r.   c                 ó*   • [        [        U 5      5      $ ©N)ÚhashÚidr†   s    r&   Ú__hash__ÚWebRequest.__hash__r  s   € Ü”B�t“H‹~Ðr.   c                 ó0   • [        U 5      [        U5      :H  $ r·   )r¹   )r#   Úothers     r&   Ú__eq__ÚWebRequest.__eq__u  s   € Ü�$‹xœ2˜e›9Ñ$Ð$r.   )r   r   rj   r   rM   r8   r<   rC   r:   r   r   rX   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r�   r³   r   r   r}   r‚   r\   r¡   r¥   rª   r�   r�   rG   rº   r¾   Ú__static_attributes__© r.   r&   r   r      s›   † ñð	÷" 	‰Ø�"ó	
÷ 
‰�˜Ó	ß	‰�˜Ó	ß	‰��sÓ	ð/ ò4ð  ñNó ðNò`0ò0òDQòLYòò$Kò0ò
ò0õ%r.   r   c                   ó*   • \ rS rSrSrS rS rS rSrg)ÚHTTPFactoryiy  z¹
Factory which takes care of tracking which protocol
instances or request instances are responsible for which
named response channels, so incoming messages can be
routed appropriately.
c                 óN   • [         R                  R                  U 5        Xl        g r·   )r   rÈ   r   r   )r#   r   s     r&   r   ÚHTTPFactory.__init__‚  s   € Ü×Ñ×!Ñ! $Ô'Ø�r.   c                 óÐ   •  [         R                  R                  X5      n[        Ul        U$ ! [
         a-    [        R                  S[        R                  " 5       -  5        e f = f)zr
Builds protocol instances. This override is used to ensure we use our
own Request object instead of the default.
zCannot build protocol: %s)
r   rÈ   rW   r   ÚrequestFactoryr   r   r    r!   r"   )r#   Úaddrr`   s      r&   rW   ÚHTTPFactory.buildProtocol†  sW   € ð
	Ü×'Ñ'×5Ñ5°dÓAˆHÜ&0ˆHÔ#ØˆOøÜó 	Ü�L‰LÐ4´y×7KÒ7KÓ7MÑMÔNØð	ús	   ‚+. ®7A%c                 óZ   • S/n[         R                  (       a  UR                  SS5        U$ )a  
Protocols this server can speak after ALPN negotiation. Currently that
is HTTP/1.1 and optionally HTTP/2. Websockets cannot be negotiated
using ALPN, so that doesn't go here: anyone wanting websockets will
negotiate HTTP/1.1 and then do the upgrade dance.
s   http/1.1r   s   h2)r   Ú
H2_ENABLEDÚinsert)r#   ÚbaseProtocolss     r&   ÚacceptableProtocolsÚHTTPFactory.acceptableProtocols”  s(   € ð %˜ˆä�?�?Ø× Ñ   EÔ*àÐr.   )r   N)	rÀ   rÁ   rÂ   rÃ   rÄ   r   rW   rÓ   rÅ   rÆ   r.   r&   rÈ   rÈ   y  s   † ñòòõr.   rÈ   )ÚloggingrB   r!   Úurllib.parser   Útwisted.internet.deferr   r   Útwisted.internet.interfacesr   Útwisted.protocols.policiesr   Útwisted.webr   Úzope.interfacer	   Úutilsr   r   Ú	getLoggerrÀ   r   r   r   rÈ   rÆ   r.   r&   Ú<module>rÞ      sm   ðÛ Û Û Ý  ç AÝ CÝ 6Ý Ý &ç 8à	×	Ò	˜8Ó	$€ôe%�—‘ô e%ñP Ð(Ó)ô&�$×"Ñ"ó &ó *ñ&r.   