HEX
Server: LiteSpeed
System: Linux s787.bom1.mysecurecloudhost.com 4.18.0-477.13.1.lve.el8.x86_64 #1 SMP Thu Jun 1 16:40:47 EDT 2023 x86_64
User: mobilech (5348)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/cherrypy/lib/__pycache__/cptools.cpython-310.pyc
o

;j \�@s8dZddlZddlZddlmZddlZddlZddlm	Z	ddl
mZddl
m
Z
d7dd	�Zd
d�Zd8dd
�Z		d9dd�Zd:dd�Zd8dd�Zde_		d;dd�ZGdd�de�Zdd �Zejdfd!d"�Zd<d#d$�Zd<d%d&�Zd=d(d)�Zd>d*d+�Zd<d,d-�Zd8d.d/�Z Gd0d1�d1ej!�Z"d8d2d3�Z#e$d4fd5d6�Z%dS)?z%Functions for builtin CherryPy tools.�N)�md5)�
text_or_bytes)�httputil)�is_iteratorFc	Cs�tjj}t|d�rdSt�|j�\}}}|j�d�}|r'|r&t�	d|d�n3|s2|r1t�	dd�n(|dkr?|r>t�	dd�n|�
�}dt|���}|rUt�	d	|d�||jd<||_
|rgt�	d
|d�|dkr�|dkr�tjj}|j�d�pzg}d
d�|D�}|r�t�	dt|�d�|r�|dgks�||vs�t�dd||f��|j�d�p�g}dd�|D�}|r�t�	dt|�d�|dgks�||vr�|r�t�	d|jd�|jdvr�t�gd��t�dd||f��dSdSdS)aValidate the current ETag against If-Match, If-None-Match headers.

    If autotags is True, an ETag response-header value will be provided
    from an MD5 hash of the response body (unless some other code has
    already provided an ETag header). If False (the default), the ETag
    will not be automatic.

    WARNING: the autotags feature is not designed for URL's which allow
    methods other than GET. For example, if a POST to the same URL returns
    no content, the automatic ETag will be incorrect, breaking a fundamental
    use for entity tags in a possibly destructive fashion. Likewise, if you
    raise 304 Not Modified, the response body will be empty, the ETag hash
    will be incorrect, and your application will break.
    See :rfc:`2616` Section 14.24.
    �ETagNzETag already set: %szTOOLS.ETAGSzAutotags off��zStatus not 200z"%s"zSetting ETag: %sz
Status: %s�+zIf-MatchcS�g|]}t|��qS���str��.0�xr
r
�H/opt/saltstack/salt/lib/python3.10/site-packages/cherrypy/lib/cptools.py�
<listcomp>F�z"validate_etags.<locals>.<listcomp>zIf-Match conditions: %s�*�z)If-Match failed: ETag %r did not match %rz
If-None-MatchcSr	r
rr
r
r
rrOrzIf-None-Match conditions: %szrequest.method: %s��GET�HEAD�0z(If-None-Match failed: ETag %r matched %r)�cherrypy�serving�response�hasattr�	_httputil�valid_status�status�headers�get�logZ
collapse_bodyr�	hexdigestr�request�elements�repr�	HTTPError�method�HTTPRedirect)	Zautotags�debugrr�reason�msgZetagr$Z
conditionsr
r
r�validate_etagssr
���
�����
��r-cCs�tjj}|j�d�}|r^t�|j�\}}}tjj}|j�d�}|r6||kr6|dkr-|dks1|dkr6t�	d��|j�d�}|r`||krb|dkrJ|dksN|dkrd|j
dvrYt�gd��t�	d��d	Sd	Sd	Sd	S)
z�Validate the current Last-Modified against If-Modified-Since headers.

    If no code has set the Last-Modified response header, then no
    validation will be performed.
    z
Last-ModifiedzIf-Unmodified-SincerrrzIf-Modified-SincerrN)rrrr r!rrrr$r'r(r))rZlastmodrr+r,r$Zsincer
r
r�validate_since^s$


�r.cCs�t|ttf�s
|g}dd�|D�}|sddg}n
d|vr%d|vr%|�d�d�|�tjjd<tjj	|vrG|rBt�
dtjj	|fd�t�d	��|rWt�
d
tjj	|fd�dSdS)a�Raise 405 if request.method not in methods (default ['GET', 'HEAD']).

    The given methods are case-insensitive, and may be in any order. If
    only one method is allowed, you may supply a single string; if more
    than one, supply a list of strings.

    Regardless of whether the current method is allowed or not, this
    also emits an 'Allow' response header, containing the given methods.
    cSsg|]}|r|���qSr
)�upper)r�mr
r
rr�szallow.<locals>.<listcomp>rr�, �Allowz#request.method %r not in methods %rzTOOLS.ALLOW�zrequest.method %r in methods %rN)�
isinstance�tuple�list�append�joinrrr r$r(r"r')�methodsr*r
r
r�allow{s.



��

���r:�X-Forwarded-Host�X-Forwarded-For�X-Forwarded-Protoc
CsLtjj}|r(|j�|d�}|rt�d||fd�|dkr&d|��vr&d}n|}|s5|jd|j�d��}|rU|j�|d�}|rJt�d||fd�|durU|�	d	�d
}|sft
j�|j�j
}|j�d|�}|�d�dkrs|d|}||_|r�|j�|�}	|r�t�d
||	fd�|	r�|dkr�tdd�|	�	d	�D��}	|	|j_dSdSdS)a�Change the base URL (scheme://host[:port][/path]).

    For running a CP server behind Apache, lighttpd, or other HTTP
    server.

    For Apache and lighttpd, you should leave the 'local' argument at
    the default value of 'X-Forwarded-Host'. For Squid, you probably
    want to set tools.proxy.local = 'Origin'.

    If you want the new request.base to include path info (not just the
    host), you must explicitly set base to the full base path, and ALSO
    set 'local' to '', so that the X-Forwarded-Host request header
    (which never includes path info) does not override it. Regardless,
    the value for 'base' MUST NOT end in a slash.

    cherrypy.request.remote.ip (the IP address of the client) will be
    rewritten if the header specified by the 'remote' arg is valid. By
    default, 'remote' is set to 'X-Forwarded-For'. If you do not want to
    rewrite remote.ip, set the 'remote' arg to an empty string.
    NzTesting scheme %r:%rzTOOLS.PROXY�on�ssl�httpsz://zTesting local %r:%r�,r�Host���zTesting remote %r:%rr<css�|]}|��VqdS�N)�strip)r�ipr
r
r�	<genexpr>�s�zproxy.<locals>.<genexpr>)rrr$r r!r"�lower�base�find�split�urllib�parse�urlparse�netloc�next�remoterF)
rI�localrQ�schemer*r$�sZlbase�defaultZxffr
r
r�proxy�s@�rV�ZRangecCs<tjj}|D]}||jvr|rt�d|d�|j|=qdS)aDelete request headers whose field names are included in 'headers'.

    This is a useful tool for working behind certain HTTP servers; for
    example, Apache duplicates the work that CP does for 'Range'
    headers, and will doubly-truncate the response.
    zIgnoring request header %rzTOOLS.IGNORE_HEADERSN)rrr$r r")r r*r$�namer
r
r�ignore_headers�s

���rYcCs<|rt�dt|�d�|pgD]\}}|tjjj|<qdS)zSet headers on the response.zSetting response headers: %szTOOLS.RESPONSE_HEADERSN)rr"r&rrr )r r*rX�valuer
r
r�response_headers�s��r[T��Forbidden Referer header.cCs�z$tjjjd}tt�||��}|rt�d||fd�||kr#WdSWnty:|r3t�dd�|r8YdSYnwt�	||��)a�Raise HTTPError if Referer header does/does not match the given pattern.

    pattern
        A regular expression pattern to test against the Referer.

    accept
        If True, the Referer must match the pattern; if False,
        the Referer must NOT match the pattern.

    accept_missing
        If True, permit requests with no Referer header.

    error
        The HTTP error code to return to the client on failure.

    message
        A string to include in the response body on failure.

    ZRefererzReferer %r matches %rz
TOOLS.REFERERNzNo Referer header)
rrr$r �bool�re�matchr"�KeyErrorr')�pattern�acceptZaccept_missing�error�messager*�refr`r
r
r�referer�s$����rgc@szeZdZdZdZdZdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
ddd�Zddd�Zddd�Z
dd�Zifdd�Zdd�ZdS)�SessionAuthz"Assert that the user is logged in.�usernameFcC�dSrDr
)�selfri�passwordr
r
r�check_username_and_password"�z'SessionAuth.check_username_and_passwordcCsdS)z2Provide a temporary user name for anonymous users.Nr
�rkr
r
r�	anonymous%szSessionAuth.anonymouscCrjrDr
�rkrir
r
r�on_login)rnzSessionAuth.on_logincCrjrDr
rqr
r
r�	on_logout,rnzSessionAuth.on_logoutcCrjrDr
rqr
r
r�on_check/rnzSessionAuth.on_check�..�cKstd�t��d�S)Nas<html><body>
Message: %(error_msg)s
<form method="post" action="do_login">
    Login: <input type="text" name="username" value="%(username)s" size="10" />
    <br />
    Password: <input type="password" name="password" size="10" />
    <br />
    <input type="hidden" name="from_page" value="%(from_page)s" />
    <br />
    <input type="submit" />
</form>
</body></html>zutf-8)r�vars�encode)rk�	from_pageri�	error_msg�kwargsr
r
r�login_screen2s
��zSessionAuth.login_screencKsptjj}|�||�}|r!|�|||�}||_d|jvr|jd=dS|tjj_|tj	|j
<|�|�t�|p6d��)zOLogin.

        May raise redirect, or return True if request handled.
        �Content-LengthT�/)
rrrrmr|�bodyr r$�login�session�session_keyrrr))rkrirlryr{rrzrr
r
r�do_loginAs


zSessionAuth.do_logincKs>tj}|�|j�}d||j<|rdtjj_|�|�t�|��)zPLogout.

        May raise redirect, or return True if request handled.
        N)	rr�r!r�rr$r�rsr))rkryr{�sessrir
r
r�	do_logoutUs



zSessionAuth.do_logoutcCs�tj}tjj}tjj}|�|j�}|s!|��||j<}|�d�|sBtj	|j
d�}|�dt��|�|�|_
d|jvr@|jd=dS|�dt��||_|�|�dS)zUAssert username.

        Raise redirect, or return True if request handled.
        z&No session[username], trying anonymous)�qsz;No username, routing to login_screen with from_page %(url)rr}Tz%Setting request.login to %(username)rN)rr�rr$rr!r�rp�_debug_message�url�query_string�localsr|rr r�rt)rkr�r$rrir�r
r
r�do_checkbs(
�
zSessionAuth.do_checkcCs|jsdSt�||d�dS)NzTOOLS.SESSAUTH)r*rr")rk�template�contextr
r
rr�~szSessionAuth._debug_messagecCs�tjj}tjj}|j}|�d�r|�dt��|��|_	dS|�d�rG|j
dkr7d|jd<|�d�t�d��|�d	t��|j
d
i|j��S|�d
�rk|j
dkr[d|jd<t�d��|�dt��|jd
i|j��S|�d�|��S)Nr|z routing %(path)r to login_screenTr��POSTr2zdo_login requires POSTr3zrouting %(path)r to do_loginr�zrouting %(path)r to do_logoutz!No special path, running do_checkr
)rrr$r�	path_info�endswithr�r�r|rr(r r'r��paramsr�r�)rkr$r�pathr
r
r�run�s,











zSessionAuth.runN)rurvrv)ru)�__name__�
__module__�__qualname__�__doc__r�r*rmrprrrsrtr|r�r�r�r�r�r
r
r
rrhs



rhcKsHdd�dd�tt�D��t�}|��D]
\}}t|||�q|��S)Nz�Session authentication hook.

    Any attribute of the SessionAuth class may be overridden
    via a keyword arg to this function:
    
z
    css2�|]}|�d�sd�|ttt|��j�VqdS)�__z
{!s}: {!s}N)�
startswith�format�type�getattrrhr�)r�kr
r
rrG�s��
�zsession_auth.<locals>.<genexpr>)r8�dirrh�items�setattrr�)r{�sar��vr
r
r�session_auth�s
��	r�cCstjdd|dd�dS)z;Write the last error's traceback to the cherrypy error log.rv�HTTPT)�severity�	tracebackN)rr")r�r*r
r
r�
log_traceback�sr�cCs.dd�tjjjD�}t�dd�|�d�dS)z0Write request headers to the cherrypy error log.cSsg|]
\}}d||f�qS)z  %s: %sr
)rr�r�r
r
rr�sz'log_request_headers.<locals>.<listcomp>z
Request Headers:
�
r�N)rrr$Zheader_listr"r8)r*�hr
r
r�log_request_headers�sr�cCs�tjj}g}ddlm}|j}|j��D]}||vr|�|�q|D] }|�d|�|j�|g�}|�	�|D]	}|�d|�q8q"t�
dt��dd�|�d�d	S)
z.Write request.hooks to the cherrypy error log.r)�
_cprequestz    %s:z
        %rz
Request Hooks for z:
r�r�N)
rrr$r�Z
hookpoints�hooks�keysr7r!�sortr"r�r8)r*r$r,r�Zpointsr�r�r�r
r
r�	log_hooks�s,
�����r�rvcCs:|rt�dddd�||fd�|rt�|��t�|��)z8Raise InternalRedirect or HTTPRedirect to the given url.zRedirecting %sto: %sz	internal rv)TFzTOOLS.REDIRECT)rr"ZInternalRedirectr))r�Zinternalr*r
r
r�redirect�s��

r�cCs�tjj}|j}|rt�d|j|||fd�|jdur8|r4|�d�s6t�|d|j�}tj	||p1dd��dSdS|jdur\|r^|�d�r`|dkrbt�|dd	�|j�}tj	||pYdd��dSdSdSdS)
z9Redirect if path_info has (missing|extra) trailing slash.z3is_index: %r, missing: %r, extra: %r, path_info: %rzTOOLS.TRAILING_SLASHTr~i-)rFNrC)
rrr$r�r"Zis_indexr�r�r�r))�missing�extrarr*r$�piZnew_urlr
r
r�trailing_slash�s.��

�
�r�cs&��fdd��tjj}�|j�|_dS)z�Wrap response.body in a generator that recursively iterates over body.

    This allows cherrypy.response.body to consist of 'nested
    generators'; that is, a set of generators that yield generators.
    c3s`�d}|D]}t|�s|d7}|Vq�|�D]	}|d7}|Vqq�r.t�d|d�dSdS)Nr�zFlattened %d chunksz
TOOLS.FLATTEN)rrr")�inputZ	numchunksr�y�r*�	flattenerr
rr��s���zflatten.<locals>.flattenerN)rrrr)r*rr
r�r�flatten�sr�c	Cs>|sdSt|t�r|g}tjj}|j�d�}|s$|r t�dd�|dS|D]X}|jdkr~|j	dkr@|r:t�dd�|dS|j	�
d�ri|j	dd	�}|D]}|�|�rg|rat�d
|j	d�|SqOq&|j	|vr~|ryt�d
|j	d�|j	Sq&|j�d�}|dur�d}nd|}|d
d�
|�7}t�d|��)apReturn the client's preferred media-type (from the given Content-Types).

    If 'media' is None (the default), no test will be performed.

    If 'media' is provided, it should be the Content-Type value (as a string)
    or values (as a list or tuple of strings) which the current resource
    can emit. The client's acceptable media ranges (as declared in the
    Accept request header) will be matched in order to these Content-Type
    values; the first such string is returned. That is, the return value
    will always be one of the strings provided in the 'media' arg (or None
    if 'media' is None).

    If no match is found, then HTTPError 406 (Not Acceptable) is raised.
    Note that most web browsers send */* as a (low-quality) acceptable
    media range, which should match any Content-Type. In addition, "...if
    no Accept header field is present, then it is assumed that the client
    accepts all media types."

    Matching types are checked in order of client preference first,
    and then in the order of the given 'media' values.

    Note that this function does not honor accept-params (other than "q").
    NZAcceptzNo Accept header elementszTOOLS.ACCEPTrz*/*zMatch due to */*z/*rCzMatch due to %sz*Your client did not send an Accept header.z(Your client sent this Accept header: %s.z4 But this resource only emits these media types: %s.r1i�)r4rrrr$r r%r"ZqvaluerZr�r�r!r8r')	Zmediar*r$Zranges�elementZmtyper0Zahr,r
r
rrcsT



���
�
��rccs(eZdZ�fdd�Z�fdd�Z�ZS)�MonitoredHeaderMapcs|j�|�tt|��|�SrD)�accessed_headers�add�superr��
transform_key)rk�key��	__class__r
rr�Tsz MonitoredHeaderMap.transform_keycst�|_tt|���dSrD)�setr�r�r��__init__ror�r
rr�XszMonitoredHeaderMap.__init__)r�r�r�r�r��
__classcell__r
r
r�rr�Rsr�csZtjj��j}t��_�j�|��durtgd������fdd�}�j�d|d�dS)zKAuto-populate the Vary response header based on request.header access.
    N)zContent-Dispositionr}zContent-Typecsttjjj}tdd�|�d�D��}�rt�d�jjd�|��jj�}|�	��}t
|�}|��d�|�|d<dS)NcSsg|]}|j�qSr
)rZ)r�er
r
rrjsz9autovary.<locals>.set_response_header.<locals>.<listcomp>ZVaryzAccessed headers: %szTOOLS.AUTOVARYr1)
rrrr r�r%r"r��union�
differencer6r�r8)Zresp_hr��r*�ignorer$r
r�set_response_headerhs

�
z%autovary.<locals>.set_response_headerZbefore_finalize�_)	rrr$r r��updater�r��attach)r�r*Zreq_hr�r
r�r�autovary]sr�i�cCsttjj}|jjj}tj�||�� t|��	|j
�D]}|||j
|�|j
|<qWd�dS1s3wYdS)aLConvert request params based on function annotations.

    This function also processes errors that are subclasses of ``exception``.

    :param BaseException exception: Exception class to catch.
    :type exception: BaseException

    :param error: The HTTP status code to return to the client on failure.
    :type error: int
    N)rrr$�handler�callable�__annotations__r'�handler��intersectionr�)�	exceptionrdr$�typesr�r
r
r�convert_paramsws
�"�r�)FF)NF)Nr;r<r=F)rWF)TFr\r]F)F)rvTF)TFNF)&r��loggingr_�hashlibr�urllib.parserLrZcherrypy._cpcompatrZcherrypy.librrrr-r.r:rVrYr[Zfailsaferg�objectrhr��ERRORr�r�r�r�r�r�rcZ	HeaderMapr�r��
ValueErrorr�r
r
r
r�<module>sD
N

�
A
	
�&





K