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__ / views.cpython-35.pyc
Size: Mime:


£OY×Fã@svdZddlmZddlmZddlmZddlmZddl	m
Z
ddlmZddl
mZdd	lmZmZdd
lmZddlmZddlmZdd
lmZddlmZmZddlmZddl m!Z!ddl"m#Z#ddl$m%Z%ddl&m'Z'ddd„Z(ddd„Z)dd„Z*Gdd„deƒZ+dS)zL
Provides an APIView class that is the base of all views in REST framework.
é)Úunicode_literals)Úsettings)ÚPermissionDenied)Úmodels)ÚHttp404)ÚHttpResponseBase)Úsix)Úcc_delim_reÚpatch_vary_headers)Ú
smart_text)Ú
ugettext_lazy)Úcsrf_exempt)ÚView)Ú
exceptionsÚstatus)Úset_rollback)ÚRequest)ÚResponse)Úapi_settings)Ú
formattingNcCsT|j}tj|dƒ}tj|dƒ}tj|ƒ}|rP|d|7}|S)zØ
    Given a view class, return a textual name to represent the view.
    This name is used in the browsable API, and in OPTIONS responses.

    This function is the default for the `VIEW_NAME_FUNCTION` setting.
    rZViewSetú )Ú__name__rZremove_trailing_stringZcamelcase_to_spaces)Úview_clsÚsuffixÚname©rúS/Users/carlton/Documents/Django-Stack/django-rest-framework/rest_framework/views.pyÚ
get_view_names	rFcCs;|jpd}tjt|ƒƒ}|r7tj|ƒS|S)zæ
    Given a view class, return a textual description to represent the view.
    This name is used in the browsable API, and in OPTIONS responses.

    This function is the default for the `VIEW_DESCRIPTION_FUNCTION` setting.
    Ú)Ú__doc__rÚdedentrZmarkup_description)rÚhtmlÚdescriptionrrrÚget_view_description+s

r#cCsEt|tjƒr­i}t|ddƒr7|j|d<t|ddƒrZd|j|d<t|jttfƒr~|j}nd|ji}t	ƒt
|d|jd	|ƒSt|tƒr÷t
d
ƒ}dtj|ƒi}t	ƒt
|dtjƒSt|tƒrAt
dƒ}dtj|ƒi}t	ƒt
|dtjƒSdS)a4
    Returns the response that should be used for any given exception.

    By default we handle the REST framework `APIException`, and also
    Django's built-in `Http404` and `PermissionDenied` exceptions.

    Any unhandled exceptions may return `None`, which will cause a 500 error
    to be raised.
    Úauth_headerNzWWW-AuthenticateÚwaitz%dzRetry-AfterÚdetailrÚheadersz
Not found.zPermission denied.)Ú
isinstancerÚAPIExceptionÚgetattrr$r%r&ÚlistÚdictrrÚstatus_coderÚ_rÚ	text_typerÚHTTP_404_NOT_FOUNDrÚHTTP_403_FORBIDDEN)ÚexcÚcontextr'ÚdataÚmsgrrrÚexception_handler9s,

r6cseZdZejZejZejZ	ej
ZejZ
ejZejZejZeZdZe‡fdd†ƒZedd„ƒZedd„ƒZdd	„Zd
dd„Zd
d„Zdd„Zdd„Zdd„Z dd„Z!dd„Z"ddd„Z#dd„Z$dd„Z%dd „Z&d!d"„Z'd#d$„Z(d%d&„Z)d'd(„Z*d)d*„Z+dd+d,„Z,d-d.„Z-d/d0„Z.d1d2„Z/d3d4„Z0d5d6„Z1d7d8„Z2d9d:„Z3d;d<„Z4d=d>„Z5d?d@„Z6dAdB„Z7dCdD„Z8‡S)EÚAPIViewFcsmtt|ddƒtjjƒr9dd„}||j_tt|ƒj	|}||_
||_t|ƒS)zÈ
        Store the original class on the view function.

        This allows us to discover information about the view when we do URL
        reverse lookups.  Used for breadcrumb generation.
        ÚquerysetNcSstdƒ‚dS)NzDo not evaluate the `.queryset` attribute directly, as the result will be cached and reused between requests. Use `.all()` or call `.get_queryset()` instead.)ÚRuntimeErrorrrrrÚforce_evaluation~sz)APIView.as_view.<locals>.force_evaluation)
r(r*rÚqueryÚQuerySetr8Ú
_fetch_allÚsuperr7Úas_viewÚclsÚ
initkwargsr
)r@rAr:Úview)Ú	__class__rrr?us!		zAPIView.as_viewcCs
|jƒS)zZ
        Wrap Django's private `_allowed_methods` interface in a public property.
        )Ú_allowed_methods)ÚselfrrrÚallowed_methodsŽszAPIView.allowed_methodscCs;ddj|jƒi}t|jƒdkr7d|d<|S)NÚAllowz, éÚAcceptÚVary)ÚjoinrFÚlenÚrenderer_classes)rEr'rrrÚdefault_response_headers•s
z APIView.default_response_headerscOstj|jƒ‚dS)z
        If `request.method` does not correspond to a handler method,
        determine what kind of exception to raise.
        N)rÚMethodNotAllowedÚmethod)rEÚrequestÚargsÚkwargsrrrÚhttp_method_not_allowedžszAPIView.http_method_not_allowedNcCs5|jr|jrtjƒ‚tjd|ƒ‚dS)zY
        If request is not permitted, determine what kind of exception to raise.
        r&N)ÚauthenticatorsÚsuccessful_authenticatorrÚNotAuthenticatedr)rErQÚmessagerrrÚpermission_denied¥szAPIView.permission_deniedcCstj|ƒ‚dS)zU
        If request is throttled, determine what kind of exception to raise.
        N)rÚ	Throttled)rErQr%rrrÚ	throttled­szAPIView.throttledcCs'|jƒ}|r#|dj|ƒSdS)z‚
        If a request is unauthenticated, determine the WWW-Authenticate
        header to use for 401 responses, if any.
        rN)Úget_authenticatorsZauthenticate_header)rErQrUrrrÚget_authenticate_header³szAPIView.get_authenticate_headerc	Cs.d|dt|dfƒdt|diƒiS)z|
        Returns a dict that is passed through to Parser.parse(),
        as the `parser_context` keyword argument.
        rBrRrS)r*)rEÚhttp_requestrrrÚget_parser_context¼szAPIView.get_parser_contextcCs@d|dt|dfƒdt|diƒdt|ddƒiS)z
        Returns a dict that is passed through to Renderer.render(),
        as the `renderer_context` keyword argument.
        rBrRrSrQN)r*)rErrrÚget_renderer_contextÉszAPIView.get_renderer_contextcCs@d|dt|dfƒdt|diƒdt|ddƒiS)zp
        Returns a dict that is passed through to EXCEPTION_HANDLER,
        as the `context` argument.
        rBrRrSrQN)r*)rErrrÚget_exception_handler_context×sz%APIView.get_exception_handler_contextcCs(|jj}||jt|ddƒƒS)zf
        Return the view name, as used in OPTIONS responses and in the
        browsable API.
        rN)rÚVIEW_NAME_FUNCTIONrCr*)rEÚfuncrrrrãszAPIView.get_view_namecCs|jj}||j|ƒS)z{
        Return some descriptive text for the view, as used in OPTIONS responses
        and in the browsable API.
        )rÚVIEW_DESCRIPTION_FUNCTIONrC)rEr!rcrrrr#ëszAPIView.get_view_descriptioncKs#|jjr|j|jjƒSdS)zQ
        Determine if the request includes a '.json' style format suffix
        N)rÚFORMAT_SUFFIX_KWARGÚget)rErSrrrÚget_format_suffixõszAPIView.get_format_suffixcCsdd„|jDƒS)zX
        Instantiates and returns the list of renderers that this view can use.
        cSsg|]}|ƒ‘qSrr)Ú.0Úrendererrrrú
<listcomp>s	z)APIView.get_renderers.<locals>.<listcomp>)rM)rErrrÚ
get_renderersüszAPIView.get_rendererscCsdd„|jDƒS)zV
        Instantiates and returns the list of parsers that this view can use.
        cSsg|]}|ƒ‘qSrr)rhÚparserrrrrjs	z'APIView.get_parsers.<locals>.<listcomp>)Úparser_classes)rErrrÚget_parsersszAPIView.get_parserscCsdd„|jDƒS)z]
        Instantiates and returns the list of authenticators that this view can use.
        cSsg|]}|ƒ‘qSrr)rhÚauthrrrrjs	z.APIView.get_authenticators.<locals>.<listcomp>)Úauthentication_classes)rErrrr\szAPIView.get_authenticatorscCsdd„|jDƒS)z[
        Instantiates and returns the list of permissions that this view requires.
        cSsg|]}|ƒ‘qSrr)rhÚ
permissionrrrrjs	z+APIView.get_permissions.<locals>.<listcomp>)Úpermission_classes)rErrrÚget_permissionsszAPIView.get_permissionscCsdd„|jDƒS)zU
        Instantiates and returns the list of throttles that this view uses.
        cSsg|]}|ƒ‘qSrr)rhÚthrottlerrrrjs	z)APIView.get_throttles.<locals>.<listcomp>)Úthrottle_classes)rErrrÚ
get_throttlesszAPIView.get_throttlescCs(t|ddƒs!|jƒ|_|jS)zN
        Instantiate and return the content negotiation class to use.
        Ú_negotiatorN)r*Úcontent_negotiation_classrw)rErrrÚget_content_negotiatorszAPIView.get_content_negotiatorcCs
|jjS)zD
        Returns the exception handler that this view uses.
        )rÚEXCEPTION_HANDLER)rErrrÚget_exception_handler"szAPIView.get_exception_handlercCsi|jƒ}|jƒ}y|j|||jƒSWn0tk
rd|r]|d|djfS‚YnXdS)zU
        Determine which renderer and media type to use render the response.
        rN)rkryZselect_rendererÚformat_kwargÚ	ExceptionÚ
media_type)rErQÚforceÚ	renderersZconnegrrrÚperform_content_negotiation*s
z#APIView.perform_content_negotiationcCs|jdS)a
        Perform authentication on the incoming request.

        Note that if you override this and simply 'pass', then authentication
        will instead be performed lazily, the first time either
        `request.user` or `request.auth` is accessed.
        N)Úuser)rErQrrrÚperform_authentication8szAPIView.perform_authenticationcCsLxE|jƒD]7}|j||ƒs
|j|dt|ddƒƒq
WdS)z„
        Check if the request should be permitted.
        Raises an appropriate exception if the request is not permitted.
        rXN)rsZhas_permissionrYr*)rErQrqrrrÚcheck_permissionsBszAPIView.check_permissionscCsOxH|jƒD]:}|j|||ƒs
|j|dt|ddƒƒq
WdS)z—
        Check if the request should be permitted for a given object.
        Raises an appropriate exception if the request is not permitted.
        rXN)rsZhas_object_permissionrYr*)rErQÚobjrqrrrÚcheck_object_permissionsMsz APIView.check_object_permissionscCsCx<|jƒD].}|j||ƒs
|j||jƒƒq
WdS)z|
        Check if request should be throttled.
        Raises an appropriate exception if the request is throttled.
        N)rvZ
allow_requestr[r%)rErQrtrrrÚcheck_throttlesXszAPIView.check_throttlescOs8|jdkrdS|jƒ}|j|||Ž|fS)z£
        If versioning is being used, then determine any API version for the
        incoming request. Returns a two-tuple of (version, versioning_scheme)
        N)NN)Úversioning_classÚdetermine_version)rErQrRrSÚschemerrrr‰aszAPIView.determine_versionc
OsC|j|ƒ}t|d|jƒd|jƒd|jƒd|ƒS)z5
        Returns the initial request object.
        ÚparsersrUÚ
negotiatorÚparser_context)r_rrnr\ry)rErQrRrSrrrrÚinitialize_requestmszAPIView.initialize_requestcOsŒ|j||_|j|ƒ}|\|_|_|j|||Ž\}}|||_|_|j|ƒ|j	|ƒ|j
|ƒdS)zX
        Runs anything that needs to occur prior to calling the method handler.
        N)rgr|rÚaccepted_rendererÚaccepted_media_typer‰ÚversionÚversioning_schemerƒr„r‡)rErQrRrSÚnegr‘rŠrrrÚinitial{s

zAPIView.initialc	Osùt|tƒs%tdt|ƒƒ‚t|tƒr”t|ddƒsm|j|ddƒ}|\|_|_|j|_|j|_|j	ƒ|_
|jjddƒ}|dk	rËt
|tj|ƒƒx'|jjƒD]\}}|||<qÛW|S)z4
        Returns the final response object.
        zrExpected a `Response`, `HttpResponse` or `HttpStreamingResponse` to be returned from the view, but received a `%s`rNrTrJ)r(rÚAssertionErrorÚtyperr*rrrr`Úrenderer_contextr'Úpopr
r	ÚsplitÚitems)	rErQÚresponserRrSr“Úvary_headersÚkeyÚvaluerrrÚfinalize_responseŽs zAPIView.finalize_responsecCs˜t|tjtjfƒrK|j|jƒ}|r?||_ntj|_	|j
ƒ}|jƒ}|||ƒ}|dkr‹|j|ƒd|_
|S)zz
        Handle any exception that occurs, by returning an appropriate response,
        or re-raising the error.
        NT)r(rrWÚAuthenticationFailedr]rQr$rr1r-r{raÚraise_uncaught_exceptionÚ	exception)rEr2r$r6r3r›rrrÚhandle_exception¬s
	zAPIView.handle_exceptioncCsDtjr=|j}t|jdƒ}|dk}|j|ƒ‚dS)NÚformatr!ÚapiÚadmin)zhtmlzapizadmin)rÚDEBUGrQr*rÚforce_plaintext_errors)rEr2rQZrenderer_formatZuse_plaintext_tracebackrrrr¡Æs		
z APIView.raise_uncaught_exceptioncOs||_||_|j|||Ž}||_|j|_yk|j|||Ž|jjƒ|j	kr‹t
||jjƒ|jƒ}n	|j}||||Ž}Wn4tk
rÝ}z|j
|ƒ}WYdd}~XnX|j||||Ž|_|jS)z¡
        `.dispatch()` is pretty much the same as Django's regular dispatch,
        but with extra hooks for startup, finalize, and exception handling.
        N)rRrSrŽrQrNr'r”rPÚlowerÚhttp_method_namesr*rTr}r£rŸr›)rErQrRrSÚhandlerr›r2rrrÚdispatchÑs 				"zAPIView.dispatchcOsM|jdkr"|j|||ŽS|jƒj||ƒ}t|dtjƒS)z<
        Handler method for HTTP 'OPTIONS' request.
        Nr)Úmetadata_classrTZdetermine_metadatarrÚHTTP_200_OK)rErQrRrSr4rrrÚoptionsîszAPIView.options)9rÚ
__module__Ú__qualname__rÚDEFAULT_RENDERER_CLASSESrMÚDEFAULT_PARSER_CLASSESrmÚDEFAULT_AUTHENTICATION_CLASSESrpÚDEFAULT_THROTTLE_CLASSESruÚDEFAULT_PERMISSION_CLASSESrrÚ!DEFAULT_CONTENT_NEGOTIATION_CLASSrxÚDEFAULT_METADATA_CLASSr­ÚDEFAULT_VERSIONING_CLASSrˆrZexclude_from_schemaÚclassmethodr?ÚpropertyrFrNrTrYr[r]r_r`rarr#rgrkrnr\rsrvryr{rrƒr„r†r‡r‰rŽr”rŸr£r¡r¬r¯rr)rCrr7csV										


	r7),rÚ
__future__rÚdjango.confrÚdjango.core.exceptionsrÚ	django.dbrÚdjango.httprÚdjango.http.responserÚdjango.utilsrÚdjango.utils.cacher	r
Údjango.utils.encodingrÚdjango.utils.translationrr.Zdjango.views.decorators.csrfr
Zdjango.views.genericrÚrest_frameworkrrÚrest_framework.compatrÚrest_framework.requestrÚrest_framework.responserÚrest_framework.settingsrZrest_framework.utilsrrr#r6r7rrrrÚ<module>s,*