Ñò
ÎÑAHc           @   s
  d  Z  d d k l Z d e i d Z e i Z d d g 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 Z d d k Z d d k l Z d d	 k l Z l Z l Z l Z d d
 k l Z d d k l Z d d k Te i d  d j o2 d d k	 l Z l Z l Z d „  Z e e	 _ n e  Z! e" d h e! i# d 6e! i# d 6ƒ Z# e" d h e! i$ d 6e! i% d 6ƒ Z& e" d h e! i' d 6e! i% d 6ƒ Z( e) e# e& e( g d ƒ Z* d „  Z+ e, d „ Z- d e i f d „  ƒ  YZ. d d d „  ƒ  YZ/ d S(   s-  Tools for inspecting Python objects.

Uses syntax highlighting for presenting the various information elements.

Similar in spirit to the inspect module, but all calls take a name argument to
reference the name under which an object is being read.

$Id: OInspect.py 2843 2007-10-15 21:22:32Z fperez $
iÿÿÿÿ(   t   Releases   %s <%s>t   Fernandot	   Inspectort   InspectColorsN(   t
   PyColorize(   t   paget   indentt   Termt   mkdict(   t   itpl(   t   list_namespace(   t   *i   i   (   t   ismodulet
   getabsfilet   modulesbyfilec      	   C   s—  t  |  ƒ o |  St |  d ƒ o t i i |  i ƒ Sy t |  ƒ } Wn t j
 o d SX| t	 j o t i i t	 | ƒ SxJ t i i
 ƒ  D]9 } t | d ƒ o# | i t	 t i i t | ƒ ƒ <q q W| t	 j o t i i t	 | ƒ St i d } t |  d ƒ p d St | |  i ƒ o( t | |  i ƒ } | |  j o | Sn t i d } t | |  i ƒ o( t | |  i ƒ } | |  j o | Sn d S(   sA   Return the module an object was defined in, or None if not found.t
   __module__t   __file__t   __main__t   __name__t   __builtin__N(   R   t   hasattrt   syst   modulest   getR   R   t	   TypeErrort   NoneR   t   valuesR   t   ost   patht   realpatht   getattr(   t   objectt   filet   modulet   maint
   mainobjectt   builtint   builtinobject(    (    sH   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/OInspect.pyt	   getmodule.   s8     '	t   NoColort   headert   normalt   Linuxt   LightBGc      	   C   sh   d } y t i |  ƒ } Wn n Xy |  i ƒ  } Wn n( X| d j o
 | } n d | | f } | S(   s8  Stable wrapper around inspect.getdoc.

    This can't crash because of attribute problems.

    It also attempts to call a getdoc() method on the given object.  This
    allows objects which provide their docstrings via non-standard mechanisms
    (like Pyro proxies) to still be inspected by ipython's ? system.s   %s
%sN(   R   t   inspectt   getdoc(   t   objt   dst   ds2(    (    sH   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/OInspect.pyR-   n   s    	
c         C   s   | o d St i |  ƒ Sd S(   s½  Wrapper around inspect.getsource.

    This can be modified by other projects to provide customized source
    extraction.

    Inputs:

    - obj: an object whose source code we will attempt to extract.

    Optional inputs:

    - is_binary: whether the object is known to come from a binary source.
    This implementation will skip returning any output for binary objects, but
    custom extractors may know how to meaningfully process them.N(   R   R,   t	   getsource(   R.   t	   is_binary(    (    sH   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/OInspect.pyR1   ‹   s    t
   myStringIOc           B   s   e  Z d  Z d „  Z RS(   s)   Adds a writeln method to normal StringIO.c         O   s!   |  i  | | Ž  |  i  d ƒ d S(   s$   Does a write() and then a write('
')s   
N(   t   write(   t   selft   argt   kw(    (    sH   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/OInspect.pyt   writeln¥   s    (   R   R   t   __doc__R8   (    (    (    sH   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/OInspect.pyR3   £   s   c           B   sž   e  Z d  d „ Z d „  Z d d „ Z d „  Z d „  Z d „  Z d d „ Z d d d	 „ Z
 d d
 „ Z d d „ Z d d d d  d „ Z g  e e d „ Z RS(   i    c         C   sJ   | |  _  t i | d d ƒ|  _ |  i i |  _ | |  _ |  i | ƒ d  S(   Nt   outt   str(   t   color_tableR   t   Parsert   parsert   formatt   str_detail_levelt   set_active_scheme(   R5   R<   t   code_color_tablet   schemeR@   (    (    sH   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/OInspect.pyt   __init__«   s
    		c         C   sn   t  i | ƒ o
 | } n' t  i | ƒ o | i } n
 t d ‚ t  i | i ƒ \ } } } | | | | i f S(   sÑ  Get the names and default values of a function's arguments.

        A tuple of four things is returned: (args, varargs, varkw, defaults).
        'args' is a list of the argument names (it may contain nested lists).
        'varargs' and 'varkw' are the names of the * and ** arguments or None.
        'defaults' is an n-tuple of the default values of the last n arguments.

        Modified version of inspect.getargspec from the Python Standard
        Library.s   arg is not a Python function(   R,   t
   isfunctiont   ismethodt   im_funcR   t   getargst	   func_codet   func_defaults(   R5   R.   t   func_objt   argst   varargst   varkw(    (    sH   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/OInspect.pyt   __getargspec³   s    
	t    c         C   s-   y | t  i |  i | ƒ Œ  SWn d SXd S(   sŸ   Return the definition header for any callable object.

        If any exception is generated, None is returned instead and the
        exception is suppressed.N(   R,   t   formatargspect   _Inspector__getargspecR   (   R5   R.   t   oname(    (    sH   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/OInspect.pyt   __getdefÇ   s    c         C   s#   d |  i  i i | |  i  i i f S(   s*   Return a header string with proper colors.s   %s%s%s(   R<   t   active_colorsR(   R)   (   R5   t   h(    (    sH   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/OInspect.pyt   __headÒ   s    c         C   s'   |  i  i | ƒ |  i i  i | ƒ d  S(   N(   R<   RA   R>   (   R5   RC   (    (    sH   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/OInspect.pyRA   ×   s    c         C   s!   d | G| o d | GHn Hd S(   s-   Generic message when no information is found.s   No %s founds   for %sN(    (   R5   t   msgRS   (    (    sH   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/OInspect.pyt   noinfoÛ   s    c         C   s¿   t  | ƒ p
 d GHd Sd } t i | ƒ o |  i d ƒ } | i } n$ t | ƒ t i j o | i } n |  i	 | | ƒ } | d j o |  i d | ƒ n t i | I|  i | ƒ Id S(   sz   Print the definition header for any callable object.

        If the object is a class, print the constructor information.s   Object is not callable.NRP   s   Class constructor information:
s   definition header(   t   callableR,   t   isclasst   _Inspector__headRD   t   typet   typest   InstanceTypet   __call__t   _Inspector__getdefR   RY   R   t   coutR?   (   R5   R.   RS   R(   t   output(    (    sH   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/OInspect.pyt   pdefã   s    c   	      C   s÷   |  i  } t | ƒ } | o | | ƒ } n t i | ƒ o t | i ƒ } t d ƒ } nm t | ƒ t i j p t	 | t
 ƒ o@ t | d ƒ o0 t | i ƒ } | o t d ƒ } qÇ | } n | } | d j o |  i d | ƒ d St | ƒ d S(   sž   Print the docstring for any object.

        Optional:
        -formatter: a function to run the docstring through for specially
        formatted docstrings.sV   $head("Class Docstring:")
$indent(ds)
$head("Constructor Docstring"):
$indent(init_ds)R`   sR   $head("Class Docstring:")
$indent(ds)
$head("Calling Docstring:")
$indent(call_ds)t   documentationN(   R\   R-   R,   R[   RD   R	   R]   R^   R_   t
   isinstanceR   R   R`   R   RY   R   (	   R5   R.   RS   t	   formattert   headR/   t   init_dsRc   t   call_ds(    (    sH   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/OInspect.pyt   pdocú   s$    	&
c         C   sK   t  i ƒ  y t | ƒ } Wn |  i d | ƒ n Xt |  i | ƒ ƒ d S(   s$   Print the source code for an object.t   sourceN(   t	   linecachet
   checkcacheR1   RY   R   R?   (   R5   R.   RS   t   src(    (    sH   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/OInspect.pyt   psource  s    
c         C   sµ   y t  i | ƒ \ } } Wn |  i d | ƒ n Xt  i | ƒ } | i d ƒ p | i d ƒ o d | GHnC t i i | ƒ p d | GHn# t |  i	 t
 | ƒ i ƒ  ƒ | ƒ d S(   s0   Show the whole file where an object was defined.R    s   .sos   .dlls    File %r is binary, not printing.s%   File %r does not exist, not printing.N(   R,   t   getsourcelinesRY   R   t   endswithR   R   t   isfileR   R?   t   opent   read(   R5   R.   RS   t   sourcelinest   linenot   ofile(    (    sH   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/OInspect.pyt   pfile&  s     c   $   $   C   s.  t  | ƒ } |  i } | d. j o d } d }	 d }
 n | i } | i }	 | i }
 |	 op t | ƒ p0 y d | d } WqÆ d t | ƒ } qÆ Xqí d t | ƒ } | i o | d | i 7} qí n$ t	 | ƒ } | d. j o
 d } n | d. j	 o | | ƒ } n t
 ƒ  } d	 } t | d
 d ƒ } | o
 d } n |	 o
 d } n
 | i } | i | d ƒ | ƒ y* | i } | i | d ƒ t | ƒ ƒ Wn n X| |  i j oØ yÊ t | ƒ } d } | of t | ƒ | j oS | |  d | | } d d t | i ƒ  ƒ i t t i | i d ƒ ƒ ƒ } n | i d ƒ d j o
 d } n d } | i d | | ƒ | | f ƒ Wq‹q‹Xn |
 o | i | d ƒ |
 ƒ n y- t t | ƒ ƒ } | i | d ƒ | ƒ Wn n Xt } y® y t i | ƒ } Wn9 t j
 o- t | d ƒ o t i | i ƒ } q<n X| i d ƒ o
 d } n | i d ƒ p | i d ƒ o
 t } n | i | d ƒ | ƒ Wn t } n X|  i | | ƒ } | o$ | i  | d ƒ |  i! | ƒ ƒ n | o. | d j o! | i | d  ƒ t" | ƒ ƒ n | oò t# i$ ƒ  t } y– y t% | | ƒ } Wn9 t j
 o- t | d ƒ o t% | i | ƒ } qƒn X| d. j	 o6 |  i! | ƒ } | i  | d! ƒ | i& ƒ  ƒ t } n Wn t' j
 o	 } n X| o) | o! | i | d" ƒ t" | ƒ ƒ qn t i( | ƒ oè y | i) } Wn t* j
 o d. } } nA X|  i | | ƒ } t	 | ƒ } | o | i+ d# ƒ o
 d. } n | p | oj | i | d$ ƒ ƒ | o$ | i  | d ƒ |  i! | ƒ ƒ n | o! | i | d  ƒ t" | ƒ ƒ qq	nÿ| t, i- j p t. | t/ ƒ oÞ| o© y t0 | d ƒ } Wn d. }  n Xt	 | ƒ }  |  o: |  i+ d% ƒ p  |  i+ d& ƒ p |  i+ d' ƒ o
 d. }  n |  o. | |  j o! | i | d( ƒ t" |  ƒ ƒ qÛn y4 t	 | i) ƒ } | o | i+ d# ƒ o
 d. } n Wn t* j
 o d. } n X| o! | i | d) ƒ t" | ƒ ƒ n t | d* ƒ o¢ |  i | i1 | ƒ }! |! d. j	 o$ | i | d+ ƒ |  i! |! ƒ ƒ n t	 | i1 ƒ }" |" o |" i+ d, ƒ o
 d. }" n |" o! | i | d- ƒ t" |" ƒ ƒ qq	n | i2 ƒ  }# |# o t3 |# ƒ n d. S(/   s…  Show detailed information about an object.

        Optional arguments:
        
        - oname: name of the variable pointing to the object.

        - formatter: special formatter for docstrings (see pdoc)

        - info: a structure with some information fields which may have been
        precomputed already.

        - detail_level: if set to 1, more information is given.
        i    RP   s!   Alias to the system command:
  %si   s   Alias: s	   Alias to s   
Docstring:
s   <no docstring>iÈ   i   i   s   Magic functions   System aliass   Type:		s   Base Class:	s   String Form:s    <...> s   
t    iÿÿÿÿs   	s   %s%s%ss   Namespace:	s	   Length:		t	   __class__s   <string>s9   Dynamically generated function. No source code available.s   .sos   .dlls   File:		s   Definition:	s   Docstring:
s   Source:
s%   Docstring [source file open failed]:
s   x.__init__(...) initializess   
Constructor information:s   function(code, globals[,s"   instancemethod(function, instance,s   module(name[,s   Class Docstring:
s   Constructor Docstring:
R`   s
   Call def:	s   x.__call__(...) <==> x(...)s   Call docstring:
N(4   R]   R\   R   t   ismagict   isaliast	   namespaceRZ   R;   R9   R-   R3   t   intR   R8   R{   R@   t   lent
   expandtabst   joint   mapt   stringt   stript   splitt   findt   FalseR,   R   R   R   Rr   t   TrueRa   R4   R?   R   Rm   Rn   R1   t   rstript	   ExceptionR[   RD   t   AttributeErrort
   startswithR^   R_   Rf   R   R   R`   t   getvalueR   ($   R5   R.   RS   Rg   t   infot   detail_levelt   obj_typeR(   R|   R}   t   ospaceR/   R:   t
   string_maxt   shalft   obj_type_namet   bclasst   ostrt   str_headt   str_sept   lengtht   binary_filet   fnamet   deflnt   source_successRo   Rl   RX   t   obj_initt   init_defRi   t   clst   class_dst   call_defRj   Rc   (    (    sH   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/OInspect.pyt   pinfo:  s*   	
			

	

		! "
$ 
 

$!

$)

$
)c         C   s  d } d } | i  ƒ  } t | ƒ }	 |	 d j o | d } n. |	 d j o | \ } } n t d | ƒ ‚ x; | D]3 }
 |
 | j o  t d |
 | i ƒ  f ƒ ‚ qs qs Wg  } xI | D]A } | | } t t | | | d | d	 | ƒƒ } | i | ƒ q· W| i ƒ  t d
 i	 | ƒ ƒ d S(   sO  Search namespaces with wildcards for objects.

        Arguments:

        - pattern: string containing shell-like wildcards to use in namespace
        searches and optionally a type specification to narrow the search to
        objects of that type.

        - ns_table: dict of name->namespaces for search.

        Optional arguments:
        
          - ns_search: list of namespace names to include in search.

          - ignore_case(False): make the search case-insensitive.

          - show_all(False): show all names, including those starting with
          underscores.
        t   allRP   i   i    i   s)   invalid argument string for psearch: <%s>s'   invalid namespace <%s>. Valid names: %st   ignore_caset   show_alls   
N(
   R†   R€   t
   ValueErrort   keyst   listR
   t   extendt   sortR   R‚   (   R5   t   patternt   ns_tablet	   ns_searchR¦   R§   t   type_patternt   filtert   cmdst   len_cmdst   namet   search_resultt   ns_namet   nst   tmp_res(    (    sH   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/OInspect.pyt   psearch  s2    
  

N(   R   R   RD   RR   Ra   R\   RA   RY   Rd   R   Rk   Rp   Ry   R¤   Rˆ   R¹   (    (    (    sH   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/OInspect.pyR   ª   s   				 à(   i   i   (    (0   R9   t   IPythonR    t   authorst
   __author__t   licenset   __license__t   __all__R   R,   Rm   R„   t   StringIOR^   R   R   R   t   IPython.genutilsR   R   R   R   t   IPython.ItplR	   t   IPython.wildcardR
   t   IPython.ColorANSIt   version_infoR   R   R   R&   t
   TermColorst   Colorst   ColorSchemeR'   t   LightRedt   Normalt   LinuxColorst   Redt   LightBGColorst   ColorSchemeTableR   R-   Rˆ   R1   R3   R   (    (    (    sH   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/OInspect.pyt   <module>
   sP   		"
	 


		