
    1Vh                         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y)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                 J    d| v r
t               t        | |j                        S )z! Filter function for completion. ()
ValueErrorevaluser_ns)namecontexts     B/home/dcms/DCMS/lib/python3.12/site-packages/h5py/ipy_completer.py_retrieve_objr   :   s$     d{lgoo&&    c                    t         j                  |      ddd   \  }}	 t        ||       }t	        j                  |      \  }	 rfd|   j                         D        }n|j                         }t        |      }|D cg c]  }|dt        |       |k(  s| c}S # t        $ r g cY S w xY w# t        $ r g cY S w xY wc c}w )z3Compute possible item matches for dict-like objectsr         c              3   J   K   | ]  }t        j                  |        y wN)	posixpathjoin).0r   paths     r   	<genexpr>z&h5py_item_completer.<locals>.<genexpr>U   s     MDY^^D$/Ms    #N)	re_item_matchsplitr   	Exceptionr   keysAttributeErrorlistlen)	r   commandbaseitemobj_itemsir   s	           @r   h5py_item_completerr+   G   s     $$W-a!e4JD$D'* ood#GD!MCINN<LMEHHJE KE6!*3t9 5A66  	  	
 7s/   B" /B3 CC"B0/B03C Cc                 \   t         j                  |      dd \  }}|j                         }	 t        ||       }t        |      }	 t        j                  ||      }	 t               j                  j                  }|dk(  r"|D cg c]  }|j                  d      r| }}n&|dk(  r!|D cg c]  }|j                  d      r| }}|D cg c]  }|dt        |       |k(  s|d| c}S # t        $ r g cY S w xY w# t        $ r Y w xY w# t        $ r d}Y w xY wc c}w c c}w c c}w )	z:Compute possible attr matches for nested dict-like objectsr      r   __r   r(   N.)re_attr_matchr   stripr   r   dirr   complete_objectr   r   	Completeromit__namesr!   
startswithr#   )r   r$   r%   attrr'   attrsr5   as           r   h5py_attr_completerr:   `   s2    $$W-a2JD$::<DD'* HE((e4!m--99 a!<qd);<<		!;qc):;;).HA!JSY-42GtQHH)  	     =;HsY   C. C? D DD*D$D$D)"	D).C<;C<?	D
DDDc                    t         j                  |j                        d   }	 | j                  |      j                  }t        |t        t        f      st        	 t        | |j                        S # t
        $ r# | j                  |      j                  d      }Y ^w xY w# t        $ r Y nw xY w	 t        | |j                        S # t        $ r Y g S w xY 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'   s       r   h5py_completerrC      s      ,Q/D+kk$## c,h78"444  +kk$##E*+  "444 Is5   A2 B! 2)BB!	B-,B-1C 	CCc                 L    | 
t               } | j                  dt        d       y)z& Load completer function into IPython Ncomplete_commandz(?:.*\=)?(.+?)\[)re_key)r   set_hookrC   )ips    r   load_ipython_extensionrI      s"    	z]KK"N;NKOr   r   )__doc__r   re	_hl.attrsr   _hl.baser   IPythonr   IPython.core.errorr   IPython.utilsr   compiler0   r   r<   r   r+   r:   rC   rI    r   r   <module>rS      sq    4  	 '    & "

;<

NO"**45
'72I>2Pr   