
    h"              
          d Z ddlmZ ddlmZ ddlm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 dd	lmZ dd
lmZ d Zd Z G d d      Z G d deej0                        Z G d deej4                        Z G d dej8                  ej:                  e      Z G d dej>                  ej8                  ej@                  ejB                  ej:                  e      Z"y)a  
ViewSets are essentially just a type of class based view, that doesn't provide
any method handlers, such as `get()`, `post()`, etc... but instead has actions,
such as `list()`, `retrieve()`, `create()`, etc...

Actions are only bound to methods at the point of instantiating the views.

    user_list = UserViewSet.as_view({'get': 'list'})
    user_detail = UserViewSet.as_view({'get': 'retrieve'})

Typically, rather than instantiate views from viewsets directly, you'll
register the viewset with a router and let the URL conf be determined
automatically.

    router = DefaultRouter()
    router.register(r'users', UserViewSet, 'user')
    urlpatterns = router.urls
    )OrderedDict)update_wrapper)
getmembers)NoReverseMatch)classonlymethod)csrf_exempt)genericsmixinsviews)MethodMapper)reversec                 R    t        | d      xr t        | j                  t              S )Nmapping)hasattr
isinstancer   r   )attrs    Z/var/www/html/ranktracker/api/venv/lib/python3.12/site-packages/rest_framework/viewsets.py_is_extra_actionr       s    4#N
4<<(NN    c                 T    | j                   |k(  sJ dj                  | |             | S )NzExpected function (`{func.__name__}`) to match its attribute name (`{name}`). If using a decorator, ensure the inner function is decorated with `functools.wraps`, or that `{func.__name__}.__name__` is otherwise set to `{name}`.funcname)__name__formatr   s     r   _check_attr_namer   $   s9    ==D  F	( *0T)E	F 
 Kr   c                   P     e Zd ZdZedd       Z fdZd Zed        Z	d Z
 xZS )ViewSetMixinad  
    This is the magic.

    Overrides `.as_view()` so that it takes an `actions` keyword that performs
    the binding of HTTP methods to actions on the Resource.

    For example, to create a concrete view binding the 'GET' and 'POST' methods
    to the 'list' and 'create' actions...

    view = MyViewSet.as_view({'get': 'list', 'post': 'create'})
    c                     d _         d _        d _        d _        d _        st        d      D ]R  }| j                  v rt        d|d j                  d      t         |      r:t         j                  d|       dv rdv rt        d	 j                  z         fd
}t        | d       t        | j                  d        |_        |_        |_        t        |      S )z
        Because of the way class based views create a closure around the
        instantiated view, we need to totally reimplement `.as_view`,
        and slightly modify the view function that is created and returned.
        NzwThe `actions` argument must be provided when calling `.as_view()` on a ViewSet. For example `.as_view({'get': 'list'})`zYou tried to pass in the z& method name as a keyword argument to z(). Don't do that.z() received an invalid keyword r   suffixzO%s() received both `name` and `suffix`, which are mutually exclusive arguments.c                      di 	}dv rdvrd   d<   |_         j                         D ]  \  }}t        ||      }t        |||         | |_        ||_        ||_         |j                  | g|i |S )Ngethead )
action_mapitemsgetattrsetattrrequestargskwargsdispatch)
r)   r*   r+   selfmethodactionhandleractionscls
initkwargss
          r   viewz"ViewSetMixin.as_view.<locals>.viewg   s    $$DF'$9")%.
 &DO #*--/ /!$/fg./ #DLDI DK !4==:4:6::r   r$   )updated)assigned)r   descriptionr    detailbasename	TypeErrorhttp_method_namesr   r   r   r,   r2   r3   r1   r   )r2   r1   r3   keyr4   s   ```  r   as_viewzViewSetMixin.as_view:   s    
 
 
   : ; ;
  	(Cc+++#&!6 7 7 3$LL#!' ( (	( ZH
$: <?B||M N N	;2 	tS"- 	tS\\B7
 $4  r   c                     t        |   |g|i |}|j                  j                         }|dk(  r	d| _        |S | j
                  j                  |      | _        |S )z[
        Set the `.action` attribute on the view, depending on the request method.
        optionsmetadata)superinitialize_requestr.   lowerr/   r%   r"   )r-   r)   r*   r+   r.   	__class__s        r   rB   zViewSetMixin.initialize_request   se     ',WFtFvF%%'Y %DK  //--f5DKr   c                    | j                   d|}d}| j                  r6| j                  j                  r | j                  j                  j                  }|r|dz   |z   }|j	                  d| j                         t        |g|i |S )z>
        Reverse the action for the given `url_name`.
        -N:r)   )r9   r)   resolver_match	namespace
setdefaultr   )r-   url_namer*   r+   rI   s        r   reverse_actionzViewSetMixin.reverse_action   sy     #mmX6	<<DLL7733==I 31H)T\\2x1$1&11r   c                 h    t        | t              D cg c]  \  }}t        ||       c}}S c c}}w )zP
        Get the methods that are marked as an extra ViewSet `@action`.
        )r   r   r   )r2   r   r.   s      r   get_extra_actionszViewSetMixin.get_extra_actions   s7     c#346 D& !. 6 	6 6s   .c                    t               }| j                  |S | j                         D cg c]  }|j                  | j                  k(  r| }}|D ]z  }	 | j                  d|j                  }t        || j                  | j                  | j                        } | j                  di |j                  }|||j                         <   | |S c c}w # t        $ r Y w xY w)z
        Build a map of {names: urls} for the extra actions.

        This method will noop if `detail` was not provided as a view initkwarg.
        rF   )r)   r$   )r   r8   rN   r9   rK   r   r*   r+   r)   rD   get_view_namer   )r-   action_urlsr/   r1   rK   urlr4   s          r   get_extra_action_url_mapz%ViewSetMixin.get_extra_action_url_map   s     "m ;; "&!7!7!9
}}+ 
 

  	F&*mmV__Eh		4;;U%t~~6647D..01	 
 " s   "CA7C	C! C!)N)r   
__module____qualname____doc__r   r=   rB   rL   classmethodrN   rS   __classcell__)rD   s   @r   r   r   -   sB    
 Q! Q!f2 6 6r   r   c                       e Zd ZdZy)ViewSetzI
    The base ViewSet class does not provide any actions by default.
    Nr   rT   rU   rV   r$   r   r   rZ   rZ      s     	r   rZ   c                       e Zd ZdZy)GenericViewSetz
    The GenericViewSet class does not provide any actions by default,
    but does include the base set of generic view behavior, such as
    the `get_object` and `get_queryset` methods.
    Nr[   r$   r   r   r]   r]      s    
 	r   r]   c                       e Zd ZdZy)ReadOnlyModelViewSetzL
    A viewset that provides default `list()` and `retrieve()` actions.
    Nr[   r$   r   r   r_   r_      s     	r   r_   c                       e Zd ZdZy)ModelViewSetz
    A viewset that provides default `create()`, `retrieve()`, `update()`,
    `partial_update()`, `destroy()` and `list()` actions.
    Nr[   r$   r   r   ra   ra      s     	r   ra   N)#rV   collectionsr   	functoolsr   inspectr   django.urlsr   django.utils.decoratorsr   django.views.decorators.csrfr   rest_frameworkr	   r
   r   rest_framework.decoratorsr   rest_framework.reverser   r   r   r   APIViewrZ   GenericAPIViewr]   RetrieveModelMixinListModelMixinr_   CreateModelMixinUpdateModelMixinDestroyModelMixinra   r$   r   r   <module>rr      s   $ $ $  & 3 4 2 2 2 *Ob bJ	lEMM 		\8#:#: 		644!00)	
	6**,,**++((!
	r   