ó
pÁìVc           @  sG  d  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 d d	 l m Z d d
 l 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 „ Z$ e% d „ Z& d „  Z' d e f d „  ƒ  YZ( d S(   uL   
Provides an APIView class that is the base of all views in REST framework.
iÿÿÿÿ(   t   unicode_literals(   t   PermissionDenied(   t   models(   t   Http404(   t   HttpResponseBase(   t   six(   t
   smart_text(   t   ugettext_lazy(   t   csrf_exempt(   t   View(   t
   exceptionst   status(   t   set_rollback(   t   Request(   t   Response(   t   api_settings(   t
   formattingc         C  sW   |  j  } t j | d ƒ } t j | d ƒ } t j | ƒ } | rS | d | 7} n  | S(   uØ   
    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.
    u   Viewu   ViewSetu    (   t   __name__R   t   remove_trailing_stringt   camelcase_to_spaces(   t   view_clst   suffixt   name(    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyt   get_view_name   s    	c         C  s;   |  j  p d } t j t | ƒ ƒ } | r7 t j | ƒ S| S(   uæ   
    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.
    u    (   t   __doc__R   t   dedentR   t   markup_description(   R   t   htmlt   description(    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyt   get_view_description)   s
    c         C  sN  t  |  t j ƒ r´ i  } t |  d d ƒ r: |  j | d <n  t |  d d ƒ r` d |  j | d <n  t  |  j t t	 f ƒ r„ |  j } n i |  j d 6} t
 ƒ  t | d |  j d | ƒSt  |  t ƒ rÿ t d	 ƒ } i t j | ƒ d 6} t
 ƒ  t | d t j ƒSt  |  t ƒ rJt d
 ƒ } i t j | ƒ d 6} t
 ƒ  t | d t j ƒSd S(   u4  
    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.
    u   auth_headeru   WWW-Authenticateu   waitu   %du   Retry-Afteru   detailR   t   headersu
   Not found.u   Permission denied.N(   t
   isinstanceR
   t   APIExceptiont   getattrt   Nonet   auth_headert   waitt   detailt   listt   dictR   R   t   status_codeR   t   _R   t	   text_typeR   t   HTTP_404_NOT_FOUNDR   t   HTTP_403_FORBIDDEN(   t   exct   contextR   t   datat   msg(    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyt   exception_handler7   s,    
t   APIViewc           B  sˆ  e  Z e j Z e j Z e j Z e j	 Z
 e j Z e j Z e j Z e j Z e Z e d  „  ƒ Z e d „  ƒ Z e d „  ƒ Z d „  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d	 „  Z  d
 „  Z! e" d „ Z# d „  Z$ d „  Z% d „  Z& d „  Z' d „  Z( d „  Z) d „  Z* e" d „ Z+ d „  Z, d „  Z- d „  Z. d „  Z/ d „  Z0 d „  Z1 d „  Z2 d „  Z3 d „  Z4 d „  Z5 d „  Z6 RS(    c         K  sp   t  t |  d d ƒ t j j ƒ rE d „  } | |  j _ | |  j _ n  t	 t
 |  ƒ j |   } |  | _ t | ƒ S(   uÈ   
        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.
        u   querysetc           S  s   t  d ƒ ‚ d  S(   Nu   Do not evaluate the `.queryset` attribute directly, as the result will be cached and reused between requests. Use `.all()` or call `.get_queryset()` instead.(   t   RuntimeError(    (    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyt   force_evaluationz   s    N(   R   R!   R"   R   t   queryt   QuerySett   querysett
   _fetch_allt   _result_itert   superR2   t   as_viewt   clsR   (   R<   t
   initkwargsR4   t   view(    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyR;   q   s    !		c         C  s
   |  j  ƒ  S(   uZ   
        Wrap Django's private `_allowed_methods` interface in a public property.
        (   t   _allowed_methods(   t   self(    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyt   allowed_methodsŠ   s    c         C  s?   i d j  |  j ƒ d 6} t |  j ƒ d k r; d | d <n  | S(   Nu   , u   Allowi   u   Acceptu   Vary(   t   joinRA   t   lent   renderer_classes(   R@   R   (    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyt   default_response_headers‘   s
    c         O  s   t  j | j ƒ ‚ d S(   u   
        If `request.method` does not correspond to a handler method,
        determine what kind of exception to raise.
        N(   R
   t   MethodNotAllowedt   method(   R@   t   requestt   argst   kwargs(    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyt   http_method_not_allowedš   s    c         C  s.   | j  s t j ƒ  ‚ n  t j d | ƒ ‚ d S(   uY   
        If request is not permitted, determine what kind of exception to raise.
        R%   N(   t   successful_authenticatorR
   t   NotAuthenticatedR   (   R@   RH   t   message(    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyt   permission_denied¡   s    	c         C  s   t  j | ƒ ‚ d S(   uU   
        If request is throttled, determine what kind of exception to raise.
        N(   R
   t	   Throttled(   R@   RH   R$   (    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyt	   throttled©   s    c         C  s'   |  j  ƒ  } | r# | d j | ƒ Sd S(   u‚   
        If a request is unauthenticated, determine the WWW-Authenticate
        header to use for 401 responses, if any.
        i    N(   t   get_authenticatorst   authenticate_header(   R@   RH   t   authenticators(    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyt   get_authenticate_header¯   s    c         C  s1   i |  d 6t  |  d d ƒ d 6t  |  d i  ƒ d 6S(   u|   
        Returns a dict that is passed through to Parser.parse(),
        as the `parser_context` keyword argument.
        u   viewu   argsu   kwargs(    (   R!   (   R@   t   http_request(    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyt   get_parser_context¸   s    c         C  sD   i |  d 6t  |  d d ƒ d 6t  |  d i  ƒ d 6t  |  d d ƒ d 6S(   u   
        Returns a dict that is passed through to Renderer.render(),
        as the `renderer_context` keyword argument.
        u   viewu   argsu   kwargsu   request(    N(   R!   R"   (   R@   (    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyt   get_renderer_contextÅ   s
    c         C  sD   i |  d 6t  |  d d ƒ d 6t  |  d i  ƒ d 6t  |  d d ƒ d 6S(   up   
        Returns a dict that is passed through to EXCEPTION_HANDLER,
        as the `context` argument.
        u   viewu   argsu   kwargsu   request(    N(   R!   R"   (   R@   (    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyt   get_exception_handler_contextÓ   s
    c         C  s(   |  j  j } | |  j t |  d d ƒ ƒ S(   uf   
        Return the view name, as used in OPTIONS responses and in the
        browsable API.
        u   suffixN(   t   settingst   VIEW_NAME_FUNCTIONt	   __class__R!   R"   (   R@   t   func(    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyR   ß   s    c         C  s   |  j  j } | |  j | ƒ S(   u{   
        Return some descriptive text for the view, as used in OPTIONS responses
        and in the browsable API.
        (   RZ   t   VIEW_DESCRIPTION_FUNCTIONR\   (   R@   R   R]   (    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyR   ç   s    c         K  s#   |  j  j r | j |  j  j ƒ Sd S(   uQ   
        Determine if the request includes a '.json' style format suffix
        N(   RZ   t   FORMAT_SUFFIX_KWARGt   get(   R@   RJ   (    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyt   get_format_suffixñ   s    c         C  s   g  |  j  D] } | ƒ  ^ q
 S(   uX   
        Instantiates and returns the list of renderers that this view can use.
        (   RD   (   R@   t   renderer(    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyt   get_renderersø   s    c         C  s   g  |  j  D] } | ƒ  ^ q
 S(   uV   
        Instantiates and returns the list of parsers that this view can use.
        (   t   parser_classes(   R@   t   parser(    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyt   get_parsersþ   s    c         C  s   g  |  j  D] } | ƒ  ^ q
 S(   u]   
        Instantiates and returns the list of authenticators that this view can use.
        (   t   authentication_classes(   R@   t   auth(    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyRR     s    c         C  s   g  |  j  D] } | ƒ  ^ q
 S(   u[   
        Instantiates and returns the list of permissions that this view requires.
        (   t   permission_classes(   R@   t
   permission(    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyt   get_permissions
  s    c         C  s   g  |  j  D] } | ƒ  ^ q
 S(   uU   
        Instantiates and returns the list of throttles that this view uses.
        (   t   throttle_classes(   R@   t   throttle(    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyt   get_throttles  s    c         C  s+   t  |  d d ƒ s$ |  j ƒ  |  _ n  |  j S(   uN   
        Instantiate and return the content negotiation class to use.
        u   _negotiatorN(   R!   R"   t   content_negotiation_classt   _negotiator(   R@   (    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyt   get_content_negotiator  s    c         C  sh   |  j  ƒ  } |  j ƒ  } y | j | | |  j ƒ SWn/ t k
 rc | r] | d | d j f S‚  n Xd S(   uU   
        Determine which renderer and media type to use render the response.
        i    N(   Rc   Rq   t   select_renderert   format_kwargt	   Exceptiont
   media_type(   R@   RH   t   forcet	   rendererst   conneg(    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyt   perform_content_negotiation   s    c         C  s   | j  d S(   u  
        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(   t   user(   R@   RH   (    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyt   perform_authentication.  s    c         C  sO   xH |  j  ƒ  D]: } | j | |  ƒ s |  j | d t | d d ƒ ƒq q Wd S(   u„   
        Check if the request should be permitted.
        Raises an appropriate exception if the request is not permitted.
        RN   u   messageN(   Rk   t   has_permissionRO   R!   R"   (   R@   RH   Rj   (    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyt   check_permissions8  s    c         C  sR   xK |  j  ƒ  D]= } | j | |  | ƒ s |  j | d t | d d ƒ ƒq q Wd S(   u—   
        Check if the request should be permitted for a given object.
        Raises an appropriate exception if the request is not permitted.
        RN   u   messageN(   Rk   t   has_object_permissionRO   R!   R"   (   R@   RH   t   objRj   (    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyt   check_object_permissionsC  s    c         C  sF   x? |  j  ƒ  D]1 } | j | |  ƒ s |  j | | j ƒ  ƒ q q Wd S(   u|   
        Check if request should be throttled.
        Raises an appropriate exception if the request is throttled.
        N(   Rn   t   allow_requestRQ   R$   (   R@   RH   Rm   (    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyt   check_throttlesN  s    c         O  s8   |  j  d k r d S|  j  ƒ  } | j | | | Ž | f S(   u£   
        If versioning is being used, then determine any API version for the
        incoming request. Returns a two-tuple of (version, versioning_scheme)
        N(   NN(   t   versioning_classR"   t   determine_version(   R@   RH   RI   RJ   t   scheme(    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyR„   W  s    c      
   O  sC   |  j  | ƒ } t | d |  j ƒ  d |  j ƒ  d |  j ƒ  d | ƒS(   u5   
        Returns the initial request object.
        t   parsersRT   t
   negotiatort   parser_context(   RW   R   Rf   RR   Rq   (   R@   RH   RI   RJ   Rˆ   (    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyt   initialize_requestc  s    c         O  sŒ   |  j  |   |  _ |  j | ƒ |  j | ƒ |  j | ƒ |  j | ƒ } | \ | _ | _ |  j | | | Ž \ } } | | | _	 | _
 d S(   uX   
        Runs anything that needs to occur prior to calling the method handler.
        N(   Ra   Rs   R{   R}   R‚   Ry   t   accepted_renderert   accepted_media_typeR„   t   versiont   versioning_scheme(   R@   RH   RI   RJ   t   negRŒ   R…   (    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyt   initialq  s    c         O  sÈ   t  | t ƒ s% t d t | ƒ ƒ ‚ t  | t ƒ rš t | d d ƒ sp |  j | d t ƒ} | \ | _	 | _
 n  | j	 | _	 | j
 | _
 |  j ƒ  | _ n  x' |  j j ƒ  D] \ } } | | | <qª W| S(   u4   
        Returns the final response object.
        ur   Expected a `Response`, `HttpResponse` or `HttpStreamingResponse` to be returned from the view, but received a `%s`u   accepted_rendererRv   N(   R   R   t   AssertionErrort   typeR   R!   R"   Ry   t   TrueRŠ   R‹   RX   t   renderer_contextR   t   items(   R@   RH   t   responseRI   RJ   RŽ   t   keyt   value(    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyt   finalize_response„  s    c         C  s”   t  | t j t j f ƒ rN |  j |  j ƒ } | r? | | _ qN t j | _	 n  |  j
 j } |  j ƒ  } | | | ƒ } | d k r‡ ‚  n  t | _ | S(   uz   
        Handle any exception that occurs, by returning an appropriate response,
        or re-raising the error.
        N(   R   R
   RM   t   AuthenticationFailedRU   RH   R#   R   R,   R(   RZ   t   EXCEPTION_HANDLERRY   R"   R’   t	   exception(   R@   R-   R#   R1   R.   R•   (    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyt   handle_exception  s    	c         O  sî   | |  _  | |  _ |  j | | | Ž } | |  _ |  j |  _ yk |  j | | | Ž | j j ƒ  |  j	 k r‹ t
 |  | j j ƒ  |  j ƒ } n	 |  j } | | | | Ž } Wn" t k
 rË } |  j | ƒ } n X|  j | | | | Ž |  _ |  j S(   u¡   
        `.dispatch()` is pretty much the same as Django's regular dispatch,
        but with extra hooks for startup, finalize, and exception handling.
        (   RI   RJ   R‰   RH   RE   R   R   RG   t   lowert   http_method_namesR!   RK   Rt   Rœ   R˜   R•   (   R@   RH   RI   RJ   t   handlerR•   R-   (    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyt   dispatchº  s     				c         O  sM   |  j  d k r" |  j | | | Ž S|  j  ƒ  j | |  ƒ } t | d t j ƒS(   u<   
        Handler method for HTTP 'OPTIONS' request.
        R   N(   t   metadata_classR"   RK   t   determine_metadataR   R   t   HTTP_200_OK(   R@   RH   RI   RJ   R/   (    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyt   options×  s    N(7   R   t
   __module__R   t   DEFAULT_RENDERER_CLASSESRD   t   DEFAULT_PARSER_CLASSESRd   t   DEFAULT_AUTHENTICATION_CLASSESRg   t   DEFAULT_THROTTLE_CLASSESRl   t   DEFAULT_PERMISSION_CLASSESRi   t!   DEFAULT_CONTENT_NEGOTIATION_CLASSRo   t   DEFAULT_METADATA_CLASSR¡   t   DEFAULT_VERSIONING_CLASSRƒ   RZ   t   classmethodR;   t   propertyRA   RE   RK   R"   RO   RQ   RU   RW   RX   RY   R   t   FalseR   Ra   Rc   Rf   RR   Rk   Rn   Rq   Ry   R{   R}   R€   R‚   R„   R‰   R   R˜   Rœ   R    R¤   (    (    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyR2   b   sP   																	
							
	
										N()   R   t
   __future__R    t   django.core.exceptionsR   t	   django.dbR   t   django.httpR   t   django.http.responseR   t   django.utilsR   t   django.utils.encodingR   t   django.utils.translationR   R)   t   django.views.decorators.csrfR   t   django.views.genericR	   t   rest_frameworkR
   R   t   rest_framework.compatR   t   rest_framework.requestR   t   rest_framework.responseR   t   rest_framework.settingsR   t   rest_framework.utilsR   R"   R   R°   R   R1   R2   (    (    (    sn   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/views.pyt   <module>   s(   	+