3
d                  @   s   d Z ddlZddlmZ ddlmZmZ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d
lmZ dd Ze	jG dd dejZdd Zeje ejeee eje dS )a   Defines the core CTrait class.

The CTrait class extends the C-level cTrait type to provide the full CTrait
API. CTraits are the core objects that are used to generate defaults and
validate as well as maintaining a list of notifiers and calling them when
values are modified.
    N   )ctraits)ComparisonModeDefaultValuedefault_value_map)IObservable)SequenceTypes	Undefined)TraitDictObject)TraitListObject)TraitSetObjectc             G   s   | j | f| S )z" Unpickles new-style objects.
    )__new__)clsargs r   //tmp/pip-build-7vycvbft/traits/traits/ctrait.py
__newobj__   s    r   c                   s   e Zd ZdZdd Zedd Zedd Zedd	 Zed
d Z	e fddZ
e
jdd Z
edd Zejdd Zdd Zdd Zd!ddZdd Zdd Zdd Zdd  Z  ZS )"CTraitz1 Extends the underlying C-based cTrait type.
    c             O   sf   ddl m} ddlm} | j}t||rJ| jp0i j }|j| |||S |j	d|  ||| f |S )z8 Allows a derivative trait to be defined from this one. r   )	TraitType)Traitparent)

trait_typer   traitsr   handler
isinstance__dict__copyupdate
setdefault)selfr   metadatar   r   r   dictr   r   r   __call__)   s    


zCTrait.__call__c             C   sr   | j  \}}|tjtjtjtjfkr(tS |tjtjtj	tj
tjfkrL|j S |tjtjhkr`|S tdj|d S )Nz#Unexpected default value kind: {!r})default_valuer   objectZcallable_and_argscallableZdisallowr	   Z	dict_copytrait_dict_objecttrait_set_objectZ	list_copytrait_list_objectr   ZconstantmissingRuntimeErrorformat)r   kindvaluer   r   r   default8   s$    

zCTrait.defaultc             C   s   t | j d  S )Nr   )r   r#   )r   r   r   r   default_kindR   s    zCTrait.default_kindc             C   s&   | j }|d k	r|S ddlm} |S d S )Nr   )Any)r   Ztrait_typesr0   )r   r   r0   r   r   r   r   V   s
    zCTrait.trait_typec             C   s   | j }|d k	r|j S f S )N)r   inner_traits)r   r   r   r   r   r1   `   s    zCTrait.inner_traitsc                s   t  j}t|S )z Get or set the comparison mode on the trait.
        Getter returns a ComparisonMode enum.
        Setter acceps either an int or a ComparisonMode enum.
        )supercomparison_moder   )r   Zi_comparison_mode)	__class__r   r   r3   h   s    zCTrait.comparison_modec             C   s   t jjj| | d S )N)r   cTraitr3   __set__)r   r-   r   r   r   r3   q   s    c             C   s   | j  S )zS Return a tuple of callables (fget, fset, validate) for the
        property trait.)Z_get_property)r   r   r   r   property_fieldsu   s    zCTrait.property_fieldsc             C   sP   g }x<|D ]4}|dkrd}nt j|}t|j}|j||g q
W | j|  dS )z Set the fget, fset, validate callables for the property.

        Parameters
        ----------
        value : tuple
            Value should be the tuple of callables (fget, fset, validate).

        Nr   )inspect	signaturelen
parametersextendZ_set_property)r   r-   Zfunc_arg_countsargnargssigr   r   r   r7   {   s    



c             C   s   t | j|S )zI Returns whether or not this trait is of a specified trait type.
        )r   r   )r   r   r   r   r   is_trait_type   s    zCTrait.is_trait_typec             C   s   ddl m} | j}|dkrJ| j}|dk	r2|j| }|dkrJddl m} |}t||sf }i }t|tkrx^|dd D ]N}t|tkrt	|}qvt|t
r|}|jdddkr|j }| |d< qv|}qvW |||}|| _|S )zF Returns the user interface editor associated with the trait.
        r   )EditorFactoryN)
TextEditorZtrait)Ztraitsui.apirA   editorr   
get_editorrB   r   typer   tupler!   getr   )r   rA   rC   r   rB   r   r   itemr   r   r   rD      s2    





zCTrait.get_editorTc             C   sZ   |r| j }|dk	r|S | j}|dk	r2d|j  }nd}| j}| jdkrN|j S d||f S )a   Returns the help text for a trait.

        If *full* is False or the trait does not have a **help** string,
        the returned string is constructed from the **desc** attribute on the
        trait and the **info** string on the trait's handler.

        Parameters
        ----------
        full : bool
            Indicates whether to return the value of the *help* attribute of
            the trait itself.
        Nzmust be %s.zmay be any value.zSpecifies %s and %s)helpr   infodesc
capitalize)r   fullrI   r   rJ   rK   r   r   r   get_help   s    
zCTrait.get_helpc             C   s    | j }|dk	r|j|||S dS )z- Returns a description of the trait.
        Nz	any value)r   	full_info)r   r$   namer-   r   r   r   r   rO      s    zCTrait.full_infoc             C   s   | j }|dk	r|j S dS )z- Returns a description of the trait.
        Nz	any value)r   rJ   )r   r   r   r   r   rJ      s    zCTrait.infoc             C   s   | S )z0 Method that returns self for trait converters. r   )r   r   r   r   	as_ctrait   s    zCTrait.as_ctraitc             C   s   t | jdf| j fS )z1 Returns the pickleable form of a CTrait object. r   )r   r4   __getstate__)r   protocolr   r   r   __reduce_ex__   s    zCTrait.__reduce_ex__)T)__name__
__module____qualname____doc__r"   propertyr.   r/   r   r1   r3   setterr7   r@   rD   rN   rO   rJ   rQ   rT   __classcell__r   r   )r4   r   r   $   s"   
	,
		r   c              O   s    ddl m} tj| || |S )Nr   )adapt)Ztraits.adaptation.apir\   r   _adapt)r   kwr\   r   r   r   _adapt_wrapper   s    
r_   )rX   r8    r   	constantsr   r   r   Zobservation.i_observabler   Z
trait_baser   r	   r&   r
   r(   r   r'   r   r   registerr5   r   r_   Z_ctraitZ_list_classesr]   r   r   r   r   <module>   s    
 Y
