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/lib/__pycache__/encoding.cpython-310.pyc
o

�N�g�B�@s�ddlZddlZddlZddlZddlmZddlmZddlmZddlm	Z	dZ
dZdd	d
�ZGdd�d�Z
Gd
d�d�Zdd�Zdd�Zdd�Zdddgdfdd�ZdS)�N)�
text_or_bytes)�file_generator)�is_closable_iterator)�set_vary_header��	�utf-8cCsRtjj}|durt|t�s|g}||_dS|r't|t�s|g}|j||_dSdS)a;Replace or extend the list of charsets used to decode a request entity.

    Either argument may be a single string or a list of strings.

    encoding
        If not None, restricts the set of charsets attempted while decoding
        a request entity to the given set (even if a different charset is
        given in the Content-Type request header).

    default_encoding
        Only in effect if the 'encoding' argument is not given.
        If given, the set of charsets attempted while decoding a request
        entity is *extended* with the given value(s).

    N)�cherrypy�request�body�
isinstance�listZattempt_charsets)�encoding�default_encodingr�r�I/opt/saltstack/salt/lib/python3.10/site-packages/cherrypy/lib/encoding.py�decodes


�rc@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�UTF8StreamEncodercCs
||_dS�N)�	_iterator)�self�iteratorrrr�__init__,s
zUTF8StreamEncoder.__init__cCs|Srr�rrrr�__iter__/szUTF8StreamEncoder.__iter__cCs|��Sr)�__next__rrrr�next2szUTF8StreamEncoder.nextcCs"t|j�}t|t�r|�d�}|S�Nr)rrr�str�encode)r�resrrrr5s


zUTF8StreamEncoder.__next__cCst|j�r|j��dSdSr)rr�closerrrrr!;s
�zUTF8StreamEncoder.closecCs |�d�r
t||��t|j|�S)N�__)�
startswith�AttributeError�getattrr)r�attrrrr�__getattr__?s

zUTF8StreamEncoder.__getattr__N)	�__name__�
__module__�__qualname__rrrrr!r'rrrrr+src@sPeZdZdZdZdZdZdZdZdZ	dd�Z
d	d
�Zdd�Zd
d�Z
dd�ZdS)�ResponseEncoderrz+Response body could not be encoded with %r.N�strictTFcKs`|��D]
\}}t|||�qt�|_tjj}|jdur.|jr%t�	dd�|j|_
||_dSdS)NzReplacing request.handler�TOOLS.ENCODE)�items�setattr�set�attempted_charsetsr	�servingr
�handler�debug�log�
oldhandler)r�kwargs�k�vr
rrrrOs

�zResponseEncoder.__init__cs8��jvrdS�j�����fdd�}|�j��_dS)z�Encode a streaming response body.

        Use a generator wrapper, and just pray it works as the stream is
        being written out.
        Fc3s.�|D]}t|t�r|���j�}|VqdSr)rrr�errors)r�chunk�rrrr�encoderfs�
�z.ResponseEncoder.encode_stream.<locals>.encoderT)r1�addr)rrr=rr<r�
encode_stream\s
zResponseEncoder.encode_streamc
Csv||jvrdS|j�|�g}|jD]#}t|t�r0z	|�||j�}Wn
ttfy/YdSw|�	|�q||_dS)z Encode a buffered response body.FT)
r1r>rrrrr:�LookupError�UnicodeError�append)rrrr;rrr�
encode_stringns


�zResponseEncoder.encode_stringcCstjj}tjj}|jrt�d|jd�|jr|j}n|j}d|j	vr'|j	d=|j	�
d�}dd�|D�}|jrAt�dt|�d�|jdurr|j�
�}|jrVt�d|d�|r`d	|vs`||vrq|jrkt�d
|d�||�rq|Snt|s�|jr�t�d|jd�||j�r�|jSt�d|j|j��|D]8}|jd
kr�|jd	kr�|jr�t�d|d�||j�r�|jSq�|j}|jr�t�d|d�||�r�|Sq�d	|vr�d}||vr�|jr�t�dd�||�r�|S|j	�d�}	|	dur�d}
nd|	}
d�t|j��}|
d|f7}
t�d|
��)Nzresponse.stream %rr-�Content-LengthzAccept-CharsetcSsg|]}|j���qSr)�value�lower)�.0�encrrr�
<listcomp>�sz;ResponseEncoder.find_acceptable_charset.<locals>.<listcomp>zcharsets %szSpecified encoding %r�*zAttempting encoding %rzAttempting default encoding %ri�rz%Attempting default encoding due to %rz"Attempting encoding %s (qvalue >0)z
iso-8859-1zAttempting ISO-8859-1 encodingz2Your client did not send an Accept-Charset header.z0Your client sent this Accept-Charset header: %s.z, z We tried these charsets: %s.�)r	r2r
�responser4r5�streamr?rC�headers�elements�reprrrFr�	HTTPError�failmsg�qvaluerE�get�join�sortedr1)rr
rLr=ZencsZcharsetsr�elementZisoZac�msgZ	_charsetsrrr�find_acceptable_charset~s���


�������

�

��

�����z'ResponseEncoder.find_acceptable_charsetcOstjj}|j|i|��|_t|j�|_|j�d�}|jr)t�	ddd�|D�d�|r|j
r|d}|jrY|j�
��d�rK|jrHt�	d|d�d	}n|jrVt�	d
|d�d}n|jrbt�	dd�d	}|r|��|jd
<|jrxt�	d|d�t|�|jd<|jS)N�Content-TypezContent-Type: %rcSsg|]}t|��qSr)r)rG�hrrrrI�s�z,ResponseEncoder.__call__.<locals>.<listcomp>r-rztext/z#Content-Type %s starts with "text/"Tz?Not finding because Content-Type %s does not start with "text/"FzFinding because not text_only�charsetzSetting Content-Type %s)r	r2rLr6r�prepare_iterrNrOr4r5�add_charset�	text_onlyrErFr#rY�paramsr)r�argsr7rL�ctZdo_findrrr�__call__�sP��
����
�zResponseEncoder.__call__)r(r)r*rrRrr:r_r^r4rr?rCrYrcrrrrr+Es
_r+cCsFt|t�r|r|g}|Sg}|St|d�rt|�}|S|dur!g}|S)zL
    Ensure response body is iterable and resolves to False when empty.
    �readN)rr�hasattrr)rErrrr]s

�
��r]ccs��ddl}dVdVdVt�dtt���tdd�@�V|tkr&d	Vn|tkr.d
VndVdV|�d�}d}|�||j	|j
|jd�}|D]}|t|�7}|�||�}|�
|�VqJ|��Vt�d|tdd�@�Vt�d|tdd�@�VdS)
z,Compress 'body' at the given compress_level.rNs���z<LZFFFFFFFF������)�zlib�struct�pack�int�time�_COMPRESSION_LEVEL_BEST�_COMPRESSION_LEVEL_FAST�crc32�compressobj�DEFLATED�	MAX_WBITS�
DEF_MEM_LEVEL�len�compress�flush)r�compress_levelrm�crc�sizeZzobj�linerrrrz s2� 

�
rzcCsFddl}t��}|�|�|�d�|jd|d�}|��}|��|S)Nr�rb)�mode�fileobj)�gzip�io�BytesIO�write�seek�GzipFilerdr!)rr�ZzbufZzfile�datarrr�
decompressNs

r��z	text/htmlz
text/plainFcCs.tjj}tjj}t|d�|js|rtjddd�dSt|dd�r,|r*tjddd�dS|j�	d�}|s?|r=tjd	dd�dS|j�
d
d��d�d
}|D]�}|jdkrg|j
d
krg|rdtjd|dd�dS|jdv�r|j
d
kr�|r}tjd|dd�dS||vr�d}d|vr�|�d�\}	}
|D];}d|vr�|�d�\}}
|	|kr�|
dkr�d}n#d|
vr�d|
vr�|
�d�\}}|
�d�\}}|dkr�||kr�d}nq�|s�|r�tjd||fdd�dS|r�tjddd�d|jd<t|j|�|_d|jvr�|jd=dSqM|�r
tjddd�t�dd���dS)a�Try to gzip the response body if Content-Type in mime_types.

    cherrypy.response.headers['Content-Type'] must be set to one of the
    values in the mime_types arg before calling this function.

    The provided list of mime-types must be of one of the following form:
        * `type/subtype`
        * `type/*`
        * `type/*+subtype`

    No compression is performed if any of the following hold:
        * The client sends no Accept-Encoding request header
        * No 'gzip' or 'x-gzip' is present in the Accept-Encoding header
        * No 'gzip' or 'x-gzip' with a qvalue > 0 is present
        * The 'identity' value is given with a qvalue > 0.

    zAccept-EncodingzNo response bodyz
TOOLS.GZIP)�contextN�cachedFzNot gzipping cached responsezNo Accept-EncodingrZ��;r�identityzNon-zero identity qvalue: %s)r�zx-gzipzZero gzip qvalue: %s�/rJT�+z$Content-Type %s not in mime_types %rZGzippingr�zContent-EncodingrDzNo acceptable encoding found.ZGZIPrKzidentity, gzip)r	r2r
rLrrr5r%rNrOrT�splitrErSrzrQZset_response)r|Z
mime_typesr4r
rLZ
acceptablerbZcoding�foundZ
ct_media_typeZct_sub_typeZ	mime_typeZ
media_typeZsub_typeZct_leftZct_right�left�rightrrrr�Zs�

�

����

�1r�r)rnrqr�r	Zcherrypy._cpcompatrZcherrypy.librrrrsrrrrr+r]rzr�r�rrrr�<module>s(
C.�