
    ^f                     x    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          Z G 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                       e Zd Zd ZddZdS )BaseContentNegotiationc                      t          d          )Nz$.select_parser() must be implementedNotImplementedError)selfrequestparserss      L/var/www/html/env/lib/python3.11/site-packages/rest_framework/negotiation.pyselect_parserz$BaseContentNegotiation.select_parser   s    !"HIII    Nc                      t          d          )Nz&.select_renderer() must be implementedr   )r   r   	renderersformat_suffixs       r   select_rendererz&BaseContentNegotiation.select_renderer   s    !"JKKKr   N)__name__
__module____qualname__r   r    r   r   r   r      s@        J J JL L L L L Lr   r   c                   ,    e Zd ZeZd ZddZd Zd ZdS )DefaultContentNegotiationc                 L    |D ] }t          |j        |j                  r|c S !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   parsers       r   r   z'DefaultContentNegotiation.select_parser   s>    
  	 	F!&"3W5IJJ tr   Nc                 Z   | j         j        }|p|j                            |          }|r|                     ||          }|                     |          }t          |          D ]}|D ]}|D ]}	t          |j        |	          rt          |	          }
t          |j                  j
        |
j
        k    rVd                    |j        ft          d |
j                                        D                       z             }||fc c c S ||	fc c c S t          j        |          )zq
        Given a request and a list of renderers, return a two-tuple of:
        (renderer, media type).
        ;c              3   H   K   | ]\  }}d                      ||          V  dS )z{}={}Nformat).0keyvalues      r   	<genexpr>z<DefaultContentNegotiation.select_renderer.<locals>.<genexpr>C   sH       &" &"(2U %,NN3$>$>&" &" &" &" &" &"r   )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_types               r   r   z)DefaultContentNegotiation.select_renderer#   s    "]>N'"6":":;M"N"N 	A--i@@I&&w// 2':: 	8 	8N% 8 8"0 8 8J)(*=zJJ 8-7
-C-C*&x':;;F.9: :
 /2hh!)!4 6 % &" &"6H6O6U6U6W6W&" &" &" !" !"!"/ /O $,_#<<<<<<<< $,Z#77777777)8880 &9EEEEr   c                 6    f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                 *    g | ]}|j         k    |S r   r'   )r)   r=   r(   s     r   
<listcomp>z>DefaultContentNegotiation.filter_renderers.<locals>.<listcomp>U   s/     3 3 3( 611 111r   r   )r   r   r(   s     `r   r2   z*DefaultContentNegotiation.filter_renderersP   s=    
3 3 3 3i 3 3 3	 	Mr   c                 v    |j                             dd          }d |                    d          D             S )zd
        Given the incoming request, return a tokenized list of media
        type strings.
        HTTP_ACCEPTz*/*c                 6    g | ]}|                                 S r   )strip)r)   tokens     r   rB   z=DefaultContentNegotiation.get_accept_list.<locals>.<listcomp>a   s     ===%===r   ,)METAr1   split)r   r   headers      r   r3   z)DefaultContentNegotiation.get_accept_list[   s;    
 !!-77==6<<+<+<====r   r   )	r   r   r   r   r.   r   r   r2   r3   r   r   r   r   r      s_        H  +F +F +F +FZ	 	 	> > > > >r   r   N)__doc__django.httpr   rest_frameworkr   rest_framework.settingsr   rest_framework.utils.mediatypesr   r   r	   r   r   r   r   r   <module>rQ      s            % % % % % % 0 0 0 0 0 0         
L L L L L L L LK> K> K> K> K> 6 K> K> K> K> K>r   