
    ^f/                     N   d Z ddlZddlmZmZ ddlm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 dd
lmZ ddlmZ ddlmZ  edg d          Z edg d          Zd Zd Z G d d          Z G d de          Z G d dej                  Z G d de          Z dS )a  
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
    N)OrderedDict
namedtuple)ImproperlyConfigured)NoReverseMatchre_path)views)Response)reverse)SchemaGenerator)
SchemaView)api_settings)format_suffix_patternsRouteurlmappingnamedetail
initkwargsDynamicRouter   r   r   r   c                 V    |                      dd                               dd          S )zK
    Double brackets in regex of url_path for escape string formatting
    {z{{}z}})replace)url_paths    H/var/www/html/env/lib/python3.11/site-packages/rest_framework/routers.pyescape_curly_bracketsr   "   s*     C&&..sD999    c                     t          j        |  S )zX
    Takes an iterable of iterables, returns a single iterable containing all items
    )	itertoolschain)list_of_listss    r   flattenr$   )   s     ?M**r   c                   >    e Zd Zd ZddZd Zd Zed             ZdS )
BaseRouterc                     g | _         d S N)registryselfs    r   __init__zBaseRouter.__init__1   s    r   Nc                     ||                      |          }| j                            |||f           t          | d          r| `d S d S N_urls)get_default_basenamer)   appendhasattrr/   )r+   prefixviewsetbasenames       r   registerzBaseRouter.register4   s_    0099Hfgx8999 4!! 	


	 	r   c                      t          d          )q
        If `basename` is not specified, attempt to automatically determine
        it from the viewset.
        z'get_default_basename must be overriddenNotImplementedError)r+   r4   s     r   r0   zBaseRouter.get_default_basename=   s    
 ""KLLLr   c                      t          d          )zO
        Return a list of URL patterns, given the registered viewsets.
        zget_urls must be overriddenr9   r*   s    r   get_urlszBaseRouter.get_urlsD   s     ""?@@@r   c                 b    t          | d          s|                                 | _        | j        S r.   )r2   r<   r/   r*   s    r   urlszBaseRouter.urlsJ   s+    tW%% 	)DJzr   r(   )	__name__
__module____qualname__r,   r6   r0   r<   propertyr>    r   r   r&   r&   0   sv             M M MA A A   X  r   r&   c            
            e Zd Z eddddddddi	           ed
ddi            eddddddddddi	           edddi           gZd fd	Zd Zd Zd Z	d Z
d dZd Z xZS )!SimpleRouterz^{prefix}{trailing_slash}$listcreate)getpostz{basename}-listFsuffixListr   z%^{prefix}/{url_path}{trailing_slash}$z{basename}-{url_name}r   z#^{prefix}/{lookup}{trailing_slash}$retrieveupdatepartial_updatedestroy)rH   putpatchdeletez{basename}-detailTInstancez.^{prefix}/{lookup}/{url_path}{trailing_slash}$c                 ^    |rdnd| _         t                                                       d S )N/ )trailing_slashsuperr,   )r+   rW   	__class__s     r   r,   zSimpleRouter.__init__~   s0    %3;ccr   c                     t          |dd          }|
J d            |j        j        j                                        S )r8   querysetNz`basename` argument not specified, and could not automatically determine the name from the viewset, as it does not have a `.queryset` attribute.)getattrmodel_metaobject_namelower)r+   r4   r[   s      r   r0   z!SimpleRouter.get_default_basename   sH    
 7J55## &8### ~#/55777r   c                 &   	 t          t          d  j        D                                 |                                }fd|D             }|r'd}t	          |d                    |          z            d |D             }d |D             }g } j        D ]u	t          	t                    r	j        r|	 fd|D             z  }1t          	t                    r	j        s|	 fd|D             z  }`|	                    	           v|S )	z
        Augment `self.routes` with any dynamically generated routes.

        Returns a list of the Route namedtuple.
        c                 j    g | ]0}t          |t                    |j                                        1S rC   )
isinstancer   r   values).0routes     r   
<listcomp>z+SimpleRouter.get_routes.<locals>.<listcomp>   s8    %r%r%rYcdikpYqYq%rem&:&:&<&<%r%r%rr   c                 0    g | ]}|j         v |j         S rC   )r?   )re   actionknown_actionss     r   rg   z+SimpleRouter.get_routes.<locals>.<listcomp>   s2     
 
 
 &-// O///r   zZCannot use the @action decorator on the following methods, as they are existing routes: %sz, c                      g | ]}|j         	|S rC   r   re   ri   s     r   rg   z+SimpleRouter.get_routes.<locals>.<listcomp>   s    NNNVN&NNNr   c                      g | ]}|j         	|S rC   rl   rm   s     r   rg   z+SimpleRouter.get_routes.<locals>.<listcomp>   s    PPP6&-PPPPr   c                 <    g | ]}                     |          S rC   _get_dynamic_routere   ri   rf   r+   s     r   rg   z+SimpleRouter.get_routes.<locals>.<listcomp>   s)    ___f4225&AA___r   c                 <    g | ]}                     |          S rC   rp   rr   s     r   rg   z+SimpleRouter.get_routes.<locals>.<listcomp>   s)    ]]]f4225&AA]]]r   )
rF   r$   routesget_extra_actionsr   joinrc   r   r   r1   )
r+   r4   extra_actionsnot_allowedmsgdetail_actionslist_actionsrt   rj   rf   s
   `       @@r   
get_routeszSimpleRouter.get_routes   sp    W%r%r$+%r%r%rsstt1133
 
 
 
*7
 
 
  	E>C&sTYY{-C-C'CDDD ON}NNNPP]PPP[ 	% 	%E%.. %5< %_____P^____E<00 % %]]]]]P\]]]]e$$$$r   c                 :   |j                                         }|                    |j                   t	          |j                  }t          |j                            d|          |j	        |j
                            d|j                  |j        |          S )Nz
{url_path}z
{url_name}r   )r   copyrM   kwargsr   r   r   r   r   r   r   url_namer   )r+   rf   ri   r   r   s        r   rq   zSimpleRouter._get_dynamic_route   s    %**,,
&-((((99	!!,99N##L&/BB<!
 
 
 	
r   c                 h    i }|                                 D ]\  }}t          ||          r|||<   |S )z
        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.
        )itemsr2   )r+   r4   
method_mapbound_methodsmethodri   s         r   get_method_mapzSimpleRouter.get_method_map   sK     (..00 	/ 	/NFFw'' /(.f%r   rV   c                     d}t          |dd          }t          |dd          p|}t          |dd          }|                    |||          S )	a  
        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
        z5(?P<{lookup_prefix}{lookup_url_kwarg}>{lookup_value})lookup_fieldpklookup_url_kwargNlookup_value_regexz[^/.]+)lookup_prefixr   lookup_value)r\   format)r+   r4   r   
base_regexr   r   r   s          r   get_lookup_regexzSimpleRouter.get_lookup_regex   sm     M
 w=="7,>EEUw(<hGG  '-% ! 
 
 	
r   c           	      J   g }| j         D ]\  }}}|                     |          }|                     |          }|D ]}|                     ||j                  }|s |j                            ||| j                  }	|s|	dd         dk    rd|	dd         z   }	|j        	                                }
|

                    ||j        d            |j        |fi |
}|j                            |          }|                    t          |	||                     |S )	zQ
        Use the registered viewsets to generate a list of URL patterns.
        )r3   lookuprW   N   z^/^)r5   r   r5   r   )r)   r   r|   r   r   r   r   rW   r   r~   rM   r   as_viewr   r1   r   )r+   retr3   r4   r5   r   rt   rf   r   regexr   viewr   s                r   r<   zSimpleRouter.get_urls   sp    )- !	< !	<%FGX**733F__W--F < < --gu}EE  	((!!#'#6 )    ,%)t"3"3%)OE"-2244
!! (#l# #   
 'ww==*==z((((;;

75$T:::;;;;;<> 
r   )T)rV   )r?   r@   rA   r   r   rt   r,   r0   r|   rq   r   r   r<   __classcell__rY   s   @r   rE   rE   Q   sb        	-   # &)		
 		
 		
 	8(		
 	
 	
 	6!)#	  % *-	
 	
 	
 	A(		
 	
 	
G)FV     8 8 8" " "H
 
 

 
 

 
 
 
.) ) ) ) ) ) )r   rE   c                   $    e Zd ZdZdZdZdZd ZdS )APIRootViewz7
    The default basic root view for DefaultRouter
    TNc           
         t                      }|j        j        }| j                                        D ]J\  }}|r|dz   |z   }	 t          |||||                    d                    ||<   ;# t          $ r Y Gw xY wt          |          S )N:r   )argsr   requestr   )	r   resolver_match	namespaceapi_root_dictr   r
   rH   r   r	   )r+   r   r   r   r   r   keyr   s           r   rH   zAPIRootView.get  s    mm*4	!/5577 	 	MC 6$s?X5
"!#!::h//  C "    }}s   *A//
A<;A<)r?   r@   rA   __doc___ignore_model_permissionsschemar   rH   rC   r   r   r   r     s?          !%FM    r   r   c                   P     e Zd ZdZdZdZdZdZeZe	Z
eZ fdZddZ fdZ xZS )	DefaultRouterz
    The default router extends the SimpleRouter, but also adds in a default
    API root view, and adds format suffix patterns to the URLs.
    Tzapi-rootNc                     d|v r|                     d          | _        nt          t          j                  | _         t                      j        |i | d S )Nroot_renderers)popr   rF   r   DEFAULT_RENDERER_CLASSESrX   r,   )r+   r   r   rY   s      r   r,   zDefaultRouter.__init__;  s[    v%%"(**-=">">D"&|'L"M"MD$)&)))))r   c                     t                      }| j        d         j        }| j        D ]\  }}}|                    |          ||<    | j                            |          S )z+
        Return a basic root view.
        r   r   )r   )r   rt   r   r)   r   r   r   )r+   api_urlsr   	list_namer3   r4   r5   s          r   get_api_root_viewzDefaultRouter.get_api_root_viewB  sm     $KN'	)- 	H 	H%FGX$-$4$4h$4$G$GM&!!''m'DDDr   c                    t                                                      }| j        rB|                     |          }t	          d|| j                  }|                    |           | j        rt          |          }|S )z
        Generate the list of URL patterns, including a default root view
        for the API, and appending `.json` style format suffixes.
        )r   z^$r   )	rX   r<   include_root_viewr   r   root_view_namer1   include_format_suffixesr   )r+   r>   r   root_urlrY   s       r   r<   zDefaultRouter.get_urlsM  s    
 ww!!! 	"))4)88Dud1DEEEHKK!!!' 	0)$//Dr   r(   )r?   r@   rA   r   r   r   r   default_schema_renderersr   r   APISchemaViewr   r,   r   r<   r   r   s   @r   r   r   .  s          "N#KM%O* * * * *	E 	E 	E 	E        r   r   )!r   r!   collectionsr   r   django.core.exceptionsr   django.urlsr   r   rest_frameworkr   rest_framework.responser	   rest_framework.reverser
   rest_framework.schemasr   rest_framework.schemas.viewsr   rest_framework.settingsr   rest_framework.urlpatternsr   r   r   r   r$   r&   rE   APIViewr   r   rC   r   r   <module>r      s        / / / / / / / / 7 7 7 7 7 7 / / / / / / / /             , , , , , , * * * * * * 2 2 2 2 2 2 3 3 3 3 3 3 0 0 0 0 0 0 = = = = = =
7NNNOOz.*Q*Q*QRR: : :+ + +       B| | | | |: | | |~    %-   <. . . . .L . . . . .r   