+
    Dfj<Q                        R t ^ RIHt ^ RIHt ^ RIHtHt ^ RIH	t	 ^ RI
Ht ^ RIHt ^ RIHt ^ RIHt ^ R	IHt ^ R
IHt ^ RIHt R R ltR R lt ! R R4      t ! R R4      t ! R R4      t]! ]4       ! R R4      4       tR.tR# )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_YETc                R    V ^8  d   QhR\         \        \        3,          R\        /#    stringreturn)r   strbytes)formats   "2/usr/lib/python3/dist-packages/twisted/web/wsgi.py__annotate__r   %   s#     + +c5j) +c +    c                    \        V \        4      '       d!   V P                  R4      P                  R4      # V P                  R4      # )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)
isinstancer   encodedecoder   s   &r   _wsgiStringr   %   s:     &#}}\*11,??}}\**r   c                0    V ^8  d   QhR\         R\        /# r   )r   r   )r   s   "r   r   r   7   s     
' 
's 
'u 
'r   c                $    V P                  R4      # )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                   \   a  ] tR t^Dt o Rt]! 4       tV 3R lR ltV 3R lR ltR t	Rt
V tR# )	_ErrorStreama  
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.
c                $   < V ^8  d   QhRS[ RR/# )r   datar   N)r   )r   __classdict__s   "r   r   _ErrorStream.__annotate__R   s     L L# L$ Lr   c                    \        V\        4      '       g(   \        RV: R\        V4      P                  : R24      hV P
                  P                  VRRV3R7       R# )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,,.  			VTD7Kr   c                4   < V ^8  d   QhRS[ S[,          RR/# )r   iovecr   N)r   r   )r   r'   s   "r   r   r(   g   s     # #S	 #d #r   c                F    V P                  RP                  V4      4       R# )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)r6   join)r5   r9   s   &&r   
writelines_ErrorStream.writelinesg   s     	

2775>"r   c                    R# )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 r5   s   &r   flush_ErrorStream.flushu   s    r   r@   N)r2   
__module____qualname____firstlineno____doc__r	   r3   r6   r=   rB   __static_attributes____classdictcell__r'   s   @r   r$   r$   D   s3     	 8DL L*# # r   r$   c                   N   a  ] tR t^~t o RtR tR	R ltR	R ltR	R ltR t	Rt
V tR# )
_InputStreamal  
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                    Wn         R# )z\
Initialize the instance.

This is called in the I/O thread, not a WSGI application thread.
N_wrapped)r5   inputs   &&r   __init___InputStream.__init__   s	     r   Nc                t    Vf   V P                   P                  4       # V P                   P                  V4      # )zk
Pass through to the underlying C{read}.

This is called in a WSGI application thread, not the I/O thread.
)rO   readr5   sizes   &&r   rT   _InputStream.read   s1     <==%%''}}!!$''r   c                    VR8X  g   Vf   V P                   P                  4       # V P                   P                  V4      # )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.
)rO   readlinerU   s   &&r   rZ   _InputStream.readline   s7     2:==))++}}%%d++r   c                t    Vf   V P                   P                  4       # V P                   P                  V4      # )zp
Pass through to the underlying C{readlines}.

This is called in a WSGI application thread, not the I/O thread.
)rO   	readlinesrU   s   &&r   r]   _InputStream.readlines   s1     <==**,,}}&&t,,r   c                ,    \        V P                  4      # )zo
Pass through to the underlying C{__iter__}.

This is called in a WSGI application thread, not the I/O thread.
)iterrO   rA   s   &r   __iter___InputStream.__iter__   s     DMM""r   rN   N)r2   rD   rE   rF   rG   rQ   rT   rZ   r]   ra   rH   rI   rJ   s   @r   rL   rL   ~   s(     	(,	-# #r   rL   c                   d   a  ] tR t^t o RtRt]! 4       tR tR t	RR lt
R tR tR	 tR
 tRtV tR# )_WSGIResponsea  
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                8   R V n         Wn        W n        W0n        W@n        V P                  P                  4       P                  V P                  4       VP                  '       d$   RRP                  VP                  4      ,           pMRpVP                  '       d$   RRP                  VP                  4      ,           pMRpVP                  P                  R^4      p\        V4      ^8X  d   RpM	V^,          pVP                  4       p	R\        VP                   4      R\        V	P"                  4      R\        \%        V	P&                  4      4      R\        V4      R\        V4      R	\        V4      R
\        VP)                  R4      ;'       g    R4      R\        VP)                  R4      ;'       g    R4      R\        VP+                  4       4      R\        \%        VP-                  4       P&                  4      4      R\        VP.                  4      /V n        RV P                  n        VP4                  P7                  4        Fj  w  rR\        V
4      P9                  4       P;                  RR4      ,           p
RP                  R V 4       4      P;                  RR4      V P0                  V
&   Kl  	  V P0                  P=                  RR$RVP?                  4       ;'       d    R;'       g    RRR RR R!R R"\A        4       R#\C        VPD                  4      /4       R# )%F   /r      ?REQUEST_METHODREMOTE_ADDRREMOTE_PORTSCRIPT_NAME	PATH_INFOQUERY_STRINGCONTENT_TYPEs   content-typer;   CONTENT_LENGTHs   content-lengthSERVER_NAMESERVER_PORTSERVER_PROTOCOLNHTTP_-_,c              3   8   "   T F  p\        V4      x  K  	  R # 5irc   )r   ).0vs   & r   	<genexpr>)_WSGIResponse.__init__.<locals>.<genexpr>  s     )I&Q+a..&s   
 zwsgi.versionzwsgi.url_schemehttpshttpzwsgi.run_oncezwsgi.multithreadTzwsgi.multiprocesszwsgi.errorsz
wsgi.input)       )#startedreactor
threadpoolapplicationrequestnotifyFinishaddBoth	_finishedprepathr<   postpathurisplitlengetClientAddressr   methodhostr   port	getHeadergetRequestHostnamegetHostclientprotoenvirondefaultContentTyperequestHeadersgetAllRawHeadersupperreplaceupdateisSecurer$   rL   content)r5   r   r   r   r   
scriptNamepathInfopartsqueryString
remotePeernamevaluess   &&&&&       r   rQ   _WSGIResponse.__init__   s|   $&!!#++DNN;???		'// ::JJdii(8(899HH!!$*u:?K(K --/
k'..9;z7;s:??';<;z2X.K4K(9(9/(J(P(PbQk'*;*;<M*N*T*TRTU;w'A'A'CD;s7??+<+A+A'BC{7+>+>?
" +/'#22CCELD[.446>>sCHHD "%)I&)I!I!Q!Qc"DLL	 F 	!7#3#3#5#A#A'#K#KV"D#U|~ l7??;+	
r   c                    RV n         R# )zK
Record the end of the response generation for the request being
serviced.
TN)_requestFinished)r5   ignoreds   &&r   r   _WSGIResponse._finished2  s    
 !%r   Nc           	        V P                   '       d$   Ve    V^,          P                  V^,          4      h\        V\        4      '       g/   \	        RP                  V\        V4      P                  4      4      h\        V\        4      '       d   Mk\        V\        4      '       d/   \        RV: R\        V4      P                  : R2\        R7       M'\	        RV: R\        V4      P                  : R24      hV F  p\        V\        4      '       d   Mk\        V\        4      '       d/   \        RV: R\        V4      P                  : R2\        R7       M'\	        RV: R\        V4      P                  : R24      h\        V4      ^8w  d   \	        RV: 24      hV F(  p\        V\        4      '       d   K  \	        R	V: 24      h	  K  	  Wn        W n        V P                   # )
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.
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 )r   with_tracebackr   r   r0   r   r1   r2   listr   r   RuntimeWarningtupler   statusheadersr6   )r5   r   r   excInfoheaderelems   &&&&  r   startResponse_WSGIResponse.startResponse9  s    <<<G/!*++GAJ77 &#&&3::DL11  gt$$**DM224' DM224  F&%((FH--tF|446+  tF|446  6{a"I& TUU
 !$,,#&KF:$VWW - 4 zzr   c                ~   a a VV 3R lp \        S P                  VS P                  4      RS n        #   RS n        i ; i)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                 n   < V '       g   SP                  4        SP                  P                  S4       R # rc   )_sendResponseHeadersr   r6   )r   r&   r5   s   &r   	wsgiWrite&_WSGIResponse.write.<locals>.wsgiWrite  s$    ))+LLt$r   T)r   r   r   )r5   r&   r   s   ff r   r6   _WSGIResponse.write~  s1    B	%
	 )$,,	4<<PDL4DLs    3 	<c                j   V P                   P                  R^4      w  r\        V4      pV P                  P	                  V\        V4      4       V P                   FT  w  r4VP                  4       R9  g   K  V P                  P                  P                  \        V4      \        V4      4       KV  	  R# )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.
N)serverdate)
r   r   intr   setResponseCoder"   r   lowerresponseHeadersaddRawHeader)r5   coder/   r   values   &    r   r   "_WSGIResponse._sendResponseHeaders  s     ))$24y$$T+=g+FG<<KDzz|#55,,99&t,.@.G (r   c                P    V P                   P                  V P                  4       R# )zW
Start the WSGI application in the threadpool.

This must be called in the I/O thread.
N)r   callInThreadrunrA   s   &r   start_WSGIResponse.start  s     	$$TXX.r   c                  a   S P                  S P                  S P                  4      pV F0  pV'       d   S P                  V4       S P                  '       g   K0   M	  \        VRR4      pVe   V! 4        V 3R lpS P                  P                  VS P                  4       RS n        R#   \         d;    T 3R lpS P                  P                  ! TS P                  .\        4       O5!    LMi ; i)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                    < SP                   '       g5   V '       g   SP                  4        SP                  P                  4        R # R # rc   )r   r   r   finish)r   r5   s   &r   
wsgiFinish%_WSGIResponse.run.<locals>.wsgiFinish  s3    ,,,"113LL'') -r   c                   < SP                   P                  R \        W!V4      R7       V '       d   SP                  P	                  4        R# SP                  P                  \        4       SP                  P                  4        R# )zWSGI application error)failureN)r3   r   r
   r   loseConnectionr   r   r   )r   r1   r   	tracebackr5   s   &&&&r   	wsgiError$_WSGIResponse.run.<locals>.wsgiError  s^    		!!,ge96U "  LL//1LL001FGLL'')r   T)r   r   r   r6   r   getattrr   callFromThreadr   BaseExceptionr   )r5   appIteratorr   r   r   r   s   f     r   r   _WSGIResponse.run  s    	B**4<<9K9KLK#JJt$(((	 $
 K$7E  * LL''
DLLA-  	N* LL''	4<<M(*M	Ns   AB, B, ,AC10C1)	r   r   r   r   r   r   r   r   r   rc   )r2   rD   rE   rF   rG   r   r	   r3   rQ   r   r   r6   r   r   r   rH   rI   rJ   s   @r   re   re      sG     B 8DN
`%CJ) V(/' 'r   re   c                   @   a  ] tR tRt o RtRtR tR tR tR t	Rt
V tR	# )
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                *    Wn         W n        W0n        R # rc   )_reactor_threadpool_application)r5   r   r   r   s   &&&&r   rQ   WSGIResource.__init__  s    %'r   c                    \        V P                  V P                  V P                  V4      pVP	                  4        \
        # )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.
)re   r   r   r   r   r   )r5   r   responses   && r   renderWSGIResource.render
  s9     !MM4++T->->
 	r   c                    \        R4      h)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)r5   r   r   s   &&&r   getChildWithDefault WSGIResource.getChildWithDefault  s     LMMr   c                    \        R4      h)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   )r5   pathchilds   &&&r   putChildWSGIResource.putChild"  s     MNNr   )r   r   r   N)r2   rD   rE   rF   rG   isLeafrQ   r   r   r   rH   rI   rJ   s   @r   r   r     s-     $ F(
 NO Or   r   N)rG   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   r"   r$   rL   re   r   __all__r@   r   r   <module>r     s   
 %    & ; ! * 2 * + +$
'7 7t<# <#~o od	 Y8O 8O 8Ov 
r   