Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.12/site-packages/werkzeug/datastructures/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.12/site-packages/werkzeug/datastructures/__pycache__/accept.cpython-312.pyc

�

'ٜg�/���ddlmZddlZddlmZddlZddlZddl	m
Z
Gd�de
eee
f�Zejd�Zdd�ZGd	�d
e�Zejd�Zdd�ZGd
�de�ZGd�de�Zy)�)�annotationsN�)�
ImmutableListc�~��eZdZdZ	d			d�fd�
Zdd�Zdd�Zejdd��Z	ejdd��Z	ejdd��Z					dd�Z	dd	�Z
dd
�Zdd�Zd d�Z
d d
�Zd!d�Zdd�Zdd�Zd"d�Zejd#d��Zejd$d%d��Z	d&					d'd�Zed(d��Z�xZS))�Accepta�An :class:`Accept` object is just a list subclass for lists of
    ``(value, quality)`` tuples.  It is automatically sorted by specificity
    and quality.

    All :class:`Accept` objects work similar to a list but provide extra
    functionality for working with the data.  Containment checks are
    normalized to the rules of that header:

    >>> a = CharsetAccept([('ISO-8859-1', 1), ('utf-8', 0.7)])
    >>> a.best
    'ISO-8859-1'
    >>> 'iso-8859-1' in a
    True
    >>> 'UTF8' in a
    True
    >>> 'utf7' in a
    False

    To get the quality for an item you can use normal item lookup:

    >>> print a['utf-8']
    0.7
    >>> a['utf7']
    0

    .. versionchanged:: 0.5
       :class:`Accept` objects are forced immutable now.

    .. versionchanged:: 1.0.0
       :class:`Accept` internal values are no longer ordered
       alphabetically for equal quality tags. Instead the initial
       order is preserved.

    c�����|�t����d�_yt|t�r!|j�_t���|�yd�_t|�fd�d��}t���|�y)NFTc�6���j|d�|dfS)Nrr)�_specificity)�x�selfs ��I/usr/local/lib/python3.12/site-packages/werkzeug/datastructures/accept.py�<lambda>z!Accept.__init__.<locals>.<lambda>;s���t�'8�'8��1��'>��!��&E�)�key�reverse)�super�__init__�provided�
isinstancer�sorted)r�values�	__class__s` �r
rzAccept.__init__/sf����>��G���!�D�M�
���
'�"�O�O�D�M��G��V�$� �D�M���E�t��F�
�G��V�$rc��|dk7fS)z3Returns a tuple describing the value's specificity.�*��r�values  r
r
zAccept._specificity?s������rc�R�|dk(xs!|j�|j�k(S)z-Check if a value matches a given accept item.r)�lower�rr�items   r
�_value_matcheszAccept._value_matchesCs"���s�{�;�d�j�j�l�e�k�k�m�;�;rc��y�Nr�rrs  r
�__getitem__zAccept.__getitem__Gs��.1rc��yr$rr%s  r
r&zAccept.__getitem__Is��FIrc��yr$rr%s  r
r&zAccept.__getitem__Ks��BErc�p�t|t�r|j|�Stj	||�S)z�Besides index lookup (getting item n) you can also pass it a string
        to get the quality for the item.  If the item is not in the list, the
        returned quality is ``0``.
        )r�str�quality�listr&r%s  r
r&zAccept.__getitem__Ms0���c�3���<�<��$�$�����c�*�*rc�D�|D]\}}|j||�s�|cSy)z�Returns the quality of the key.

        .. versionadded:: 0.6
           In previous versions you had to use the item-lookup syntax
           (eg: ``obj[key]`` instead of ``obj.quality(key)``)
        r�r")rrr!r+s    r
r+zAccept.qualityXs,��"�M�D�'��"�"�3��-���"�rc�@�|D]\}}|j||�s�yy)NTFr.)rrr!�_qualitys    r
�__contains__zAccept.__contains__ds(��"�N�D�(��"�"�5�$�/��#�rc�h�djd�|D��}t|�j�d|�d�S)N�, c3�4K�|]\}}d|�d|�d����y�w)�(r3�)Nr)�.0r�ys   r
�	<genexpr>z"Accept.__repr__.<locals>.<genexpr>ks#����?�$�$�!�Q��!��b���1�o�$�s�z([z]))�join�type�__name__)r�	pairs_strs  r
�__repr__zAccept.__repr__js4���I�I�?�$�?�?�	��t�*�%�%�&�b���2�6�6rc��t|t�r7t|�D]\}\}}|j||�s�|cSt	|��t
j
||�S)z�Get the position of an entry or raise :exc:`ValueError`.

        :param key: The key to be looked up.

        .. versionchanged:: 0.5
           This used to raise :exc:`IndexError`, which was inconsistent
           with the list API.
        )rr*�	enumerater"�
ValueErrorr,�index)rr�idxr!r0s     r
rBzAccept.indexnsX���c�3��)2�4��%��%�d�H��&�&�s�D�1��J�*9��S�/�!��z�z�$��$�$rc�D�	|j|�S#t$rYywxYw)zaGet the position of an entry or return -1.

        :param key: The key to be looked up.
        ���)rBrAr%s  r
�findzAccept.find~s'��
	��:�:�c�?�"���	��	�s��	�c#�(K�|D]	}|d���y�w)zIterate over all values.rNr)rr!s  r
rz
Accept.values�s�����D��q�'�M��s�c�v�g}|D]"\}}|dk7r|�d|��}|j|��$dj|�S)z2Convert the header set into an HTTP header string.rz;q=�,)�appendr:)r�resultrr+s    r
�	to_headerzAccept.to_header�sI����"�N�E�7��!�|� �'��W�I�.���M�M�%� �#��x�x���rc�"�|j�Sr$)rL�rs r
�__str__zAccept.__str__�s���~�~��rc�H�|D]\}}|j||�s�||fcSyr$r.)r�match�client_itemr+s    r
�_best_single_matchzAccept._best_single_match�s1��$(� �K���"�"�5�+�6�"�G�+�+�%)�rc��yr$r�r�matchess  r
�
best_matchzAccept.best_match����EHrc��yr$r�rrV�defaults   r
rWzAccept.best_match����RUrc��|}d}d}|D]H}|j|�}|s�|\}}	|j|�}
|	dks|	|kr�8|	|kDs|
|kDs�C|}|	}|
}�J|S)aVReturns the best match from a list of possible matches based
        on the specificity and quality of the client. If two items have the
        same quality and specificity, the one is returned that comes first.

        :param matches: a list of matches to check for
        :param default: the value that is returned if none match
        rE)rEr)rSr
)rrVr[rK�best_quality�best_specificity�server_itemrQrRr+�specificitys           r
rWzAccept.best_match�s����� ��.3��"�K��+�+�K�8�E���#(� �K���+�+�K�8�K��!�|�w��5����%��7G�)G�$��&��#.� �#��
rc��|r|ddSy)zThe best match as value.rNrrNs r
�bestzAccept.best�s�����7�1�:��r)r)rz0Accept | cabc.Iterable[tuple[str, float]] | None�return�None�rr*rdztuple[bool, ...]�rr*r!r*rd�bool)rr*rd�float)rzt.SupportsIndexrdztuple[str, float])r�slicerdzlist[tuple[str, float]])rzstr | t.SupportsIndex | slicerdz3float | tuple[str, float] | list[tuple[str, float]])rr*rdrh)rdr*)rzstr | tuple[str, float]rd�int)rdzcabc.Iterator[str])rQr*rdztuple[str, float] | None�rV�cabc.Iterable[str]rd�
str | None�.�rVrmr[r*rdr*r$�rVrmr[rnrdrn)rdrn)r<�
__module__�__qualname__�__doc__rr
r"�t�overloadr&r+r1r>rBrFrrLrOrSrW�propertyrc�
__classcell__�rs@r
rrs���!�HJL�%�F�%�	
�%� �<��Z�Z�1��1��Z�Z�I��I��Z�Z�E��E�	+�0�	+�	<�	+�
��7�%� ��
 � ���Z�Z�H��H��Z�Z�U��U�AE��)��4>��	��8���rrz
/|(?:\s*;\s*)c�H�tj|j��Sr$)�_mime_split_re�splitr�rs r
�_normalize_mimer~�s��������
�.�.rc�V�eZdZdZdd�Zd	d�Zed
d��Zed
d��Zed
d��Z	y)�
MIMEAcceptzRLike :class:`Accept` but with special methods and behavior for
    mimetypes.
    c�L�td�tj|�D��S)Nc3�&K�|]	}|dk7���y�w)rNr)r7rs  r
r9z*MIMEAccept._specificity.<locals>.<genexpr>�s����C�'B�!�Q�#�X�'B�s�)�tupler{r|rs  r
r
zMIMEAccept._specificity�s���C�~�';�';�E�'B�C�C�Crc�t�d|vryd|vrtd|����t|�}|dd\}}t|dd�}|dk(r|dk7rtd|����t|�}|dd\}}	t|dd�}
|dk(r|	dk7ry|dk(xr|	dk(xs|dk(xr|dk(xs!||k(xr|	dk(xs|dk(xs|	|k(xr|
|k(S)N�/Fzinvalid mimetype �r)rAr~r)rrr!�normalized_value�
value_type�
value_subtype�value_params�normalized_item�	item_type�item_subtype�item_paramss           r
r"zMIMEAccept._value_matches�s1���d�?���e���0��	�:�;�;�+�5�1��$4�R�a�$8�!�
�M��.�q�r�2�3������#�!5��0��	�:�;�;�*�$�/��"1�"�1�"5��	�<��_�Q�R�0�1������� 3���#�
�
5�,�#�"5�
<��c�!�:�m�s�&:�

�
��#�
���#�S� �C�'�S� �M�1�Q�k�\�6Q�
	
rc�&�d|vxs|jS)z!True if this object accepts HTML.z	text/html)�accept_xhtmlrNs r
�accept_htmlzMIMEAccept.accept_htmls���d�"�7�d�&7�&7�7rc��d|vxsd|vS)z"True if this object accepts XHTML.zapplication/xhtml+xmlzapplication/xmlrrNs r
r�zMIMEAccept.accept_xhtmls��'�$�.�K�2C�t�2K�Krc�
�d|vS)z!True if this object accepts JSON.zapplication/jsonrrNs r
�accept_jsonzMIMEAccept.accept_json
s��"�T�)�)rNrfrg)rdrh)
r<rrrsrtr
r"rwr�r�r�rrr
r�r��sQ���D�&
�P�8��8��L��L��*��*rr�z[_-]c�H�tj|j��S)z$Process a language tag for matching.)�_locale_delim_rer|rr}s r
�_normalize_langr�s���!�!�%�+�+�-�0�0rc���eZdZdZdd�Zejdd��Zejdd	d��Z	d
					d�fd�
Z�xZS)�LanguageAcceptz>Like :class:`Accept` but with normalization for language tags.c�>�|dk(xst|�t|�k(S)Nr)r�r s   r
r"zLanguageAccept._value_matchess ���s�{�M�o�e�4���8M�M�Mrc��yr$rrUs  r
rWzLanguageAccept.best_matchrXrc��yr$rrZs   r
rWzLanguageAccept.best_match r\rc	�t���t�|�|�����St|D�cgc]#}tj	|dd�d|df��%c}�}|j|�����S|D�cgc]}tj	|d�d��}}t�|�|����t�fd�|D��S|Scc}wcc}w)a�Given a list of supported values, finds the best match from
        the list of accepted values.

        Language tags are normalized for the purpose of matching, but
        are returned unchanged.

        If no exact match is found, this will fall back to matching
        the first subtag (primary language only), first with the
        accepted values then with the match values. This partial is not
        applied to any other language subtags.

        The default is returned if no exact or fallback match is found.

        :param matches: A list of supported languages to find a match.
        :param default: The value that is returned if none match.
        rrc3�F�K�|]}|j��s�|���y�wr$)�
startswith)r7r!rKs  �r
r9z,LanguageAccept.best_match.<locals>.<genexpr>Os�����L���D�O�O�F�4K���s�!�!)rrWrr�r|�next)rrVr[r!�fallback�fallback_matchesrKrs      @�r
rWzLanguageAccept.best_match"s����*��#�G�,�����M�
�JN�O�$�$��$�$�T�!�W�a�0��3�T�!�W�
=�$�O�
���$�$�W�-�����M�LS�S�7�4�,�2�2�4��;�A�>�7��S���#�$4�5�����L��L�L�L����#
P��Ts�(B0�' B5rgrlrorpr$rq)	r<rrrsrtr"rurvrWrxrys@r
r�r�sW���H�N��Z�Z�H��H��Z�Z�U��U�AE�/�)�/�4>�/�	�/�/rr�c��eZdZdZdd�Zy)�
CharsetAcceptz9Like :class:`Accept` but with normalization for charsets.c�:�dd�}|dk(xs||�||�k(S)Nc��	tj|�jS#t$r|j	�cYSwxYwr$)�codecs�lookup�name�LookupErrorr)r�s r
�
_normalizez0CharsetAccept._value_matches.<locals>._normalizeXs7��
$��}�}�T�*�/�/�/���
$��z�z�|�#�
$�s�!�=�=r)r�r*rdr*r)rrr!r�s    r
r"zCharsetAccept._value_matchesWs'��	$��s�{�C�j��/�:�d�3C�C�CrNrg)r<rrrsrtr"rrr
r�r�Ts��C�Drr�)rr*rdz	list[str])�
__future__rr��collections.abc�abc�cabc�re�typingru�
structuresrr�r*rir�compiler{r~r�r�r�r�r�rrr
�<module>r�s���"�
��	��%�{�]�5��e��,�
-�{�|����,�-��/�=*��=*�@�2�:�:�g�&��1�
9�V�9�x
D�F�
Dr

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists