§
    Âi‚  ã                   ó`   — d Z ddlmZ ddlmZ dZdZdZdZdZ	d	„ Z
d
„ Zd„ Zd„ Zd„ Zd„ Zd„ ZdS )au  MIME-Type Parser

This module provides basic functions for handling mime-types. It can handle
matching mime-types against a list of media-ranges. See section 14.1 of the
HTTP specification [RFC 2616] for a complete explanation.

   http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1

Contents:
 - parse_mime_type():   Parses a mime-type into its component parts.
 - parse_media_range(): Media-ranges are mime-types with wild-cards and a 'q'
                          quality parameter.
 - quality():           Determines the quality ('q') of a mime-type when
                          compared against a list of media-ranges.
 - quality_parsed():    Just like quality() except the second parameter must be
                          pre-parsed.
 - best_match():        Choose the mime-type with the highest quality ('q')
                          from a list of candidates.
é    )Úabsolute_import)Úreducez0.1.3zJoe Gregoriozjoe@bitworking.orgzMIT LicenseÚ c                 ó4  — |                       d¦  «        }t          d„ |dd…         D ¦   «         ¦  «        }|d                              ¦   «         }|dk    rd}|                      d¦  «        \  }}|                     ¦   «         |                     ¦   «         |fS )	aR  Parses a mime-type into its component parts.

    Carves up a mime-type and returns a tuple of the (type, subtype, params)
    where 'params' is a dictionary of all the parameters for the media range.
    For example, the media range 'application/xhtml;q=0.5' would get parsed
    into:

       ('application', 'xhtml', {'q', '0.5'})
    ú;c           	      óh   — g | ]/}t          d „ |                     dd¦  «        D ¦   «         ¦  «        ‘Œ0S )c                 ó6   — g | ]}|                      ¦   «         ‘ŒS © ©Ústrip)Ú.0Úss     úc/var/www/html/jarvis.com/web/backend/venv/lib/python3.11/site-packages/googleapiclient/mimeparse.pyú
<listcomp>z.parse_mime_type.<locals>.<listcomp>.<listcomp>/   s    € Ð7Ð7Ð7˜a�—’‘	”	Ð7Ð7Ð7ó    ú=é   )ÚtupleÚsplit)r   Úparams     r   r   z#parse_mime_type.<locals>.<listcomp>/   s=   € ÐPÐPÐP¸U�Ð7Ð7 5§;¢;¨s°AÑ#6Ô#6Ð7Ñ7Ô7Ñ	8Ô	8ÐPÐPÐPr   r   Nr   Ú*z*/*ú/)r   Údictr   )Ú	mime_typeÚpartsÚparamsÚ	full_typeÚtypeÚsubtypes         r   Úparse_mime_typer    #   s–   € ð �OŠO˜CÑ Ô €EÝØPÐPÀeÈAÈBÈBÄiÐPÑPÔPñô €Fð �a”—’Ñ Ô €Ið �CÒÐØˆ	Ø—o’o cÑ*Ô*�O€Tˆ7à�JŠJ‰LŒL˜'Ÿ-š-™/œ/¨6Ð2Ð2r   c                 óâ   — t          | ¦  «        \  }}}d|vsO|d         rGt          |d         ¦  «        r2t          |d         ¦  «        dk    st          |d         ¦  «        dk     rd|d<   |||fS )aï  Parse a media-range into its component parts.

    Carves up a media range and returns a tuple of the (type, subtype,
    params) where 'params' is a dictionary of all the parameters for the media
    range.  For example, the media range 'application/*;q=0.5' would get parsed
    into:

       ('application', '*', {'q', '0.5'})

    In addition this function also guarantees that there is a value for 'q'
    in the params dictionary, filling it in with a proper default if
    necessary.
    Úqr   r   Ú1)r    Úfloat)Úranger   r   r   s       r   Úparse_media_ranger&   ;   s‰   € õ .¨eÑ4Ô4Ñ€Tˆ7�Fà�6ÐÐØ�cŒ{ð 	å�V˜C”[Ñ!Ô!ð 	õ �˜”ÑÔ Ò!Ð!Ý�˜”ÑÔ Ò!Ð!àˆˆs‰à�'˜6Ð"Ð"r   c                 ón  ‡— d}d}t          | ¦  «        \  }}}|D ]Š\  }}Š||k    p|dk    p|dk    }	||k    p|dk    p|dk    }
|	r^|
r\t          d„ ˆfd„|                     ¦   «         D ¦   «         d¦  «        }||k    rdpd}|||k    rdpdz  }||z  }||k    r
|}‰d         }Œ‹|t          |¦  «        fS )	a³  Find the best match for a mime-type amongst parsed media-ranges.

    Find the best match for a given mime-type against a list of media_ranges
    that have already been parsed by parse_media_range(). Returns a tuple of
    the fitness value and the value of the 'q' quality parameter of the best
    match, or (-1, 0) if no match was found. Just as for quality_parsed(),
    'parsed_ranges' must be a list of parsed media ranges.
    éÿÿÿÿr   r   c                 ó   — | |z   S ©Nr
   )ÚxÚys     r   ú<lambda>z,fitness_and_quality_parsed.<locals>.<lambda>i   s
   € ˜Q ™U€ r   c                 óF   •— g | ]\  }}|d k    ¯|‰v ¯|‰|         k    ¯d‘ŒS )r"   r   r
   )r   ÚkeyÚvaluer   s      €r   r   z.fitness_and_quality_parsed.<locals>.<listcomp>j   sF   ø€ ð ð ð á$˜˜eØ˜c’z�z c¨V m m¸ÀÈÄÒ8LÐ8Lð à8LÐ8LÐ8Lr   éd   é
   r"   )r&   r   Úitemsr$   )r   Úparsed_rangesÚbest_fitnessÚ
best_fit_qÚtarget_typeÚtarget_subtypeÚtarget_paramsr   r   Ú
type_matchÚsubtype_matchÚparam_matchesÚfitnessr   s                @r   Úfitness_and_quality_parsedr>   V   s9  ø€ ð €LØ€JÝ3DÀYÑ3OÔ3OÑ0€[�. -Ø#0ð )ð )Ñˆˆw˜Ø˜[Ò(ÐM¨D°CªKÐM¸;È#Ò;Mˆ
à�~Ò%ÐP¨°CªÐP¸>ÈSÒ;Pð 	ð ð 	)˜-ð 	)Ý"Ø"Ð"ðð ð ð à(5×(;Ò(;Ñ(=Ô(=ðñ ô ð
 ñô ˆMð ˜{Ò*Ð3°Ð8°qˆGØ˜ >Ò1Ð9°rÐ>¸QÑ>ˆGØ�}Ñ$ˆGØ˜Ò%Ð%Ø&�Ø# Cœ[�
øà�˜zÑ*Ô*Ð*Ð*r   c                 ó.   — t          | |¦  «        d         S )a–  Find the best match for a mime-type amongst parsed media-ranges.

    Find the best match for a given mime-type against a list of media_ranges
    that have already been parsed by parse_media_range(). Returns the 'q'
    quality parameter of the best match, 0 if no match was found. This function
    bahaves the same as quality() except that 'parsed_ranges' must be a list of
    parsed media ranges.
    r   )r>   )r   r4   s     r   Úquality_parsedr@   {   s   € õ & i°Ñ?Ô?ÀÔBÐBr   c                 ó`   — d„ |                      d¦  «        D ¦   «         }t          | |¦  «        S )aK  Return the quality ('q') of a mime-type against a list of media-ranges.

    Returns the quality 'q' of a mime-type when compared against the
    media-ranges in ranges. For example:

    >>> quality('text/html','text/*;q=0.3, text/html;q=0.7,
                  text/html;level=1, text/html;level=2;q=0.4, */*;q=0.5')
    0.7

    c                 ó,   — g | ]}t          |¦  «        ‘ŒS r
   ©r&   ©r   Úrs     r   r   zquality.<locals>.<listcomp>“   s!   € ÐEÐEÐE¨aÕ& qÑ)Ô)ÐEÐEÐEr   ú,)r   r@   )r   Úrangesr4   s      r   ÚqualityrH   ˆ   s4   € ð FÐE°6·<²<ÀÑ3DÔ3DÐEÑEÔE€Må˜) ]Ñ3Ô3Ð3r   c                 ó6  — t          |                     d¦  «        ¦  «        }d„ |D ¦   «         }g }d}| D ]-}|                     t          ||¦  «        ||f¦  «         |dz  }Œ.|                     ¦   «          |d         d         d         r|d         d         pdS )aY  Return mime-type with the highest quality ('q') from list of candidates.

    Takes a list of supported mime-types and finds the best match for all the
    media-ranges listed in header. The value of header must be a string that
    conforms to the format of the HTTP Accept: header. The value of 'supported'
    is a list of mime-types. The list of supported mime-types should be sorted
    in order of increasing desirability, in case of a situation where there is
    a tie.

    >>> best_match(['application/xbel+xml', 'text/xml'],
                   'text/*;q=0.5,*/*; q=0.1')
    'text/xml'
    rF   c                 ó,   — g | ]}t          |¦  «        ‘ŒS r
   rC   rD   s     r   r   zbest_match.<locals>.<listcomp>§   s!   € Ð@Ð@Ð@¨aÕ& qÑ)Ô)Ð@Ð@Ð@r   r   r   r(   é   r   )Ú_filter_blankr   Úappendr>   Úsort)Ú	supportedÚheaderÚsplit_headerÚparsed_headerÚweighted_matchesÚposr   s          r   Ú
best_matchrU   ˜   s¿   € õ ! §¢¨cÑ!2Ô!2Ñ3Ô3€LØ@Ð@°<Ð@Ñ@Ô@€MØÐØ
€CØð ð ˆ	Ø×ÒÝ'¨	°=ÑAÔAÀ3È	ÐRñ	
ô 	
ð 	
ð 	ˆq‰ˆˆØ×ÒÑÔÐà˜BÔ Ô" 1Ô%ÐAÐ*:¸2Ô*>¸qÔ*AÐGÀRÐGr   c              #   óD   K  — | D ]}|                      ¦   «         r|V — Œd S r*   r   )Úir   s     r   rL   rL   ´   s9   è è € Øð ð ˆØ�7Š7‰9Œ9ð 	ØˆGˆGˆGøðð r   N)Ú__doc__Ú
__future__r   Ú	functoolsr   Ú__version__Ú
__author__Ú	__email__Ú__license__Ú__credits__r    r&   r>   r@   rH   rU   rL   r
   r   r   ú<module>r`      sÈ   ðð
ð ð& 'Ð &Ð &Ð &Ð &Ð &à Ð Ð Ð Ð Ð à€Ø€
Ø €	Ø€Ø€ð3ð 3ð 3ð0#ð #ð #ð6"+ð "+ð "+ðJ
Cð 
Cð 
Cð4ð 4ð 4ð Hð Hð Hð8ð ð ð ð r   