B
    d:                 @   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| krt  t| |jS )z! Filter function for completion. ()
ValueErrorevalZuser_ns)namecontext r   D/var/www/html/venv/lib/python3.7/site-packages/h5py/ipy_completer.py_retrieve_obj:   s    r   c                s   t |ddd \} yt|| }W n tk
r:   g S X t \}y,rlfdd|  D }n| }W n tk
r   g S X 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 )N)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 \  yt| }W n tk
r@   g S X t|}yt||}W n tk
rn   Y nX yt	 j
j}W n tk
r   d}Y nX |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   s    z'h5py_attr_completer.<locals>.<listcomp>r   c             S   s   g | ]}| d s|qS )r$   )r)   )r   r*   r   r   r   r   z   s    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   )r   r!   r#   attrsr/   r   )r+   r"   r   h5py_attr_completer`   s(    
r1   c             C   sv   t |jd }t| |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_ofindgetr   r   r   r1   r	   r&   )selfeventr"   r   r   r   h5py_completer   s    r8   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_hookr8   )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   compiler,   r   r2   r   r&   r1   r8   r:   r   r   r   r   <module>(   s   


