o
    `oi                     @   sr   d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	 ddl
mZ ddlmZ G dd	 d	ZG d
d deZdS )aL  
The metadata API is used to allow customization of how `OPTIONS` requests
are handled. We currently provide a single default implementation that returns
some fairly ad-hoc information about the view.

Future implementations might use JSON schema or other definitions in order
to return this information in a more standardized way.
    )PermissionDenied)Http404	force_str)
exceptionsserializers)clone_request)ClassLookupDictc                   @   s   e Zd Zdd ZdS )BaseMetadatac                 C   s   t d)zx
        Return a dictionary of metadata about the view.
        Used to return responses for OPTIONS requests.
        z).determine_metadata() must be overridden.)NotImplementedError)selfrequestview r   _/var/www/html/kuke-dev/django-kuke/venv/lib/python3.10/site-packages/rest_framework/metadata.pydetermine_metadata   s   zBaseMetadata.determine_metadataN)__name__
__module____qualname__r   r   r   r   r   r
      s    r
   c                   @   s   e Zd ZdZei ejdejdejdej	dej
dejdejdejdejd	ejd
ejdejdejdejdejdejdejdejdejdejdejdejdiZdd Zdd Zdd Zdd Z dS )SimpleMetadataz
    This is the default metadata implementation.
    It returns an ad-hoc set of information about the view.
    There are not any formalized standards for `OPTIONS` responses
    for us to base this on.
    fieldbooleanstringurlemailregexZslugintegerfloatdecimaldatedatetimetimedurationchoicezmultiple choicezfile uploadzimage uploadlistznested objectc                 C   sT   |  | dd |jD dd |jD d}t|dr(| ||}|r(||d< |S )Nc                 S      g | ]}|j qS r   
media_type).0rendererr   r   r   
<listcomp>?       z5SimpleMetadata.determine_metadata.<locals>.<listcomp>c                 S   r%   r   r&   )r(   parserr   r   r   r*   @   r+   )namedescriptionZrendersZparsesget_serializeractions)Zget_view_nameZget_view_descriptionZrenderer_classesZparser_classeshasattrdetermine_actions)r   r   r   metadatar0   r   r   r   r   ;   s   
z!SimpleMetadata.determine_metadatac                 C   s   i }ddht |j@ D ]D}t|||_z8zt|dr ||j |dkr-t|dr-|  W n tjt	t
fy;   Y nw | }| |||< W ||_q||_w |S )z
        For generic class based views we return information about
        the fields that are accepted for 'PUT' and 'POST' methods.
        PUTPOSTcheck_permissions
get_object)setallowed_methodsr   r   r1   r6   r7   r   ZAPIExceptionr   r   r/   get_serializer_info)r   r   r   r0   method
serializerr   r   r   r2   H   s"   
z SimpleMetadata.determine_actionsc                    s(   t |dr|j} fdd|j D S )zn
        Given an instance of a serializer, return a dictionary of metadata
        about its fields.
        childc                    s(   i | ]\}}t |tjs| |qS r   )
isinstancer   ZHiddenFieldget_field_info)r(   
field_namer   r   r   r   
<dictcomp>l   s    

z6SimpleMetadata.get_serializer_info.<locals>.<dictcomp>)r1   r=   fieldsitems)r   r<   r   rA   r   r:   c   s
   

z"SimpleMetadata.get_serializer_infoc                 C   s   | j | t|ddd}g d}|D ]}t||d}|dur*|dkr*t|dd||< qt|d	dr:| |j|d	< nt|d
drG| ||d< |dsft|tj	tj
fsft|drfdd |j D |d< |S )zl
        Given an instance of a serializer field, return a dictionary
        of metadata about it.
        requiredF)typerE   )		read_onlylabel	help_textZ
min_length
max_lengthZ	min_valueZ	max_valueZ
max_digitsZdecimal_placesN TZstrings_onlyr=   rC   childrenrG   choicesc                 S   s"   g | ]\}}|t |d ddqS )TrL   )valuedisplay_namer   )r(   Zchoice_valueZchoice_namer   r   r   r*      s    
z1SimpleMetadata.get_field_info.<locals>.<listcomp>)label_lookupgetattrr   r?   r=   r:   getr>   r   ZRelatedFieldZManyRelatedFieldr1   rN   rD   )r   r   Z
field_infoattrsattrrO   r   r   r   r?   r   s,   


zSimpleMetadata.get_field_infoN)!r   r   r   __doc__r	   r   FieldZBooleanFieldZ	CharFieldZ	UUIDFieldZURLFieldZ
EmailFieldZ
RegexFieldZ	SlugFieldZIntegerFieldZ
FloatFieldZDecimalFieldZ	DateFieldZDateTimeFieldZ	TimeFieldZDurationFieldZChoiceFieldZMultipleChoiceFieldZ	FileFieldZ
ImageFieldZ	ListFieldZ	DictField
SerializerrQ   r   r2   r:   r?   r   r   r   r   r      s^    	
r   N)rV   Zdjango.core.exceptionsr   Zdjango.httpr   Zdjango.utils.encodingr   Zrest_frameworkr   r   Zrest_framework.requestr   Z"rest_framework.utils.field_mappingr	   r
   r   r   r   r   r   <module>   s    	