Ñò
ÎÑAHc           @   sÙ   d  Z  d d k l Z d Z e i Z d d k Z d d k Z d d k Z d d k	 Z	 d d k
 Z
 d d k Z d d k l Z d g d „ Z e ƒ  \ Z Z d „  Z e d	 „ Z d
 e f d „  ƒ  YZ e e d „ Z d S(   sp   Support for wildcard pattern matching in object inspection.

$Id: OInspect.py 608 2005-07-06 17:52:32Z fperez $
iÿÿÿÿ(   t   Releases0   JÃ¶rgen Stenarson <jorgen.stenarson@bostream.nu>N(   t   dir2t   lambdac         C   s³   g  } x6 t  t ƒ D]( } | d d j o | i | ƒ q q Wh  } h  } x[ | D]S } | d  i ƒ  } t t | ƒ } t t | ƒ | | <| |  j o | | | <qR qR W| | f S(   sl   Return dictionaries mapping lower case typename to type objects, from
    the types package, and vice versa.iüÿÿÿt   Type(   t   dirt   typest   appendt   lowert   getattr(   t   dont_include_in_type2type2strt   typenamelistt   tnamet   typestr2typet   type2typestrt   namet   obj(    (    sH   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/wildcard.pyt   create_typestr2type_dicts   s      c         C   sa   | d j o t  St | ƒ t i j o
 | } n t i | t ƒ } | o t |  | ƒ St Sd S(   sò   is_type(obj,typestr_or_type) verifies if obj is of a certain type or
    group of types takes strings as parameters of the for 'tuple'<->TupleType
    'all' matches all types.  TODO: Should be extended for choosing more than
    one type
    t   allN(   t   Truet   typeR   t   TypeTypeR   t   gett   Falset
   isinstance(   R   t   typestr_or_typet	   test_type(    (    sH   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/wildcard.pyt   is_type.   s    
c         C   s%   | p |  i  d ƒ p |  i  d ƒ S(   sC   Return true for strings starting with single _ if show_all is true.t   __t   _(   t
   startswith(   t   strt   show_all(    (    sH   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/wildcard.pyt   show_hidden?   s    t	   NameSpacec           B   s\   e  Z d  Z d d e e d „ Z d „  Z e e ƒ Z d „  Z e e d d ƒZ	 d „  Z
 RS(	   s]   NameSpace holds the dictionary for a namespace and implements filtering
    on name and typest   *R   c      	   C   sÊ   | |  _  | |  _ | |  _ | |  _ | |  _ t | ƒ t i j o | |  _ nw g  } x^ t	 | ƒ D]P } t
 | t ƒ o: y  | i | t | | ƒ f ƒ Wq³ t j
 o q³ Xqc qc Wt | ƒ |  _ d  S(   N(   R   t   objectt   name_patternt   type_patternt   ignore_caseR   R   t   DictTypet   _nsR   R   t
   basestringR   R   t   AttributeErrort   dict(   t   selfR   R$   R%   R&   R   t   kvt   key(    (    sH   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/wildcard.pyt   __init__F   s     					  c         C   s   |  i  |  i |  i ƒ S(   sJ   Return name space dictionary with objects matching type and name patterns.(   t   filterR$   R%   (   R,   (    (    sH   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/wildcard.pyt   get_nsa   s    c         C   s   |  i  i ƒ  S(   sA   Return list of object names in namespace that match the patterns.(   t   nst   keys(   R,   (    (    sH   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/wildcard.pyt   get_ns_namesf   s    t   docsD   List of objects in name space that match the type and name patterns.c         C   s©   d „  } |  i  } g  } | | i ƒ  | |  i |  i ƒ D] } | | | | f q8 ~ } g  } | D]- \ }	 }
 t |
 | ƒ o | |	 |
 f qc qc ~ } t | ƒ } | S(   s(   Return dictionary of filtered namespace.c   	      S   sž   | i  d d ƒ i  d d ƒ } | o t i | d t i ƒ } n t i | d ƒ } g  } |  D]1 } | i | ƒ o t | | ƒ o | | q` q` ~ } | S(   s4   Return list of elements in lista that match pattern.R"   s   .*t   ?t   .t   $(   t   replacet   ret   compilet   It   matchR    (	   t   listaR$   t
   hidehiddenR&   t   patternt   regt   _[1]t   xt   result(    (    sH   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/wildcard.pyt   glob_filtern   s    E(   R(   R3   R   R&   R   R+   (   R,   R$   R%   RE   R2   RB   RC   R   t   _[2]R.   R   (    (    sH   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/wildcard.pyR0   l   s    			0A(   t   __name__t
   __module__t   __doc__R   R/   R1   t   propertyR2   R4   t   ns_namesR0   (    (    (    sH   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/wildcard.pyR!   C   s   			c      
   C   s
  | i  d ƒ } t | ƒ d j o0 t |  d | d d | d | d | ƒ} | i St |  d | d d d d | d | ƒ} h  } | i } xv | i ƒ  D]h \ }	 }
 t |
 | d i | d ƒ d | d | ƒ} x. | i ƒ  D]  \ } } | | d	 |	 | f <qÚ Wq– W| Sd
 S(   sW   Return dictionary of all objects in namespace that matches type_pattern
    and filter.R7   i   R$   i    R%   R&   R   R   s   %s.%sN(   t   splitt   lenR!   R2   t	   iteritemst   list_namespacet   join(   t	   namespaceR%   R0   R&   R   t   pattern_listR2   t   rest   nsdictR   R   t
   inner_namet	   inner_obj(    (    sH   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/wildcard.pyRO   ‚   s"    	  (   RI   t   IPythonR    t
   __author__t   licenset   __license__t   __builtin__t
   exceptionst   pdbt   pprintR:   R   t   IPython.genutilsR   R   R   R   R   R   R    R#   R!   RO   (    (    (    sH   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/wildcard.pyt   <module>   s    			?