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

�N�ggC�@s�dZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZddlm
Z
ddlmZddlZddlZddlmZmZe
j��Zd	ed
<ded<ejejjd
d�Zdd�Zdd�Zdd�Zdd�Z Gdd�de!�Z"e�#d�Z$Gdd�de"�Z%e�#d�Z&dd�Z'dd �Z(d!d"�Z)d#d$�Z*d8d&d'�Z+e�#d(�Z,d9d)d*�Z-Gd+d,�d,ej.j/�Z0e1e2kr�d-�3d.d/�e4d0�D��Z5d-�3d1d/�e4d2�D��e6d3�Z7n
dZ5e2e4d2��e2d3g�Z7Gd4d5�d5e0�Z8Gd6d7�d7e!�Z9dS):a@HTTP library functions.

This module contains functions for building an HTTP application
framework: any one, not just one whose name starts with "Ch". ;) If you
reference any modules from some popular framework inside *this* module,
FuManChu will personally hang you up by your thumbs and submit you
to a public caning.
�N)�
b2a_base64��parse_header)�
decode_header)�BaseHTTPRequestHandler)�unquote_plus)�ntob�ntou)zInternal Server Errorz^The server encountered an unexpected condition which prevented it from fulfilling the request.i�)zService UnavailablezqThe server is currently unable to handle the request due to a temporary overloading or maintenance of the server.i�T)�usegmtcG�8d�dd�|D��}d|vr|�dd�}d|vs|pdS)z�Return the given path \*atoms, joined into a single URL.

    This will correctly join a SCRIPT_NAME and PATH_INFO into the
    original URL, even if either atom is blank.
    �/cS�g|]}|r|�qS�r��.0�xrr�I/opt/saltstack/salt/lib/python3.10/site-packages/cherrypy/lib/httputil.py�
<listcomp>.�zurljoin.<locals>.<listcomp>z//��join�replace��atoms�urlrrr�urljoin(�
�rcGr)z�Return the given path `*atoms`, joined into a single URL.

    This will correctly join a SCRIPT_NAME and PATH_INFO into the
    original URL, even if either atom is blank.
    �/cSr
rrrrrrr;rz!urljoin_bytes.<locals>.<listcomp>s//rrrrr�
urljoin_bytes5rrcCst|d�t|d�fS)z9Return a protocol tuple from the given 'HTTP/x.y' string.��)�int)Zprotocol_strrrr�protocol_from_httpBsr"cCs�|sdSg}|�dd�\}}|�d�D]T}dd�|�dd�D�\}}|rI|s*|d}t|�t|�}}||kr8q||kr?dS|�||df�q|sNdSt|�|kr\|�d|f�q|�|t|�|f�q|S)	a�Return a list of (start, stop) indices from a Range header, or None.

    Each (start, stop) tuple will be composed of two ints, which are suitable
    for use in a slicing operation. That is, the header "Range: bytes=3-6",
    if applied against a Python string, is requesting resource[3:7]. This
    function will return the list [(3, 7)].

    If this function returns an empty list, you should return HTTP 416.
    N�=��,cSsg|]}|���qSr)�striprrrrrXrzget_ranges.<locals>.<listcomp>�-r)�splitr!�append)Zheadervalue�content_length�resultZ	bytesunitZ
byterangesZbrange�start�stoprrr�
get_rangesGs*	r.c@sZeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	e
dd��Zedd��Z
dS)�
HeaderElementz@An element (with parameters) from an HTTP header's element list.NcCs||_|dur	i}||_dS�N)�value�params)�selfr1r2rrr�__init__�s
zHeaderElement.__init__cCst�|j|j�Sr0)�builtins�cmpr1�r3�otherrrr�__cmp__�szHeaderElement.__cmp__cCs|j|jkSr0�r1r7rrr�__lt__��zHeaderElement.__lt__cCs,dd�|j��D�}td|jd�|�f�S)NcSsg|]
\}}d||f�qS)z;%s=%sr)r�k�vrrrr�sz)HeaderElement.__str__.<locals>.<listcomp>z%s%s�)r2�items�strr1r)r3�prrr�__str__�szHeaderElement.__str__cC�t|���Sr0)rrC�r3rrr�	__bytes__�r<zHeaderElement.__bytes__cCrDr0)r	rCrErrr�__unicode__�r<zHeaderElement.__unicode__cCst|�\}}||fS)z7Transform 'token;key=val' to ('token', {'key': 'val'}).r)�
elementstrZ
initial_valuer2rrr�parse�szHeaderElement.parsecCs|�|�\}}|||�S)z@Construct an instance from a string of the form 'token;key=val'.)rI)�clsrHZivalr2rrr�from_str�s
zHeaderElement.from_strr0)�__name__�
__module__�__qualname__�__doc__r4r9r;rCrFrG�staticmethodrI�classmethodrKrrrrr/�s

r/z; *q *=c@s8eZdZdZedd��Zedd��Zdd�Zdd	�Z	d
S)�
AcceptElementa�An element (with parameters) from an Accept* header's element list.

    AcceptElement objects are comparable; the more-preferred object will be
    "less than" the less-preferred object. They are also therefore sortable;
    if you sort a list of AcceptElement objects, they will be listed in
    priority order; the most preferred value will be first. Yes, it should
    have been the other way around, but it's too late to fix now.
    cCs\d}t�|d�}|�d���}|rt�|d���}|�|�\}}|dur)||d<|||�S)Nr$r�q)�q_separatorr(�popr&r/rKrI)rJrH�qvaluerZmedia_rangeZ
media_typer2rrrrK�s
zAcceptElement.from_strc
Cs\|j�dd�}t|t�r|j}zt|�WSty-}z
	t�dd�	t
|���|�d}~ww)z'The qvalue, or priority, of this value.rS�1i�zMalformed HTTP header: `{}`N)r2�get�
isinstancer/r1�float�
ValueError�cherrypy�	HTTPError�formatrA)r3�valZval_errrrrrV�s 


����zAcceptElement.qvaluecCs0t�|j|j�}|dkrt�t|�t|��}|S)Nr)r5r6rVrA)r3r8�diffrrrr9�szAcceptElement.__cmp__cCs(|j|jkrt|�t|�kS|j|jkSr0)rVrAr7rrrr;�szAcceptElement.__lt__N)
rLrMrNrOrQrK�propertyrVr9r;rrrrrR�s	

rRz,(?=(?:[^"]*"[^"]*")*[^"]*$)cCs^|sgSg}t�|�D]}|�d�s|dkrt�|�}nt�|�}|�|�qttt	|���S)zMReturn a sorted HeaderElement list from a comma-separated header string.
    ZAcceptZTE)
�RE_HEADER_SPLITr(�
startswithrRrKr/r)�list�reversed�sorted)�	fieldnameZ
fieldvaluer+�elementZhvrrr�header_elements�s
ricCs8t|�}d}|D]\}}|dur|�|�}||7}q|S)zv
    Decode :rfc:`2047` TEXT

    >>> decode_TEXT("=?utf-8?q?f=C3=BCr?=") == b'f\xfcr'.decode('latin-1')
    True
    r?N)r�decode)r1rZdecodedvalueZatom�charsetrrr�decode_TEXT�s

rlcCsd|vrt|�S|S)z9
    Decode the text but only if '=?' appears in it.
    z=?)rlr:rrr�decode_TEXT_maybesrmc	Cs�|sd}|d}}t|t�r|�d�\}}}|��pd}zt|�}Wnttfy3tdt|���w|dks<|dkrDtdt|���|tvrMd\}}nt|\}}|durY|}|||fS)	aReturn legal HTTP status Code, Reason-phrase and Message.

    The status arg must be an int, a str that begins with an int
    or the constant from ``http.client`` stdlib module.

    If status has no reason-phrase is supplied, a default reason-
    phrase will be provided.

    >>> import http.client
    >>> from http.server import BaseHTTPRequestHandler
    >>> valid_status(http.client.ACCEPTED) == (
    ...     int(http.client.ACCEPTED),
    ... ) + BaseHTTPRequestHandler.responses[http.client.ACCEPTED]
    True
    ��N� z8Illegal response status from server (%s is non-numeric).�diWz9Illegal response status from server (%s is out of range).)r?r?)	rYrA�	partitionr&r!�	TypeErrorr[�repr�response_codes)�status�code�reason�_Zdefault_reason�messagerrr�valid_statuss.

���

rz�utf-8c
Cs�dd�|�d�D�}i}|D]]}|s|sq|�dd�}t|�dkr3|r*td|f��|r2|�d�nqt|d�s;|rkt|d	|d
d�}t|d|d
d�}	||vrgt||t�s_||g||<||�|	�q|	||<q|S)a�Parse a query given as a string argument.

    Arguments:

    qs: URL-encoded query string to be parsed

    keep_blank_values: flag indicating whether blank values in
        URL encoded queries should be treated as blank strings.  A
        true value indicates that blanks should be retained as blank
        strings.  The default false value indicates that blank values
        are to be ignored and treated as if they were  not included.

    strict_parsing: flag indicating what to do with parsing errors. If
        false (the default), errors are silently ignored. If true,
        errors raise a ValueError exception.

    Returns a dict, as G-d intended.
    cSs g|]}|�d�D]}|�q	qS)�;)r()r�s1�s2rrrrXs z_parse_qs.<locals>.<listcomp>�&r#r$�zbad query field: %rr?r�strict)�errors)r(�lenr[r)rrYrd)
�qs�keep_blank_values�strict_parsing�encoding�pairs�d�
name_value�nv�namer1rrr�	_parse_qsEs,�r�z
[0-9]+,[0-9]+cCsDt�|�r|�d�}t|d�t|d�d�}|St|||d�}|S)z�Build a params dictionary from a query_string.

    Duplicate key/value pairs in the provided query_string will be
    returned as {'key': [val1, val2, ...]}. Single key/values will
    be returned as strings: {'key': 'value'}.
    r%rr$)r�y)r�)�image_map_pattern�matchr(r!r�)Zquery_stringr�r�Zpmrrr�parse_query_stringus

�r�c@seZdZdZedd��ZdS)�CaseInsensitiveDictzWA case-insensitive dict subclass.

    Each key is changed on entry to title case.
    cCs|durdS|��S)N�None)�title)�keyrrr�
transform_key�sz!CaseInsensitiveDict.transform_keyN)rLrMrNrOrPr�rrrrr��sr�r?cC�g|]}t|��qSr��chr�r�irrrr�rr�cCr�rr�r�rrrr�r� �c@sZeZdZdZdZdgZdZdd�Zdd�Zd	d
�Z	e
dd��Ze
d
d��Ze
dd��Z
dS)�	HeaderMapaA dict subclass for HTTP request and response headers.

    Each key is changed on entry to str(key).title(). This allows headers
    to be case-insensitive and avoid duplicates.

    Values are header values (decoded according to :rfc:`2047` if necessary).
    �r$r$z
ISO-8859-1TcCst|�|�|�|��S)z<Return a sorted list of HeaderElements for the given header.)rir�rX�r3r�rrr�elements�szHeaderMap.elementscCsdd�|�|�D�S)zAReturn a sorted list of HeaderElement.value for the given header.cSsg|]}|j�qSrr:)r�errrr�sz$HeaderMap.values.<locals>.<listcomp>)r�r�rrr�values�szHeaderMap.valuescCst|�|����S)z3Transform self into a list of (name, value) tuples.)rd�encode_header_itemsr@rErrr�output�szHeaderMap.outputccsF�|D]\}}t|t�st|t�st|�}tt|j||f��VqdS)z�
        Prepare the sequence of name, value tuples into a form suitable for
        transmitting on the wire for HTTP.
        N)rYrA�bytes�tuple�map�encode_header_item)rJZheader_itemsr=r>rrrr��s��zHeaderMap.encode_header_itemscCs t|t�r
|�|�}|�tt�Sr0)rYrA�encode�	translate�header_translate_table�header_translate_deletechars)rJ�itemrrrr��s


�zHeaderMap.encode_header_itemc	Csp|jD]}z|�|�WStyYqw|jdkr/|jr/t|�d��}d|�d�dStd||jf��)z?Return the given header name or value, encoded for HTTP output.r�r{s
=?utf-8?b?�
s?=z>Could not encode header part %r using any of the encodings %r.)�	encodingsr��UnicodeEncodeError�protocol�use_rfc_2047rr&r[)rJr>�encrrrr��s
��zHeaderMap.encodeN)rLrMrNrOr�r�r�r�r�r�rQr�r�r�rrrrr��s

	r�c@s.eZdZdZdZdZdZd
dd�Zdd	�ZdS)�Hostz�An internet address.

    name
        Should be the client's host name. If not available (because no DNS
        lookup is performed), the IP address should be used instead.

    z0.0.0.0�Pzunknown.tldNcCs"||_||_|dur|}||_dSr0��ip�portr�)r3r�r�r�rrrr4�s

z
Host.__init__cCsd|j|j|jfS)Nzhttputil.Host(%r, %r, %r)r�rErrr�__repr__sz
Host.__repr__r0)	rLrMrNrOr�r�r�r4r�rrrrr��s
r�)rrr{)Tr{):rO�	functools�email.utils�email�rer5�binasciirZcgirZemail.headerrZhttp.serverr�urllib.parserZjaraco.collectionsZjaracor\Zcherrypy._cpcompatrr	�	responses�copyrt�partial�utils�
formatdateZHTTPDaterrr"r.�objectr/�compilerTrRrbrirlrmrzr�r�r��collectionsZKeyTransformingDictr�rAr�r�ranger�r�r�r�r�rrrr�<module>sX	


:
'
<
3
-
��M