ó
k4Vdc           @  sw  d  Z  d d l m 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 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 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   NoReverseMatch(   t
   exceptionst	   rendererst   views(   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(    (    sd   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/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(    (    sd   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/rest_framework/routers.pyt   flatten1   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(    (    sd   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/rest_framework/routers.pyt   __init__9   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(    (    sd   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/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    (    (    sd   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/rest_framework/routers.pyR   A   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   (    (    sd   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/rest_framework/routers.pyt   get_urlsH   s    c         C  s(   t  |  d ƒ s! |  j ƒ  |  _ n  |  j S(   Nu   _urls(   t   hasattrR$   t   _urls(   R   (    (    sd   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/rest_framework/routers.pyt   urlsN   s    N(	   t   __name__t
   __module__R   R   R"   R   R$   t   propertyR'   (    (    (    sd   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/rest_framework/routers.pyR   8   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   R/   (    (    sd   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/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(    (    sd   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/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   (    sd   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/rest_framework/routers.pys
   <dictcomp>µ   s   	 R-   R.   (   R1   t   kwargsR.   t   copyt   updatet   popR   R   t   RouteR   R   R-   (   t   routet   dynamic_routesR   t   httpmethodst   method_kwargsR.   t   url_path(   R    (   R   sd   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/rest_framework/routers.pyt   _get_dynamic_routes¬   s    N(   t   listR   t   routest
   isinstanceR>   R,   t   valuest   dirR1   R   t   TrueR   R6   R   t   DynamicDetailRoutet   DynamicListRoute(   R   R    R?   t   known_actionst   detail_routest   list_routesR   t   attrRA   t   detailt   methodRD   R   (    (   R    sd   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/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_methodsRR   t   action(    (    sd   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/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(   R1   R   t   format(   R   R    RY   t
   base_regext   lookup_fieldRZ   R[   (    (    sd   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/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 ƒ }	 | 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   lookupR/   t   basenameR-   (   R   R_   RS   RX   R,   R   R\   R/   t   as_viewR.   R-   R   (   R   R   R   R    Ra   R`   RF   R?   R,   t   regext   viewR-   (    (    sd   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/rest_framework/routers.pyR$   í   s     $(   R(   R)   R>   RL   RK   RF   RJ   R   R   RS   RX   R_   R$   (    (    (    sd   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/rest_framework/routers.pyR+   U   s<   

		;	t   DefaultRouterc           B  sJ   e  Z d  Z e Z e Z d Z e j g Z	 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' d | k s' t  d ƒ ‚ n  d | k rN d | k sN 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_renderersu   schema_titleu    Missing "schema_title" argument.u
   schema_urlu   root_renderers(   R2   R=   R   t   schema_titlet
   schema_urlt   default_schema_rendererst   schema_rendererst   root_renderersRE   R   t   DEFAULT_RENDERER_CLASSESR0   Re   R   (   R   t   argsR:   (    (    sd   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/rest_framework/routers.pyR     s    c           sø   t  ƒ  ‰  |  j d j } x0 |  j D]% \ } } } | j d | ƒ ˆ  | <q# Wt |  j ƒ ‰ g  ‰ | rÆ |  j rÆ ˆ t |  j ƒ 7‰ t	 d |  j d |  j
 d | ƒ ‰ g  |  j D] } | j ^ q® ‰ n  d t j f ‡  ‡ ‡ ‡ f d †  ƒ  Y} | j ƒ  S(   u7   
        Return a view to use as the API root.
        i    Ra   t   titleR   t   patternst   APIRootc             s)   e  Z e Z ˆ Z ‡  ‡ ‡ f d  †  Z RS(   c   	        sè   | j  j ˆ k rF ˆ j | ƒ } | d  k r< t j ƒ  ‚ n  t | ƒ St ƒ  } | j j	 } x€ ˆ  j
 ƒ  D]r \ } } | r‹ | d | } n  y8 t | d | d | d | d | j d d  ƒ ƒ| | <Wqh t k
 rÙ qh qh Xqh Wt | ƒ S(   Nu   :Rl   R:   t   requestR\   u   format(   t   accepted_renderert
   media_typet
   get_schemaR   R   t   PermissionDeniedR	   R   t   resolver_matcht	   namespaceRT   R
   t   getR   (	   R   Rp   Rl   R:   t   schemaR   Rv   t   keyt   url_name(   t   api_root_dictt   schema_generatort   schema_media_types(    sd   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/rest_framework/routers.pyRw   @  s(    
	(   R(   R)   RJ   t   _ignore_model_permissionst   renderer_classesRw   (    (   R{   R|   R}   t   view_renderers(    sd   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/rest_framework/routers.pyRo   <  s   (   R   RF   R-   R   R\   RE   Rj   Rf   Ri   R   Rg   Rr   R   t   APIViewRb   (   R   t   api_urlst	   list_nameR   R    Ra   t   rendererRo   (    (   R{   R|   R}   R€   sd   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/rest_framework/routers.pyt   get_api_root_view$  s     				( c         C  st   t  t |  ƒ j ƒ  } |  j rX |  j d | ƒ } t d | d |  j ƒ} | j | ƒ n  |  j rp 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-   (
   R0   Re   R$   t   include_root_viewR…   R   t   root_view_nameR   t   include_format_suffixesR   (   R   R'   Rd   t   root_url(    (    sd   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/rest_framework/routers.pyR$   ^  s    		N(   R(   R)   t   __doc__RJ   R†   Rˆ   R‡   R   t   CoreJSONRendererRh   R   R   R…   R$   (    (    (    sd   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/rest_framework/routers.pyRe     s   	:($   RŠ   t
   __future__R    R   t   collectionsR   R   t   django.conf.urlsR   t   django.core.exceptionsR   t   django.core.urlresolversR   t   rest_frameworkR   R   R   t   rest_framework.responseR	   t   rest_framework.reverseR
   t   rest_framework.schemasR   t   rest_framework.settingsR   t   rest_framework.urlpatternsR   R>   RK   RL   R   R   t   objectR   R+   Re   (    (    (    sd   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/rest_framework/routers.pyt   <module>   s(   		·