3
^½µ_  ã            '   @   sf  d Z ddlZddlZddlZddlmZ ddlmZ yddlm	Z	 W nF e
k
rŠ   yddlmZ	 W n  e
k
r„   ddlmZ	 Y nX Y nX yddlmZ W n  e
k
r¼   ddlmZ Y nX ydd	lmZ W nJ e
k
�r   ydd	lmZ W n" e
k
�r   dd	lmZ Y nX Y nX ejd
ƒZejdƒZejdƒZdd„ Zdd„ Zdd„ Zdd„ Zddd„ZdS )a5  
    This is the h5py completer extension for ipython.  It is loaded by
    calling the function h5py.enable_ipython_completer() from within an
    interactive IPython session.

    It will let you do things like::

      f=File('foo.h5')
      f['<tab>
      # or:
      f['ite<tab>

    which will do tab completion based on the subgroups of `f`. Also::

      f['item1'].at<tab>

    will perform tab completion for the attributes in the usual way. This should
    also work::

      a = b = f['item1'].attrs.<tab>

    as should::

      f['item1/item2/it<tab>
é    Né   )ÚAttributeManager)ÚHLObject)Úget_ipython)Úget)Úgenerics)ÚTryNextz(?:.*\=)?(.+\[.*\].*)\.(\w*)$z,(?:.*\=)?(.*)\[(?P<s>['|"])(?!.*(?P=s))(.*)$z(?:.*\=)?(.+?)(?:\[)c             C   sF   d| krt ƒ ‚yt| |jjƒ}W n  tk
r@   t| |jƒ}Y nX |S )z! Filter function for completion. ú()Ú
ValueErrorÚevalÚshellZuser_nsÚAttributeError)ÚnameÚcontextÚobj© r   ú4/tmp/pip-install-xpigntgx/h5py/h5py/ipy_completer.pyÚ_retrieve_objO   s    r   c                s°   t j|ƒddd… \}‰ yt|| ƒ}W n tk
r:   g S X tjˆ ƒ\‰}y,ˆrl‡fdd„|ˆ jƒ D ƒ}n|jƒ }W n tk
rŠ   g S X t|ƒ}tj	dƒ ‡ fdd„|D ƒS )	z3Compute possible item matches for dict-like objectsr   é   é   c             3   s   | ]}t jˆ |ƒV  qd S )N)Ú	posixpathÚjoin)Ú.0r   )Úpathr   r   ú	<genexpr>p   s    z&h5py_item_completer.<locals>.<genexpr>z 	
`!@#$^&*()=+[{]}\|;:'",<>?c                s$   g | ]}|d t ˆ ƒ… ˆ kr|‘qS )N)Úlen)r   Úi)Úitemr   r   ú
<listcomp>y   s    z'h5py_item_completer.<locals>.<listcomp>)
Úre_item_matchÚsplitr   Ú	Exceptionr   Úkeysr   ÚlistÚreadlineÚset_completer_delims)r   ÚcommandÚbaser   Ú_Úitemsr   )r   r   r   Úh5py_item_completerb   s    
r*   c          +      sB  t j|ƒdd… \‰‰ ˆjƒ ‰ytˆ| ƒ}W n tk
r@   g S X t|ƒ}ytj||ƒ}W n tk
rn   Y nX d}yt	ƒ j
j}W n tk
r–   Y nX |dkrÂyt	ƒ j}W n tk
rÀ   Y nX |dkròyt	ƒ jj}W n tk
rð   d}Y nX |dk�rdd„ |D ƒ}n|dk�r$dd„ |D ƒ}tjd	ƒ ‡ ‡fd
d„|D ƒS )z:Compute possible attr matches for nested dict-like objectsr   é   Nr   c             S   s   g | ]}|j d ƒs|‘qS )Ú__)Ú
startswith)r   Úar   r   r   r       s    z'h5py_attr_completer.<locals>.<listcomp>r   c             S   s   g | ]}|j d ƒs|‘qS )r(   )r-   )r   r.   r   r   r   r   ¢   s    z =c                s,   g | ]$}|d t ˆ ƒ… ˆ krdˆ|f ‘qS )Nz%s.%s)r   )r   r.   )Úattrr'   r   r   r   ¦   s    )Úre_attr_matchr    Ústripr   r!   Údirr   Zcomplete_objectr   r   Z	CompleterÚomit__namesr   Zreadline_omit__namesÚoptionsr$   r%   )r   r&   r   Úattrsr3   r   )r/   r'   r   Úh5py_attr_completer|   s@    



r6   c             C   sv   t j|jƒd }t| j|ƒjdƒttfƒs.t‚yt	| |jƒS  t
k
rN   Y nX yt| |jƒS  t
k
rp   Y nX g S )z. Completer function to be loaded into IPython r   r   )Úre_object_matchr    ÚlineÚ
isinstanceZ_ofindr   r   r   r   r6   r
   r*   )ÚselfÚeventr'   r   r   r   Úh5py_completer©   s    r<   c             C   s"   | dkrt ƒ } | jdtdd� dS )z& Load completer function into IPython NZcomplete_commandz(?:.*\=)?(.+?)\[)Zre_key)r   Zset_hookr<   )Úipr   r   r   Úload_ipython_extension½   s    r>   )N)Ú__doc__r   Úrer$   Z	_hl.attrsr   Z_hl.baser   ZIPythonr   ÚImportErrorZIPython.core.ipapir   ZIPython.ipapiZIPython.utilsr   ZIPython.core.errorr   Úcompiler0   r   r7   r   r*   r6   r<   r>   r   r   r   r   Ú<module>(   s>   


-