Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib/python3.7/site-packages/webob/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/webob/__pycache__/acceptparse.cpython-37.pyc

B

��vP�'�@s�dZddlZddlmZddlmZmZe�d�Z	dd�Z
Gdd	�d	e�ZGd
d�de�Z
Gdd
�d
e
�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de
�Zdd�Zee
fdd�ZdS)z�
Parses a variety of ``Accept-*`` headers.

These headers generally take the form of::

    value1; q=0.5, value2; q=0

Where the ``q`` parameter is optional.  In theory other parameters
exists, but this ignores them.
�N)�_trans_name)�header_docstring�warn_deprecationz*,\s*([^\s;,\n]+)(?:[^,]*?;\s*q=([0-9.]*))?cCstddd�dS)NzUse best_match insteadz1.2�)r�rr�B/opt/alt/python37/lib/python3.7/site-packages/webob/acceptparse.py�_warn_first_matchsrc@szeZdZdZdd�Zedd��Zdd�Zdd	�Zd
d�Z	dd
d�Z
dd�Zdd�Zddd�Z
dd�Zddd�Zdd�ZdS) �Acceptz�
    Represents a generic ``Accept-*`` style header.

    This object should not be modified.  To add items you can use
    ``accept_obj + 'accept_thing'`` to get a new object
    cCs,||_t|�|��|_dd�|jD�|_dS)NcSsg|]\}}|r||f�qSrr)�.0�m�qrrr�
<listcomp>)sz#Accept.__init__.<locals>.<listcomp>)�header_value�list�parse�_parsed�_parsed_nonzero)�selfrrrr�__init__&szAccept.__init__c	cs�x�t�d|�D]n}|�d�}|dkr(q|�d�p4d}|rty$ttt|�d�d�}||fVwWntk
rrYnX|dfVqWdS)z�
        Parse ``Accept-*`` style header.

        Return iterator of ``(value, quality)`` pairs.
        ``quality`` defaults to 1.
        �,�r��rN)�part_re�finditer�group�max�min�float�
ValueError)�value�match�name�qualityrrrr+s

zAccept.parsecCsd|jjt|�fS)Nz<%s(%r)>)�	__class__�__name__�str)rrrr�__repr__AszAccept.__repr__ccs,x&t|jdd�dd�D]\}}|VqWdS)NcSs|dS)Nrr)�irrr�<lambda>G�z!Accept.__iter__.<locals>.<lambda>T)�key�reverse)�sortedr)rrrrrr�__iter__Ds
zAccept.__iter__cCsZg}xJ|jD]@\}}|dkrBd|ttt|��d�d�d�|f}|�|�qWd�|�S)Nrz
%s;q=%0.*f�.rz, )rr�lenr&�split�append�join)r�result�maskr#rrr�__str__Ls$zAccept.__str__Fc	Cs�t|t�r|j}t|d�r.t|��dd�d�}t|ttf�r�g}x@|D]8}t|ttf�rt|\}}|�d||f�qF|�|�qFWd�	|�}t
|�}|j}|r�||}}|s�|}n|s�|}n|d|}|�|�S)N�itemscSs
|dS)Nrr)�itemrrrr)Yr*z Accept.__add__.<locals>.<lambda>)r+z%s; q=%sz, )�
isinstancer	r�hasattrr-r7r�tupler2r3r&r$)	r�other�reversedr4r8r"r#Zmy_valueZ	new_valuerrr�__add__Us,




zAccept.__add__cCs|�|d�S)NT)r>)rr<rrr�__radd__oszAccept.__radd__cCs(x"|jD]\}}|�||�rdSqWdS)z[
        Returns true if the given object is listed in the accepted
        types.
        TN)r�_match)r�offerr5r#rrr�__contains__rszAccept.__contains__rcCs:d}x,|jD]"\}}|�||�rt|||�}qW|p8dS)zl
        Return the quality of the given offer.  Returns None if there
        is no match (not 0).
        rN)rr@r)rrA�modifierZbestqr5rrrrr#{s
zAccept.qualitycCs
t�dS)z�
        DEPRECATED
        Returns the first allowed offered type. Ignores quality.
        Returns the first offered type if nothing else matches; or if you include None
        at the end of the match list then that will be returned.
        N)r)r�offersrrr�first_match�szAccept.first_matchNcCs�d}|}d}x�|D]~}t|ttf�r.|\}}nd}x\|jD]R\}}	||	}
|
|krVq:n|
|krt|�d�|�d�krtq:|�||�r:|
}|}|}q:WqW|S)a�
        Returns the best match in the sequence of offered types.

        The sequence can be a simple sequence, or you can have
        ``(match, server_quality)`` items in the sequence.  If you
        have these tuples then the client quality is multiplied by the
        server_quality to get a total.  If two matches have equal
        weight, then the one that shows up first in the `offers` list
        will be returned.

        But among matches with the same quality the match to a more specific
        requested type will be chosen. For example a match to text/* trumps */*.

        default_match (default None) is returned if there is no intersection.
        ���z*/*r�*)r9r;rr�countr@)rrD�
default_match�best_quality�
best_offerZ
matched_byrAZserver_qualityr5r#Zpossible_qualityrrr�
best_match�s&

zAccept.best_matchcCs t|�|dkp|��|��kS)NrG)�_check_offer�lower)rr5rArrrr@�sz
Accept._match)F)r)N)r%�
__module__�__qualname__�__doc__r�staticmethodrr'r.r6r>r?rBr#rErLr@rrrrr	s	
	
	
'r	c@sheZdZeZdd�Zdd�Zdd�ZeZdd�Z	d	d
�Z
dd�Zd
d�Zddd�Z
dd�Zddd�ZdS)�	NilAcceptcCsd|jj|jfS)Nz<%s: %s>)r$r%�MasterClass)rrrrr'�szNilAccept.__repr__cCsdS)Nrr)rrrrr6�szNilAccept.__str__cCsdS)NFr)rrrr�__nonzero__�szNilAccept.__nonzero__cCstd�S)Nr)�iter)rrrrr.�szNilAccept.__iter__cCs"t||j�r|S|�d�|SdS)Nr)r9rT)rr8rrrr>�szNilAccept.__add__cCs"t||j�r|S||�d�SdS)Nr)r9rT)rr8rrrr?�szNilAccept.__radd__cCst|�dS)NT)rM)rr8rrrrB�szNilAccept.__contains__rcCsdS)Nrr)rrAZdefault_qualityrrrr#�szNilAccept.qualitycCs
t�dS)N)r)rrDrrrrE�szNilAccept.first_matchNcCsNd}|}x@|D]8}t|�t|ttf�r2|\}}nd}||kr|}|}qW|S)NrFr)rMr9rr;)rrDrIrJrKrAr#rrrrL�s

zNilAccept.best_match)r)N)r%rOrPr	rTr'r6rU�__bool__r.r>r?rBr#rErLrrrrrS�s
rSc@seZdZdd�ZdS)�NoAcceptcCsdS)NFr)rr8rrrrB�szNoAccept.__contains__N)r%rOrPrBrrrrrX�srXc@seZdZedd��ZdS)�
AcceptCharsetccsPd}x<t�|�D].\}}|��}|dks0|dkr4d}||fVqW|sLdVdS)NFrGz
iso-8859-1T)z
iso-8859-1r)r	rrN)r Zlatin1_foundrrZ_mrrrr�szAcceptCharset.parseN)r%rOrPrRrrrrrrY�srYc@seZdZdd�ZdS)�AcceptLanguagecCsL|�dd���}|��}|dkpJ||kpJ|�d�d|kpJ||�d�dkS)N�_�-rGr)�replacerNr1)rr5r8rrrr@szAcceptLanguage._matchN)r%rOrPr@rrrrrZsrZc@s4eZdZdZedd��Zdd�Zee�Zdd�Z	dS)	�
MIMEAcceptz�
        Represents the ``Accept`` header, which is a list of mimetypes.

        This class knows about mime wildcards, like ``image/*``
    c	cstxnt�|�D]`\}}ytdd�|�d��\}}Wntk
rFwYnX|dkrZ|dkrZqd||f|fVqWdS)NcSs|��S)N)rN)�xrrrr)r*z"MIMEAccept.parse.<locals>.<lambda>�/rGz%s/%s)r	r�mapr1r)r r5r�
mask_majorZ
mask_minorrrrrszMIMEAccept.parsecCs d|kpd|kpd|kpd|kS)z@
        Returns true if any HTML-like type is accepted
        z	text/htmlzapplication/xhtml+xmlzapplication/xmlztext/xmlr)rrrr�accept_htmlszMIMEAccept.accept_htmlcCsjt|�d|kr |��|��kS|dkr,dS|�d�s:t�|dd���}|�dd�d	��}||kSdS)
z?
            Check if the offer is covered by the mask
        rGz*/*Tz/*N���r`rr)rMrN�endswith�AssertionErrorr1)rr5rArbZoffer_majorrrrr@'szMIMEAccept._matchN)
r%rOrPrQrRrrc�propertyZaccepts_htmlr@rrrrr^s
	r^c@seZdZeZdS)�
MIMENilAcceptN)r%rOrPr^rTrrrrrh7srhcCsd|krtd|��dS)NrGz3The application should offer specific types, got %r)r)rArrrrM:srMcsJt|��t||�}���fdd�}��fdd�}�fdd�}t||||�S)Ncs|j���}|s��S�|�S)N)�environ�get)�reqr )�AcceptClass�NilClassr+rr�fgetFszaccept_property.<locals>.fgetcs:|r(t|tttf�r �d�|}t|�}|p.d|j�<dS)Nr)r9rr;�dictr&ri)rk�val)rlr+rr�fsetKs
zaccept_property.<locals>.fsetcs|j�=dS)N)ri)rk)r+rr�fdelQszaccept_property.<locals>.fdel)�
header_to_keyrrg)�headerZrfc_sectionrlrm�docrnrqrrr)rlrmr+r�accept_property@s
rv)rQ�reZ
webob.headersrrsZ
webob.utilrr�compilerr�objectr	rSrXrYrZr^rhrMrvrrrr�<module>
s 4,