https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/trac/web/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/trac/web/__pycache__/_fcgi.cpython-310.pyc
o

�k�`��@sLdZdZdZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZzddlZddl
Z
dZWneyIddlZddlZ
dZYnwee	d�sRde	_d	gZdZd
ZdZdZdZdZd
ZdZdZdZd
ZdZ dZ!dZ"e"Z#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3e�4e2�Z5e�4e3�Z6	ddl7Z7dZ8dZ9dd�Z:Gdd�de;�Z<Gd d!�d!e<�Z=Gd"d#�d#e;�Z>Gd$d%�d%e;�Z?Gd&d'�d'e;�Z@d<d(d)�ZAd*d+�ZBGd,d-�d-e;�ZCGd.d/�d/e;�ZDGd0d1�d1eD�ZEGd2d3�d3e;�ZFGd4d5�d5eF�ZGGd6d7�d7e;�ZHGd8d	�d	eH�ZIeJd9k�r$d:d;�ZKeIeK��L�dSdS)=a�
fcgi - a FastCGI/WSGI gateway.

For more information about FastCGI, see <http://www.fastcgi.com/>.

For more information about the Web Server Gateway Interface, see

<http://www.python.org/peps/pep-0333.html>.

Example usage:

  #!/usr/bin/env python
  from myapplication import app # Assume app is your WSGI application object
  from fcgi import WSGIServer
  WSGIServer(app).run()

See the documentation for WSGIServer/Server for more information.

On most platforms, fcgi will fallback to regular CGI behavior if run in a
non-FastCGI context. If you want to force CGI behavior, set the environment
variable FCGI_FORCE_CGI to "Y" or "y".
zAllan Saddi <allan@saddi.com>z$Revision: 2025 $�NTF�SHUT_WR��
WSGIServer��������	�
��FCGI_MAX_CONNS�
FCGI_MAX_REQS�FCGI_MPXS_CONNSz!BBHHBxz!HB5xz!LB3xz!B7xz
/tmp/fcgi.logcCspt|krdSz+ttddd��}|�dt��dd�|f�Wd�WdS1s*wYWdSYdS)N�azutf-8)�encodingz%sfcgi: %s
r���)�DEBUG�open�DEBUGLOG�write�time�ctime)�level�msg�f�r�0/usr/lib/python3/dist-packages/trac/web/_fcgi.py�_debugws &�r c@sbeZdZdZdd�Zdd�Zdd�Zdd	d
�Zddd
�Zddd�Z	dd�Z
dd�ZeZdd�Z
dS)�InputStreamz�
    File-like object representing FastCGI input streams (FCGI_STDIN and
    FCGI_DATA). Supports the minimum methods required by WSGI spec.
    cCs2||_|jj|_d|_g|_d|_d|_d|_dS)N�rF)	�_conn�server�inputStreamShrinkThreshold�_shrinkThreshold�_buf�_bufList�_pos�_avail�_eof)�self�connrrr�__init__�s

zInputStream.__init__cCsJ|j|jkr!|j|jd�|_|j|j8_d|_|jdks#J�dSdS)z6Gets rid of already read data (since we can't rewind).Nr)r)r&r'r*�r,rrr�
_shrinkBuffer�s�zInputStream._shrinkBuffercCs|j��dS)z(Waits for more data to become available.N)r#�
process_inputr/rrr�_waitForData��zInputStream._waitForData���cCs�|j|jkr|jrdS	|dks|j|j|kr$|jr|j}n|��q|j|}	|jr;|jd�|j�7_g|_|j|j|�}||_|��|S)Nr"Tr)r)r*r+r2r(r'�joinr0)r,�n�newPos�rrrr�read�s$
zInputStream.readNcCs�|j|jkr|jrdS	|jr|jd�|j�7_g|_|j�d|j�}|dkr5|jr0|j}n
|��q|d}	|durJ|j||krJ|j|}|j|j|�}||_|��|S)Nr"T�
rr)	r)r*r+r(r'r5�findr2r0)r,�length�ir7r8rrr�readline�s,
zInputStream.readlinercCsTd}g}|��}|r(|�|�|t|�7}d|kr!|kr"	|S|��}|s
|S)Nr)r>�append�len)r,�sizehint�total�lines�linerrr�	readlines�s
��zInputStream.readlinescCs|S�Nrr/rrr�__iter__�szInputStream.__iter__cCs|��}|st�|SrF)r>�
StopIteration)r,r8rrr�__next__�szInputStream.__next__cCs0|sd|_dS|j�|�|jt|�7_dS�NT)r+r(r?r*r@�r,�datarrr�add_data�s
zInputStream.add_data�r4rF�r)�__name__�
__module__�__qualname__�__doc__r.r0r2r9r>rErGrI�nextrMrrrrr!�s
	


r!csPeZdZdZ�fdd�Zdd�Zd�fdd�	Zd�fd
d�	Z�fdd
�Z�Z	S)�MultiplexedInputStreamz�
    A version of InputStream meant to be used with MultiplexedConnections.
    Assumes the MultiplexedConnection (the producer) and the Request
    (the consumer) are running in different threads.
    cs$t��|�t��}t�|�|_dSrF��superr.�	threading�RLock�	Condition�_lock)r,r-�lock��	__class__rrr.�szMultiplexedInputStream.__init__cCs|j��dSrF)r[�waitr/rrrr2r3z#MultiplexedInputStream._waitForDatar4c�0|j��zt��|�W|j��S|j��wrF)r[�acquirerWr9�release)r,r6r]rrr9�
zMultiplexedInputStream.readNcr`rF)r[rarWr>rb)r,r<r]rrr>rczMultiplexedInputStream.readlinecs>|j��zt��|�|j��W|j��dS|j��wrF)r[rarWrM�notifyrbrKr]rrrMs

zMultiplexedInputStream.add_datarNrF)
rPrQrRrSr.r2r9r>rM�
__classcell__rrr]rrU�s
rUc@sBeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�OutputStreamz�
    FastCGI output stream (FCGI_STDOUT/FCGI_STDERR). By default, calls to
    write() or writelines() immediately result in Records being sent back
    to the server. Buffering should be done in a higher level!
    FcCs.||_||_||_||_g|_d|_d|_dS�NF)r#�_req�_type�	_bufferedr(�dataWritten�closed)r,r-�req�type�bufferedrrrr.'s
zOutputStream.__init__cCspt|�}|r6t||jjjt�}t|j|jj�}||_	|d|�|_
|j�|�||d�}||8}|sdSdSrF)
r@�minrhr$�maxwrite�FCGI_HEADER_LEN�Recordri�	requestId�
contentLength�contentDatar#�writeRecord)r,rLr<�toWrite�recrrr�_write0s�zOutputStream._writecCs<|jrJ�|s	dSd|_|jr|j�|�dS|�|�dSrJ)rlrkrjr(r?rzrKrrrr=s
zOutputStream.writecCs"|jrJ�|D]}|�|�qdSrF)rlr�r,rCrDrrr�
writelinesJs
�zOutputStream.writelinescCs*|jrd�|j�}g|_|�|�dSdS)Nr")rjr5r(rzrKrrr�flushPs
�zOutputStream.flushcCsB|js|jr|��t|j|jj�}|j�|�d|_dSdSdS)z/Sends end-of-stream notification, if necessary.TN)	rlrkr}rsrirhrtr#rw�r,ryrrr�closeXs
�zOutputStream.closeN�F)
rPrQrRrSr.rzrr|r}rrrrrrf!s
	

rfc@�0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�TeeOutputStreamzq
    Simple wrapper around two or more output file-like objects that copies
    written data to all streams.
    cCs
||_dSrF)�_streamList)r,�
streamListrrrr.e�
zTeeOutputStream.__init__cCs|jD]}|�|�qdSrF)r�r)r,rLrrrrrhs
�zTeeOutputStream.writecC�|D]}|�|�qdSrF�rr{rrrr|l��zTeeOutputStream.writelinescCs|jD]}|��qdSrF)r�r})r,rrrrr}ps

�zTeeOutputStream.flushN)rPrQrRrSr.rr|r}rrrrr�`sr�c@r�)�
StdoutWrapperzN
    Wrapper for sys.stdout so we know if data has actually been written.
    cCs||_d|_dSrg)�_filerk)r,�stdoutrrrr.x�
zStdoutWrapper.__init__cCs|rd|_|j�|�dSrJ)rkr�rrKrrrr|szStdoutWrapper.writecCr�rFr�r{rrrr|�r�zStdoutWrapper.writelinescCst|j|�SrF)�getattrr�)r,�namerrr�__getattr__�szStdoutWrapper.__getattr__N)rPrQrRrSr.rr|r�rrrrr�tsr�cCs�t||�}|d@rt�d|||d��dd@}|d7}n|d7}t||�}|d@rBt�d|||d��dd@}|d7}n|d7}||||�}||7}||||�}||7}|||ffS)zv
    Decodes a name/value pair.

    The number of bytes decoded as well as the name/value pair
    are returned.
    ��!Lrri���r)�ord�struct�unpack)�s�pos�
nameLength�valueLengthr��valuerrr�decode_pair�s 
 
r�cCsht|�}|dkr
t|�}nt�d|dB�}t|�}|dkr$|t|�7}n
|t�d|dB�7}|||S)zI
    Encodes a name/value pair.

    The encoded string is returned.
    r�r�l)r@�chrr��pack)r�r�r�r�r�rrr�encode_pair�s
r�c@sFeZdZdZeefdd�Zedd��Zdd�Z	edd	��Z
d
d�ZdS)
rszD
    A FastCGI Record.

    Used for encoding/decoding records.
    cCs(t|_||_||_d|_d|_d|_dS)Nrr")�FCGI_VERSION_1�versionrnrtru�
paddingLengthrv)r,rnrtrrrr.�s
zRecord.__init__c
Cs�g}d}|rGz|�|�}Wn#tjy0}z|dtjkr+t�|ggg�WYd}~q�d}~ww|s4n|�|�t|�}||7}||8}|sd�|�|fS)z�
        Attempts to receive length bytes from a socket, blocking if necessary.
        (Socket may be blocking or non-blocking.)
        rNr")	�recv�socket�error�errno�EAGAIN�selectr?r@r5)�sockr<�dataList�recvLenrL�e�dataLenrrr�_recvall�s(��
�zRecord._recvallcCs�z
|�|t�\}}Wnt�|tkrt�t�t|�\|_|_|_|_	|_
tdd|��|j|j|j	f�|j	rRz|�||j	�\|_
}Wnt�||j	krRt�|j
rez
|�||j
�WdSt�dS)z'Read and decode a Record from a socket.Trz<read: fd = %d, type = %d, requestId = %d, contentLength = %dN)r�rr�EOFErrorr�r��FCGI_Headerr�rnrtrur�r �filenorv)r,r��headerr<rrrr9�s:
����
�zRecord.readc
Cs�t|�}|r?z|�|�}Wn#tjy0}z|dtjkr+t�g|gg�WYd}~q�d}~ww||d�}||8}|sdSdS)zY
        Writes data to a socket and does not return until all the data is sent.
        rN)r@�sendr�r�r�r�r�)r�rLr<�sentr�rrr�_sendalls���zRecord._sendallcCs�|jd@|_tdd|��|j|j|jf�t�t|j	|j|j|j|j�}|�
||�|jr6|�
||j�|jrD|�
|d|j�dSdS)z&Encode and write a Record to a socket.rTrz=write: fd = %d, type = %d, requestId = %d, contentLength = %d�N)rur�r r�rnrtr�r�r�r�r�rv)r,r�r�rrrrs ����zRecord.writeN)rPrQrRrS�FCGI_UNKNOWN_TYPE�FCGI_NULL_REQUEST_IDr.�staticmethodr�r9r�rrrrrrs�s
"
rsc@s6eZdZdZdd�Zdd�Zdefdd�Zd	d
�ZdS)�Requesta8
    Represents a single FastCGI request.

    These objects are passed to your handler and is the main interface
    between your handler and the fcgi module. The methods should not
    be called by your handler. However, server, params, stdin, stdout,
    stderr, and data are free for your handler's use.
    cCsL||_|j|_i|_||�|_t||t�|_t||tdd�|_||�|_	dS)NT)ro)
r#r$�params�stdinrf�FCGI_STDOUTr��FCGI_STDERR�stderrrL)r,r-�inputStreamClassrrrr..s
zRequest.__init__c
Cs�z
|j�|�\}}Wntj|jd�|j��|jjs$|j�|�t	d}}Yt
dd||f�z
|��|�||�WdSt
jy\}z|dtjkrQ�WYd}~dSd}~ww)z<Runs the handler, flushes the streams, and ends the request.)�filerTrz#protocolStatus = %d, appStatus = %dN)r$�handler�	traceback�	print_excr�r}r�rkr��FCGI_REQUEST_COMPLETEr �_flush�_endr�r��EPIPE)r,�protocolStatus�	appStatusr�rrr�run8s(
����zRequest.runrcCs|j�|||�dSrF)r#�end_request�r,r�r�rrrr�NszRequest._endcCs|j��|j��dSrF)r�rr�r/rrrr�Qs
zRequest._flushN)	rPrQrRrSr.r�r�r�r�rrrrr�%s
r�c@s.eZdZdZdd�Zdefdd�Zdd�Zd	S)
�
CGIRequestz4A normal CGI request disguised as a FastCGI request.cCsTd|_t|_d|_d|_||_ttj�|_	t
j|_tt
j
�|_
t
j|_t��|_dS)NrrF)rt�FCGI_RESPONDER�role�flags�abortedr$�dict�os�environr��sysr�r�r�r��io�BytesIOrL)r,r$rrrr.WszCGIRequest.__init__rcCst�|�dSrF)r��exitr�rrrr�eszCGIRequest._endcCsdSrFrr/rrrr�hszCGIRequest._flushN)rPrQrRrSr.r�r�r�rrrrr�Us
r�c@s�eZdZdZdZeZdd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
edfdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!S)"�
Connectionz�
    A Connection with the web server.

    Each Connection is associated with a single socket (which is
    connected to the web server) and is responsible for handling all
    the FastCGI message processing for that socket.
    FcCs||_||_||_i|_dSrF)�_sock�_addrr$�	_requests)r,r��addrr$rrrr.ws
zConnection.__init__cCsjz	|j�tj�WnYdSz	t�|jggg�\}}}|r&|j�d�s'nqWnY|j��dS)zClose the Connection's socket.NTi)r��shutdownr�rr�r�r)r,r8�wr�rrr�_cleanupSockets�zConnection._cleanupSocketc
Csxd|_|jr6z|��Wn&tyYn!tjtjfy2}z|dtjkr-WYd}~n	�d}~ww|js|��dS)z&Begin processing data from the socket.TrN)	�
_keepGoingr1r�r�r�r�r��EBADFr�)r,r�rrrr��s���
zConnection.runcCs|jr"zt�|jgggd�\}}}Wn	tyt�w|rn|js|js'dSt�}|�|j�|jtkr<|�	|�dS|jt
krH|�|�dS|jtkrT|�
|�dS|jtkr`|�|�dS|jtkrl|�|�dS|jtkrx|�|�dS|jtkr�|�|�dS	dS)z?Attempt to read a single Record from the socket and process it.��?N)r�r�r��
ValueErrorr�rsr9rn�FCGI_GET_VALUES�_do_get_values�FCGI_BEGIN_REQUEST�_do_begin_request�FCGI_ABORT_REQUEST�_do_abort_request�FCGI_PARAMS�
_do_params�
FCGI_STDIN�	_do_stdin�	FCGI_DATA�_do_datartr��_do_unknown_type)r,r8r�r�ryrrrr1�s6��






zConnection.process_inputcCs|�|j�dS)z/
        Write a Record to the socket.
        N)rr�r~rrrrw�szConnection.writeRecordrTcCsttt|j�}t�t||�|_t|_|�	|�|r|j
|j=tdd|j�|jt
@s6|j
s8|��d|_dSdSdS)a

        End a Request.

        Called by Request objects. An FCGI_END_REQUEST Record is
        sent to the web server. If the web server no longer requires
        the connection, the socket is closed, thereby ending this
        Connection (run() returns).
        Trzend_request: flags = %dFN)rs�FCGI_END_REQUESTrtr�r��FCGI_EndRequestBodyrv�FCGI_EndRequestBody_LENrurwr�r r��FCGI_KEEP_CONNr�r�)r,rmr�r��removeryrrrr��s
�


�zConnection.end_requestcCs|tt�}d}||jkr1t|j|�\}\}}|jj�|�}|dur,|jt|t	|��7_||jkst
|j�|_|�|�dS)z6Handle an FCGI_GET_VALUES request from the web server.rN)rs�FCGI_GET_VALUES_RESULTrur�rvr$�
capability�getr��strr@rw)r,�inrec�outrecr�r�r��caprrrr��s

�zConnection._do_get_valuescCsrt�t|j�\}}|j�||j�}|j|||_|_|_	d|_
|js1|jr1|j
|dtdd�dS||j|j<dS)z1Handle an FCGI_BEGIN_REQUEST from the web server.Fr)r�N)r�r��FCGI_BeginRequestBodyrvr$�
request_class�_inputStreamClassrtr�r�r��_multiplexedr�r��FCGI_CANT_MPX_CONN)r,r�r�r�rmrrrr��szConnection._do_begin_requestcCs$|j�|j�}|durd|_dSdS)z{
        Handle an FCGI_ABORT_REQUEST from the web server.

        We just mark a flag in the associated Request.
        NT)r�r�rtr��r,r�rmrrrr��s
�zConnection._do_abort_requestcC�|��dS)zRun the request.N)r��r,rmrrr�_start_requestszConnection._start_requestcCsl|j�|j�}|dur4|jr-d}||jkr+t|j|�\}\}}||j|<||jksdSdS|�|�dSdS)zw
        Handle an FCGI_PARAMS Record.

        If the last FCGI_PARAMS Record is received, start the request.
        Nr)r�r�rtrur�rvr�r)r,r�rmr�r�r�rrrr�s

��zConnection._do_paramscC�,|j�|j�}|dur|j�|j�dSdS)zHandle the FCGI_STDIN stream.N)r�r�rtr�rMrvrrrrr���zConnection._do_stdincCr)zHandle the FCGI_DATA stream.N)r�r�rtrLrMrvrrrrr�"rzConnection._do_datacCs,tt�}t�t|j�|_t|_|�	|�dS)z4Handle an unknown request type. Respond accordingly.N)
rsr�r�r��FCGI_UnknownTypeBodyrnrv�FCGI_UnknownTypeBody_LENrurw)r,r�r�rrrr�(szConnection._do_unknown_typeN)rPrQrRrSrr!r�r.r�r�r1rwr�r�r�r�r�rr�r�r�r�rrrrr�ls(%
�
r�cs�eZdZdZdZeZ�fdd�Z�fdd�Zdd�Z	d	e
df�fd
d�	Z�fdd
�Z�fdd�Z
dd�Z�fdd�Z�fdd�Z�fdd�Z�ZS)�MultiplexedConnectionz[
    A version of Connection capable of handling multiple requests
    simultaneously.
    Tcs(t��|||�t��}t�|�|_dSrFrV)r,r�r�r$r\r]rrr.7szMultiplexedConnection.__init__cs8|j��|jr|j��|js|j��t���dSrF)r[rar�r_rbrWr�r/r]rrr�As

�
z$MultiplexedConnection._cleanupSocketcCs4|j��z|�|j�W|j��dS|j��wrF)r[rarr�rbr~rrrrwJs
z!MultiplexedConnection.writeRecordrcsD|j��zt��||||�|j��W|j��dS|j��wrF)r[rarWr�rdrb)r,rmr�r�r�r]rrr�Ts

�z!MultiplexedConnection.end_requestc�4|j��zt��|�W|j��dS|j��wrF)r[rarWr�rb�r,r�r]rrr�_�
z'MultiplexedConnection._do_begin_requestcrrF)r[rarWr�rbrr]rrr�fr
z'MultiplexedConnection._do_abort_requestcCst�|jd�dS)Nr)�thread�start_new_threadr�rrrrrmsz$MultiplexedConnection._start_requestcrrF)r[rarWr�rbrr]rrr�pr
z MultiplexedConnection._do_paramscrrF)r[rarWr�rbrr]rrr�wr
zMultiplexedConnection._do_stdincrrF)r[rarWr�rbrr]rrr�~r
zMultiplexedConnection._do_data)rPrQrRrSrrUr�r.r�rwr�r�r�r�rr�r�r�rerrr]rr
/s 
	
�r
c@s�eZdZdZeZeZdZ		ddd�Z	dd	�Z
d
d�Zdd
�Zdd�Z
dd�Zdd�Zd dd�Zdd�Zd!dd�Zdd�Zdd�ZdS)"�Serverz�
    The FastCGI server.

    Waits for connections from the web server, processing each
    request.

    If run in a normal CGI context, it will instead instantiate a
    CGIRequest and run the handler through there.
    ipN� Fc		Cs�|dur||_||_trEzddl}|�|j�d}Wn
ttfy'd}Ynw|}|r4t|_	|d9}nt
|_	t|t|t
|r@dpAdi|_nt
|_	tdtdt
di|_||_||_dS)a^
        handler, if present, must reference a function or method that
        takes one argument: a Request object. If handler is not
        specified at creation time, Server *must* be subclassed.
        (The handler method below is abstract.)

        maxwrite is the maximum number of bytes (per Record) to write
        to the server. I've noticed mod_fastcgi has a relatively small
        receive buffer (8K or so).

        bindAddress, if present, must either be a string or a 2-tuple. If
        present, run() will open its own listening socket. You would use
        this if you wanted to run your application as an 'external' FastCGI
        app. (i.e. the webserver would no longer be responsible for starting
        your app) If a string, it will be interpreted as a filename and a UNIX
        socket will be opened. If a tuple, the first element, a string,
        is the interface name/IP to bind to, and the second element (an int)
        is the port number.

        Set multiplexed to True if you want to handle multiple requests
        per connection. Some FastCGI backends (namely mod_fastcgi) don't
        multiplex requests at all, so by default this is off (which saves
        on thread creation/locking overhead). If threads aren't available,
        this keyword is ignored; it's not possible to multiplex requests
        at all.
        Nr�dr	r)r�rq�thread_available�resource�	getrlimit�
RLIMIT_NOFILE�ImportError�AttributeErrorr
�_connectionClassr�rrrr��_bindAddress�_umask)	r,r�rq�bindAddress�umask�multiplexedr�maxConns�maxReqsrrrr.�s4�
��
zServer.__init__c
Cs�|jdurZd}t�ttjtj�}z|��Wn%tjy;}z|dtj	kr)d}n|dtj
kr1�WYd}~nd}~ww|rJtj�
dd����d�rX|�|�}|��t�d�|Sd}t|j�tur�t�tjtj�}zt�|j�Wn	ty|Ynw|jdur�t�|j�}n#t|j�tus�J�t|j�dks�J�t�tjtj�}|�tjtjd�|� |j�|�!tj"�|dur�t�|�|S)	NTrF�FCGI_FORCE_CGI�N�Yrr)#rr��fromfd�FCGI_LISTENSOCK_FILENO�AF_INET�SOCK_STREAM�getpeernamer�r��ENOTSOCK�ENOTCONNr�r�r��upper�
startswith�cgirequest_classr�r�r�rnr��AF_UNIX�unlink�OSErrorrr�tupler@�
setsockopt�
SOL_SOCKET�SO_REUSEADDR�bind�listen�	SOMAXCONN)r,�isFCGIr�r�rm�oldUmaskrrr�_setupSocket�sR

����

��
�
zServer._setupSocketcCr)zCloses the main socket.N)r)r,r�rrrr�szServer._cleanupSocketcCsPdd�tjtjtjfD�|_t�tj|j�t�tj|j�t�tj|j�dS)NcSsg|]	}|t�|�f�qSr)�signal�	getsignal)�.0�xrrr�
<listcomp>
sz1Server._installSignalHandlers.<locals>.<listcomp>)r;�SIGHUP�SIGINT�SIGTERM�_oldSIGs�_hupHandler�_intHandlerr/rrr�_installSignalHandlerss�zServer._installSignalHandlerscCs |jD]
\}}t�||�qdSrF)rCr;)r,�signumr�rrr�_restoreSignalHandlerss�zServer._restoreSignalHandlerscCsd|_d|_dS)NTF)�_hupReceivedr��r,rG�framerrrrDr�zServer._hupHandlercCs
d|_dSrg)r�rJrrrrEr�zServer._intHandlerr�c

Cs\tj�d�}|durttdd�|�d���}|��}d|_d|_|�	�|jr�zt
�
|ggg|�\}}}Wnt
jyP}z|dtj
krKWYd}~q$�d}~ww|r�z|��\}}Wntjyy}z|dtj
tjfvrtWYd}~q$�d}~ww|r�t|�d	ks�|d|vr�|��q$|�|||�}	t�|	jd
�|��|js'|��|�|�|jS)z�
        The main loop. Exits on SIGHUP, SIGINT, SIGTERM. Returns True if
        SIGHUP was received, False otherwise.
        �FCGI_WEB_SERVER_ADDRSNcSs|��SrF)�strip)r>rrr�<lambda>%szServer.run.<locals>.<lambda>�,TFrrr)r�r�r��list�map�splitr:r�rIrFr�r�r��EINTR�acceptr�r�r@rrrrr��_mainloopPeriodicrHr�)
r,�timeout�web_server_addrsr�r8r�r��
clientSockr�r-rrrr�sL
������
z
Server.runcCsdS)zi
        Called with just about each iteration of the main loop. Meant to
        be overridden.
        Nrr/rrrrUSszServer._mainloopPeriodiccCs|jrd|_||_dSdS)z�
        Protected convenience method for subclasses to force an exit. Not
        really thread-safe, which is why it isn't public.
        FN)r�rI)r,�reloadrrr�_exitZs
�zServer._exitcCst|jjd��)z�
        Default handler, which just raises an exception. Unless a handler
        is passed at initialization time, this must be implemented by
        a subclass.
        z.handler)�NotImplementedErrorr^rPrrrrr�cszServer.handlercCs&ddl}|j�d|�t����dS)zt
        Called by Request if an exception occurs within the handler. May and
        should be overridden.
        rNzContent-Type: text/html

)�cgitbr�r�htmlr��exc_info)r,rmr\rrrr�ks
�zServer.error)NrNNF)r�r�)rPrQrRrSr�r�r�r-r%r.r:r�rFrHrDrEr�rUrZr�r�rrrrr�s&	
�=4
5
	rcs6eZdZdZ		d
�fdd�	Zdd�Zdd	�Z�ZS)rz|
    FastCGI server that supports the Web Server Gateway Interface. See
    <http://www.python.org/peps/pep-0333.html>.
    NTcsLd|vr|d=t�jdi|��|duri}||_||_||_t��|_dS)a
        environ, if present, must be a dictionary-like object. Its
        contents will be copied into application's environ. Useful
        for passing application-specific variables.

        Set multithreaded to False if your application is not MT-safe.
        r�Nr)rWr.�applicationr��
multithreadedr�
allocate_lock�	_app_lock)r,r_r�r`�kwr]rrr.ys	zWSGIServer.__init__c
s��jtkr	tdfS�j}|�|j�d|d<�j|d<|jdur$�j}nt	t
j�jf�}||d<t�t�o:t
o:|j|d<d|d	<t�t�|d
<|�dd���d
vrWd|d<n|�dd���dkrfd|d<nd|d<|�|�g�g�d�����fdd��d���fdd�	}|js�|j��zYz0|�||��z�D]}|r��|�q��s��d�Wt�d�r����nt�d�r����wwWntjy�}z|dtjkrтWYd}~nd}~wwW|js�|j��tdfS|js�|j��ww)zSpecial handler for WSGI.r)rrzwsgi.version�
wsgi.inputN�wsgi.errorszwsgi.multithreadTzwsgi.multiprocessz
wsgi.run_once�HTTPSr")�yes�on�1�httpszwsgi.url_scheme�HTTP_X_FORWARDED_PROTO�httpcs�t|�tus
Jd���sJd���sf�\}}�dd�<d}|D]\}}|��dkr.d}nq |sM�durMzt��dkrG|�dtt|��f�WnYd|}|D]}|d	|7}qS|d
7}�j�|��j�|��j��dS)Nzwrite() argument must be stringzwrite() before start_response()Fzcontent-lengthTrzContent-LengthzStatus: %s
z%s: %s
z
)rnr��lowerr@r?r�rr})rL�status�responseHeaders�foundr�r�r�)�headers_sent�headers_setrm�resultrrr�s4�
��z!WSGIServer.handler.<locals>.writecs�|rz
�r	|d�Wd}n	d}w�rJd��t|�tus Jd��t|�dks*Jd��t|dd��s6Jd��|ddks@Jd	��t|�tusJJd
��	|D]\}}t|�tus[Jd��t|�tuseJd
��qM||g�dd�<�S)NrzHeaders already set!zStatus must be a stringrz$Status must be at least 4 charactersrz#Status must begin with 3-digit code� z#Status must have a space after codezHeaders must be a listTzHeader names must be stringszHeader values must be strings)rnr�r@�intrP)rn�response_headersr^r��val)rqrrrrr�start_response�s$�z*WSGIServer.handler.<locals>.start_responserrF)r�r��FCGI_UNKNOWN_ROLEr��updater�r�rr�r�r��
isinstancer�rr`r�rm�_sanitizeEnvrbrar_�hasattrrr�r�r�r�rbr�)r,rmr�r�rxrLr�r)rqrrrmrsrrr��sz


��



��
�
�
������
��zWSGIServer.handlercCs\d|vrd|d<d|vrd|d<dD]\}}||vr+|d�d|jj|f�|||<qdS)z7Ensure certain values are present, if required by WSGI.�SCRIPT_NAMEr"�	PATH_INFO))�REQUEST_METHOD�GET)�SERVER_NAME�	localhost)�SERVER_PORT�80)�SERVER_PROTOCOLzHTTP/1.0rez/%s: missing FastCGI param %s required by WSGI!
N)rr^rP)r,r�r��defaultrrrr|s

���zWSGIServer._sanitizeEnvrJ)rPrQrRrSr.r�r|rerrr]rrts�q�__main__ccs��ddl}|ddg�dVt|�D]}d||�||�fVq|j|d|dd	�}|jr1d
V|jD]}d|j|jfVq4dVdS)z(Probably not the most efficient example.rNz200 OK)zContent-Typez	text/htmls\<html><head><title>Hello World!</title></head>
<body>
<p>Hello World!</p>
<table border="1">s <tr><td>%s</td><td>%s</td></tr>
rdr)�fpr��keep_blank_valuess'<tr><th colspan="2">Form data</th></tr>s</table>
</body></html>
)�cgi�sorted�escape�FieldStoragerPr�r�)r�rxr�r��form�fieldrrr�test_apps$���

�
r�rO)MrS�
__author__�__version__r�r�r�r;r�r�r�r�r�rrXrr�dummy_thread�dummy_threadingr}r�__all__r%rrr�r�r�r�r�r�r�r�r�r�r�r��FCGI_MAXTYPEr�r�r��FCGI_AUTHORIZER�FCGI_FILTERr�r�FCGI_OVERLOADEDryrrrr�r�r�r�calcsizer�r	rrrr �objectr!rUrfr�r�r�r�rsr�r�r�r
rrrPr�r�rrrr�<module>s��



v*?
m0DVp
!�

https://t.me/RX1948 - 2025