
Xc           @@  s  d  Z  d d l m Z d d l Z d d l Z d d l Z d d l m Z d d l m	 Z	 y d d l
 m Z WnI e k
 r y d d l m Z Wq e k
 r d d l m Z q Xn Xy d d	 l m Z Wn! e k
 r d d	 l
 m Z n Xy d d
 l m Z WnI e k
 rQy d d
 l
 m Z WqRe k
 rMd d
 l m Z qRXn Xe j d  Z e j d  Z e j d  Z d   Z d   Z d   Z d   Z d d  Z d S(   s9  
    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>
i    (   t   absolute_importNi   (   t   AttributeManager(   t   HLObject(   t   get_ipython(   t   get(   t   generics(   t   TryNexts   (?:.*\=)?(.+\[.*\].*)\.(\w*)$s,   (?:.*\=)?(.*)\[(?P<s>['|"])(?!.*(?P=s))(.*)$s   (?:.*\=)?(.+?)(?:\[)c         C@  s[   d |  k r t     n  y t |  | j j  } Wn# t k
 rV t |  | j  } n X| S(   s!    Filter function for completion. t   ((   t
   ValueErrort   evalt   shellt   user_nst   AttributeError(   t   namet   contextt   obj(    (    s0   /tmp/pip-build-isqEY4/h5py/h5py/ipy_completer.pyt   _retrieve_objQ   s    c         @  s   t  j |  d d d  \ } } y t | |   } Wn t k
 rI g  SXt j |  \   } y9   r   f d   |   j   D } n | j   } Wn t k
 r g  SXt |  } t j	 d  g  | D]" } | t
 |   | k r | ^ q S(   s3   Compute possible item matches for dict-like objectsi   i   i   c         3@  s!   |  ] } t  j   |  Vq d  S(   N(   t	   posixpatht   join(   t   .0R   (   t   path(    s0   /tmp/pip-build-isqEY4/h5py/h5py/ipy_completer.pys	   <genexpr>r   s    s    	
`!@#$^&*()=+[{]}\|;:'",<>?(   t   re_item_matcht   splitR   t	   ExceptionR   t   keysR   t   listt   readlinet   set_completer_delimst   len(   R   t   commandt   baset   itemR   t   _t   itemst   i(    (   R   s0   /tmp/pip-build-isqEY4/h5py/h5py/ipy_completer.pyt   h5py_item_completerd   s    "#c         C@  s  t  j |  d d !\ } } | j   } y t | |   } Wn t k
 rO g  SXt |  } y t j | |  } Wn t k
 r n Xd	 } y t
   j j } Wn t k
 r n X| d	 k r y t
   j } Wq t k
 r q Xn  | d	 k r"y t
   j j } Wq"t k
 rd } q"Xn  | d k rYg  | D] } | j d  s5| ^ q5} n7 | d k rg  | D] } | j d  sl| ^ ql} n  t j d  g  | D], } | t |   | k rd | | f ^ qS(
   s:   Compute possible attr matches for nested dict-like objectsi   i   i    t   __i   R    s    =s   %s.%sN(   t   re_attr_matchR   t   stripR   R   t   dirR   t   complete_objectR   t   NoneR   t	   Completert   omit__namesR   t   readline_omit__namest   optionst
   startswithR   R   R   (   R   R   R   t   attrR   t   attrsR+   t   a(    (    s0   /tmp/pip-build-isqEY4/h5py/h5py/ipy_completer.pyt   h5py_attr_completer~   s@    ++c         C@  s   t  j | j  d } t |  j |  d t t f  sA t  n  y t |  | j  SWn t	 k
 rh n Xy t
 |  | j  SWn t	 k
 r n Xg  S(   s.    Completer function to be loaded into IPython i   R   (   t   re_object_matchR   t   linet
   isinstancet   _ofindR   R   R   R2   R   R#   (   t   selft   eventR   (    (    s0   /tmp/pip-build-isqEY4/h5py/h5py/ipy_completer.pyt   h5py_completer   s    "	c         C@  s2   |  d k r t   }  n  |  j d t d d d S(   s&    Load completer function into IPython t   complete_commandt   re_keys   (?:.*\=)?(.+?)\[N(   R)   R   t   set_hookR9   (   t   ip(    (    s0   /tmp/pip-build-isqEY4/h5py/h5py/ipy_completer.pyt   load_ipython_extension   s    (   t   __doc__t
   __future__R    R   t   reR   t	   _hl.attrsR   t   _hl.baseR   t   IPythonR   t   ImportErrort   IPython.core.ipapiR   t   IPython.ipapit   IPython.utilsR   t   IPython.core.errorR   t   compileR%   R   R3   R   R#   R2   R9   R)   R>   (    (    (    s0   /tmp/pip-build-isqEY4/h5py/h5py/ipy_completer.pyt   <module>(   s@   			-	