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


«¬šY8ã@s(dZddlmZddlZddlmZddlmZddlm	Z	ddl
mZddlm
Z
dd	lmZdd
lmZmZddlmZdd
„ZGdd„deƒZGdd„deƒZdd„Zdd„ZGdd„deƒZGdd„deƒZdS)a~
The Request class is used as a wrapper around the standard request object.

The wrapped request then offers a richer API, in particular :

    - content automatically parsed according to `Content-Type` header,
      and available as `request.data`
    - full support of PUT method, including support for file uploads
    - form overloading of HTTP method, content type and content
é)Úunicode_literalsN)Úsettings)Ú	QueryDict)Úparse_header)ÚRawPostDataException)Úsix)ÚMultiValueDict)ÚHTTP_HEADER_ENCODINGÚ
exceptions)Úapi_settingscCs1t|jtƒƒ\}}|dkp0|dkS)zC
    Return True if the media type is a valid form media type.
    z!application/x-www-form-urlencodedzmultipart/form-data)rÚencoder	)Ú
media_typeZbase_media_typeÚparams©rúU/Users/carlton/Documents/Django-Stack/django-rest-framework/rest_framework/request.pyÚis_form_media_typesrc@s:eZdZdZdd„Zdd„Zdd„ZdS)	Úoverride_methoda
    A context manager that temporarily overrides the method on a request,
    additionally setting the `view.request` attribute.

    Usage:

        with override_method(view, request, 'POST') as request:
            ... # Do stuff with `view` and `request`
    cCs4||_||_||_t|ddƒ|_dS)NÚaction)ÚviewÚrequestÚmethodÚgetattrr)ÚselfrrrrrrÚ__init__.s			zoverride_method.__init__cCsXt|j|jƒ|j_t|jdiƒ}|j|jjƒƒ|j_|jjS)NÚ
action_map)Ú
clone_requestrrrrÚgetÚlowerr)rrrrrÚ	__enter__4szoverride_method.__enter__cOs"|j|j_|j|j_dS)N)rrr)rÚargsÚkwargrrrÚ__exit__;szoverride_method.__exit__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rrr!rrrrr#s	rc@seZdZdZdS)ÚEmptyz`
    Placeholder for unset attributes.
    Cannot use `None`, as that may be a valid value.
    N)r"r#r$r%rrrrr&@sr&cCst||ƒtk	S)N)rr&)ÚobjÚnamerrrÚ_hasattrHsr)cCs<td|jd|jd|jd|jd|jƒ}|j|_|j|_|j|_|j	|_	|j
|_
||_t|dƒr–|j
|_
t|dƒr±|j|_t|dƒrÌ|j|_t|d	ƒrç|j|_t|d
ƒr|j|_t|dƒr|j|_t|dƒr8|j|_|S)
z–
    Internal helper method to clone a request, replacing with a different
    HTTP method.  Used for checking permissions against other methods.
    rÚparsersÚauthenticatorsÚ
negotiatorÚparser_contextÚ_userÚ_authÚ_authenticatorÚaccepted_rendererÚaccepted_media_typeÚversionÚversioning_scheme)ÚRequestÚ_requestr*r+r,r-Ú_dataÚ_filesÚ
_full_dataÚ
_content_typeÚ_streamrÚhasattrr.r/r0r1r2r3r4)rrÚretrrrrLs4				rc@s.eZdZdZdd„Zdd„ZdS)ÚForcedAuthenticationzy
    This authentication class is used if the test client or request factory
    forcibly authenticated the request.
    cCs||_||_dS)N)Ú
force_userÚforce_token)rr?r@rrrrss	zForcedAuthentication.__init__cCs|j|jfS)N)r?r@)rrrrrÚauthenticatewsz!ForcedAuthentication.authenticateN)r"r#r$r%rrArrrrr>msr>cseZdZdZdddddd„Zdd„Zedd„ƒZed	d
„ƒZedd„ƒZ	ed
d„ƒZ
edd„ƒZejdd„ƒZedd„ƒZ
e
jdd„ƒZ
edd„ƒZdd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Z‡fd#d$†Zed%d&„ƒZed'd(„ƒZed)d*„ƒZed+d,„ƒZd-d.„Z‡S)/r5at
    Wrapper allowing to enhance a standard `HttpRequest` instance.

    Kwargs:
        - request(HttpRequest). The original request instance.
        - parsers_classes(list/tuple). The parsers to use for parsing the
          request content.
        - authentication_classes(list/tuple). The authentications used to try
          authenticating the request's user.
    Nc	Cs||_|pf|_|p!f|_|p6|jƒ|_||_t|_t|_t|_	t|_
t|_|jdkrŠi|_||jd<|jp¦t
j|jd<t|ddƒ}t|ddƒ}|dk	sì|dk	rt||ƒ}|f|_dS)NrÚencodingZ_force_auth_userZ_force_auth_token)r6r*r+Ú_default_negotiatorr,r-r&r7r8r9r:r;rBrÚDEFAULT_CHARSETrr>)	rrr*r+r,r-r?r@Zforced_authrrrr‡s&								
zRequest.__init__cCs
tjƒS)N)rÚ!DEFAULT_CONTENT_NEGOTIATION_CLASS)rrrrrCŸszRequest._default_negotiatorcCs(|jj}|jd|jddƒƒS)NÚCONTENT_TYPEZHTTP_CONTENT_TYPEÚ)r6ÚMETAr)rÚmetarrrÚcontent_type¢szRequest.content_typecCs t|dƒs|jƒ|jS)zS
        Returns an object that may be used to stream the request content.
        r;)r)Ú_load_streamr;)rrrrÚstream§s
zRequest.streamcCs
|jjS)zA
        More semantically correct name for request.GET.
        )r6ÚGET)rrrrÚquery_params°szRequest.query_paramscCs t|dƒs|jƒ|jS)Nr9)r)Ú_load_data_and_filesr9)rrrrÚdata·s
zRequest.datacCs t|dƒs|jƒ|jS)z—
        Returns the user associated with the current request, as authenticated
        by the authentication classes provided to the request.
        r.)r<Ú
_authenticater.)rrrrÚuser½s
zRequest.usercCs||_||j_dS)ak
        Sets the user on the current request. This is necessary to maintain
        compatibility with django.contrib.auth where the user property is
        set in the login and logout functions.

        Note that we also set the user on Django's underlying `HttpRequest`
        instance, ensuring that it is available to any middleware in the stack.
        N)r.r6rR)rÚvaluerrrrRÇs
	cCs t|dƒs|jƒ|jS)z‡
        Returns any non-user authentication information associated with the
        request, such as an authentication token.
        r/)r<rQr/)rrrrÚauthÔs
zRequest.authcCs||_||j_dS)z„
        Sets any non-user authentication information associated with the
        request, such as an authentication token.
        N)r/r6rT)rrSrrrrTÞs	cCs t|dƒs|jƒ|jS)zˆ
        Return the instance of the authentication instance class that was used
        to authenticate the request, or `None`.
        r0)r<rQr0)rrrrÚsuccessful_authenticatorçs
z Request.successful_authenticatorcCswt|dƒss|jƒ\|_|_|jrX|jjƒ|_|jj|jƒn|j|_|j|j_dS)z>
        Parses the request content into `self.data`.
        r7N)r)Ú_parser7r8Úcopyr9Úupdater6)rrrrrOñs	zRequest._load_data_and_filescCs¡|jj}y(t|jd|jddƒƒƒ}Wnttfk
rTd}YnX|dkrmd|_n0|jjsˆ|j|_ntj	|j
ƒ|_dS)zF
        Return the content body of the request, as a stream.
        ÚCONTENT_LENGTHZHTTP_CONTENT_LENGTHrN)r6rHÚintrÚ
ValueErrorÚ	TypeErrorr;Ú
_read_startedrÚBytesIOÚbody)rrIÚcontent_lengthrrrrKs%zRequest._load_streamcs&d‰t‡fdd†|jDƒƒS)zJ
        Return True if this requests supports parsing form data.
        ú!application/x-www-form-urlencodedúmultipart/form-datacsg|]}|jˆk‘qSr)r
)Ú.0Úparser)Ú
form_mediarrú
<listcomp>s	z2Request._supports_form_parsing.<locals>.<listcomp>)rarb)Úanyr*)rr)rerÚ_supports_form_parsingszRequest._supports_form_parsingcCs‘|j}y
|j}WnOtk
rgt|jdƒs;‚|jƒr]|jj|jjfSd}YnX|dks€|dkrÇ|r®t|ƒr®t	dd|jj
ƒ}ni}tƒ}||fS|jj
||jƒ}|sôtj|ƒ‚y|j|||jƒ}Wn>t	dd|jj
ƒ|_tƒ|_|j|_‚YnXy|j|jfSWn%tk
rŒtƒ}||fSYnXdS)zœ
        Parse the request content, returning a two-tuple of (data, files)

        May raise an `UnsupportedMediaType`, or `ParseError` exception.
        Ú_postNrGrB)rJrLrr<r6rhÚPOSTÚFILESrrÚ	_encodingrr,Z
select_parserr*r
ÚUnsupportedMediaTypeÚparser-r7r8r9rPÚfilesÚAttributeError)rr
rLZ
empty_dataZempty_filesrdÚparsedrrrrVs<	

	

	zRequest._parsecCs…xt|jD]i}y|j|ƒ}Wn"tjk
rG|jƒ‚YnX|dk	r
||_|\|_|_dSq
W|jƒdS)zi
        Attempt to authenticate the request using each authentication instance
        in turn.
        N)r+rAr
ÚAPIExceptionÚ_not_authenticatedr0rRrT)rZ
authenticatorZuser_auth_tuplerrrrQRs
	zRequest._authenticatecCsUd|_tjr$tjƒ|_n	d|_tjrHtjƒ|_n	d|_dS)z
        Set authenticator, user & authtoken representing an unauthenticated request.

        Defaults are None, AnonymousUser & None.
        N)r0rÚUNAUTHENTICATED_USERrRÚUNAUTHENTICATED_TOKENrT)rrrrrses				zRequest._not_authenticatedcsŠytt|ƒj|ƒSWnitk
r…tjƒ}yt|j|ƒSWn4tk
r€tj	|d|d|dj
ƒYnXYnXdS)z‘
        If an attribute does not exist on this instance, then we also attempt
        to proxy it to the underlying HttpRequest object.
        rééN)Úsuperr5Ú__getattribute__rpÚsysÚexc_inforr6rÚreraiseÚtb_next)rÚattrÚinfo)Ú	__class__rrryws

zRequest.__getattribute__cCstdƒ‚dS)Nz~`request.DATA` has been deprecated in favor of `request.data` since version 3.0, and has been fully removed as of version 3.2.)ÚNotImplementedError)rrrrÚDATA…szRequest.DATAcCsEt|dƒs|jƒt|jƒr/|jStdd|jjƒS)Nr7rGrB)r)rOrrJr7rr6rl)rrrrrjŒs

zRequest.POSTcCs t|dƒs|jƒ|jS)Nr8)r)rOr8)rrrrrk•s
z
Request.FILEScCstdƒ‚dS)NzŽ`request.QUERY_PARAMS` has been deprecated in favor of `request.query_params` since version 3.0, and has been fully removed as of version 3.2.)r)rrrrÚQUERY_PARAMSžszRequest.QUERY_PARAMScs‡fdd†|j_dS)NcsˆS)Nrr)rSrrÚ<lambda>¨sz0Request.force_plaintext_errors.<locals>.<lambda>)r6Úis_ajax)rrSr)rSrÚforce_plaintext_errors¥szRequest.force_plaintext_errors)r"r#r$r%rrCÚpropertyrJrLrNrPrRÚsetterrTrUrOrKrhrVrQrsryr‚rjrkrƒr†rr)r€rr5{s2
	


	

4		r5)r%Ú
__future__rrzÚdjango.confrÚdjango.httprÚdjango.http.multipartparserrÚdjango.http.requestrÚdjango.utilsrÚdjango.utils.datastructuresrÚrest_frameworkr	r
Úrest_framework.settingsrrÚobjectrr&r)rr>r5rrrrÚ<module>
s"	!