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__/_cprequest.cpython-310.pyc
o

�N�g	��@sddlZddlZddlZddlZddlmZmZddlZddlm	Z	ddl
Z
ddlmZddl
m
Z
ddlmZmZddlmZmZmZGdd	�d	e�ZGd
d�de�Zdd
�Zdd�Zdd�Zdd�Zgd�ZGdd�de�ZGdd�de�ZGdd�de�Z Gdd�de�Z!dS)�N)�SimpleCookie�CookieError)�consume)�ntob)�
_cpreqbody)�
format_exc�
bare_error)�httputil�reprconf�encodingc@sJeZdZdZdZ	dZ	dZ	iZ	d
dd�Zdd�Z	d	d
�Z
dd�ZdS)�Hookz<A callback and its metadata: failsafe, priority, and kwargs.NF�2cKsD||_|dur
t|dd�}||_|durt|dd�}||_||_dS)N�failsafeF�priorityr
)�callback�getattrrr�kwargs)�selfrrrr�r�G/opt/saltstack/salt/lib/python3.10/site-packages/cherrypy/_cprequest.py�__init__+s
z
Hook.__init__cCs|j|jkS)zm
        Hooks sort by priority, ascending, such that
        hooks of lower priority are run first.
        )r)r�otherrrr�__lt__8szHook.__lt__cCs|jdi|j��S)z!Run self.callback(**self.kwargs).Nr)rr�rrrr�__call__?sz
Hook.__call__cCs:|j}d|j|j|j|j|jd�dd�|j��D��fS)Nz0%s.%s(callback=%r, failsafe=%r, priority=%r, %s)z, cSsg|]
\}}d||f�qS)z%s=%rr)�.0�k�vrrr�
<listcomp>Hs�z!Hook.__repr__.<locals>.<listcomp>)	�	__class__�
__module__�__name__rrr�joinr�items�r�clsrrr�__repr__Cs
���z
Hook.__repr__�NN)r!r �__qualname__�__doc__rrrrrrrr&rrrrrs

rc@sTeZdZdZddd�Zdd�Zddd�Zd	d
�Zedd��Z	d
d�Z
e
Zdd�ZdS)�HookMapz:A map of call points to lists of callbacks (Hook objects).NcCs$t�|�}|pgD]}g||<q	|S�N)�dict�__new__)r%Zpoints�d�prrrr-Ps

zHookMap.__new__cOsdSr+r)r�a�kwrrrrVszHookMap.__init__cKs"||�t|||fi|���dS)z3Append a new Hook made from the supplied arguments.N)�appendr)r�pointrrrrrrr�attachYs"zHookMap.attachcCs|�tt||���dS)z=Execute all registered Hooks (callbacks) for the given point.N)�	run_hooks�iter�sorted)rr3rrr�run]szHookMap.runc	Cs�t|tjj�s	J�tjtjtjf}tt	�
d�|�}|D]'}z|�Wq|y/|�|��tyBtj
ddd�|�|��wdS)a�Execute the indicated hooks, trapping errors.

        Hooks with ``.failsafe == True`` are guaranteed to run
        even if others at the same hookpoint fail. In this case,
        log the failure and proceed on to the next hook. The only
        way to stop all processing from one of these hooks is
        to raise a BaseException like SystemExit or
        KeyboardInterrupt and stop the whole server.
        rT�(��	tracebackZseverityN)�
isinstance�collections�abc�Iterator�cherrypy�	HTTPError�HTTPRedirect�InternalRedirect�filter�operator�
attrgetterr5�	Exception�log)r%�hooksZquiet_errors�safe�hookrrrr5as$�


��zHookMap.run_hookscCs.|��}|��D]\}}|dd�||<q|Sr+)rr#)rZnewmaprrrrr�__copy__~szHookMap.__copy__cCs|j}d|j|jt|�fS)Nz%s.%s(points=%r))rr r!�listr$rrrr&�s�zHookMap.__repr__r+r')
r!r r(r)r-rr4r8�classmethodr5rL�copyr&rrrrr*Ls


r*cCsR|�dd�d}t|t�rtjj�|�}t|t�st|�}tjj	j
|�|�dS)z%Attach bare hooks declared in config.�.�rN)�splitr<�strr@�libr
Z
attributesr�serving�requestrIr2)rrZ	hookpointrrr�hooks_namespace�s

rWcCsB|dd�dkrttjjj|dd�|�dSttjj||�dS)z-Attach request attributes declared in config.N�zbody.)�setattrr@rUrV�body�rrrrr�request_namespace��r\cCsB|dd�dkr|tjjj|�dd�d<dSttjj||�dS)z.Attach response attributes declared in config.N�zheaders.rPrQ)r@rU�response�headersrRrYr[rrr�response_namespace�r]racCs"|dkrt|�}|tjjj|<dS)z&Attach error pages declared in config.�defaultN)�intr@rUrV�
error_pager[rrr�error_page_namespace�sre)�on_start_resource�before_request_body�before_handler�before_finalize�on_end_resource�on_end_request�before_error_response�after_error_responsec	@s�eZdZdZdZ	e�dd�Z	e�dd�Z	dZ		dZ
	dZ	dZ	d	Z
	dZ	d
Z	dZ	iZ	gZ	e��Z	e�Z	dZ	dZ	d
Z	dZ	ej��Z	dZ	dZ	dZ 	dZ!	dZ"	iZ#	dZ$	dZ%	e&e'�Z(	e�)d�j*Z+	iZ,	dZ-	dZ.	e/e0ej1fZ2	dZ3	dZ4	dZ5	dZ6	e7j8d$ie9e:e;e<ej=d���Z>		d%dd�Z?dd�Z@dd�ZAdd�ZBdd�ZCdd�ZDdd�ZEd d!�ZFd"d#�ZGdS)&�Requesta,An HTTP request.

    This object represents the metadata of an HTTP request message;
    that is, it contains attributes which describe the environment
    in which the request URL, headers, and body were sent (if you
    want tools to interpret the headers and body, those are elsewhere,
    mostly in Tools). This 'metadata' consists of socket data,
    transport characteristics, and the Request-Line. This object
    also contains data regarding the configuration in effect for
    the given URL, and the execution plan for generating a response.
    Nz	127.0.0.1�PiW�http�HTTP/1.1�ZGET�utf8�rQrQT)�POST�PUT�PATCH�/��F)rIrVr_rd�toolscCsH||_||_||_||_d|_|j��|_|j��|_d|_t	�|_
dS)z�Populate a new Request object.

        local_host should be an httputil.Host object with the server info.
        remote_host should be an httputil.Host object with the client info.
        scheme should be a string, either "http" or "https".
        FN)�local�remote�scheme�server_protocol�closedrdrO�
namespaces�stage�	LazyUUID4�	unique_id)rZ
local_hostZremote_hostr}r~rrrr�szRequest.__init__cCs,|jsd|_d|_|j�d�d|_dSdS)zRun cleanup code. (Core)Trk�closeN)rr�rIr8rrrrr�s
�z
Request.closecCs�tjj}d|_zt�d�j|_||_|pd}|pd|_i|_	t
|d�t
|d�f}t
|jd�t
|jd�f}	t||	�|_
|j
|j_
|}
|rM|
d|7}
d||
|f|_t|�|_t��|_||_d	|_t�|_d	|_|jj|_|t|j�d	�|_}d
|_|�|�Wn1|jy��ty�|j r��tj!ddd
�|j"r�t#�}nd}t$|�}
|
\|_%|_|_Ynw|jdkr�g|_ztj!�&�W|Sty�tj!j'dd�Y|Sw)a�Process the Request. (Core)

        method, path, query_string, and req_protocol should be pulled directly
        from the Request-Line (e.g. "GET /path?key=val HTTP/1.0").

        path
            This should be %XX-unquoted, but query_string should not be.

            When using Python 2, they both MUST be byte strings,
            not unicode strings.

            When using Python 3, they both MUST be unicode strings,
            not byte strings, and preferably not bytes \x00-\xFF
            disguised as unicode.

        headers
            A list of (name, value) tuples.

        rfile
            A file-like object containing the HTTP request entity.

        When run() is done, the returned object should have 3 attributes:

          * status, e.g. "200 OK"
          * header_list, a list of (name, value) tuples
          * body, an iterable yielding strings

        Consumer code (HTTP servers) should then access these response
        attributes to build the outbound stream.

        r8ryrxrrrX��?z%s %s %sN�respondTr9r:�HEAD)r;)(r@rUr_r�rA�set_response�error_response�method�query_string�paramsrcr~�min�protocolr`�request_linerM�header_listr	�	HeaderMap�rfilerZr�cookie�handler�app�script_name�len�	path_infor��throwsrG�throw_errorsrH�show_tracebacksrr�
output_status�access�error)rr��pathr�Zreq_protocolr`r�r_Zrp�sp�url�pirZ�rrrrr8s^ 




�
��zRequest.runc	Cs�zSzHz|�|�Wn&tjtjfy/t��d}|��d|_|j�	d�tj
j��YnwWd|_|j�	d�WdSWd|_|j�	d�WdSd|_|j�	d�w|j
y\�tym|jrf�|��YdSw)z>Generate a response for the resource at self.path_info. (Core)rQzbefore_finalize (HTTPError)rirjN)�_do_respondr@rBrA�sys�exc_infor�r�rIr8rUr_�finalizer�rGr��handle_error)rr��instrrrr�ys4�����zRequest.respondcCstjj}|jdur
t���|jj��|_i|_d|_	|�
�d|_	|�|�tj
|j|j|jd�|_|�|j�d|_	|j�d�d|_	|��|jrT|j|jvrTd|_d|_	|j�d�|jre|j��d|_	|j�d�|jryd	|_	|��|_d
|_	|j�d
�|��dS)N�process_headers�get_resource)Zrequest_paramsrf�process_query_stringFrgrhr�ri)r@rUr_r�ZNotFoundrrIrO�toolmapsr�r�r�rZRequestBodyr�r`r�rZr��configr8r��process_request_bodyr��methods_with_bodies�processr�r�)rr�r_rrrr��s@

�

zRequest._do_respondcCsHztj|j|jd�}Wntyt�dd|j��w|j�|�dS)z5Parse the query string into Python structures. (Core))ri�zgThe given query string could not be processed. Query strings for this resource must be encoded with %r.N)	r	Zparse_query_stringr��query_string_encoding�UnicodeDecodeErrorr@rAr��update)rr/rrrr��s
����zRequest.process_query_stringcCs�|j}|jD]4\}}|��}|��}t�|�||<|dkr:z|j�|�Wqty9}zt	�
dt|���d}~wwqt�
|d�sN|jdkrNd}t	�
d|��t�|d�}|s^|jjp]|jj}d|j|f|_dS)z5Parse HTTP header data into Python structures. (Core)ZCookiei�N�Hostrtz*HTTP/1.1 requires a 'Host' request header.z%s://%s)r`r��title�stripr	Zdecode_TEXT_mayber��loadrr@rArSr,�__contains__r��getr{�name�ipr}�base)rr`r��value�exc�msg�hostrrrr��s*���
zRequest.process_headerscCs|j�|d|j�}||�dS)z?Call a dispatcher (which sets self.handler and .config). (Core)zrequest.dispatchN)r�Zfind_config�dispatch)rr�r�rrrr��s�zRequest.get_resourcecCspz|j�d�|jr|��|j�d�tjj��WdStjy7t�	�d}|�
�tjj��YdSw)z/Handle the last unanticipated exception. (Core)rlrmrQN)rIr8r�r@rUr_r�rBr�r�r�)rr�rrrr��s�zRequest.handle_errorr)rprq)Hr!r r(r)�prevr	r�r{r|r}r~r�r�r�r�r�r�r�r�r�r`rr�r�r�r�rZr@r�Z
Dispatcherr�r�Zloginr�r�r�r�Zis_indexr*�
hookpointsrIrAr�r�rdr�Zshow_mismatched_params�KeyboardInterrupt�
SystemExitrCr�r�rr�r�r
ZNamespaceSetrWr\rarerzr�rr�r8r�r�r�r�r�r�rrrrrn�s�
		��
�m1
!rnc@s&eZdZdZdZddd�Zdd�ZdS)	�ResponseBodyz4The body of the HTTP response (the response entity).zPPage handlers MUST return bytes. Use tools.encode if you wish to return unicode.NcCs|dur|S|jSr+)�_body)r�objZobjclassrrr�__get__szResponseBody.__get__cCsJt|t�r
t|j��t|t�rtdd�|D��rt|j��t�|�|_dS)Ncss�|]}t|t�VqdSr+)r<rS)r�itemrrr�	<genexpr>s�z'ResponseBody.__set__.<locals>.<genexpr>)	r<rS�
ValueError�unicode_errrM�anyrZprepare_iterr�)rr�r�rrr�__set__s



zResponseBody.__set__r+)r!r r(r)r�r�r�rrrrr�s

r�c@sbeZdZdZdZ	gZ	e��Z	e	�Z
	e�Z	dZ
	dZ	dd�Zdd�Zd	d
�Zdd�ZdS)
�Responsez6An HTTP Response, including status, headers, and body.rrNFcCsVd|_d|_g|_t��|_t��|_t�|jddt	j
t�|j�d��t�|_
dS)Nz	text/htmlz	CherryPy/)zContent-TypeZServerZDate)�statusr�r��timer	r�r`r,r�r@�__version__ZHTTPDaterr�rrrrrFs


�zResponse.__init__cCsd�|j�}||_|S)z@Collapse self.body to a single string; replace it and return it.�)r"rZ)rZnew_bodyrrr�
collapse_bodyVszResponse.collapse_bodycCstt|j��dS)z�
        Discard self.body but consume any generator such that
        any finalization can occur, such as is required by
        caching.tee_output().
        N)rr6rZrrrr�_flush_body\szResponse._flush_bodycCsjzt�|j�\}}}Wntyt�dt��djd��w|j	}d||f|_t
t|�d�d|�|�|_
|jrLt�|d�durKt�|dd�n,|d	ksT|d
vrct�|dd�|��d|_nt�|d�durx|��}t�|dt|��|��|_}|j��}|r�|�d�D]'}|�d
d�\}	}
t|	t�r�|	�d�}	t|
t�r�|�|
�}
|�|	|
f�q�dSdS)z=Transform headers (and cookies) into self.header_list. (Core)ryrQrz%s %s�ascii� zContent-LengthN��)����i0r�z
z: z
ISO-8859-1)r	Zvalid_statusr�r�r@rAr�r��argsr`rrS�encoder��streamr,r��popr�rZr��__setitem__r��outputr�r�rRr<r2)r�code�reason�_r`�content�hr��liner�r�rrrr�dsF����




�zResponse.finalize)r!r r(r)r�r�r	r�r`rr�r�rZr�r�rr�r�r�rrrrr�!s(
r�c@s eZdZdd�Zedd��ZdS)r�cCs
t|j�S)z*Return UUID4 and keep it for future calls.)rS�uuid4rrrr�__str__�s
zLazyUUID4.__str__cCs0z|jW|jStyt��|_Y|jSw)zfProvide unique id on per-request basis using UUID4.

        It's evaluated lazily on render.
        )Z_uuid4�AttributeError�uuidr�rrrrr��s��zLazyUUID4.uuid4N)r!r r(r��propertyr�rrrrr��sr�)"r�r�r=rEZhttp.cookiesrrr�Zmore_itertoolsrr@Zcherrypy._cpcompatrrZcherrypy._cperrorrrZcherrypy.libr	r
r�objectrr,r*rWr\rarer�rnr�r�r�rrrr�<module>s6:F


Kr