ó
Wa›]c        	   @` s[  d  Z  d d l m Z m Z m Z d d l Z d d l m Z m Z m	 Z	 m
 Z
 d d l m Z d d d	 d
 d d d d d g	 Z e
 d e d e d e ƒ d e f d „  ƒ  Yƒ Z d „  Z e
 d e d e ƒ d e f d „  ƒ  Yƒ Z d d d „ Z e
 d e d e d e ƒ d e f d „  ƒ  Yƒ Z d „  Z e
 d e d e d e ƒ d e f d „  ƒ  Yƒ Z d „  Z e
 d e d e d e ƒ d  e f d! „  ƒ  Yƒ Z d" „  Z e
 d e d e d e ƒ d# e f d$ „  ƒ  Yƒ Z d% „  Z e
 d e d e d e ƒ d& e f d' „  ƒ  Yƒ Z d d( „ Z e
 d e d e d e ƒ d) e f d* „  ƒ  Yƒ Z  d d+ „ Z! d S(,   s   
Commonly useful validators.
i    (   t   absolute_importt   divisiont   print_functionNi   (   t   _AndValidatort   and_t   attribt   attrs(   t   NotCallableErrorR   t   deep_iterablet   deep_mappingt   in_t   instance_oft   is_callablet
   matches_ret   optionalt   providest   reprt   slotst   hasht   _InstanceOfValidatorc           B` s#   e  Z e ƒ  Z d  „  Z d „  Z RS(   c      
   C` sX   t  | |  j ƒ sT t d j d | j d |  j d | j d | ƒ | |  j | ƒ ‚ n  d S(   sP   
        We use a callable class to be able to change the ``__repr__``.
        s?   '{name}' must be {type!r} (got {value!r} that is a {actual!r}).t   namet   typet   actualt   valueN(   t
   isinstanceR   t	   TypeErrort   formatR   t	   __class__(   t   selft   instt   attrR   (    (    s.   lib/python2.7/site-packages/attr/validators.pyt   __call__   s    				c         C` s   d j  d |  j ƒ S(   Ns)   <instance_of validator for type {type!r}>R   (   R   R   (   R   (    (    s.   lib/python2.7/site-packages/attr/validators.pyt   __repr__0   s    	(   t   __name__t
   __module__R   R   R   R    (    (    (    s.   lib/python2.7/site-packages/attr/validators.pyR      s   		c         C` s
   t  |  ƒ S(   sÒ  
    A validator that raises a `TypeError` if the initializer is called
    with a wrong type for this particular attribute (checks are performed using
    `isinstance` therefore it's also valid to pass a tuple of types).

    :param type: The type to check for.
    :type type: type or tuple of types

    :raises TypeError: With a human readable error message, the attribute
        (of type `attr.Attribute`), the expected type, and the value it
        got.
    (   R   (   R   (    (    s.   lib/python2.7/site-packages/attr/validators.pyR   6   s    t   frozent   _MatchesReValidatorc           B` s5   e  Z e ƒ  Z e ƒ  Z e ƒ  Z d  „  Z d „  Z RS(   c         C` sO   |  j  | ƒ sK t d j d | j d |  j j d | ƒ | |  j | ƒ ‚ n  d S(   sP   
        We use a callable class to be able to change the ``__repr__``.
        s7   '{name}' must match regex {regex!r} ({value!r} doesn't)R   t   regexR   N(   t
   match_funct
   ValueErrorR   R   R%   t   pattern(   R   R   R   R   (    (    s.   lib/python2.7/site-packages/attr/validators.pyR   L   s    	c         C` s   d j  d |  j ƒ S(   Ns,   <matches_re validator for pattern {regex!r}>R%   (   R   R%   (   R   (    (    s.   lib/python2.7/site-packages/attr/validators.pyR    [   s    	(   R!   R"   R   R%   t   flagsR&   R   R    (    (    (    s.   lib/python2.7/site-packages/attr/validators.pyR$   F   s
   				c         C` sù   t  t d d ƒ } | d t j t j f } | | k rk t d d j t d „  t | ƒ Dƒ ƒ ƒ f ƒ ‚ n  t j	 |  | ƒ } | t j k r˜ | j } nQ | t j k r³ | j } n6 | rÅ | j
 } n$ t j	 d j |  ƒ | ƒ } | j } t | | | ƒ S(   s}  
    A validator that raises `ValueError` if the initializer is called
    with a string that doesn't match *regex*.

    :param str regex: a regex string to match against
    :param int flags: flags that will be passed to the underlying re function
        (default 0)
    :param callable func: which underlying `re` function to call (options
        are `re.fullmatch`, `re.search`, `re.match`, default
        is ``None`` which means either `re.fullmatch` or an emulation of
        it on Python 2). For performance reasons, they won't be used directly
        but on a pre-`re.compile`\ ed pattern.

    .. versionadded:: 19.2.0
    t	   fullmatchs   'func' must be one of %s.s   , c         s` s$   |  ] } | r | j  p d  Vq d S(   t   NoneN(   R!   (   t   .0t   e(    (    s.   lib/python2.7/site-packages/attr/validators.pys	   <genexpr>y   s    s   (?:{})\ZN(   t   getattrt   reR+   t   searcht   matchR'   t   joint   sortedt   sett   compileR*   R   R$   (   R%   R)   t   funcR*   t   valid_funcsR(   R&   (    (    s.   lib/python2.7/site-packages/attr/validators.pyR   a   s$    &	t   _ProvidesValidatorc           B` s#   e  Z e ƒ  Z d  „  Z d „  Z RS(   c         C` sO   |  j  j | ƒ sK t d j d | j d |  j  d | ƒ | |  j  | ƒ ‚ n  d S(   sP   
        We use a callable class to be able to change the ``__repr__``.
        s<   '{name}' must provide {interface!r} which {value!r} doesn't.R   t	   interfaceR   N(   R9   t
   providedByR   R   R   (   R   R   R   R   (    (    s.   lib/python2.7/site-packages/attr/validators.pyR   ’   s    	c         C` s   d j  d |  j ƒ S(   Ns0   <provides validator for interface {interface!r}>R9   (   R   R9   (   R   (    (    s.   lib/python2.7/site-packages/attr/validators.pyR    ¡   s    	(   R!   R"   R   R9   R   R    (    (    (    s.   lib/python2.7/site-packages/attr/validators.pyR8   Ž   s   		c         C` s
   t  |  ƒ S(   s  
    A validator that raises a `TypeError` if the initializer is called
    with an object that does not provide the requested *interface* (checks are
    performed using ``interface.providedBy(value)`` (see `zope.interface
    <https://zopeinterface.readthedocs.io/en/latest/>`_).

    :param zope.interface.Interface interface: The interface to check for.

    :raises TypeError: With a human readable error message, the attribute
        (of type `attr.Attribute`), the expected interface, and the
        value it got.
    (   R8   (   R9   (    (    s.   lib/python2.7/site-packages/attr/validators.pyR   §   s    t   _OptionalValidatorc           B` s#   e  Z e ƒ  Z d  „  Z d „  Z RS(   c         C` s'   | d  k r d  S|  j | | | ƒ d  S(   N(   R+   t	   validator(   R   R   R   R   (    (    s.   lib/python2.7/site-packages/attr/validators.pyR   »   s    c         C` s   d j  d t |  j ƒ ƒ S(   Ns'   <optional validator for {what} or None>t   what(   R   R   R<   (   R   (    (    s.   lib/python2.7/site-packages/attr/validators.pyR    Á   s    	(   R!   R"   R   R<   R   R    (    (    (    s.   lib/python2.7/site-packages/attr/validators.pyR;   ·   s   		c         C` s)   t  |  t ƒ r t t |  ƒ ƒ St |  ƒ S(   sÂ  
    A validator that makes an attribute optional.  An optional attribute is one
    which can be set to ``None`` in addition to satisfying the requirements of
    the sub-validator.

    :param validator: A validator (or a list of validators) that is used for
        non-``None`` values.
    :type validator: callable or `list` of callables.

    .. versionadded:: 15.1.0
    .. versionchanged:: 17.1.0 *validator* can be a list of validators.
    (   R   t   listR;   R   (   R<   (    (    s.   lib/python2.7/site-packages/attr/validators.pyR   Ç   s    t   _InValidatorc           B` s#   e  Z e ƒ  Z d  „  Z d „  Z RS(   c         C` sd   y | |  j  k } Wn t k
 r, t } n X| s` t d j d | j d |  j  d | ƒ ƒ ‚ n  d  S(   Ns/   '{name}' must be in {options!r} (got {value!r})R   t   optionsR   (   R@   R   t   FalseR'   R   R   (   R   R   R   R   t
   in_options(    (    s.   lib/python2.7/site-packages/attr/validators.pyR   Ý   s    
	c         C` s   d j  d |  j ƒ S(   Ns(   <in_ validator with options {options!r}>R@   (   R   R@   (   R   (    (    s.   lib/python2.7/site-packages/attr/validators.pyR    ê   s    	(   R!   R"   R   R@   R   R    (    (    (    s.   lib/python2.7/site-packages/attr/validators.pyR?   Ù   s   		c         C` s
   t  |  ƒ S(   sÛ  
    A validator that raises a `ValueError` if the initializer is called
    with a value that does not belong in the options provided.  The check is
    performed using ``value in options``.

    :param options: Allowed options.
    :type options: list, tuple, `enum.Enum`, ...

    :raises ValueError: With a human readable error message, the attribute (of
       type `attr.Attribute`), the expected options, and the value it
       got.

    .. versionadded:: 17.1.0
    (   R?   (   R@   (    (    s.   lib/python2.7/site-packages/attr/validators.pyR
   ð   s    t   _IsCallableValidatorc           B` s   e  Z d  „  Z d „  Z RS(   c      	   C` sL   t  | ƒ sH d } t d | j d | j d | d | j ƒ d | ƒ ‚ n  d S(   sP   
        We use a callable class to be able to change the ``__repr__``.
        s?   '{name}' must be callable (got {value!r} that is a {actual!r}).t   msgR   R   R   N(   t   callableR   R   R   R   (   R   R   R   R   t   message(    (    s.   lib/python2.7/site-packages/attr/validators.pyR     s    	c         C` s   d S(   Ns   <is_callable validator>(    (   R   (    (    s.   lib/python2.7/site-packages/attr/validators.pyR      s    (   R!   R"   R   R    (    (    (    s.   lib/python2.7/site-packages/attr/validators.pyRC     s   	c           C` s   t  ƒ  S(   sw  
    A validator that raises a `attr.exceptions.NotCallableError` if the
    initializer is called with a value for this particular attribute
    that is not callable.

    .. versionadded:: 19.1.0

    :raises `attr.exceptions.NotCallableError`: With a human readable error
        message containing the attribute (`attr.Attribute`) name,
        and the value it got.
    (   RC   (    (    (    s.   lib/python2.7/site-packages/attr/validators.pyR     s    t   _DeepIterablec           B` sJ   e  Z e d  e ƒ  ƒ Z e d d d  e e ƒ  ƒ ƒ Z d „  Z d „  Z	 RS(   R<   t   defaultc         C` sM   |  j  d k	 r% |  j  | | | ƒ n  x! | D] } |  j | | | ƒ q, Wd S(   sP   
        We use a callable class to be able to change the ``__repr__``.
        N(   t   iterable_validatorR+   t   member_validator(   R   R   R   R   t   member(    (    s.   lib/python2.7/site-packages/attr/validators.pyR   .  s    c         C` sC   |  j  d  k r d n d j d |  j  ƒ } d j d | d |  j ƒ S(   Nt    s    {iterable!r}t   iterablesJ   <deep_iterable validator for{iterable_identifier} iterables of {member!r}>t   iterable_identifierRK   (   RI   R+   R   RJ   (   R   RN   (    (    s.   lib/python2.7/site-packages/attr/validators.pyR    8  s
    	N(
   R!   R"   R   R   RJ   R+   R   RI   R   R    (    (    (    s.   lib/python2.7/site-packages/attr/validators.pyRG   '  s
   	
c         C` s   t  |  | ƒ S(   s1  
    A validator that performs deep validation of an iterable.

    :param member_validator: Validator to apply to iterable members
    :param iterable_validator: Validator to apply to iterable itself
        (optional)

    .. versionadded:: 19.1.0

    :raises TypeError: if any sub-validators fail
    (   RG   (   RJ   RI   (    (    s.   lib/python2.7/site-packages/attr/validators.pyR   G  s    t   _DeepMappingc           B` s\   e  Z e d  e ƒ  ƒ Z e d  e ƒ  ƒ Z e d d d  e e ƒ  ƒ ƒ Z d „  Z	 d „  Z
 RS(   R<   RH   c         C` sd   |  j  d k	 r% |  j  | | | ƒ n  x8 | D]0 } |  j | | | ƒ |  j | | | | ƒ q, Wd S(   sP   
        We use a callable class to be able to change the ``__repr__``.
        N(   t   mapping_validatorR+   t   key_validatort   value_validator(   R   R   R   R   t   key(    (    s.   lib/python2.7/site-packages/attr/validators.pyR   \  s
    c         C` s   d j  d |  j d |  j ƒ S(   NsA   <deep_mapping validator for objects mapping {key!r} to {value!r}>RS   R   (   R   RQ   RR   (   R   (    (    s.   lib/python2.7/site-packages/attr/validators.pyR    g  s    	N(   R!   R"   R   R   RQ   RR   R+   R   RP   R   R    (    (    (    s.   lib/python2.7/site-packages/attr/validators.pyRO   V  s
   	c         C` s   t  |  | | ƒ S(   s}  
    A validator that performs deep validation of a dictionary.

    :param key_validator: Validator to apply to dictionary keys
    :param value_validator: Validator to apply to dictionary values
    :param mapping_validator: Validator to apply to top-level mapping
        attribute (optional)

    .. versionadded:: 19.1.0

    :raises TypeError: if any sub-validators fail
    (   RO   (   RQ   RR   RP   (    (    s.   lib/python2.7/site-packages/attr/validators.pyR	   m  s    ("   t   __doc__t
   __future__R    R   R   R/   t   _makeR   R   R   R   t
   exceptionsR   t   __all__RA   t   Truet   objectR   R   R$   R+   R   R8   R   R;   R   R?   R
   RC   R   RG   R   RO   R	   (    (    (    s.   lib/python2.7/site-packages/attr/validators.pyt   <module>   sJ   "		-				