o
    2h                     @   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evaluser_ns)namecontext r   M/var/www/html/chatgem/venv/lib/python3.10/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 w t \}zr7fdd|  D }n| }W n tyG   g  Y S w 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   s    z&h5py_item_completer.<locals>.<genexpr>c                    s$   g | ]}|d t    kr|qS r   len)r   i)itemr   r   
<listcomp>]   s   $ 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y!   g  Y S w t|}zt||}W n	 ty7   Y nw zt	 j
j}W n tyJ   d}Y nw |dkrWdd |D }n|dkrbdd |D } fdd|D S )	z:Compute possible attr matches for nested dict-like objectsr      r   c                 S      g | ]	}| d s|qS )__
startswithr   ar   r   r   r   x       z'h5py_attr_completer.<locals>.<listcomp>r   c                 S   r+   )r'   r-   r/   r   r   r   r   z   r1   c                    s,   g | ]}|d t    krd|f qS )Nz%s.%sr   r/   attrr%   r   r   r   |   s   , )re_attr_matchr   stripr   r    dirr   complete_objectr   r   	Completeromit__namesr"   )r   r$   r&   attrsr9   r   r2   r   h5py_attr_completer`   s.   r;   c                 C   s   t |jd }z| |j}W n ty!   | |d}Y nw t|tt	fs+t
zt| |jW S  ty;   Y nw zt| |jW S  tyM   Y g S w )z. Completer function to be loaded into IPython r   r&   )re_object_matchr   line_ofindr&   r"   get
isinstancer   r   r   r;   r	   r)   )selfeventr%   r&   r   r   r   h5py_completer   s&   rC   c                 C   s"   | du rt  } | jdtdd dS )z& Load completer function into IPython Ncomplete_commandz(?:.*\=)?(.+?)\[)re_key)r   set_hookrC   )ipr   r   r   load_ipython_extension   s   rH   r   )__doc__r   re	_hl.attrsr   _hl.baser   IPythonr   IPython.core.errorr   IPython.utilsr   compiler4   r   r<   r   r)   r;   rC   rH   r   r   r   r   <module>   s    


