Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
djangorestframework / __pycache__ / routers.cpython-35.pyc
Size: Mime:


«¬šYž8ã@s¨dZddlmZddlZddlZddlmZmZddlm	Z	ddl
mZddlm
Z
ddlmZdd	lmZdd
lmZddlmZmZddlmZdd
lmZedddddgƒZeddddgƒZeddddgƒZdd„Zdd„Zdd„Z Gdd„de!ƒZ"Gdd„de"ƒZ#Gdd „d e
j$ƒZ%Gd!d"„d"e#ƒZ&dS)#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
é)Úunicode_literalsN)ÚOrderedDictÚ
namedtuple)Úurl)ÚImproperlyConfigured)Úviews)ÚNoReverseMatch)ÚResponse)Úreverse)ÚSchemaGeneratorÚ
SchemaView)Úapi_settings)Úformat_suffix_patternsÚRouterÚmappingÚnameÚ
initkwargsÚDynamicDetailRouteÚDynamicListRoutecCs4do	d|kr0|jddƒjddƒ}|S)zK
    Double brackets in regex of url_path for escape string formatting
    Ú{Ú}z{{z}})Úreplace)Úurl_path©rúU/Users/carlton/Documents/Django-Stack/django-rest-framework/rest_framework/routers.pyÚescape_curly_brackets&srcCs@|jddƒ}|}|jd|ƒ}|jd|ƒ}|S)zs
    Partially format a format_string, swapping out any
    '{methodname}' or '{methodnamehyphen}' components.
    Ú_ú-z{methodname}z{methodnamehyphen})r)Ú
format_stringÚ
methodnameZmethodnamehyphenÚretrrrÚreplace_methodname/s
r!cCs
tj|ŒS)zX
    Takes an iterable of iterables, returns a single iterable containing all items
    )Ú	itertoolsÚchain)Z
list_of_listsrrrÚflatten;sr$c@sUeZdZdd„Zddd„Zdd„Zdd	„Zed
d„ƒZdS)Ú
BaseRoutercCs
g|_dS)N)Úregistry)ÚselfrrrÚ__init__CszBaseRouter.__init__NcCs8|dkr|j|ƒ}|jj|||fƒdS)N)Úget_default_base_namer&Úappend)r'ÚprefixÚviewsetÚ	base_namerrrÚregisterFszBaseRouter.registercCstdƒ‚dS)zr
        If `base_name` is not specified, attempt to automatically determine
        it from the viewset.
        z(get_default_base_name must be overriddenN)ÚNotImplementedError)r'r,rrrr)Ksz BaseRouter.get_default_base_namecCstdƒ‚dS)zO
        Return a list of URL patterns, given the registered viewsets.
        zget_urls must be overriddenN)r/)r'rrrÚget_urlsRszBaseRouter.get_urlscCs%t|dƒs|jƒ|_|jS)NÚ_urls)Úhasattrr0r1)r'rrrÚurlsXszBaseRouter.urls)	Ú__name__Ú
__module__Ú__qualname__r(r.r)r0Úpropertyr3rrrrr%Bs
r%cseZdZedddddddidd	d
ddiƒedd
ddd
iƒedddddddddddiddd
ddiƒeddddd
iƒgZd‡fdd†Zdd„Zdd „Z	d!d"„Z
d#d$d%„Zd&d'„Z‡S)(ÚSimpleRouterrz^{prefix}{trailing_slash}$rÚgetÚlistÚpostÚcreaterz{basename}-listrÚsuffixÚListz'^{prefix}/{methodname}{trailing_slash}$z{basename}-{methodnamehyphen}z#^{prefix}/{lookup}{trailing_slash}$ÚretrieveÚputÚupdateÚpatchZpartial_updateÚdeleteÚdestroyz{basename}-detailÚInstancez0^{prefix}/{lookup}/{methodname}{trailing_slash}$Tcs,|rdpd|_tt|ƒjƒdS)Nú/Ú)Útrailing_slashÚsuperr8r()r'rH)Ú	__class__rrr(‰szSimpleRouter.__init__cCs=t|ddƒ}|dk	s*tdƒ‚|jjjjƒS)zr
        If `base_name` is not specified, attempt to automatically determine
        it from the viewset.
        ÚquerysetNz‘`base_name` argument not specified, and could not automatically determine the name from the viewset, as it does not have a `.queryset` attribute.)ÚgetattrÚAssertionErrorÚmodelÚ_metaÚobject_nameÚlower)r'r,rKrrrr)sz"SimpleRouter.get_default_base_namecscttdd„|jDƒƒƒ}g}g}x«tˆƒD]}tˆ|ƒ}t|ddƒ}t|ddƒ}|r;||kr–td|ƒ‚dd„|Dƒ}|rÅ|j||fƒq;|j||fƒq;W‡fd	d
†}	g}
xh|jD]]}t|tƒr)|
|	||ƒ7}
qþt|t	ƒrN|
|	||ƒ7}
qþ|
j|ƒqþW|
S)z
        Augment `self.routes` with any dynamically generated routes.

        Returns a list of the Route namedtuple.
        cSs.g|]$}t|tƒr|jjƒ‘qSr)Ú
isinstancerrÚvalues)Ú.0Úrouterrrú
<listcomp>¢s	z+SimpleRouter.get_routes.<locals>.<listcomp>Zbind_to_methodsNÚdetailTz\Cannot use @detail_route or @list_route decorators on method "%s" as it is an existing routecSsg|]}|jƒ‘qSr)rQ)rTÚmethodrrrrV±s	csÞg}xÑ|D]É\}‰tˆˆƒj}|jjƒ}|j|ƒ|jddƒp\ˆ}t|ƒ}|jddƒp€|}|jtdt	|j
|ƒd‡fdd†|Dƒdt	|j|ƒd|ƒƒq
W|S)	NrÚurl_namerrcsi|]}ˆ|“qSrr)rTZ
httpmethod)rrrú
<dictcomp>Âs	zHSimpleRouter.get_routes.<locals>._get_dynamic_routes.<locals>.<dictcomp>rr)rLÚkwargsrÚcopyrAÚpoprr*rr!rr)rUZdynamic_routesr ÚhttpmethodsZ
method_kwargsrrrY)r,)rrÚ_get_dynamic_routes·s
z4SimpleRouter.get_routes.<locals>._get_dynamic_routes)
r:r$ÚroutesÚdirrLrr*rRrr)r'r,Z
known_actionsZ
detail_routesZlist_routesrÚattrr^rWr_r rUr)r,rÚ
get_routesšs0"
zSimpleRouter.get_routescCs@i}x3|jƒD]%\}}t||ƒr|||<qW|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'r,Z
method_mapZ
bound_methodsrXÚactionrrrÚget_method_map×s
zSimpleRouter.get_method_maprGcCs^d}t|ddƒ}t|ddƒp-|}t|ddƒ}|jd|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_kwargNZlookup_value_regexz[^/.]+Ú
lookup_prefixÚlookup_value)rLÚformat)r'r,rjZ
base_regexrgrirkrrrÚget_lookup_regexãs	zSimpleRouter.get_lookup_regexc	Csg}x|jD]÷\}}}|j|ƒ}|j|ƒ}xÇ|D]¿}|j||jƒ}|shqD|jjd|d|d|jƒ}	|r½|	dd…dkr½d|	dd…}	|j||j	}
|j
jd|ƒ}|jt|	|
d	|ƒƒqDWqW|S)
zQ
        Use the registered viewsets to generate a list of URL patterns.
        r+ÚlookuprHNéz^/ú^Úbasenamer)r&rmrcrfrrrlrHÚas_viewrrr*)r'r r+r,rqrnr`rUrÚregexÚviewrrrrr0ús$
$zSimpleRouter.get_urls)
r4r5r6rrrr`r(r)rcrfrmr0rr)rJrr8_s8
=r8c@s4eZdZdZdZdZdZdd„ZdS)ÚAPIRootViewz7
    The default basic root view for DefaultRouter
    TNcOs£tƒ}|jj}x|jjƒD]p\}}|rE|d|}y8t|d|d|d|d|jddƒƒ||<Wq%tk
r”w%Yq%Xq%Wt|ƒS)Nú:Úargsr[Úrequestrl)	rÚresolver_matchÚ	namespaceÚ
api_root_dictrdr
r9rr	)r'rxrwr[r rzÚkeyrYrrrr9(s	
zAPIRootView.get)r4r5r6Ú__doc__Z_ignore_model_permissionsZexclude_from_schemar{r9rrrrru s
rucs‚eZdZdZdZdZdZdZeZe	Z
eZ‡fdd†Zddd„Z
dd	d
„Z‡fdd†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.
    Tzapi-rootNcsüd|kr"tjdtddƒd|krFd|ksFtdƒ‚d|krjd|ksjtdƒ‚|jddƒ|_|jddƒ|_|jd|jƒ|_d|krÍ|jdƒ|_	nt
tjƒ|_	t
t|ƒj||ŽdS)	NÚschema_titlez\Including a schema directly via a router is now deprecated. Use `get_schema_view()` instead.Ú
stacklevelroÚschema_renderersz Missing "schema_title" argument.Ú
schema_urlÚroot_renderers)ÚwarningsÚwarnÚDeprecationWarningrMr]rr‚Údefault_schema_renderersrrƒr:r
ÚDEFAULT_RENDERER_CLASSESrIr~r()r'rwr[)rJrrr(Ks
zDefaultRouter.__init__cCs@|jd|jd|jd|ƒ}|jjd|jd|ƒS)z,
        Return a schema root view.
        ÚtitlerÚpatternsZrenderer_classesÚschema_generator)rrr‚Ú
APISchemaViewrrr)r'Úapi_urlsr‹rrrÚget_schema_root_view`s					z"DefaultRouter.get_schema_root_viewcCs_tƒ}|jdj}x0|jD]%\}}}|jd|ƒ||<q#W|jjd|ƒS)z+
        Return a basic root view.
        rrqr{)rr`rr&rlrurr)r'rr{Z	list_namer+r,rqrrrÚget_api_root_viewos
	zDefaultRouter.get_api_root_viewcsŒtt|ƒjƒ}|jrs|jr<|jd|ƒ}n|jd|ƒ}td|d|jƒ}|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)rIr~r0Úinclude_root_viewrrŽrrÚroot_view_namer*Úinclude_format_suffixesr)r'r3rtZroot_url)rJrrr0zs		
	zDefaultRouter.get_urls)r4r5r6r}rr’r‘r‡rurrŒrr(rŽrr0rr)rJrr~>sr~)'r}Ú
__future__rr"r„ÚcollectionsrrÚdjango.conf.urlsrÚdjango.core.exceptionsrÚrest_frameworkrÚrest_framework.compatrZrest_framework.responser	Úrest_framework.reverser
Zrest_framework.schemasrrÚrest_framework.settingsr
Zrest_framework.urlpatternsrrrrrr!r$Úobjectr%r8ZAPIViewrur~rrrrÚ<module>s.	Á