ó
pÁìVc           @  s¼   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 m Z d d l m Z d d	 l m Z d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   uL  
The metadata API is used to allow customization of how `OPTIONS` requests
are handled. We currently provide a single default implementation that returns
some fairly ad-hoc information about the view.

Future implementations might use JSON schema or other definitions in order
to return this information in a more standardized way.
iÿÿÿÿ(   t   unicode_literals(   t   OrderedDict(   t   PermissionDenied(   t   Http404(   t
   force_text(   t
   exceptionst   serializers(   t   clone_request(   t   ClassLookupDictt   BaseMetadatac           B  s   e  Z d  „  Z RS(   c         C  s   t  d ƒ ‚ d S(   ux   
        Return a dictionary of metadata about the view.
        Used to return responses for OPTIONS requests.
        u)   .determine_metadata() must be overridden.N(   t   NotImplementedError(   t   selft   requestt   view(    (    sq   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/metadata.pyt   determine_metadata   s    (   t   __name__t
   __module__R   (    (    (    sq   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/metadata.pyR	      s   t   SimpleMetadatac           B  s  e  Z d  Z e i d e j 6d e j 6d e j 6d e j 6d e j	 6d e j
 6d e j 6d e j 6d e j 6d	 e j 6d
 e j 6d e j 6d e j 6d e j 6d e j 6d e j 6d e j 6d e j 6d e j 6d e j 6d e j 6ƒ Z d „  Z d „  Z d „  Z d „  Z RS(   uÑ   
    This is the default metadata implementation.
    It returns an ad-hoc set of information about the view.
    There are not any formalized standards for `OPTIONS` responses
    for us to base this on.
    u   fieldu   booleanu   stringu   urlu   emailu   regexu   slugu   integeru   floatu   decimalu   dateu   datetimeu   timeu   choiceu   multiple choiceu   file uploadu   image uploadu   listu   nested objectc         C  sª   t  ƒ  } | j ƒ  | d <| j ƒ  | d <g  | j D] } | j ^ q3 | d <g  | j D] } | j ^ qV | d <t | d ƒ r¦ |  j | | ƒ } | r¦ | | d <q¦ n  | S(   Nu   nameu   descriptionu   rendersu   parsesu   get_serializeru   actions(   R   t   get_view_namet   get_view_descriptiont   renderer_classest
   media_typet   parser_classest   hasattrt   determine_actions(   R   R   R   t   metadatat   renderert   parsert   actions(    (    sq   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/metadata.pyR   >   s    	##c         C  sÞ   i  } xÑ d d h t  | j ƒ @D]¶ } t | | ƒ | _ z‘ yN t | d ƒ r` | j | j ƒ n  | d k rˆ t | d ƒ rˆ | j ƒ  n  Wn t j t	 t
 f k
 r¨ n  X| j ƒ  } |  j | ƒ | | <Wd | | _ Xq  W| S(   uŽ   
        For generic class based views we return information about
        the fields that are accepted for 'PUT' and 'POST' methods.
        u   PUTu   POSTu   check_permissionsu
   get_objectN(   t   sett   allowed_methodsR   R   R   t   check_permissionst
   get_objectR   t   APIExceptionR   R   t   get_serializert   get_serializer_info(   R   R   R   R   t   methodt
   serializer(    (    sq   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/metadata.pyR   J   s      c         C  sV   t  | d ƒ r | j } n  t g  | j j ƒ  D]! \ } } | |  j | ƒ f ^ q. ƒ S(   un   
        Given an instance of a serializer, return a dictionary of metadata
        about its fields.
        u   child(   R   t   childR   t   fieldst   itemst   get_field_info(   R   R%   t
   field_namet   field(    (    sq   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/metadata.pyR#   e   s
    c         C  s^  t  ƒ  } |  j | | d <t | d t ƒ | d <d d d d d d d	 g } xQ | D]I } t | | d ƒ } | d k	 rR | d
 k rR t | d t ƒ| | <qR qR Wt | d d ƒ rÊ |  j | j ƒ | d <n( t | d d ƒ rò |  j	 | ƒ | d <n  | j
 d ƒ rZt | d ƒ rZg  | j j ƒ  D], \ } } i | d 6t | d t ƒd 6^ q!| d <n  | S(   ul   
        Given an instance of a serializer field, return a dictionary
        of metadata about it.
        u   typeu   requiredu	   read_onlyu   labelu	   help_textu
   min_lengthu
   max_lengthu	   min_valueu	   max_valueu    t   strings_onlyu   childu   fieldsu   childrenu   choicesu   valueu   display_nameN(   R   t   label_lookupt   getattrt   Falset   NoneR   t   TrueR)   R&   R#   t   getR   t   choicesR(   (   R   R+   t
   field_infot   attrst   attrt   valuet   choice_valuet   choice_name(    (    sq   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/metadata.pyR)   s   s$    		F(   R   R   t   __doc__R   R   t   Fieldt   BooleanFieldt   NullBooleanFieldt	   CharFieldt   URLFieldt
   EmailFieldt
   RegexFieldt	   SlugFieldt   IntegerFieldt
   FloatFieldt   DecimalFieldt	   DateFieldt   DateTimeFieldt	   TimeFieldt   ChoiceFieldt   MultipleChoiceFieldt	   FileFieldt
   ImageFieldt	   ListFieldt	   DictFieldt
   SerializerR-   R   R   R#   R)   (    (    (    sq   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/metadata.pyR      s6   



















			N(   R:   t
   __future__R    t   collectionsR   t   django.core.exceptionsR   t   django.httpR   t   django.utils.encodingR   t   rest_frameworkR   R   t   rest_framework.requestR   t"   rest_framework.utils.field_mappingR   t   objectR	   R   (    (    (    sq   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/metadata.pyt   <module>   s   	