
    h                     n    d Z ddlmZ ddlmZ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)HTTP_HEADER_ENCODING
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      ]/var/www/html/ranktracker/api/venv/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   l   K   | ],  \  }}d j                  ||j                  t                     . yw)z{}={}N)formatdecoder   ).0keyvalues      r   	<genexpr>z<DefaultContentNegotiation.select_renderer.<locals>.<genexpr>C   s7      &Y(2U '.nn$'6J)K'M &Ys   24)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"6":":;M"N--i@I&&w/ 2': 	8N% 8"0 8J)(*=*=zJ-7
-C*&x':':;FF.99:
 /2hh!)!4!4 6 % &Y6H6O6O6U6U6W&Y !Y!Y/ZO
 $,_#<< $,Z#77'88	8. &&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   r2   z*DefaultContentNegotiation.filter_renderersN   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*/*,)METAr1   splitstrip)r   r   headertokens       r   r3   z)DefaultContentNegotiation.get_accept_listY   s=    
 !!-7+1<<+<=%===s   A
r   )	r   r   r   r   r.   r   r   r2   r3   r   r   r   r   r      s    H)FV	>r   r   N)__doc__django.httpr   rest_frameworkr   r   rest_framework.settingsr   rest_framework.utils.mediatypesr   r   r	   r   r   r   r   r   <module>rN      s:      ; 0 
L LI> 6 I>r   