a
    ö¦»a:  ã                   @   sœ   d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ e d	¡Ze d
¡Ze 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)ÚTryNext)Úgenericsz(?:.*\=)?(.+\[.*\].*)\.(\w*)$z,(?:.*\=)?(.*)\[(?P<s>['|"])(?!.*(?P=s))(.*)$z(?:.*\=)?(.+?)(?:\[)c                 C   s   d| v rt ƒ ‚t| |jƒS )z! Filter function for completion. ú()Ú
ValueErrorÚevalZuser_ns)ÚnameÚcontext© r   úL/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/h5py/ipy_completer.pyÚ_retrieve_obj:   s    r   c                    sª   t  |¡ddd… \}‰ zt|| ƒ}W n ty<   g  Y S 0 t ˆ ¡\‰}z,ˆrn‡fdd„|ˆ  ¡ D ƒ}n| ¡ }W n tyŽ   g  Y S 0 t|ƒ}‡ fdd„|D ƒS )z3Compute possible item matches for dict-like objectsr   é   é   c                 3   s   | ]}t  ˆ |¡V  qd S ©N)Ú	posixpathÚjoin)Ú.0r   )Úpathr   r   Ú	<genexpr>U   ó    z&h5py_item_completer.<locals>.<genexpr>c                    s$   g | ]}|d t ˆ ƒ… ˆ kr|‘qS r   ©Úlen)r   Úi)Úitemr   r   Ú
<listcomp>]   r   z'h5py_item_completer.<locals>.<listcomp>)Úre_item_matchÚsplitr   Ú	Exceptionr   ÚkeysÚAttributeErrorÚlist)r   ÚcommandÚbaseÚobjÚ_Úitemsr   )r   r   r   Úh5py_item_completerG   s    

r)   c                    sØ   t  |¡dd… \‰‰ ˆ ¡ ‰ztˆ| ƒ}W n tyB   g  Y S 0 t|ƒ}zt ||¡}W n tyn   Y n0 zt	ƒ j
j}W n ty”   d}Y n0 |dkr®dd„ |D ƒ}n|dkrÄdd„ |D ƒ}‡ ‡fdd„|D ƒS )	z:Compute possible attr matches for nested dict-like objectsr   é   r   c                 S   s   g | ]}|  d ¡s|‘qS )Ú__©Ú
startswith©r   Úar   r   r   r   x   r   z'h5py_attr_completer.<locals>.<listcomp>r   c                 S   s   g | ]}|  d ¡s|‘qS )r'   r,   r.   r   r   r   r   z   r   c                    s,   g | ]$}|d t ˆ ƒ… ˆ krdˆ|f ‘qS )Nz%s.%sr   r.   ©Úattrr%   r   r   r   |   r   )Úre_attr_matchr   Ústripr   r    Údirr   Zcomplete_objectr   r   Z	CompleterÚomit__namesr"   )r   r$   r&   Úattrsr5   r   r0   r   Úh5py_attr_completer`   s(    

r7   c                 C   sv   t  |j¡d }t|  |¡ d¡ttfƒs.t‚zt	| |jƒW S  t
yN   Y n0 zt| |jƒW S  t
yp   Y n0 g S )z. Completer function to be loaded into IPython r   r&   )Úre_object_matchr   ÚlineÚ
isinstanceZ_ofindÚgetr   r   r   r7   r	   r)   )ÚselfÚeventr%   r   r   r   Úh5py_completer   s    r>   c                 C   s"   | du 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   ÚreZ	_hl.attrsr   Z_hl.baser   ZIPythonr   ZIPython.core.errorr   ZIPython.utilsr   Úcompiler2   r   r8   r   r)   r7   r>   r@   r   r   r   r   Ú<module>   s   


