ó
O'—^c           @  s“  d  Z  d d l m Z d d l Z d d l Z d d l m Z 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 d
 l m Z d d l m Z d d l m Z d d l m Z d d l m Z e d d d d d g ƒ Z e d d d d g ƒ Z e d d d d g ƒ Z  d „  Z! d „  Z" d e# f d „  ƒ  YZ$ d e$ f d „  ƒ  YZ% d e% f d „  ƒ  YZ& d S(   uÜ  
Routers provide a convenient and consistent way of automatically
determining the URL conf for your API.

They are used by simply instantiating a Router class, and then registering
all the required ViewSets with that router.

For example, you might have a `urls.py` that looks something like this:

    router = routers.DefaultRouter()
    router.register('users', UserViewSet, 'user')
    router.register('accounts', AccountViewSet, 'account')

    urlpatterns = router.urls
iÿÿÿÿ(   t   unicode_literalsN(   t   OrderedDictt
   namedtuple(   t   url(   t   ImproperlyConfigured(   t
   exceptionst	   rendererst   views(   t   NoReverseMatch(   t   BrowsableAPIRenderer(   t   Response(   t   reverse(   t   SchemaGenerator(   t   api_settings(   t   format_suffix_patternsu   Routeu   urlu   mappingu   nameu
   initkwargsu   DynamicDetailRouteu   DynamicListRoutec         C  s@   | j  d d ƒ } |  } | j  d | ƒ } | j  d | ƒ } | S(   us   
    Partially format a format_string, swapping out any
    '{methodname}' or '{methodnamehyphen}' components.
    u   _u   -u   {methodname}u   {methodnamehyphen}(   t   replace(   t   format_stringt
   methodnamet   methodnamehyphent   ret(    (    s8   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/routers.pyt   replace_methodname'   s
    c         C  s   t  j |  Œ  S(   uX   
    Takes an iterable of iterables, returns a single iterable containing all items
    (   t	   itertoolst   chain(   t   list_of_lists(    (    s8   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/routers.pyt   flatten3   s    t
   BaseRouterc           B  s>   e  Z d  „  Z d d „ Z d „  Z d „  Z e d „  ƒ Z RS(   c         C  s   g  |  _  d  S(   N(   t   registry(   t   self(    (    s8   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/routers.pyt   __init__;   s    c         C  s;   | d  k r |  j | ƒ } n  |  j j | | | f ƒ d  S(   N(   t   Nonet   get_default_base_nameR   t   append(   R   t   prefixt   viewsett	   base_name(    (    s8   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/routers.pyt   register>   s    c         C  s   t  d ƒ ‚ d S(   ur   
        If `base_name` is not specified, attempt to automatically determine
        it from the viewset.
        u(   get_default_base_name must be overriddenN(   t   NotImplementedError(   R   R!   (    (    s8   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/routers.pyR   C   s    c         C  s   t  d ƒ ‚ d S(   uO   
        Return a list of URL patterns, given the registered viewsets.
        u   get_urls must be overriddenN(   R$   (   R   (    (    s8   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/routers.pyt   get_urlsJ   s    c         C  s(   t  |  d ƒ s! |  j ƒ  |  _ n  |  j S(   Nu   _urls(   t   hasattrR%   t   _urls(   R   (    (    s8   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/routers.pyt   urlsP   s    N(	   t   __name__t
   __module__R   R   R#   R   R%   t   propertyR(   (    (    (    s8   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/routers.pyR   :   s
   			t   SimpleRouterc           B  sî   e  Z e d  d d i d d 6d d 6d d d	 i d
 d 6ƒ e d  d d d d	 i  ƒ e d  d d i d d 6d d 6d d 6d d 6d d d	 i d d 6ƒ e d  d d d d	 i  ƒ g Z e d „ Z d „  Z d „  Z	 d „  Z
 d d „ Z d „  Z RS(    R   u   ^{prefix}{trailing_slash}$t   mappingu   listu   getu   createu   postt   nameu   {basename}-listt
   initkwargsu   Listu   suffixu'   ^{prefix}/{methodname}{trailing_slash}$u   {basename}-{methodnamehyphen}u#   ^{prefix}/{lookup}{trailing_slash}$u   retrieveu   updateu   putu   partial_updateu   patchu   destroyu   deleteu   {basename}-detailu   Instanceu0   ^{prefix}/{lookup}/{methodname}{trailing_slash}$c         C  s,   | r d p d |  _  t t |  ƒ j ƒ  d  S(   Nu   /u    (   t   trailing_slasht   superR,   R   (   R   R0   (    (    s8   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/routers.pyR      s    c         C  s=   t  | d d ƒ } | d k	 s* t d ƒ ‚ | j j j j ƒ  S(   ur   
        If `base_name` is not specified, attempt to automatically determine
        it from the viewset.
        u   querysetu‘   `base_name` argument not specified, and could not automatically determine the name from the viewset, as it does not have a `.queryset` attribute.N(   t   getattrR   t   AssertionErrort   modelt   _metat   object_namet   lower(   R   R!   t   queryset(    (    s8   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/routers.pyR   …   s    c           s  t  t g  |  j D]$ } t | t ƒ r | j j ƒ  ^ q ƒ ƒ } g  } g  } x½ t ˆ  ƒ D]¯ } t ˆ  | ƒ } t | d d ƒ } t | d t
 ƒ }	 | rY | | k r· t d | ƒ ‚ n  g  | D] }
 |
 j ƒ  ^ q¾ } |	 rò | j | | f ƒ q| j | | f ƒ qY qY W‡  f d †  } g  } xh |  j D]] } t | t ƒ rV| | | | ƒ 7} q+t | t ƒ r{| | | | ƒ 7} q+| j | ƒ q+W| S(   u   
        Augment `self.routes` with any dynamically generated routes.

        Returns a list of the Route namedtuple.
        u   bind_to_methodsu   detailu\   Cannot use @detail_route or @list_route decorators on method "%s" as it is an existing routec           s·   g  } xª | D]¢ \ } ‰  t  ˆ ˆ  ƒ j } |  j j ƒ  } | j | ƒ | j d d  ƒ p\ ˆ  } | j t d t	 |  j
 | ƒ d ‡  f d †  | Dƒ d t	 |  j | ƒ d | ƒ ƒ q W| S(   Nu   url_pathR   R-   c           s   i  |  ] } ˆ  | “ q S(    (    (   t   .0t
   httpmethod(   R   (    s8   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/routers.pys
   <dictcomp>¸   s   	 R.   R/   (   R2   t   kwargsR/   t   copyt   updatet   popR   R   t   RouteR   R   R.   (   t   routet   dynamic_routesR   t   httpmethodst   method_kwargsR/   t   url_path(   R!   (   R   s8   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/routers.pyt   _get_dynamic_routes¯   s    N(   t   listR   t   routest
   isinstanceR?   R-   t   valuest   dirR2   R   t   TrueR   R7   R   t   DynamicDetailRoutet   DynamicListRoute(   R   R!   R@   t   known_actionst   detail_routest   list_routesR   t   attrRB   t   detailt   methodRE   R   (    (   R!   s8   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/routers.pyt
   get_routes’   s0    @c         C  sC   i  } x6 | j  ƒ  D]( \ } } t | | ƒ r | | | <q q W| S(   uÀ   
        Given a viewset, and a mapping of http methods to actions,
        return a new mapping which only includes any mappings that
        are actually implemented by the viewset.
        (   t   itemsR&   (   R   R!   t
   method_mapt   bound_methodsRS   t   action(    (    s8   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/routers.pyt   get_method_mapÍ   s
    u    c         C  s^   d } t  | d d ƒ } t  | d d
 ƒ p- | } t  | d d ƒ } | j d | d | d	 | ƒ S(   u  
        Given a viewset, return the portion of URL regex that is used
        to match against a single instance.

        Note that lookup_prefix is not used directly inside REST rest_framework
        itself, but is required in order to nicely support nested router
        implementations, such as drf-nested-routers.

        https://github.com/alanjds/drf-nested-routers
        u5   (?P<{lookup_prefix}{lookup_url_kwarg}>{lookup_value})u   lookup_fieldu   pku   lookup_url_kwargu   lookup_value_regexu   [^/.]+t   lookup_prefixt   lookup_url_kwargt   lookup_valueN(   R2   R   t   format(   R   R!   RZ   t
   base_regext   lookup_fieldR[   R\   (    (    s8   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/routers.pyt   get_lookup_regexÙ   s    	c      	   C  s	  g  } xü |  j  D]ñ \ } } } |  j | ƒ } |  j | ƒ } xÁ | D]¹ } |  j | | j ƒ } | sk qD n  | j j d | d | d |  j ƒ }	 | r· |	 d  d k r· d |	 d }	 n  | j | | j	  }
 | j
 j d | ƒ } | j t |	 |
 d | ƒƒ qD Wq W| S(	   uQ   
        Use the registered viewsets to generate a list of URL patterns.
        R    t   lookupR0   i   u   ^/u   ^t   basenameR.   (   R   R`   RT   RY   R-   R   R]   R0   t   as_viewR/   R.   R   (   R   R   R    R!   Rb   Ra   RG   R@   R-   t   regext   viewR.   (    (    s8   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/routers.pyR%   ð   s$    $(   R)   R*   R?   RM   RL   RG   RK   R   R   RT   RY   R`   R%   (    (    (    s8   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/routers.pyR,   W   s<   

		;	t   DefaultRouterc           B  sY   e  Z d  Z e Z e Z d Z e j e	 g Z
 d „  Z d d „ Z d d „ Z d „  Z RS(   u‘   
    The default router extends the SimpleRouter, but also adds in a default
    API root view, and adds format suffix patterns to the URLs.
    u   api-rootc         O  sÿ   d | k r t  j d t ƒ n  d | k rF d | k sF t d ƒ ‚ n  d | k rm d | k sm t d ƒ ‚ n  | j d d  ƒ |  _ | j d d  ƒ |  _ | j d |  j ƒ |  _	 d | k rÐ | j d ƒ |  _
 n t t j ƒ |  _
 t t |  ƒ j | | Ž  d  S(   Nu   schema_titleue   Including a schema directly via a router is now pending deprecation. Use `get_schema_view()` instead.u   schema_renderersu    Missing "schema_title" argument.u
   schema_urlu   root_renderers(   t   warningst   warnt   PendingDeprecationWarningR3   R>   R   t   schema_titlet
   schema_urlt   default_schema_rendererst   schema_rendererst   root_renderersRF   R   t   DEFAULT_RENDERER_CLASSESR1   Rf   R   (   R   t   argsR;   (    (    s8   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/routers.pyR      s    
c           sV   |  j  ‰ t d |  j d |  j d | ƒ ‰  d t j f ‡  ‡ f d †  ƒ  Y} | j ƒ  S(   u,   
        Return a schema root view.
        t   titleR   t   patternst   APISchemaViewc             s)   e  Z e Z e Z ˆ Z ‡  f d  †  Z RS(   c           s4   ˆ  j  | ƒ } | d  k r* t j ƒ  ‚ n  t | ƒ S(   N(   t
   get_schemaR   R   t   PermissionDeniedR
   (   R   t   requestRp   R;   t   schema(   t   schema_generator(    s8   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/routers.pyt   getD  s    (   R)   R*   RK   t   _ignore_model_permissionst   exclude_from_schemat   renderer_classesRy   (    (   Rx   Rm   (    s8   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/routers.pyRs   ?  s   (   Rm   R   Rj   Rk   R   t   APIViewRc   (   R   t   api_urlsRs   (    (   Rx   Rm   s8   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/routers.pyt   get_schema_root_view4  s    				"c           su   t  ƒ  ‰  |  j d j } x0 |  j D]% \ } } } | j d | ƒ ˆ  | <q# Wd t j f ‡  f d †  ƒ  Y} | j ƒ  S(   u+   
        Return a basic root view.
        i    Rb   t   APIRootViewc             s#   e  Z e Z e Z ‡  f d  †  Z RS(   c           s¢   t  ƒ  } | j j } x€ ˆ  j ƒ  D]r \ } } | rE | d | } n  y8 t | d | d | d | d | j d d  ƒ ƒ| | <Wq" t k
 r“ q" q" Xq" Wt | ƒ S(   Nu   :Rp   R;   Rv   R]   u   format(	   R   t   resolver_matcht	   namespaceRU   R   Ry   R   R   R
   (   R   Rv   Rp   R;   R   R‚   t   keyt   url_name(   t   api_root_dict(    s8   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/routers.pyRy   Y  s    	(   R)   R*   RK   Rz   R{   Ry   (    (   R…   (    s8   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/routers.pyR€   U  s   (   R   RG   R.   R   R]   R   R}   Rc   (   R   R~   t	   list_nameR    R!   Rb   R€   (    (   R…   s8   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/routers.pyt   get_api_root_viewL  s    	c         C  s’   t  t |  ƒ j ƒ  } |  j rv |  j r< |  j d | ƒ } n |  j d | ƒ } t d | d |  j ƒ} | j	 | ƒ n  |  j
 rŽ t | ƒ } n  | S(   u”   
        Generate the list of URL patterns, including a default root view
        for the API, and appending `.json` style format suffixes.
        R~   u   ^$R.   (   R1   Rf   R%   t   include_root_viewRj   R   R‡   R   t   root_view_nameR   t   include_format_suffixesR   (   R   R(   Re   t   root_url(    (    s8   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/routers.pyR%   p  s    			N(   R)   R*   t   __doc__RK   Rˆ   RŠ   R‰   R   t   CoreJSONRendererR	   Rl   R   R   R   R‡   R%   (    (    (    s8   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/routers.pyRf     s   	$('   RŒ   t
   __future__R    R   Rg   t   collectionsR   R   t   django.conf.urlsR   t   django.core.exceptionsR   t   rest_frameworkR   R   R   t   rest_framework.compatR   t   rest_framework.renderersR	   t   rest_framework.responseR
   t   rest_framework.reverseR   t   rest_framework.schemasR   t   rest_framework.settingsR   t   rest_framework.urlpatternsR   R?   RL   RM   R   R   t   objectR   R,   Rf   (    (    (    s8   /tmp/pip-unpacked-wheel-62FVgP/rest_framework/routers.pyt   <module>   s,   		¿