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/cherrypy/__pycache__/_cpwsgi.cpython-310.pyc
o

�N�g
@�@s�dZddlZddlZddlZddlmZddlmZddl	m
Z
ddl	mZdd�ZGd	d
�d
e
�ZGdd�de
�ZGd
d�de
�ZGdd�de
�ZGdd�de
�ZGdd�de
�ZdS)a�WSGI interface (see PEP 333 and 3333).

Note that WSGI environ keys and values are 'native strings'; that is,
whatever the type of "" is. For Python 2, that's a byte string; for Python 3,
it's a unicode string. But PEP 3333 says: "even if Python's str type is
actually Unicode "under the hood", the content of native strings must
still be translatable to bytes via the Latin-1 encoding!"
�N)�ntou)�_cperror)�httputil)�is_closable_iteratorcCsri}|td�}|����D](\}}|td�td�td�fvr%|�|�}n
t|t�r/|�d�}|||�d�<q|S)zLReturn a new environ dict for WSGI 1.x from the given WSGI u.x environ.
    �wsgi.url_encoding�	PATH_INFO�SCRIPT_NAME�QUERY_STRING�
ISO-8859-1)r�copy�items�encode�
isinstance�str)�environZenv1xZurl_encoding�k�v�r�D/opt/saltstack/salt/lib/python3.10/site-packages/cherrypy/_cpwsgi.py�downgrade_wsgi_ux_to_1xs

rc@s4eZdZdZdZ	dZ	iZ	ddd�Zdd�ZdS)	�VirtualHosta�Select a different WSGI application based on the Host header.

    This can be useful when running multiple sites within one CP server.
    It allows several domains to point to different applications. For example::

        root = Root()
        RootApp = cherrypy.Application(root)
        Domain2App = cherrypy.Application(root)
        SecureApp = cherrypy.Application(Secure())

        vhost = cherrypy._cpwsgi.VirtualHost(
            RootApp,
            domains={
                'www.domain2.example': Domain2App,
                'www.domain2.example:443': SecureApp,
            },
        )

        cherrypy.tree.graft(vhost)
    NTcCs||_|pi|_||_dS�N)�default�domains�use_x_forwarded_host)�selfrrrrrr�__init__Ks

zVirtualHost.__init__cCsB|�dd�}|jr|�d|�}|j�|�}|dur|j}|||�S)NZ	HTTP_HOST�ZHTTP_X_FORWARDED_HOST)�getrrr)rr�start_response�domain�nextapprrr�__call__Ps
zVirtualHost.__call__�NT)	�__name__�
__module__�__qualname__�__doc__rrrrr"rrrrr$s
rc@s"eZdZdZddd�Zdd�ZdS)	�InternalRedirectorz>WSGI middleware that handles raised cherrypy.InternalRedirect.FcC�||_||_dSr)r!�	recursive)rr!r*rrrr_�
zInternalRedirector.__init__cCsg}	|��}z|�||�WStjy�t��d}|�dd�}|�dd�}|�dd�}||}|r:|d|7}|�|�|jsb||j	}	|j
rQ|	d|j
7}	|	|vrb|j��d}
t
|
|	��d	|d
<|j	|d<|j
|d<t��|d<d|d
<|j|d<Ynwq)NT�rrrr	�?z1InternalRedirector visited the same URL twice: %rZGET�REQUEST_METHOD�
wsgi.input�0�CONTENT_LENGTH�cherrypy.previous_request)rr!�	_cherrypyZInternalRedirect�_sys�exc_infor�appendr*�pathZquery_string�request�close�RuntimeError�io�BytesIO)rrrZredirectionsZirZsnr7�qsZold_uriZnew_uri�tmplrrrr"cs>


�

��zInternalRedirector.__call__N)F)r$r%r&r'rr"rrrrr([s
r(c@s(eZdZdZeeffdd�Zdd�ZdS)�ExceptionTrapperz&WSGI middleware that traps exceptions.cCr)r)r!�throws)rr!r@rrrr�r+zExceptionTrapper.__init__cCst|j|||j�Sr)�_TrappedResponser!r@�rrrrrrr"�s�zExceptionTrapper.__call__N)r$r%r&r'�KeyboardInterrupt�
SystemExitrr"rrrrr?�sr?c@s<eZdZeg�Zdd�Zdd�Zdd�Zdd�Zd	d
�Z	dS)rAcCsD||_||_||_||_d|_|�|j|j|j�|_t|j�|_dS)NF)	r!rrr@�started_response�trap�response�iter�
iter_response)rr!rrr@rrrr�s�z_TrappedResponse.__init__cCs
d|_|Sr#)rE�rrrr�__iter__�sz_TrappedResponse.__iter__cCs|�t|j�Sr)rF�nextrIrJrrr�__next__�sz_TrappedResponse.__next__cCst|jd�r
|j��dSdS)Nr9)�hasattrrGr9rJrrrr9�s�z_TrappedResponse.closecOs�z||i|��WS|jy�ty�ty{t��}tj|dd�tjjs/d}t�	|�\}}}	|�
d�}dd�|D�}|jrMtg�|_
nt|�|_
z|�||t���Wntyltjddd��w|jrwd	�|�YS|YSw)
N�()�severityrTr
cS�$g|]\}}|�d�|�d�f�qS�r
��decode��.0rrrrr�
<listcomp>����z)_TrappedResponse.trap.<locals>.<listcomp>��	tracebackrP�)r@�
StopIteration�	Exceptionr�
format_excr3�logr8Zshow_tracebacksZ
bare_errorrTrErHrIrr4r5�join)r�func�args�kwargs�tb�s�h�brrrrF�s<
�
�	�z_TrappedResponse.trapN)
r$r%r&rHrGrrKrMr9rFrrrrrA�srAc@sXeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
dddd�Z	dd�Z
dd�ZdS)�AppResponsez1WSGI response iterable for CherryPy applications.c
Cs�||_z^||_|��tjj}|j}t|t�st	d��g}|j
D]%\}}t|t�s1d}	t	|	|��t|t�s>d}	t	|	|��|�||f�q 	|�d�}dd�|D�}t
|j�|_|||�|_WdStym|���w)Nz,response.output_status is not a byte string.z1response.header_list key %r is not a byte string.z3response.header_list value %r is not a byte string.Tr
cSrQrRrSrUrrrrWrXz(AppResponse.__init__.<locals>.<listcomp>)�cpappr�runr3�servingrGZ
output_statusr�bytes�	TypeErrorZheader_listr6rTrH�bodyrI�write�
BaseExceptionr9)
rrrri�rZ	outstatusZ
outheadersrrr>rrrr�s:


�
��zAppResponse.__init__cCs|SrrrJrrrrKszAppResponse.__iter__cCs
t|j�Sr)rLrIrJrrrrMs
zAppResponse.__next__cCsbtjjj}|j��|r-t|j�r/|jj}z|�WdSt	y,tj
ddd�YdSwdSdS)z?Close and de-reference the current request and response. (Core)TrOrYN)r3rkrG�streamriZrelease_servingrrIr9r]r_)rZ	streamingZ
iter_closerrrr9s

��zAppResponse.closecCsF|jj}t�dt|dd�pd�|dd��}t�|dd�t|dd�p"d�|dd��}|d	�}|d
d�}|j�||||�\}}|d�pF|d
�pFd|_|jd|_|jd|_	|j|_
|dd�|_|jd}t�|j�dd�|j�dd��}	|j�dd�}
|�
|	|
�p�|	|
f\}	}
|j�d�}|�|j�}|jd}
|�||	|
|||
�dS)z&Create a Request object using environ.rZSERVER_PORT�P���ZSERVER_NAME�REMOTE_ADDRZREMOTE_PORT�REMOTE_HOSTzwsgi.url_schemeZACTUAL_SERVER_PROTOCOLzHTTP/1.1Z
LOGON_USERZREMOTE_USERNzwsgi.multithreadzwsgi.multiprocessr2r.rrr	ZSERVER_PROTOCOLr/)rrr�Host�intriZget_servingZloginZmultithreadZmultiprocessZwsgi_environ�prev�urljoin�recode_path_qs�translate_headersrj)r�env�localZremote�schemeZsprotor8Zresp�methr7r=Zrproto�headersZrfilerrrrj's<��

�
zAppResponse.runZ
AuthorizationzContent-LengthzContent-TypezRemote-HostzRemote-Addr)ZHTTP_CGI_AUTHORIZATIONr1ZCONTENT_TYPErvruc	Csx|j�dd�}|j�|j�dd�dd�}|��|��krdSz|�|��|�|�|��|�fWSttfy;YdSw)Nrr
rrzrequest.uri_encodingzutf-8)	rrriZfind_config�lowerr
rT�UnicodeEncodeError�UnicodeDecodeError)rr7r=Zold_encZnew_encrrrr{Ys���zAppResponse.recode_path_qsccsb�|D]+}||jvr|j|||fVq|dd�dkr.|dd��dd�}|||fVqdS)z8Translate CGI-environ header names to HTTP header names.N�ZHTTP_�_�-)�headerNames�replace)rrZcgiNameZtranslatedHeaderrrrr|rs�
��zAppResponse.translate_headersN)r$r%r&r'rrKrMr9rjr�r{r|rrrrrh�s)+�rhc@sVeZdZdZdefdefgZ	dZ	iZ	e	Z
	d
dd�Zdd�Zd	d
�Z
dd�ZdS)�	CPWSGIAppz5A WSGI application object for a CherryPy Application.r?r(NcCs6||_|jdd�|_|r|j�|�|j��|_dSr)ri�pipeline�extend�configr)rrir�rrrr�s
zCPWSGIApp.__init__cCs|�|||j�S)z�WSGI application callable for the actual CherryPy application.

        You probably shouldn't call this; call self.__call__ instead,
        so that any WSGI middleware in self.pipeline can run first.
        )�response_classrirBrrr�tail�szCPWSGIApp.tailcCs\|j}|dur)|j}|jddd�D]\}}|j�|i�}||fi|��}q||_|||�S)Nrt)�headr�r�r�r)rrrr��name�callableZconfrrrr"�s
zCPWSGIApp.__call__cCsT|dkr|j�|�dS|dkr||_dS|�dd�\}}|j�|i�}|||<dS)z(Config handler for the 'wsgi' namespace.r�r��.r,N)r�r�r��splitr��
setdefault)rrrr��argZbucketrrr�namespace_handler�s
zCPWSGIApp.namespace_handlerr)r$r%r&r'r?r(r�r�r�rhr�rr�r"r�rrrrr�~s �
r�)r'�sysr4r;Zcherrypyr3Zcherrypy._cpcompatrrZcherrypy.librrr�objectrr(r?rArhr�rrrr�<module>s 	70H