ó
    ×›‘h<Q  ã                   ó*  • S r SSKJ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  SS
KJr  SSKJr  SSKJr  S\\\4   S\4S jrS\S\4S jr " S S5      r " S S5      r " S S5      r\" \5       " S S5      5       rS/r g)zo
An implementation of
U{Python Web Server Gateway Interface v1.0.1<http://www.python.org/dev/peps/pep-3333/>}.
é    )ÚSequence)Úexc_info)ÚListÚUnion)Úwarn)Úimplementer)ÚblockingCallFromThread)ÚLogger)ÚFailure)ÚINTERNAL_SERVER_ERROR)Ú	IResource)ÚNOT_DONE_YETÚstringÚreturnc                 óŽ   • [        U [        5      (       a   U R                  S5      R                  S5      $ U R                  S5      $ )a;  
Convert C{string} to a WSGI "bytes-as-unicode" string.

If it's a byte string, decode as ISO-8859-1. If it's a Unicode string,
round-trip it to bytes and back using ISO-8859-1 as the encoding.

@type string: C{str} or C{bytes}
@rtype: C{str}

@raise UnicodeEncodeError: If C{string} contains non-ISO-8859-1 chars.
ú
iso-8859-1)Ú
isinstanceÚstrÚencodeÚdecode©r   s    ÚTC:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/web/wsgi.pyÚ_wsgiStringr   %   s:   € ô �&œ#×ÑØ�}‰}˜\Ó*×1Ñ1°,Ó?Ð?à�}‰}˜\Ó*Ð*ó    c                 ó$   • U R                  S5      $ )zÆ
Convert C{string} from a WSGI "bytes-as-unicode" string to an
ISO-8859-1 byte string.

@type string: C{str}
@rtype: C{bytes}

@raise UnicodeEncodeError: If C{string} contains non-ISO-8859-1 chars.
r   )r   r   s    r   Ú_wsgiStringToBytesr   7   s   € ð �=‰=˜Ó&Ð&r   c                   óV   • \ rS rSrSr\" 5       rS\SS4S jrS\	\   SS4S jr
S	 rS
rg)Ú_ErrorStreaméD   a—  
File-like object instances of which are used as the value for the
C{'wsgi.errors'} key in the C{environ} dictionary passed to the application
object.

This simply passes writes on to L{logging<twisted.logger>} system as
error events from the C{'wsgi'} system.  In the future, it may be desirable
to expose more information in the events it logs, such as the application
object which generated the message.
Údatar   Nc                 ó¶   • [        U[        5      (       d'  [        SU< S[        U5      R                  < S35      eU R
                  R                  USSU4S9  g)zØ
Generate an event for the logging system with the given bytes as the
message.

This is called in a WSGI application thread, not the I/O thread.

@type data: str

@raise TypeError: if C{data} is not a native string.
z"write() argument must be str, not ú (Ú)ÚwsgiT)ÚsystemÚisErrorÚmessageN)r   r   Ú	TypeErrorÚtypeÚ__name__Ú_logÚerror)Úselfr    s     r   ÚwriteÚ_ErrorStream.writeR   sN   € ô ˜$¤×$Ñ$Ýãœ˜d›×,Ô,ð.óð ð 	�	‰	�‰˜ V°TÀDÀ7ˆÒKr   Úiovecc                 óD   • U R                  SR                  U5      5        g)a"  
Join the given lines and pass them to C{write} to be handled in the
usual way.

This is called in a WSGI application thread, not the I/O thread.

@param iovec: A C{list} of C{'\n'}-terminated C{str} which will be
    logged.

@raise TypeError: if C{iovec} contains any non-native strings.
Ú N)r.   Újoin)r-   r0   s     r   Ú
writelinesÚ_ErrorStream.writelinesg   s   € ð 	�
‰
�2—7‘7˜5“>Õ"r   c                 ó   • g)z¨
Nothing is buffered, so flushing does nothing.  This method is required
to exist by PEP 333, though.

This is called in a WSGI application thread, not the I/O thread.
N© ©r-   s    r   ÚflushÚ_ErrorStream.flushu   s   � r   r7   )r*   Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r
   r+   r   r.   r   r4   r9   Ú__static_attributes__r7   r   r   r   r   D   sB   † ñ	ñ ‹8€DðL˜#ð L $ô Lð*#  S¡	ð #¨dô #õr   r   c                   óB   • \ rS rSrSrS rS
S jrS
S jrS
S jrS r	S	r
g)Ú_InputStreamé~   al  
File-like object instances of which are used as the value for the
C{'wsgi.input'} key in the C{environ} dictionary passed to the application
object.

This only exists to make the handling of C{readline(-1)} consistent across
different possible underlying file-like object implementations.  The other
supported methods pass through directly to the wrapped object.
c                 ó   • Xl         g)z\
Initialize the instance.

This is called in the I/O thread, not a WSGI application thread.
N©Ú_wrapped)r-   Úinputs     r   Ú__init__Ú_InputStream.__init__‰   s	   € ð �r   Nc                 ór   • Uc  U R                   R                  5       $ U R                   R                  U5      $ )zk
Pass through to the underlying C{read}.

This is called in a WSGI application thread, not the I/O thread.
)rE   Úread©r-   Úsizes     r   rJ   Ú_InputStream.read‘   s1   € ð ‰<Ø—=‘=×%Ñ%Ó'Ð'Ø�}‰}×!Ñ! $Ó'Ð'r   c                 ó~   • US:X  d  Uc  U R                   R                  5       $ U R                   R                  U5      $ )z¥
Pass through to the underlying C{readline}, with a size of C{-1} replaced
with a size of L{None}.

This is called in a WSGI application thread, not the I/O thread.
éÿÿÿÿ)rE   ÚreadlinerK   s     r   rP   Ú_InputStream.readlineœ   s7   € ð �2‹:˜™Ø—=‘=×)Ñ)Ó+Ð+Ø�}‰}×%Ñ% dÓ+Ð+r   c                 ór   • Uc  U R                   R                  5       $ U R                   R                  U5      $ )zp
Pass through to the underlying C{readlines}.

This is called in a WSGI application thread, not the I/O thread.
)rE   Ú	readlinesrK   s     r   rS   Ú_InputStream.readlines©   s1   € ð ‰<Ø—=‘=×*Ñ*Ó,Ð,Ø�}‰}×&Ñ& tÓ,Ð,r   c                 ó,   • [        U R                  5      $ )zo
Pass through to the underlying C{__iter__}.

This is called in a WSGI application thread, not the I/O thread.
)ÚiterrE   r8   s    r   Ú__iter__Ú_InputStream.__iter__´   s   € ô �D—M‘MÓ"Ð"r   rD   ©N)r*   r;   r<   r=   r>   rG   rJ   rP   rS   rW   r?   r7   r   r   rA   rA   ~   s    † ñòô	(ô,ô	-õ#r   rA   c                   óX   • \ rS rSrSrSr\" 5       rS rS r	SS jr
S rS	 rS
 rS rSrg)Ú_WSGIResponseé½   aÌ  
Helper for L{WSGIResource} which drives the WSGI application using a
threadpool and hooks it up to the L{http.Request}.

@ivar started: A L{bool} indicating whether or not the response status and
    headers have been written to the request yet.  This may only be read or
    written in the WSGI application thread.

@ivar reactor: An L{IReactorThreads} provider which is used to call methods
    on the request in the I/O thread.

@ivar threadpool: A L{ThreadPool} which is used to call the WSGI
    application object in a non-I/O thread.

@ivar application: The WSGI application object.

@ivar request: The L{http.Request} upon which the WSGI environment is
    based and to which the application's output will be sent.

@ivar environ: The WSGI environment L{dict}.

@ivar status: The HTTP response status L{str} supplied to the WSGI
    I{start_response} callable by the application.

@ivar headers: A list of HTTP response headers supplied to the WSGI
    I{start_response} callable by the application.

@ivar _requestFinished: A flag which indicates whether it is possible to
    generate more response data or not.  This is L{False} until
    L{http.Request.notifyFinish} tells us the request is done,
    then L{True}.
Fc                 óè  • SU l         Xl        X l        X0l        X@l        U R                  R                  5       R                  U R                  5        UR                  (       a  SSR                  UR                  5      -   nOSnUR                  (       a  SSR                  UR                  5      -   nOSnUR                  R                  SS5      n[        U5      S:X  a  SnOUS   nUR                  5       n	[        UR                   5      [        U	R"                  5      [        [%        U	R&                  5      5      [        U5      [        U5      [        U5      [        UR)                  S5      =(       d    S5      [        UR)                  S5      =(       d    S5      [        UR+                  5       5      [        [%        UR-                  5       R&                  5      5      [        UR.                  5      S	.U l        S U R                  l        UR4                  R7                  5        Hf  u  p«S
[        U
5      R9                  5       R;                  SS5      -   n
SR                  S U 5       5      R;                  SS5      U R0                  U
'   Mh     U R0                  R=                  SUR?                  5       =(       a    S=(       d    SSSS[A        5       [C        URD                  5      S.5        g )NFó   /r   ó   ?é   s   content-typer2   s   content-length)ÚREQUEST_METHODÚREMOTE_ADDRÚREMOTE_PORTÚSCRIPT_NAMEÚ	PATH_INFOÚQUERY_STRINGÚCONTENT_TYPEÚCONTENT_LENGTHÚSERVER_NAMEÚSERVER_PORTÚSERVER_PROTOCOLÚHTTP_Ú-Ú_Ú,c              3   ó8   #   • U  H  n[        U5      v •  M     g 7frY   )r   )Ú.0Úvs     r   Ú	<genexpr>Ú)_WSGIResponse.__init__.<locals>.<genexpr>  s   é € Ð)IÂ&¸Q¬+°a¯.¨.Â&ùs   ‚Ú
Ú )r`   r   ÚhttpsÚhttpT)zwsgi.versionzwsgi.url_schemezwsgi.run_oncezwsgi.multithreadzwsgi.multiprocesszwsgi.errorsz
wsgi.input)#ÚstartedÚreactorÚ
threadpoolÚapplicationÚrequestÚnotifyFinishÚaddBothÚ	_finishedÚprepathr3   ÚpostpathÚuriÚsplitÚlenÚgetClientAddressr   ÚmethodÚhostr   ÚportÚ	getHeaderÚgetRequestHostnameÚgetHostÚclientprotoÚenvironÚdefaultContentTypeÚrequestHeadersÚgetAllRawHeadersÚupperÚreplaceÚupdateÚisSecurer   rA   Úcontent)r-   rz   r{   r|   r}   Ú
scriptNameÚpathInfoÚpartsÚqueryStringÚ
remotePeerÚnameÚvaluess               r   rG   Ú_WSGIResponse.__init__â   sG  € ØˆŒØŒØ$ŒØ&ÔØŒØ�‰×!Ñ!Ó#×+Ñ+¨D¯N©NÔ;à�?�?Ø §	¡	¨'¯/©/Ó :Ñ:‰JàˆJà××Ø˜dŸi™i¨×(8Ñ(8Ó9Ñ9‰HàˆHà—‘×!Ñ! $¨Ó*ˆÜˆu‹:˜‹?Ø‰Kà ™(ˆKð ×-Ñ-Ó/ˆ
ä)¨'¯.©.Ó9Ü& z§¡Ó7Ü&¤s¨:¯?©?Ó';Ó<Ü& zÓ2Ü$ XÓ.Ü'¨Ó4Ü'¨×(9Ñ(9¸/Ó(J×(PÈbÓQÜ)¨'×*;Ñ*;Ð<MÓ*N×*TÐRTÓUÜ& w×'AÑ'AÓ'CÓDÜ&¤s¨7¯?©?Ó+<×+AÑ+AÓ'BÓCÜ*¨7×+>Ñ+>Ó?ñ
ˆŒð" +/ˆ�‰Ô'à#×2Ñ2×CÑCÖE‰LˆDØœ[¨Ó.×4Ñ4Ó6×>Ñ>¸sÀCÓHÑHˆDð "%§¡Ñ)IÁ&Ó)IÓ!I×!QÑ!QØ�có"ˆD�L‰L˜Óñ	 Fð 	�‰×Ñà &Ø#*×#3Ñ#3Ó#5×#A¸'×#KÀVØ!&Ø$(Ø%*Ü+›~ô +¨7¯?©?Ó;ñ+õ	
r   c                 ó   • SU l         g)zK
Record the end of the response generation for the request being
serviced.
TN)Ú_requestFinished)r-   Úignoreds     r   r€   Ú_WSGIResponse._finished2  s   € ð
 !%ˆÕr   Nc           	      óª  • U R                   (       a  Ub  US   R                  US   5      e[        U[        5      (       d.  [	        SR                  U[        U5      R                  5      5      e[        U[        5      (       a  Og[        U[        5      (       a+  [        SU< S[        U5      R                  < S3[        S9  O'[	        SU< S[        U5      R                  < S35      eU HË  n[        U[        5      (       a  Og[        U[        5      (       a+  [        S	U< S[        U5      R                  < S3[        S9  O'[	        S
U< S[        U5      R                  < S35      e[        U5      S:w  a  [	        S
U< 35      eU H'  n[        U[        5      (       a  M  [	        SU< 35      e   MÍ     Xl        X l        U R                   $ )zœ
The WSGI I{start_response} callable.  The given values are saved until
they are needed to generate the response.

This will be called in a non-I/O thread.
r`   é   z!status must be str, not {!r} ({})zheaders should be a list, not r"   r#   )Úcategoryzheaders must be a list, not z)header should be a (str, str) tuple, not z'header must be a (str, str) tuple, not z%header must be (str, str) tuple, not )ry   Úwith_tracebackr   r   r(   Úformatr)   r*   Úlistr   r   ÚRuntimeWarningÚtupler…   ÚstatusÚheadersr.   )r-   r«   r¬   ÚexcInfoÚheaderÚelems         r   ÚstartResponseÚ_WSGIResponse.startResponse9  s‘  € ð �<�<˜GÑ/Ø˜!‘*×+Ñ+¨G°A©JÓ7Ð7ô ˜&¤#×&Ñ&ÜØ3×:Ñ:ØœD ›L×1Ñ1óóð ô �gœt×$Ñ$ØÜ˜¤×*Ñ*ÝãœD ›M×2Ô2ð4ä'óõ ãœD ›M×2Ô2ð4óð ó ˆFÜ˜&¤%×(Ñ(ØÜ˜F¤H×-Ñ-Ýãœt F›|×4Ô4ð6ä+óõ  ãœt F›|×4Ô4ð6óð ô �6‹{˜aÓÜÐ"IÈ&ÉÐ TÓUÐUó
 �Ü! $¬×,Ó,Ü#Ð&KÈFÉ:Ð$VÓWÐWó ñ- ð4 ŒØŒØ�z‰zÐr   c                 ó~   ^ ^• UU 4S jn [        T R                  UT R                  5      ST l        $ ! ST l        f = f)zØ
The WSGI I{write} callable returned by the I{start_response} callable.
The given bytes will be written to the response body, possibly flushing
the status and headers first.

This will be called in a non-I/O thread.
c                 ój   >• U (       d  TR                  5         TR                  R                  T5        g rY   )Ú_sendResponseHeadersr}   r.   )ry   r    r-   s    €€r   Ú	wsgiWriteÚ&_WSGIResponse.write.<locals>.wsgiWriteŸ  s$   ø€ ÞØ×)Ñ)Ô+Ø�L‰L×Ñ˜tÕ$r   T)r	   rz   ry   )r-   r    rµ   s   `` r   r.   Ú_WSGIResponse.write~  s1   ù€ öB	%ð
	 Ü)¨$¯,©,¸	À4Ç<Á<ÓPàˆD�Lø˜4ˆD�Lús   ‹ 3 ³	<c                 óf  • U R                   R                  SS5      u  p[        U5      nU R                  R	                  U[        U5      5        U R                   HS  u  p4UR                  5       S;  d  M  U R                  R                  R                  [        U5      [        U5      5        MU     g)zü
Set the response code and response headers on the request object, but
do not flush them.  The caller is responsible for doing a write in
order for anything to actually be written out in response to the
request.

This must be called in the I/O thread.
Nr`   )ÚserverÚdate)
r«   r„   Úintr}   ÚsetResponseCoder   r¬   ÚlowerÚresponseHeadersÚaddRawHeader)r-   Úcoder'   rœ   Úvalues        r   r´   Ú"_WSGIResponse._sendResponseHeaders©  s†   € ð Ÿ™×)Ñ)¨$°Ó2‰ˆÜ�4‹yˆØ�‰×$Ñ$ TÔ+=¸gÓ+FÔGàŸ<œ<‰KˆDà�z‰z‹|Ð#5Õ5Ø—‘×,Ñ,×9Ñ9Ü& tÓ,Ô.@ÀÓ.Göò (r   c                 óN   • U R                   R                  U R                  5        g)zW
Start the WSGI application in the threadpool.

This must be called in the I/O thread.
N)r{   ÚcallInThreadÚrunr8   s    r   ÚstartÚ_WSGIResponse.start½  s   € ð 	�‰×$Ñ$ T§X¡XÕ.r   c                 óÜ  ^ •  T R                  T R                  T R                  5      nU H.  nU(       a  T R                  U5        T R                  (       d  M.    O   [        USS5      nUb  U" 5         U 4S jnT R                  R                  UT R                  5        ST l        g! [         a9    U 4S jnT R                  R                  " UT R                  /[        5       Q76    NJf = f)z�
Call the WSGI application object, iterate it, and handle its output.

This must be called in a non-I/O thread (ie, a WSGI application
thread).
ÚcloseNc                 óŒ   >• TR                   (       d2  U (       d  TR                  5         TR                  R                  5         g g rY   )r    r´   r}   Úfinish)ry   r-   s    €r   Ú
wsgiFinishÚ%_WSGIResponse.run.<locals>.wsgiFinishå  s0   ø€ Ø×,×,Þ"Ø×1Ñ1Ô3Ø—L‘L×'Ñ'Õ)ð -r   c                 ó  >• TR                   R                  S[        X!U5      S9  U (       a  TR                  R	                  5         g TR                  R                  [        5        TR                  R                  5         g )NzWSGI application error)Úfailure)r+   rÏ   r   r}   ÚloseConnectionr¼   r   rË   )ry   r)   rÁ   Ú	tracebackr-   s       €r   Ú	wsgiErrorÚ$_WSGIResponse.run.<locals>.wsgiErrorØ  s^   ø€ Ø—	‘	×!Ñ!Ø,´g¸eÈ9Ó6Uð "ñ ö Ø—L‘L×/Ñ/Õ1à—L‘L×0Ñ0Ô1FÔGØ—L‘L×'Ñ'Õ)r   T)r|   rŽ   r°   r.   r    Úgetattrrz   ÚcallFromThreadry   ÚBaseExceptionr   )r-   ÚappIteratorr¯   rÉ   rÌ   rÒ   s   `     r   rÅ   Ú_WSGIResponse.runÅ  sÇ   ø€ ð	BØ×*Ñ*¨4¯<©<¸×9KÑ9KÓLˆKÛ#�ÞØ—J‘J˜tÔ$Ø×(×(Ñ(Ùñ	 $ô
 ˜K¨°$Ó7ˆEØÑ Ù”õ *ð �L‰L×'Ñ'¨
°D·L±LÔAØˆ�øô- ó 	Nõ*ð �L‰L×'Ò'¨	°4·<±<ÐMÄ(Ã*ÕMð	Nús   ƒAB( ÁB( Â(A C+Ã*C+)	r    r|   rŽ   r¬   rz   r}   ry   r«   r{   rY   )r*   r;   r<   r=   r>   r    r
   r+   rG   r€   r°   r.   r´   rÆ   rÅ   r?   r7   r   r   r[   r[   ½   s?   † ñðB ÐÙ‹8€DòN
ò`%ôCòJ) òVò(/õ'r   r[   c                   ó4   • \ rS rSrSrSrS rS rS rS r	Sr
g	)
ÚWSGIResourceiï  a/  
An L{IResource} implementation which delegates responsibility for all
resources hierarchically inferior to it to a WSGI application.

The C{environ} argument passed to the application, includes the
C{REMOTE_PORT} key to complement the C{REMOTE_ADDR} key.

@ivar _reactor: An L{IReactorThreads} provider which will be passed on to
    L{_WSGIResponse} to schedule calls in the I/O thread.

@ivar _threadpool: A L{ThreadPool} which will be passed on to
    L{_WSGIResponse} to run the WSGI application object.

@ivar _application: The WSGI application object.
Tc                 ó(   • Xl         X l        X0l        g rY   )Ú_reactorÚ_threadpoolÚ_application)r-   rz   r{   r|   s       r   rG   ÚWSGIResource.__init__  s   € ØŒØ%ÔØ'Õr   c                 ó†   • [        U R                  U R                  U R                  U5      nUR	                  5         [
        $ )a†  
Turn the request into the appropriate C{environ} C{dict} suitable to be
passed to the WSGI application object and then pass it on.

The WSGI application object is given almost complete control of the
rendering process.  C{NOT_DONE_YET} will always be returned in order
and response completion will be dictated by the application object, as
will the status, headers, and the response body.
)r[   rÜ   rÝ   rÞ   rÆ   r   )r-   r}   Úresponses      r   ÚrenderÚWSGIResource.render
  s9   € ô !Ø�M‰M˜4×+Ñ+¨T×->Ñ->Àó
ˆð 	�‰ÔÜÐr   c                 ó   • [        S5      e)z›
Reject attempts to retrieve a child resource.  All path segments beyond
the one which refers to this resource are handled by the WSGI
application object.
z/Cannot get IResource children from WSGIResource©ÚRuntimeError)r-   rœ   r}   s      r   ÚgetChildWithDefaultÚ WSGIResource.getChildWithDefault  s   € ô ÐLÓMÐMr   c                 ó   • [        S5      e)z¶
Reject attempts to add a child resource to this resource.  The WSGI
application object handles all path segments beneath this resource, so
L{IResource} children can never be found.
z0Cannot put IResource children under WSGIResourcerå   )r-   ÚpathÚchilds      r   ÚputChildÚWSGIResource.putChild"  s   € ô ÐMÓNÐNr   )rÞ   rÜ   rÝ   N)r*   r;   r<   r=   r>   ÚisLeafrG   râ   rç   rì   r?   r7   r   r   rÚ   rÚ   ï  s$   † ñð$ €Fò(ò
ò NõOr   rÚ   N)!r>   Úcollections.abcr   Úsysr   Útypingr   r   Úwarningsr   Úzope.interfacer   Útwisted.internet.threadsr	   Útwisted.loggerr
   Útwisted.python.failurer   Útwisted.web.httpr   Útwisted.web.resourcer   Útwisted.web.serverr   r   Úbytesr   r   r   rA   r[   rÚ   Ú__all__r7   r   r   Ú<module>rü      s«   ðñõ
 %Ý ß Ý å &å ;Ý !Ý *Ý 2Ý *Ý +ð +˜˜c 5˜jÑ)ð +¨cô +ð$
'˜sð 
' uô 
'÷7ñ 7÷t<#ñ <#÷~oñ oñd	 ˆYÓ÷8Oð 8Oó ð8Oðv Ð
�r   