o
    ÖèFhÌ  ã                   @   s^   d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	m
Z
 G dd„ dƒZG dd	„ d	eƒZd
S )zœ
Content negotiation deals with selecting an appropriate renderer given the
incoming request.  Typically this will be based on the request's Accept header.
é    ©ÚHttp404)Ú
exceptions)Úapi_settings)Ú
_MediaTypeÚmedia_type_matchesÚorder_by_precedencec                   @   s   e Zd Zdd„ Zddd„ZdS )ÚBaseContentNegotiationc                 C   ó   t dƒ‚)Nz$.select_parser() must be implemented©ÚNotImplementedError)ÚselfÚrequestÚparsers© r   úS/var/www/html/loop/nvenv/lib/python3.10/site-packages/rest_framework/negotiation.pyÚselect_parser   ó   z$BaseContentNegotiation.select_parserNc                 C   r
   )Nz&.select_renderer() must be implementedr   )r   r   Ú	renderersÚformat_suffixr   r   r   Úselect_renderer   r   z&BaseContentNegotiation.select_renderer©N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r	      s    r	   c                   @   s2   e Zd ZeZdd„ Zd
dd„Zdd„ Zdd	„ ZdS )ÚDefaultContentNegotiationc                 C   s$   |D ]}t |j|jƒr|  S qdS )z�
        Given a list of parsers and a media type, return the appropriate
        parser to handle the incoming request.
        N)r   Ú
media_typeÚcontent_type)r   r   r   Úparserr   r   r   r      s
   ÿz'DefaultContentNegotiation.select_parserNc              
   C   sÔ   | j j}|p|j |¡}|r|  ||¡}|  |¡}t|ƒD ]F}|D ]A}|D ]<}	t|j|	ƒrat	|	ƒ}
t	|jƒj
|
j
krWd |jftdd„ |
j ¡ D ƒƒ ¡}||f      S ||	f      S q%q!qtj|d�‚)zq
        Given a request and a list of renderers, return a two-tuple of:
        (renderer, media type).
        ú;c                 s   s    � | ]\}}d   ||¡V  qdS )z{}={}N©Úformat)Ú.0ÚkeyÚvaluer   r   r   Ú	<genexpr>C   s
   € 
ÿ
ÿz<DefaultContentNegotiation.select_renderer.<locals>.<genexpr>)Úavailable_renderers)ÚsettingsÚURL_FORMAT_OVERRIDEÚquery_paramsÚgetÚfilter_renderersÚget_accept_listr   r   r   r   Ú
precedenceÚjoinÚtupleÚparamsÚitemsr   ÚNotAcceptable)r   r   r   r   Úformat_query_paramr!   ÚacceptsÚmedia_type_setÚrendererr   Úmedia_type_wrapperÚfull_media_typer   r   r   r   #   s4   

ÿþÿÿìÿÿz)DefaultContentNegotiation.select_rendererc                    s   ‡ fdd„|D ƒ}|st ‚|S )zœ
        If there is a '.json' style format suffix, filter the renderers
        so that we only negotiation against those that accept that format.
        c                    s   g | ]	}|j ˆ kr|‘qS r   r    )r"   r6   r    r   r   Ú
<listcomp>U   s    
ÿz>DefaultContentNegotiation.filter_renderers.<locals>.<listcomp>r   )r   r   r!   r   r    r   r+   P   s   z*DefaultContentNegotiation.filter_renderersc                 C   s"   |j  dd¡}dd„ | d¡D ƒS )zd
        Given the incoming request, return a tokenized list of media
        type strings.
        ÚHTTP_ACCEPTz*/*c                 S   s   g | ]}|  ¡ ‘qS r   )Ústrip)r"   Útokenr   r   r   r9   a   s    z=DefaultContentNegotiation.get_accept_list.<locals>.<listcomp>ú,)ÚMETAr*   Úsplit)r   r   Úheaderr   r   r   r,   [   s   z)DefaultContentNegotiation.get_accept_listr   )	r   r   r   r   r'   r   r   r+   r,   r   r   r   r   r      s    

-r   N)Ú__doc__Údjango.httpr   Úrest_frameworkr   Úrest_framework.settingsr   Úrest_framework.utils.mediatypesr   r   r   r	   r   r   r   r   r   Ú<module>   s    