ó
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 e f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   uK  
We perform uniqueness checks explicitly on the serializer class, rather
the using Django's `.full_clean()`.

This gives us better separation of concerns, allows us to use single-step
object creation, and makes it possible to switch between using the implicit
`ModelSerializer` class and an equivalent explicit `Serializer` class.
iÿÿÿÿ(   t   unicode_literals(   t   ugettext_lazy(   t   unicode_to_repr(   t   ValidationError(   t
   smart_reprt   UniqueValidatorc           B  sS   e  Z d  Z e d ƒ Z d d „ Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z RS(	   uˆ   
    Validator that corresponds to `unique=True` on a model field.

    Should be applied to an individual field on the serializer.
    u   This field must be unique.c         C  s(   | |  _  d  |  _ | p |  j |  _ d  S(   N(   t   querysett   Nonet   serializer_fieldt   message(   t   selfR   R	   (    (    ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pyt   __init__   s    		c         C  s,   | j  d |  _ t | j d d ƒ |  _ d S(   ur   
        This hook is called by the serializer instance,
        prior to the validation call being made.
        i    u   instanceN(   t   source_attrst
   field_namet   getattrt   parentR   t   instance(   R
   R   (    (    ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pyt   set_context   s    c         C  s   i | |  j  6} | j |   S(   uT   
        Filter the queryset to all instances matching the given attribute.
        (   R   t   filter(   R
   t   valueR   t   filter_kwargs(    (    ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pyt   filter_queryset*   s    c         C  s)   |  j  d k	 r% | j d |  j  j ƒ S| S(   u}   
        If an instance is being updated, then do not include
        that instance itself as a uniqueness conflict.
        t   pkN(   R   R   t   excludeR   (   R
   R   (    (    ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pyt   exclude_current_instance1   s    c         C  sL   |  j  } |  j | | ƒ } |  j | ƒ } | j ƒ  rH t |  j ƒ ‚ n  d  S(   N(   R   R   R   t   existsR   R	   (   R
   R   R   (    (    ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pyt   __call__:   s
    	c         C  s#   t  d |  j j t |  j ƒ f ƒ S(   Nu   <%s(queryset=%s)>(   R   t	   __class__t   __name__R   R   (   R
   (    (    ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pyt   __repr__A   s    	N(   R   t
   __module__t   __doc__t   _R	   R   R   R   R   R   R   R   (    (    (    ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pyR      s   					t   UniqueTogetherValidatorc           B  sh   e  Z d  Z e d ƒ Z e d ƒ Z d
 d „ Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d	 „  Z RS(   uŸ   
    Validator that corresponds to `unique_together = (...)` on a model class.

    Should be applied to the serializer class, not to an individual field.
    u0   The fields {field_names} must make a unique set.u   This field is required.c         C  s1   | |  _  | |  _ d  |  _ | p' |  j |  _ d  S(   N(   R   t   fieldsR   R   R	   (   R
   R   R"   R	   (    (    ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pyR   Q   s    			c         C  s   t  | d d ƒ |  _ d S(   ur   
        This hook is called by the serializer instance,
        prior to the validation call being made.
        u   instanceN(   R   R   R   (   R
   t
   serializer(    (    ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pyR   W   s    c           sH   ˆ  j  d k	 r d S‡  ‡ f d †  ˆ  j Dƒ } | rD t | ƒ ‚ n  d S(   u~   
        The `UniqueTogetherValidator` always forces an implied 'required'
        state on the fields it applies to.
        Nc           s(   i  |  ] } | ˆ k r ˆ  j  | “ q S(    (   t   missing_message(   t   .0R   (   R
   t   attrs(    ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pys
   <dictcomp>h   s   	(   R   R   R"   R   (   R
   R&   t   missing(    (   R
   R&   ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pyt   enforce_required_fields_   s    c           sq   |  j  d k	 rK x9 |  j D]+ } | ˆ  k r t |  j  | ƒ ˆ  | <q q Wn  ‡  f d †  |  j Dƒ } | j |   S(   uU   
        Filter the queryset to all instances matching the given attributes.
        c           s   i  |  ] } ˆ  | | “ q S(    (    (   R%   R   (   R&   (    ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pys
   <dictcomp>|   s   	N(   R   R   R"   R   R   (   R
   R&   R   R   R   (    (   R&   ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pyR   o   s     c         C  s)   |  j  d k	 r% | j d |  j  j ƒ S| S(   u}   
        If an instance is being updated, then do not include
        that instance itself as a uniqueness conflict.
        R   N(   R   R   R   R   (   R
   R&   R   (    (    ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pyR      s    c         C  sº   |  j  | ƒ |  j } |  j | | ƒ } |  j | | ƒ } g  | j ƒ  D]! \ } } | |  j k rG | ^ qG } d  | k r¶ | j ƒ  r¶ d j |  j ƒ } t	 |  j
 j d | ƒ ƒ ‚ n  d  S(   Nu   , t   field_names(   R(   R   R   R   t   itemsR"   R   R   t   joinR   R	   t   format(   R
   R&   R   t   fieldR   t   checked_valuesR)   (    (    ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pyR   Š   s    	4c         C  s/   t  d |  j j t |  j ƒ t |  j ƒ f ƒ S(   Nu   <%s(queryset=%s, fields=%s)>(   R   R   R   R   R   R"   (   R
   (    (    ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pyR   ˜   s    	N(   R   R   R   R    R	   R$   R   R   R   R(   R   R   R   R   (    (    (    ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pyR!   H   s   						t   BaseUniqueForValidatorc           B  s\   e  Z d Z e d  ƒ Z d d „ Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z RS(	   u   This field is required.c         C  s1   | |  _  | |  _ | |  _ | p' |  j |  _ d  S(   N(   R   R-   t
   date_fieldR	   (   R
   R   R-   R0   R	   (    (    ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pyR   ¤   s    			c         C  sM   | j  |  j j d |  _ | j  |  j j d |  _ t | d d ƒ |  _ d S(   ur   
        This hook is called by the serializer instance,
        prior to the validation call being made.
        i    u   instanceN(	   R"   R-   R   R   R0   t   date_field_nameR   R   R   (   R
   R#   (    (    ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pyR   ª   s    c           s>   ‡  ‡ f d †  ˆ  j  ˆ  j g Dƒ } | r: t | ƒ ‚ n  d S(   u   
        The `UniqueFor<Range>Validator` classes always force an implied
        'required' state on the fields they are applied to.
        c           s(   i  |  ] } | ˆ k r ˆ  j  | “ q S(    (   R$   (   R%   R   (   R
   R&   (    ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pys
   <dictcomp>¼   s   	N(   R-   R0   R   (   R
   R&   R'   (    (   R
   R&   ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pyR(   ¶   s    c         C  s   t  d ƒ ‚ d  S(   Nu&   `filter_queryset` must be implemented.(   t   NotImplementedError(   R
   R&   R   (    (    ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pyR   Ã   s    c         C  s)   |  j  d k	 r% | j d |  j  j ƒ S| S(   u}   
        If an instance is being updated, then do not include
        that instance itself as a uniqueness conflict.
        R   N(   R   R   R   R   (   R
   R&   R   (    (    ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pyR   Æ   s    c         C  s{   |  j  | ƒ |  j } |  j | | ƒ } |  j | | ƒ } | j ƒ  rw |  j j d |  j ƒ } t i | |  j	 6ƒ ‚ n  d  S(   NR0   (
   R(   R   R   R   R   R	   R,   R0   R   R-   (   R
   R&   R   R	   (    (    ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pyR   Ï   s    	c         C  s;   t  d |  j j t |  j ƒ t |  j ƒ t |  j ƒ f ƒ S(   Nu*   <%s(queryset=%s, field=%s, date_field=%s)>(   R   R   R   R   R   R-   R0   (   R
   (    (    ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pyR   Ø   s
    	N(   R   R   R   R	   R    R$   R   R   R(   R   R   R   R   (    (    (    ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pyR/       s   							t   UniqueForDateValidatorc           B  s   e  Z e d  ƒ Z d „  Z RS(   u6   This field must be unique for the "{date_field}" date.c         C  sv   | |  j  } | |  j } i  } | | |  j <| j | d |  j <| j | d |  j <| j | d |  j <| j |   S(   Nu   %s__dayu	   %s__monthu   %s__year(   R-   R0   R   t   dayR1   t   montht   yearR   (   R
   R&   R   R   t   dateR   (    (    ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pyR   ä   s    (   R   R   R    R	   R   (    (    (    ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pyR3   á   s   t   UniqueForMonthValidatorc           B  s   e  Z e d  ƒ Z d „  Z RS(   u7   This field must be unique for the "{date_field}" month.c         C  sN   | |  j  } | |  j } i  } | | |  j <| j | d |  j <| j |   S(   Nu	   %s__month(   R-   R0   R   R5   R1   R   (   R
   R&   R   R   R7   R   (    (    ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pyR   ó   s    (   R   R   R    R	   R   (    (    (    ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pyR8   ð   s   t   UniqueForYearValidatorc           B  s   e  Z e d  ƒ Z d „  Z RS(   u6   This field must be unique for the "{date_field}" year.c         C  sN   | |  j  } | |  j } i  } | | |  j <| j | d |  j <| j |   S(   Nu   %s__year(   R-   R0   R   R6   R1   R   (   R
   R&   R   R   R7   R   (    (    ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pyR      s    (   R   R   R    R	   R   (    (    (    ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pyR9   ý   s   N(   R   t
   __future__R    t   django.utils.translationR   R    t   rest_framework.compatR   t   rest_framework.exceptionsR   t#   rest_framework.utils.representationR   t   objectR   R!   R/   R3   R8   R9   (    (    (    ss   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/validators.pyt   <module>   s   6XA