a
    còfh  ã                   @   s|   d Z ddlZddlmZ ddlmZ ddd„Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zddd„ZG dd„ deƒZdS )aP  
The most important decorator in this module is `@api_view`, which is used
for writing function-based views with REST framework.

There are also various decorators for setting the API policies on function
based views, as well as the `@action` decorator, which is used to annotate
methods on viewsets that should be included by routers.
é    N)Úpretty_name)ÚAPIViewc                    s"   ˆ du rdgnˆ ‰ ‡ fdd„}|S )z’
    Decorator that converts a function-based view into an APIView subclass.
    Takes a list of allowed methods for the view as an argument.
    NÚGETc                    s  t dtfdˆ jiƒ}tˆtjƒr(J dƒ‚tˆttfƒsHJ dt ˆƒj ƒ‚t	ˆƒdhB }dd„ |D ƒ|_
‡ fdd	„}ˆD ]}t|| ¡ |ƒ qvˆ j|_ˆ j|_tˆ d
tjƒ|_tˆ dtjƒ|_tˆ dtjƒ|_tˆ dtjƒ|_tˆ dtjƒ|_tˆ dtjƒ|_| ¡ S )NÚWrappedAPIViewÚ__doc__z.@api_view missing list of allowed HTTP methodsz1@api_view expected a list of strings, received %sÚoptionsc                 S   s   g | ]}|  ¡ ‘qS © ©Úlower©Ú.0Úmethodr   r   úV/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/rest_framework/decorators.pyÚ
<listcomp>/   ó    z/api_view.<locals>.decorator.<locals>.<listcomp>c                    s   ˆ |i |¤ŽS ©Nr   )ÚselfÚargsÚkwargs©Úfuncr   r   Úhandler1   s    z,api_view.<locals>.decorator.<locals>.handlerÚrenderer_classesÚparser_classesÚauthentication_classesÚthrottle_classesÚpermission_classesÚschema)Útyper   r   Ú
isinstanceÚtypesÚFunctionTypeÚlistÚtupleÚ__name__ÚsetÚhttp_method_namesÚsetattrr
   Ú
__module__Úgetattrr   r   r   r   r   r   Zas_view)r   r   Úallowed_methodsr   r   ©r&   r   r   Ú	decorator   sJ    ýÿÿÿÿÿÿÿÿzapi_view.<locals>.decoratorr   )r&   r,   r   r+   r   Úapi_view   s    7r-   c                    s   ‡ fdd„}|S )Nc                    s
   ˆ | _ | S r   ©r   r   r.   r   r   r,   R   s    z#renderer_classes.<locals>.decoratorr   )r   r,   r   r.   r   r   Q   s    r   c                    s   ‡ fdd„}|S )Nc                    s
   ˆ | _ | S r   ©r   r   r/   r   r   r,   Y   s    z!parser_classes.<locals>.decoratorr   )r   r,   r   r/   r   r   X   s    r   c                    s   ‡ fdd„}|S )Nc                    s
   ˆ | _ | S r   ©r   r   r0   r   r   r,   `   s    z)authentication_classes.<locals>.decoratorr   )r   r,   r   r0   r   r   _   s    r   c                    s   ‡ fdd„}|S )Nc                    s
   ˆ | _ | S r   ©r   r   r1   r   r   r,   g   s    z#throttle_classes.<locals>.decoratorr   )r   r,   r   r1   r   r   f   s    r   c                    s   ‡ fdd„}|S )Nc                    s
   ˆ | _ | S r   ©r   r   r2   r   r   r,   n   s    z%permission_classes.<locals>.decoratorr   )r   r,   r   r2   r   r   m   s    r   c                    s   ‡ fdd„}|S )Nc                    s
   ˆ | _ | S r   )r   r   ©Úview_inspectorr   r   r,   u   s    zschema.<locals>.decoratorr   )r4   r,   r   r3   r   r   t   s    r   c                    s`   ˆdu rdgnˆ‰dd„ ˆD ƒ‰ˆ dus0J dƒ‚dˆv rHdˆv rHt dƒ‚‡ ‡‡‡‡fd	d
„}|S )aQ  
    Mark a ViewSet method as a routable action.

    `@action`-decorated functions will be endowed with a `mapping` property,
    a `MethodMapper` that can be used to add additional method-based behaviors
    on the routed action.

    :param methods: A list of HTTP method names this action responds to.
                    Defaults to GET only.
    :param detail: Required. Determines whether this action applies to
                   instance/detail requests or collection/list requests.
    :param url_path: Define the URL segment for this action. Defaults to the
                     name of the method decorated.
    :param url_name: Define the internal (`reverse`) URL name for this action.
                     Defaults to the name of the method decorated with underscores
                     replaced with dashes.
    :param kwargs: Additional properties to set on the view.  This can be used
                   to override viewset-level *_classes settings, equivalent to
                   how the `@renderer_classes` etc. decorators work for function-
                   based API views.
    NÚgetc                 S   s   g | ]}|  ¡ ‘qS r   r	   r   r   r   r   r   ’   r   zaction.<locals>.<listcomp>z-@action() missing required argument: 'detail'ÚnameÚsuffixz5`name` and `suffix` are mutually exclusive arguments.c                    st   t | ˆƒ| _ˆ | _ˆrˆn| j| _ˆr*ˆn| j dd¡| _ˆ| _dˆvr`dˆvr`t| jƒ| jd< | j	phd | jd< | S )NÚ_ú-r6   r7   Údescription)
ÚMethodMapperÚmappingÚdetailr$   Úurl_pathÚreplaceÚurl_namer   r   r   r   ©r=   r   Úmethodsr@   r>   r   r   r,   œ   s    zaction.<locals>.decorator)Ú	TypeError)rB   r=   r>   r@   r   r,   r   rA   r   Úaction{   s    
ÿrD   c                   @   s`   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ ZdS )r;   au  
    Enables mapping HTTP methods to different ViewSet methods for a single,
    logical action.

    Example usage:

        class MyViewSet(ViewSet):

            @action(detail=False)
            def example(self, request, **kwargs):
                ...

            @example.mapping.post
            def create_example(self, request, **kwargs):
                ...
    c                 C   s    || _ |D ]}| j j| |< q
d S r   )rD   r$   )r   rD   rB   r   r   r   r   Ú__init__Ã   s    zMethodMapper.__init__c                 C   s@   || vsJ d|| | f ƒ‚|j | jj ks2J dƒ‚|j | |< |S )Nz-Method '%s' has already been mapped to '.%s'.z}Method mapping does not behave like the property decorator. You cannot use the same method name for each mapping declaration.)r$   rD   )r   r   r   r   r   r   Ú_mapÈ   s    
ÿÿ
zMethodMapper._mapc                 C   s   |   d|¡S )Nr5   ©rF   ©r   r   r   r   r   r5   Ó   s    zMethodMapper.getc                 C   s   |   d|¡S )NÚpostrG   rH   r   r   r   rI   Ö   s    zMethodMapper.postc                 C   s   |   d|¡S )NÚputrG   rH   r   r   r   rJ   Ù   s    zMethodMapper.putc                 C   s   |   d|¡S )NÚpatchrG   rH   r   r   r   rK   Ü   s    zMethodMapper.patchc                 C   s   |   d|¡S )NÚdeleterG   rH   r   r   r   rL   ß   s    zMethodMapper.deletec                 C   s   |   d|¡S )NÚheadrG   rH   r   r   r   rM   â   s    zMethodMapper.headc                 C   s   |   d|¡S )Nr   rG   rH   r   r   r   r   å   s    zMethodMapper.optionsc                 C   s   |   d|¡S )NÚtracerG   rH   r   r   r   rN   è   s    zMethodMapper.traceN)r$   r(   Ú__qualname__r   rE   rF   r5   rI   rJ   rK   rL   rM   r   rN   r   r   r   r   r;   ±   s   r;   )N)NNNN)r   r    Zdjango.forms.utilsr   Zrest_framework.viewsr   r-   r   r   r   r   r   r   rD   Údictr;   r   r   r   r   Ú<module>   s   
A
6