HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/cherrypy/lib/__pycache__/static.cpython-310.pyc
o

�N�g�@�@s�dZddlZddlZddlZddlZddlZddlZddlZddl	m
Zddlm
Z
ddlZddlmZddlmZmZmZdd�Ze�d	d
�Z		ddd
�Z		ddd�Zddd�Zddd�Zddd�Z		ddd�Zddd�ZdS) z-Module with helpers for serving static files.�N)�_make_boundary)�UnsupportedOperation)�ntob)�cptools�httputil�file_generator_limitedcCs:tjst��dtjd<dtjd<dtjd<dtjd<d	S)
z#Pre-initialize global mimetype map.zimage/x-dwgz.dwgzimage/x-iconz.icozapplication/x-bzip2z.bz2zapplication/x-gzipz.gzN)�	mimetypesZinited�init�	types_map�rr�G/opt/saltstack/salt/lib/python3.10/site-packages/cherrypy/lib/static.py�_setup_mimetypess


r
cCsLt�d|�jddd���}d�||�}||kr$tj�|�}|d�|�7}|S)z�Create HTTP header for downloading a file with a UTF-8 filename.

    This function implements the recommendations of :rfc:`6266#appendix-D`.
    See this and related answers: https://stackoverflow.com/a/8996249/2173868.
    �NFKC�ascii�ignore)�errorsz{}; filename="{}"z; filename*=UTF-8''{})�unicodedata�	normalize�encode�decode�format�urllib�parse�quote)�disposition�	file_nameZ
ascii_name�headerZquoted_namerrr�_make_content_disposition s
��rFc

Cs�tjj}tj�|�sd|}|rt�|d�t|��zt�|�}Wnt	t
tfy9|r5t�d|d�t���wt�|j
�rN|rJt�d|d�t���t�|j�|jd<t��|duryd}|�d	�}	|	d
krr||	d���}tj�|d�}|dur�||jd<|r�t�d|d�d}
|dur�|dur�tj�|�}t||�}
|
|jd
<|r�t�d|
d�|j}t|d�}t||||d�S)a<Set status, headers, and body in order to serve the given path.

    The Content-Type header will be set to the content_type arg, if provided.
    If not provided, the Content-Type will be guessed by the file extension
    of the 'path' argument.

    If disposition is not None, the Content-Disposition header will be set
    to "<disposition>; filename=<name>; filename*=utf-8''<name>"
    as described in :rfc:`6266#appendix-D`.
    If name is None, it will be set to the basename of path.
    If disposition is None, no Content-Disposition header will be written.
    z'%s' is not an absolute path.�TOOLS.STATICFILEzos.stat(%r) failed�TOOLS.STATICz%r is a directory�
Last-ModifiedN��.����Content-Type�Content-Type: %r�Content-Disposition�Content-Disposition: %r�rb��debug)�cherrypy�serving�response�os�path�isabs�log�
ValueError�stat�OSError�	TypeError�NotFound�S_ISDIR�st_moder�HTTPDate�st_mtime�headersr�validate_since�rfind�lowerrr
�get�basenamer�st_size�open�_serve_fileobj)
r/�content_typer�namer*r-�msg�st�ext�i�cd�content_length�fileobjrrr�
serve_file8sP�	




rMc	Cs�tjj}z	t�|���}Wnty |rt�dd�d}Ynty*d}Ynwt	�
|j�|jd<t
��|j}|durD||jd<|rNt�d|d�d}|dure|dur[|}nt||�}||jd<|rot�d|d�t||||d	�S)
acSet status, headers, and body in order to serve the given file object.

    The Content-Type header will be set to the content_type arg, if provided.

    If disposition is not None, the Content-Disposition header will be set
    to "<disposition>; filename=<name>; filename*=utf-8''<name>"
    as described in :rfc:`6266#appendix-D`.
    If name is None, 'filename' will not be set.
    If disposition is None, no Content-Disposition header will be written.

    CAUTION: If the request contains a 'Range' header, one or more seek()s will
    be performed on the file object.  This may cause undesired behavior if
    the file object is not seekable.  It could also produce undesired results
    if the caller set the read position of the file object prior to calling
    serve_fileobj(), expecting that the data would be served starting from that
    position.
    zos has no fstat attributerNr r$r%r&r'r))r+r,r-r.�fstat�fileno�AttributeErrorr1rrr9r:r;rr<rArrC)	rLrDrrEr*r-rGrKrJrrr�
serve_fileobj�s4�


rQcsttjj}tjj}|jdkr�d|jd<t�|j�d�����gkr7d�|jd<d}�r1t�	|d�t�
d	|���r�t��d
kr}�d\}}|�krK�}||}	�r[t�	d||fd�d
|_d||d
�f|jd<|	|jd<��
|�t�|	�|_|jSd
|_t��d�}
|
|jd<d|jvr�|jd=������fdd�}|�|_|jS�r�t�	dd��|jd<�|_|jS)zEInternal. Set response.body to the given file object, perhaps ranged.)�rR�bytesz
Accept-RangesZRangez
bytes */%sz
Content-Rangez:Invalid Range (first-byte-pos greater than Content-Length)ri�rRrz Single part; start: %r, stop: %rz206 Partial Contentzbytes %s-%s/%szContent-Lengthz!multipart/byteranges; boundary=%sr$c3s��dV�D]D\}}�rt�d||fd�td�d�Vtd�d�Vtd||d�fd�V��|�t�||�}|D]}|VqAdVqtd�dd�VdVdS)	Ns
zMultipart; start: %r, stop: %rrz--rz
Content-type: %sz#
Content-range: bytes %s-%s/%s

rR)r+r1r�seekr)�start�stop�gen�chunk��boundaryrKrDr*rL�rrr�file_ranges�s6����
��

z#_serve_fileobj.<locals>.file_rangeszNo byteranges requested)r+r,r-�request�protocolr;rZ
get_rangesr?r1�	HTTPError�len�statusrTr�body�
make_boundary)rLrDrKr*r-r]�messagerUrVZr_len�ctr\rrYrrC�sV


��

'�


rCcCst|dd|�S)z5Serve 'path' as an application/x-download attachment.zapplication/x-download�
attachment)rM)r/rErrr�serve_downloadsrgcCs�|rt�d||fd�z d}|r#tj�|�\}}|�|dd�d�}t|||d�WdStjy?|r<t�dd�YdSw)	Nz Attempting %r (content_types %r)�TOOLS.STATICDIRrR)rDr*Tr6rF)r+r1r.r/�splitextr?rMr6)�filename�
content_typesr*rDr[rHrrr�_attempts$���rlr!cCsztjj}|jdvr|rt�dd�dS|r+t�||j�s+|r)t�d|j|fd�dStj	�
|�}tj	�|�sN|sGd}|rCt�|d�t|��tj	�
||�}|dkrTd}|�d	�}|jt|�d
d�}	tj�|	�d	��}	t��dkry|	�dd
�}	tj	�
||	�}
|r�t�d|
|jfd�tj	�|
��tj	�|��s�t�d��t|
|�}|s�|r�ttj	�
|
|�|�}|r�|
dd	v|_|S)aServe a static resource from the given (root +) dir.

    match
        If given, request.path_info will be searched for the given
        regular expression before attempting to serve static content.

    content_types
        If given, it should be a Python dictionary of
        {file-extension: content-type} pairs, where 'file-extension' is
        a string (e.g. "gif") and 'content-type' is the value to write
        out in the Content-Type response header (e.g. "image/gif").

    index
        If provided, it should be the (relative) name of a file to
        serve for directory requests. For example, if the dir argument is
        '/home/me', the Request-URI is 'myapp', and the index arg is
        'index.html', the file '/home/me/myapp/index.html' will be sought.
    �ZGET�HEAD�request.method not GET or HEADrhF�.request.path_info %r does not match pattern %rz.Static dir requires an absolute dir (or root).�global�/z\/rRN�Windows�\zChecking file %r to fulfill %ri�r#)r+r,r]�methodr1�re�search�	path_infor.r/�
expanduserr0r2�join�rstripr`rr�unquote�lstrip�platform�system�replace�normpath�
startswithr_rlZis_index)�section�dir�root�matchrk�indexr*r]rF�branchrjZhandledrrr�	staticdir*sX
��
��

r�cCs�tjj}|jdvr|rt�dd�dS|r+t�||j�s+|r)t�d|j|fd�dStj	�
|�sK|sDd|f}|r@t�|d�t|��tj	�||�}t
|||d�S)a�Serve a static resource from the given (root +) filename.

    match
        If given, request.path_info will be searched for the given
        regular expression before attempting to serve static content.

    content_types
        If given, it should be a Python dictionary of
        {file-extension: content-type} pairs, where 'file-extension' is
        a string (e.g. "gif") and 'content-type' is the value to write
        out in the Content-Type response header (e.g. "image/gif").

    rmrorFrpz5Static tool requires an absolute filename (got '%s').r))r+r,r]rur1rvrwrxr.r/r0r2rzrl)rjr�r�rkr*r]rFrrr�
staticfile|s.
���r�)NNNF)F)N)r!r!Nr!F)Nr!NF)�__doc__r.r~rvr3r�urllib.parserr�email.generatorrrc�iorr+Zcherrypy._cpcompatrZcherrypy.librrrr
rrMrQrCrgrlr�r�rrrr�<module>s:

�M
�
6
T

�R