ó
æNXc           @   s¢   d  Z  d d l Z d d l Z d d l m Z d d l m Z d g d „ Z e ƒ  \ Z Z	 d „  Z
 e d	 „ Z d
 „  Z d d e e d „ Z e e d „ Z d S(   s‘   Support for wildcard pattern matching in object inspection.

Authors
-------
- JÃ¶rgen Stenarson <jorgen.stenarson@bostream.nu>
- Thomas Kluyver
iÿÿÿÿN(   t   dir2i   (   t	   iteritemst   lambdac         C   s˜   g  t  t ƒ D] } | j d ƒ r | ^ q } i  i  } } xP | D]H } | d  j ƒ  } t t | ƒ } | | | <| |  k rB | | | <qB qB W| | f S(   sz   Return dictionaries mapping lower case typename (e.g. 'tuple') to type
    objects from the types package, and vice versa.t   Typeiüÿÿÿ(   t   dirt   typest   endswitht   lowert   getattr(   t   dont_include_in_type2typestrt   tnamet   typenamelistt   typestr2typet   type2typestrt   namet   obj(    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/wildcard.pyt   create_typestr2type_dicts   s    .
c         C   sT   | d k r t  St | ƒ t k r+ | } n t j | t ƒ } | rP t |  | ƒ St S(   s  is_type(obj, typestr_or_type) verifies if obj is of a certain type. It
    can take strings or actual python types for the second argument, i.e.
    'tuple'<->TupleType. 'all' matches all types.

    TODO: Should be extended for choosing more than one type.t   all(   t   Truet   typeR   t   gett   Falset
   isinstance(   R   t   typestr_or_typet	   test_type(    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/wildcard.pyt   is_type'   s    	c         C   s#   | p" |  j  d ƒ p" |  j  d ƒ S(   sC   Return true for strings starting with single _ if show_all is true.t   __t   _(   t
   startswith(   t   strt   show_all(    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/wildcard.pyt   show_hidden7   s    c         C   sL   i  } x? t  |  ƒ D]1 } y t |  | ƒ | | <Wq t k
 rC q Xq W| S(   sw   Produce a dictionary of an object's attributes. Builds on dir2 by
    checking that a getattr() call actually succeeds.(   R    R   t   AttributeError(   R   t   nst   key(    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/wildcard.pyt   dict_dir;   s    t   *R   c            sy   | j  d d ƒ j  d d ƒ } | r@ t j | d t j ƒ ‰ n t j | d ƒ ‰ t ‡  ‡ ‡ f d †  t |  ƒ Dƒ ƒ S(   s<   Filter a namespace dictionary by name pattern and item type.R$   s   .*t   ?t   .t   $c         3   sN   |  ]D \ } } ˆ j  | ƒ r t | ˆ  ƒ r t | ˆ ƒ r | | f Vq d  S(   N(   t   matchR   R   (   t   .0R"   R   (   R   t   type_patternt   reg(    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/wildcard.pys	   <genexpr>V   s    (   t   replacet   ret   compilet   It   dictR   (   R!   t   name_patternR*   t   ignore_caseR   t   pattern(    (   R   R*   R+   sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/wildcard.pyt	   filter_nsL   s
    c      
   C   sü   | j  d ƒ } t | ƒ d k rG t |  d | d d | d | d | ƒSt |  d | d d d d | d | ƒ} i  } x| t | ƒ D]n \ } }	 t t |	 ƒ | d j | d ƒ d | d | ƒ}
 x. t |
 ƒ D]  \ } } | | d	 | | f <qÌ Wq‚ W| Sd
 S(   sb   Return dictionary of all objects in a namespace dictionary that match
    type_pattern and filter.R&   i   R1   i    R*   R2   R   R   s   %s.%sN(   t   splitt   lenR4   R   t   list_namespaceR#   t   join(   t	   namespaceR*   t   filterR2   R   t   pattern_listt   filteredt   resultsR   R   R!   t
   inner_namet	   inner_obj(    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/wildcard.pyR7   Z   s     (   t   __doc__R-   R   t   IPython.utils.dir2R    t	   py3compatR   R   R   R   R   R   R   R#   R   R4   R7   (    (    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/wildcard.pyt   <module>   s   				