3
ˆdÈ  ã               @   s@   d Z ddlmZ i aG dd„ deƒZG dd„ deƒZdd„ Zd	S )
a!   Defines the TraitFactory class and related objects.

A TraitFactory is a class which allows deferred, but cached, creation of
CTrait instances.  The TraitFactory API provides the ``as_ctrait`` method
so that the trait conversion functions can generate CTrait instances in a
standard way.
é   )Ú
TraitErrorc               @   s*   e Zd ZdZd	dd„Zdd„ Zdd„ ZdS )
ÚTraitFactoryzÛ A factory class that allows deferred creation of traits

    Traits created by TraitFactory instances are cached, and the cached
    trait is returned by all subsequent calls to the same TraitFactory
    instance.
    Nc             C   s   |d k	r|| _ |j| _d S )N)Úmaker_functionÚ__doc__)Úselfr   © r   ú6/tmp/pip-build-7vycvbft/traits/traits/trait_factory.pyÚ__init__!   s    zTraitFactory.__init__c             O   s   | j ||ŽS )z Creates a CTrait instance. )r   )r   ÚargsÚmetadatar   r   r   Ú__call__&   s    zTraitFactory.__call__c             C   s   t | ƒS )z+ Get the CTrait instance from the factory. )Útrait_factory)r   r   r   r   Ú	as_ctrait*   s    zTraitFactory.as_ctrait)N)Ú__name__Ú
__module__Ú__qualname__r   r	   r   r   r   r   r   r   r      s   
r   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚTraitImportErrorzÚ TraitFactory subclass that always fails when creating a CTrait

    This class is designed for uses such as deferring import problems until
    encountering code that actually tries to use the unimportable trait.
    c             C   s
   || _ d S )N)Úmessage)r   r   r   r   r   r	   6   s    zTraitImportError.__init__c             O   s   t | jƒ‚dS )z6 Raises an TraitError with the message as is payload. N)r   r   )r   r
   r   r   r   r   r   9   s    zTraitImportError.__call__N)r   r   r   r   r	   r   r   r   r   r   r   /   s   r   c             C   s"   t | ƒ}|tkr| ƒ t|< t| S )z6 Returns a trait created from a TraitFactory instance )ÚidÚ_trait_factory_instances)ZtraitÚtidr   r   r   r   >   s    
r   N)r   Ztrait_errorsr   r   Úobjectr   r   r   r   r   r   r   Ú<module>   s
   