ó
O'—^c           @  s
  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
 m Z m Z d e f d „  ƒ  YZ d	 e e j f d
 „  ƒ  YZ d e e
 j f d „  ƒ  YZ d e j e j e f d „  ƒ  YZ d e j e j e j e j e j e f d „  ƒ  YZ d S(   u  
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
iÿÿÿÿ(   t   unicode_literals(   t   update_wrapper(   t   classonlymethod(   t   csrf_exempt(   t   genericst   mixinst   viewst   ViewSetMixinc           B  s)   e  Z d  Z e d d „ ƒ Z d „  Z RS(   ud  
    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           sı   d ˆ _ ˆ  s t d ƒ ‚ n  xd ˆ D]\ } | ˆ j k rV t d | ˆ j f ƒ ‚ n  t ˆ | ƒ s% t d ˆ j | f ƒ ‚ q% q% W‡  ‡ ‡ f d †  } t | ˆ d d	 ƒt | ˆ j d d
 ƒˆ | _ ˆ | _	 ˆ j
 d d ƒ | _ ˆ  | _ t | ƒ S(   uä   
        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.
        uw   The `actions` argument must be provided when calling `.as_view()` on a ViewSet. For example `.as_view({'get': 'list'})`uU   You tried to pass in the %s method name as a keyword argument to %s(). Don't do that.u#   %s() received an invalid keyword %rc           sd   ˆ ˆ   } ˆ  | _  x9 ˆ  j ƒ  D]+ \ } } t | | ƒ } t | | | ƒ q" W| j |  | |  S(   N(   t
   action_mapt   itemst   getattrt   setattrt   dispatch(   t   requestt   argst   kwargst   selft   methodt   actiont   handler(   t   actionst   clst
   initkwargs(    s9   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/viewsets.pyt   viewE   s    	t   updatedt   assignedu   suffixN(    (    (   t   Nonet   suffixt	   TypeErrort   http_method_namest   __name__t   hasattrR   R   R   R   t   getR   R   (   R   R   R   t   keyR   (    (   R   R   R   s9   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/viewsets.pyt   as_view*   s$    					c         O  s^   t  t |  ƒ j | | |  } | j j ƒ  } | d k rE d |  _ n |  j j | ƒ |  _ | S(   uc   
        Set the `.action` attribute on the view,
        depending on the request method.
        u   optionsu   metadata(   t   superR   t   initialize_requestR   t   lowerR   R   R    (   R   R   R   R   R   (    (    s9   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/viewsets.pyR$   e   s    N(   R   t
   __module__t   __doc__R   R   R"   R$   (    (    (    s9   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/viewsets.pyR      s   :t   ViewSetc           B  s   e  Z d  Z RS(   uI   
    The base ViewSet class does not provide any actions by default.
    (   R   R&   R'   (    (    (    s9   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/viewsets.pyR(   v   s   t   GenericViewSetc           B  s   e  Z d  Z RS(   uÀ   
    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.
    (   R   R&   R'   (    (    (    s9   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/viewsets.pyR)   }   s   t   ReadOnlyModelViewSetc           B  s   e  Z d  Z RS(   uL   
    A viewset that provides default `list()` and `retrieve()` actions.
    (   R   R&   R'   (    (    (    s9   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/viewsets.pyR*   †   s   t   ModelViewSetc           B  s   e  Z d  Z RS(   u‰   
    A viewset that provides default `create()`, `retrieve()`, `update()`,
    `partial_update()`, `destroy()` and `list()` actions.
    (   R   R&   R'   (    (    (    s9   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/viewsets.pyR+      s   	N(   R'   t
   __future__R    t	   functoolsR   t   django.utils.decoratorsR   t   django.views.decorators.csrfR   t   rest_frameworkR   R   R   t   objectR   t   APIViewR(   t   GenericAPIViewR)   t   RetrieveModelMixint   ListModelMixinR*   t   CreateModelMixint   UpdateModelMixint   DestroyModelMixinR+   (    (    (    s9   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/viewsets.pyt   <module>   s"   Y			