3
ˆd«  ã               @   s<   d Z ddlmZ ddlmZ ddlmZ G dd„ deƒZdS )a  
Defines the TraitHandler class.

A trait handler mediates the assignment of values to object traits. It
verifies (via its validate() method) that a specified value is consistent
with the object trait, and generates a TraitError exception if it is not
consistent.
é   )ÚBaseTraitHandler)Úclass_of)Ú
TraitErrorc               @   s   e Zd ZdZdd„ ZdS )ÚTraitHandlera   The task of this class and its subclasses is to verify the correctness
    of values assigned to object trait attributes.

    This class is an alternative to trait validator functions. A trait handler
    has several advantages over a trait validator function, due to being an
    object:

    * Trait handlers have constructors and state. Therefore, you can use
      them to create *parametrized types*.
    * Trait handlers can have multiple methods, whereas validator functions
      can have only one callable interface. This feature allows more
      flexibility in their implementation, and allows them to handle a
      wider range of cases, such as interactions with other components.

    The only method of TraitHandler that *must* be implemented by subclasses
    is validate().
    c             C   s   t d|t|ƒf ƒ‚dS )a5   Verifies whether a new value assigned to a trait attribute is
        valid.

        This method *must* be implemented by subclasses of TraitHandler. It is
        called whenever a new value is assigned to a trait attribute defined
        using this trait handler.

        If the value received by validate() is not valid for the trait
        attribute, the method must called the predefined error() method to
        raise a TraitError exception

        Parameters
        ----------
        object : HasTraits instance
            The object whose attribute is being assigned.
        name : str
            The name of the attribute being assigned.
        value : any
            The proposed new value for the attribute.

        Returns
        -------
        any
            If the new value is valid, this method must return either the
            original value passed to it, or an alternate value to be assigned
            in place of the original value. Whatever value this method returns
            is the actual value assigned to *object.name*.

        z`The '%s' trait of %s instance has an unknown type. Contact the developer to correct the problem.N)r   r   )ÚselfÚobjectÚnameÚvalue© r
   ú6/tmp/pip-build-7vycvbft/traits/traits/trait_handler.pyÚvalidate-   s    zTraitHandler.validateN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r
   r
   r
   r   r      s   r   N)r   Zbase_trait_handlerr   Z
trait_baser   Ztrait_errorsr   r   r
   r
   r
   r   Ú<module>   s   