3
6ßL]š  ã               @   st   d dl mZmZmZ ddlmZ ddlmZ ddlm	Z	 G dd„ deƒZ
G dd	„ d	eƒZG d
d„ deƒZdd„ ZdS )é    )ÚAnyÚCallableÚ	HasTraitsé   )Ú	BindEvent)Úget_script_manager)Úmake_object_scriptablec               @   s(   e Zd ZdZeZeZeZeZ	dd„ Z
dS )ÚFactoryWrapperz7The FactoryWrapper class wraps a factory for an object.c             C   s4   | j ƒ }tƒ }t||d�|_t|| j| j| jƒ |S )z@Invoke the factory to create the object then make it scriptable.)ÚnameÚobj)Úfactoryr   r   Ú
bind_eventr   ÚapiÚincludesÚexcludes)Úselfr
   r   Úsm© r   úJ/tmp/pip-install-5sebvq2j/apptools/apptools/appscripting/lazy_namespace.pyÚcreate_scriptable_object.   s
    z'FactoryWrapper.create_scriptable_objectN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   r   r   r   r	      s   r	   c                   s    e Zd ZdZ‡ fdd„Z‡  ZS )Ú	_LazyNodez|The _LazyNode class implements a node in a lazy namespace that will
    automatically invoke a factory if one is referenced.c                s4   t t| ƒj|ƒ}t|tƒr0|j|ƒ}t| ||ƒ |S )N)Úsuperr   Ú__getattribute__Ú
isinstancer	   r   Úsetattr)r   r
   Úvalue)Ú	__class__r   r   r   ?   s
    

z_LazyNode.__getattribute__)r   r   r   r   r   Ú__classcell__r   r   )r    r   r   ;   s   r   c                   s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚLazyNamespacezvThe LazyNamespace class implements a lazy namespace that will
    automatically invoke a factory if one is referenced.c                s0   t t| ƒj|ƒ}t|tƒr,|j|ƒ}|| |< |S )N)r   r"   Ú__getitem__r   r	   r   )r   r
   r   )r    r   r   r#   N   s
    

zLazyNamespace.__getitem__)r   r   r   r   r#   r!   r   r   )r    r   r"   J   s   r"   c                sÊ   ‡ fdd„}|j dƒ}xŽ|dd… D ]~}tˆ tƒr\yˆ | }W q” tk
rX   tƒ }Y q”X n8tˆ tƒr�yˆ | }W q” tk
rŒ   tƒ }Y q”X nt‚|||ƒ |‰ q$W tˆ ttfƒs¸t‚|| |d ƒ dS )z¯Add a named scriptable object (or a factory for one) to a lazy
    namespace.  If a name is a dotted name then intermediary nodes in the
    namespace are created as required.c                s$   t ˆ tƒr| ˆ |< ntˆ || ƒ d S )N)r   r"   r   )r   r
   )Únspacer   r   Úsave_obj^   s    

z"add_to_namespace.<locals>.save_objÚ.Nr   éÿÿÿÿr'   )Úsplitr   r"   ÚKeyErrorr   Ú	NameError)Úsor
   r$   r%   ÚpartsÚpartZnext_nspacer   )r$   r   Úadd_to_namespaceY   s&    



r.   N)Z
traits.apir   r   r   r   r   Zpackage_globalsr   Zscriptable_typer   r	   Úobjectr   Údictr"   r.   r   r   r   r   Ú<module>   s   "