
    d                         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j        d	          Z ej        d
          Z ej        d          Zd Zd Zd Zd Z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                 P    d| v rt                      t          | |j                  S )z! Filter function for completion. ()
ValueErrorevaluser_ns)namecontexts     2lib/python3.11/site-packages/h5py/ipy_completer.py_retrieve_objr   :   s)     d{{llgo&&&    c                    t                               |          ddd         \  }	 t          ||           }n# t          $ r g cY S w xY wt	          j                  \  }	 r'fd|                                         D             }n|                                }n# t          $ r g cY S w xY wt          |          }fd|D             S )z3Compute possible item matches for dict-like objectsr         c              3   B   K   | ]}t          j        |          V  d S N)	posixpathjoin).0r   paths     r   	<genexpr>z&h5py_item_completer.<locals>.<genexpr>U   s/      MMDY^D$//MMMMMMr   c                 J    g | ]}|d t                             k    | S r   len)r   iitems     r   
<listcomp>z'h5py_item_completer.<locals>.<listcomp>]   s1    666!*3t99* 5 5A 5 5 5r   )re_item_matchsplitr   	Exceptionr   keysAttributeErrorlist)r   commandbaseobj_itemsr!   r   s         @@r   h5py_item_completerr.   G   s    $$W--a!e4JD$D'**   			 od##GD! 	MMMMCINN<L<LMMMEEHHJJE   			 KKE6666u6666s!   ; A
	A
%=B# #B21B2c                    t                               |          dd         \                                  	 t          |           }n# t          $ r g cY S w xY wt          |          }	 t          j        ||          }n# t          $ r Y nw xY w	 t                      j
        j        }n# t          $ r d}Y nw xY w|dk    rd |D             }n|dk    rd |D             }fd|D             S )z:Compute possible attr matches for nested dict-like objectsr      r   c                 <    g | ]}|                     d           |S )__
startswithr   as     r   r"   z'h5py_attr_completer.<locals>.<listcomp>x   s)    <<<qd););<<<<r   r   c                 <    g | ]}|                     d           |S )r,   r3   r5   s     r   r"   z'h5py_attr_completer.<locals>.<listcomp>z   s)    ;;;qc):):;;;;r   c                 T    g | ]$}|d t                             k    d|%S )N.r   )r   r6   attrr*   s     r   r"   z'h5py_attr_completer.<locals>.<listcomp>|   s<    HHHA!JSYYJ-42G2GtttQQ2G2G2Gr   )re_attr_matchr$   stripr   r%   dirr   complete_objectr   r   	Completeromit__namesr'   )r   r)   r+   attrsr@   r:   r*   s        @@r   h5py_attr_completerrB   `   sJ    $$W--ac2JD$::<<DD'**   			 HHE(e44   !mm-9    a<<E<<<			;;E;;;HHHHHHHHHs5   A AA0B 
BBB0 0B?>B?c                    t                               |j                  d         }	 |                     |          j        }n8# t
          $ r+ |                     |                              d          }Y nw xY wt          |t          t          f          st          	 t          | |j                  S # t          $ r Y nw xY w	 t          | |j                  S # t          $ r Y nw xY wg S )z. Completer function to be loaded into IPython r   r+   )re_object_matchr$   line_ofindr+   r'   get
isinstancer   r   r   rB   r   r.   )selfeventr*   r+   s       r   h5py_completerrK      s	     ,,Q/D+kk$# + + +kk$##E**+ c,h788 "4444   "4444    Is5   A 2A76A7B3 3
C ?C C 
C&%C&c                 `    | t                      } |                     dt          d           dS )z& Load completer function into IPython Ncomplete_commandz(?:.*\=)?(.+?)\[)re_key)r   set_hookrK   )ips    r   load_ipython_extensionrQ      s0    	z]]KK"N;NKOOOOOr   r   )__doc__r   re	_hl.attrsr   _hl.baser   IPythonr   IPython.core.errorr   IPython.utilsr   compiler;   r#   rD   r   r.   rB   rK   rQ    r   r   <module>r[      s    4     				 ' ' ' ' ' '              & & & & & & " " " " " "
;<<
NOO"*455
' 
' 
'7 7 72I I I>  2P P P P P Pr   