a
    v=ic:                     @   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   c/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/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rdd |D }n|dkrd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   


