
    Nwg                     j    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y
)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y)BaseContentNegotiationc                     t        d      )Nz$.select_parser() must be implementedNotImplementedError)selfrequestparserss      Q/var/www/horilla/myenv/lib/python3.12/site-packages/rest_framework/negotiation.pyselect_parserz$BaseContentNegotiation.select_parser   s    !"H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Kr   N)__name__
__module____qualname__r   r    r   r   r
   r
      s    JLr   r
   c                   *    e Zd ZeZd ZddZd Zd Zy)DefaultContentNegotiationc                 Z    |D ]&  }t        |j                  |j                        s$|c S  y)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   s3    
  	F!&"3"3W5I5IJ	 r   Nc                 n   | j                   j                  }|xs |j                  j                  |      }|r| j	                  ||      }| j                  |      }t        |      D ]  }|D ]  }|D ]  }	t        |j                  |	      st        |	      }
t        |j                        j                  |
j                  kD  rQdj                  |j                  ft        d |
j                  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   F   K   | ]  \  }}d j                  ||        yw)z{}={}N)format).0keyvalues      r   	<genexpr>z<DefaultContentNegotiation.select_renderer.<locals>.<genexpr>C   s'      &"(2U %,NN3$>&"s   !)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#   s8    "]]>>N'"6"6":":;M"N--i@I&&w/ 2': 	8N% 8"0 8J)(*=*=zJ-7
-C*&x':':;FF.99:
 /2hh!)!4!4 6 % &"6H6O6O6U6U6W&" !"!"/O $,_#<< $,Z#77+88	82 &&9EEr   c                 \    |D cg c]  }|j                   |k(  r| }}|st        |S c c}w )z
        If there is a '.json' style format suffix, filter the renderers
        so that we only negotiation against those that accept that format.
        )r&   r   )r   r   r&   r;   s       r   r0   z*DefaultContentNegotiation.filter_renderersP   s?    
 /8 3( 61  3	 3M	3s   )c                     |j                   j                  dd      }|j                  d      D cg c]  }|j                          c}S c c}w )zd
        Given the incoming request, return a tokenized list of media
        type strings.
        HTTP_ACCEPTz*/*,)METAr/   splitstrip)r   r   headertokens       r   r1   z)DefaultContentNegotiation.get_accept_list[   s=    
 !!-7+1<<+<=%===s   A
r   )	r   r   r   r   r,   r   r   r0   r1   r   r   r   r   r      s    H+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>rL      s:      % 0 
L LK> 6 K>r   