HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/cheroot/__pycache__/wsgi.cpython-310.pyc
o

�N�g:�@s�dZddlmZmZmZeZddlZddlZddl	m
Z
ddlmZddl
mZddlmZmZGd	d
�d
ej�ZGdd�dej�ZGd
d�de�ZGdd�de�Ze��ZGdd�d�Ze�jeeeeed�dS)a�This class holds Cheroot WSGI server implementation.

Simplest example on how to use this server::

    from cheroot import wsgi

    def my_crazy_app(environ, start_response):
        status = '200 OK'
        response_headers = [('Content-type','text/plain')]
        start_response(status, response_headers)
        return [b'Hello world!']

    addr = '0.0.0.0', 8070
    server = wsgi.Server(addr, my_crazy_app)
    server.start()

The Cheroot WSGI server can serve as many WSGI applications
as you want in one instance by using a PathInfoDispatcher::

    path_map = {
        '/': my_crazy_app,
        '/blog': my_blog_app,
    }
    d = wsgi.PathInfoDispatcher(path_map)
    server = wsgi.Server(addr, d)
�)�absolute_import�division�print_functionN)�filter�)�server)�
threadpool)�ntob�btoncsJeZdZdZdZ					d
�fdd	�	Zed
d��Zejdd��Z�Z	S)�Serverz8A subclass of HTTPServer which calls a WSGI application.�rr�
N����Fc

sVtt|�j|t|j|||d�||_||_||_||_t	j
||p"d||	|
d�|_dS)a�Initialize WSGI Server instance.

        Args:
            bind_addr (tuple): network interface to listen to
            wsgi_app (callable): WSGI application callable
            numthreads (int): number of threads for WSGI thread pool
            server_name (str): web server name to be advertised via
                Server HTTP header
            max (int): maximum number of worker threads
            request_queue_size (int): the 'backlog' arg to
                socket.listen(); max queued connections
            timeout (int): the timeout in seconds for accepted connections
            shutdown_timeout (int): the total time, in seconds, to
                wait for worker threads to cleanly exit
            accepted_queue_size (int): maximum number of active
                requests in queue
            accepted_queue_timeout (int): timeout for putting request
                into queue
        )Zgateway�server_name�peercreds_enabled�peercreds_resolve_enabledr)�min�max�accepted_queue_size�accepted_queue_timeoutN)�superr�__init__�
wsgi_gateways�wsgi_version�wsgi_app�request_queue_size�timeout�shutdown_timeoutrZ
ThreadPool�requests)
�self�	bind_addrr�
numthreadsrrrrrrrrr��	__class__��@/opt/saltstack/salt/lib/python3.10/site-packages/cheroot/wsgi.pyr/s 
�
�zServer.__init__cCs|jjS)zSet minimum number of threads.�rr�r r%r%r&r"YszServer.numthreadscCs||j_dS�Nr')r �valuer%r%r&r"^s)
r
Nrrr
rrr
FF)
�__name__�
__module__�__qualname__�__doc__rr�propertyr"�setter�
__classcell__r%r%r#r&r)s�*
rcsZeZdZdZ�fdd�Zedd��Zdd�Zdd	�Zddd�Z	e
d
d��Zdd�Z�Z
S)�Gatewayz/A base class to interface HTTPServer with WSGI.cs*tt|��|�d|_|��|_d|_dS)zzInitialize WSGI Gateway instance with request.

        Args:
            req (HTTPRequest): current HTTP request
        FN)rr2r�started_response�get_environ�env�remaining_bytes_out)r �reqr#r%r&rfs

zGateway.__init__cCsdd�|��D�S)z�Create a mapping of gateways and their versions.

        Returns:
            dict[tuple[int,int],class]: map of gateway version and
                corresponding class

        cSsi|]}|j|�qSr%)�version)�.0Zgwr%r%r&�
<dictcomp>zsz'Gateway.gateway_map.<locals>.<dictcomp>)�__subclasses__)�clsr%r%r&�gateway_mapqs	zGateway.gateway_mapcCst�)�;Return a new environ dict targeting the given wsgi.version.)�NotImplementedErrorr(r%r%r&r4|szGateway.get_environc	Cs�|jj�|j|j�}z*td|�D]}t|tj�st	d��|�
|�qW|j��t|d�r3|�
�dSdS|j��t|d�rD|�
�ww)a�Process the current request.

        From :pep:`333`:

            The start_response callable must not actually transmit
            the response headers. Instead, it must store them for the
            server or gateway to transmit only after the first
            iteration of the application return value that yields
            a NON-EMPTY string, or upon the application's first
            invocation of the write() callable.
        Nz"WSGI Applications must yield bytes�close)r7rrr5�start_responser�
isinstance�sixZbinary_type�
ValueError�write�ensure_headers_sent�hasattrr@)r �response�chunkr%r%r&�respond�s�

�
�

�zGateway.respondNcCs�|jr	|s	td��d|_|jjrz	tj|�Wd}nd}w|�|�|j_|D]4\}}t|t	�s5t
d|��t|t	�s@t
d|��|��dkrKt|�|_
t|�t|�f}|jj�|�q&|jS)z)WSGI callable to begin the HTTP response.z:WSGI start_response called a second time with no exc_info.TNz/WSGI response header key %r is not of type str.z1WSGI response header value %r is not of type str.zcontent-length)r3�AssertionErrorr7�sent_headersrCZreraise�_encode_status�statusrB�str�	TypeError�lower�intr6r	Z
outheaders�appendrE)r rN�headers�exc_info�k�vZ
out_headerr%r%r&rA�s0
�
�
�
zGateway.start_responsecCs&tjr|St|t�std��|�d�S)a:Cast status to bytes representation of current Python version.

        According to :pep:`3333`, when using Python 3, the response status
        and headers must be bytes masquerading as Unicode; that is, they
        must be of type "str" but are restricted to code points in the
        "Latin-1" set.
        z(WSGI response status is not of type str.�
ISO-8859-1)rC�PY2rBrOrP�encode)rNr%r%r&rM�s
	

zGateway._encode_statuscCs�|jstd��t|�}|j}|dur(||kr(|jjs"|j�dd�n|d|�}|j��|j�|�|durC||8}|dkrEt	d��dSdS)z�WSGI callable to write unbuffered data to the client.

        This method is also used internally by start_response (to write
        data from the iterable returned by the WSGI application).
        z(WSGI write called before start_response.Nz500 Internal Server ErrorzLThe requested resource returned more bytes than the declared Content-Length.rz2Response body exceeds the declared Content-Length.)
r3rK�lenr6r7rLZsimple_responserFrErD)r rIZchunklenZrbor%r%r&rE�s*�
��z
Gateway.writer))r+r,r-r.r�classmethodr=r4rJrA�staticmethodrMrEr1r%r%r#r&r2cs


&
r2c@seZdZdZdZdd�ZdS)�
Gateway_10z8A Gateway class to interface HTTPServer with WSGI 1.0.x.rcCs�|j}|j}id|jj�dt|j��dt|j��d|jpd�dt|j	p$d��dt|j
��dt|j��d	d�d
|jj�dt|j
��d|jj�d
tj�d|j�dt|j��dd�dd�dd�t|j�|jd��}t|jjtj�r�d|d<z+t|j�|d<t|j�|d<t|j�|d<t|j�|d<t|j�|d<|d|d<Wnty�Ynwt|jjd�|d<|� dd�|j!�"�D��|�#d d!�}|d!ur�||d"<|�#d#d!�}|d!ur�||d$<|jj$r�|� |jj$�|S)%r>ZACTUAL_SERVER_PROTOCOL�	PATH_INFO�QUERY_STRINGZREMOTE_ADDR�ZREMOTE_PORTZREQUEST_METHOD�REQUEST_URI�SCRIPT_NAMEZSERVER_NAMEZSERVER_PROTOCOLZSERVER_SOFTWAREzwsgi.errors�
wsgi.inputzwsgi.input_terminatedzwsgi.multiprocessFzwsgi.multithreadTz
wsgi.run_once)zwsgi.url_schemezwsgi.versionZSERVER_PORTZX_REMOTE_PIDZX_REMOTE_UIDZX_REMOTE_GIDZ
X_REMOTE_USERZX_REMOTE_GROUPZREMOTE_USERrcss8�|]\}}djt|����dd�d�t|�fVqdS)zHTTP_{header_name!s}�-�_)�header_nameN)�formatr
�upper�replace)r9rVrWr%r%r&�	<genexpr>+s����
�z)Gateway_10.get_environ.<locals>.<genexpr>ZHTTP_CONTENT_TYPENZCONTENT_TYPEZHTTP_CONTENT_LENGTHZCONTENT_LENGTH)%r7�connr�protocolr
�path�qsZremote_addrrOZremote_port�methodZurirZrequest_protocolZsoftware�sys�stderrZrfile�boolZchunked_read�schemer8rBr!rCZstring_typesZpeer_pidZpeer_uidZpeer_gidZ	peer_userZ
peer_group�RuntimeError�updateZ	inheaders�items�popZssl_env)r r7Zreq_connr5�ctZclr%r%r&r4�s��
�
�
��
	�

���
����
������
�
zGateway_10.get_environN)r+r,r-r.r8r4r%r%r%r&r^�sr^cs<eZdZdZdZ�fdd�Zedd��Zedd��Z�Z	S)	�
Gateway_u0z�A Gateway class to interface HTTPServer with WSGI u.0.

    WSGI u.0 is an experimental protocol, which uses Unicode for keys
    and values in both Python 2 and Python 3.
    )�urcs�|j}tt|���}tt|j|����}|�t	�
d�t	�
d��}z|j�|�|d<|j
�|�|d<WntyKd|d<|d|d<|d|d<Ynw|�t|j|����|S)r>zwsgi.url_encodingzutf-8r_r`rX)r7rrzr4�dict�map�_decode_keyrw�
setdefaultrCr{rn�decodero�UnicodeDecodeErrorrv�
_decode_value)r r7Zenv_10r5�encr#r%r&r4Ks�zGateway_u0.get_environcCs |\}}tjr|�d�}||fS)NrX)rCrYr�)�itemrVrWr%r%r&r~`s
zGateway_u0._decode_keycCs:|\}}d}tjrt|t�r||vr||fS||�d�fS)N)rbrdrX)rCrYrB�bytesr�)r�rVrWZ	skip_keysr%r%r&r�gs
zGateway_u0._decode_value)
r+r,r-r.r8r4r]r~r�r1r%r%r#r&rzBs
rzc@s eZdZdZdd�Zdd�ZdS)�PathInfoDispatcherz6A WSGI dispatcher for dispatch based on the PATH_INFO.cCsNzt|���}Wn	tyYnwdd�}|j|dd�dd�|D�|_dS)z�Initialize path info WSGI app dispatcher.

        Args:
            apps (dict[str,object]|list[tuple[str,object]]): URI prefix
                and WSGI app pairs
        cSst|d�S)Nr)r[)�appr%r%r&�by_path_len�sz0PathInfoDispatcher.__init__.<locals>.by_path_lenT)�key�reversecSsg|]\}}|�d�|f�qS)�/)�rstrip)r9�p�ar%r%r&�
<listcomp>�sz/PathInfoDispatcher.__init__.<locals>.<listcomp>N)�listrw�AttributeError�sort�apps)r r�r�r%r%r&rvs�zPathInfoDispatcher.__init__cCs�|dpd}|jD]0\}}|�dj|d��s||kr9|��}|�dd�||d<|t|�d�|d<|||�Sq	|dd	d
g�dgS)aProcess incoming WSGI request.

        Ref: :pep:`3333`

        Args:
            environ (Mapping): a dict containing WSGI environment variables
            start_response (callable): function, which sets response
                status and headers

        Returns:
            list[bytes]: iterable containing bytes to be returned in
                HTTP response body

        r_r�z	{path!s}/)rnrcraNz
404 Not Found)zContent-Typez
text/plain)zContent-Length�0)r��
startswithrh�copy�getr[)r �environrArnr�r�r%r%r&�__call__�s���zPathInfoDispatcher.__call__N)r+r,r-r.rr�r%r%r%r&r�ssr�)Z
WSGIServerZWSGIGatewayZWSGIGateway_u0ZWSGIGateway_10ZWSGIPathInfoDispatcher)r.Z
__future__rrr�typeZ
__metaclass__rqrCZ	six.movesrrar�workersrZ_compatr	r
Z
HTTPServerrr2r^rzr=rr��globalsrvr%r%r%r&�<module>s.:Q.:
�