a
    còfæ  ã                   @   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ƒ‚dS )zx
        Return a dictionary of metadata about the view.
        Used to return responses for OPTIONS requests.
        z).determine_metadata() must be overridden.N)ÚNotImplementedError)ÚselfÚrequestÚview© r   úT/home/httpd/docs/test/DocsMgr/lib/python3.9/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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ƒrP|  ||¡}|rP||d< |S )Nc                 S   s   g | ]
}|j ‘qS r   ©Ú
media_type)Ú.0Úrendererr   r   r   Ú
<listcomp>?   ó    z5SimpleMetadata.determine_metadata.<locals>.<listcomp>c                 S   s   g | ]
}|j ‘qS 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   Úmetadatar/   r   r   r   r   ;   s    ü
z!SimpleMetadata.determine_metadatac                 C   s¦   i }ddht |jƒ@ D ]Š}t||ƒ|_zpz4t|dƒr@| |j¡ |dkrZt|dƒrZ| ¡  W n tjt	t
fyv   Y n0 | ¡ }|  |¡||< W ||_q||_0 q|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   r0   r5   r6   r   ZAPIExceptionr   r   r.   Úget_serializer_info)r   r   r   r/   ÚmethodÚ
serializerr   r   r   r1   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>)r0   r<   ÚfieldsÚitems)r   r;   r   r@   r   r9   c   s
    

þz"SimpleMetadata.get_serializer_infoc                 C   sÐ   | j | t|ddƒdœ}g d¢}|D ]0}t||dƒ}|dur$|dkr$t|dd�||< q$t|d	dƒrt|  |j¡|d	< nt|d
dƒrŽ|  |¡|d< | d¡sÌt|tj	tj
fƒsÌt|dƒrÌdd„ |j ¡ D ƒ|d< |S )zl
        Given an instance of a serializer field, return a dictionary
        of metadata about it.
        ÚrequiredF)ÚtyperD   )	Ú	read_onlyÚlabelÚ	help_textZ
min_lengthÚ
max_lengthZ	min_valueZ	max_valueZ
max_digitsZdecimal_placesNÚ T©Zstrings_onlyr<   rB   ÚchildrenrF   Úchoicesc                 S   s"   g | ]\}}|t |d d�dœ‘qS )TrK   )ÚvalueZdisplay_namer   )r'   Zchoice_valueZchoice_namer   r   r   r)   �   s   ý
þz1SimpleMetadata.get_field_info.<locals>.<listcomp>)Úlabel_lookupÚgetattrr   r>   r<   r9   Úgetr=   r   ZRelatedFieldZManyRelatedFieldr0   rM   rC   )r   r   Z
field_infoÚattrsÚattrrN   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Ú
SerializerrO   r   r1   r9   r>   r   r   r   r   r      s:   êr   N)rT   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   	