
    &e                        U d Z ddgZddlmZ ddlmZ ddlmZ ddlZddl	Z	ddlZddl
ZddlZddlZddlZddlZddlZddlmZmZmZmZmZm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  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) ddl(m*Z* ddl+m,Z,m-Z-m.Z. ddl/m0Z0 ddl1m2Z2 ddl3m4Z4 ddl5m6Z6 ddl7m8Z8 ddl9m:Z: dZ;ee<eee<e<f                  f         Z=ee>d<   ee<e<f         Z?ee>d<   e G d d                      Z@d  ZAejB        jC        j         ZDeEjF        j         ZGd! ejH        ejI        ejB        eJfD             ZK eLeM          ZN eLe<jO                  ZPe,ZQe jR        ZSg d"ZTd# ZUd$ ZVd%ee<df         fd&ZWd3d%ee<df         fd(ZXd) ZYe4d*             ZZe4d+             Z[e4d4d-            Z\d. Z]d%e<fd/Z^d0 Z_ G d1 de2          Z`d%e<fd2ZadS )5zTools 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.
	InspectorInspectColors    )	dataclass)	signature)dedentN)AnyOptionalDictUnionListTuple)	TypeAlias)page)pretty)skip_doctest)
PyColorize)openpy)safe_hasattr)compress_user)indent)list_namespace)typestr2type)
TermColorsColorSchemeColorSchemeTable)cast_unicode)	Colorable)undoc)	highlight)PythonLexer)HtmlFormatter__custom_documentations__UnformattedBundleBundlec                   ^    e Zd ZU eed<   eed<   eed<   ee         ed<   eed<   eed<   d ZdS )	OInfoismagicisaliasfound	namespaceparentobjc                 "    t          | |          S )zGet a field from the object for backward compatibility with before 8.12

        see https://github.com/h5py/h5py/issues/2253
        )getattr)selffields     5lib/python3.11/site-packages/IPython/core/oinspect.pygetz	OInfo.getE   s     tU###    N)	__name__
__module____qualname__bool__annotations__r	   strr   r2    r3   r1   r&   r&   <   sb         MMMMMMKKK}KKK	HHH$ $ $ $ $r3   r&   c                 X    t          | t                      t          d                    S )NT)	noclasses)r   r    r!   )codes    r1   pylightr>   V   s#    T;==-$*G*G*GHHHr3   c                 6    h | ]}t          j        |          S r:   )inspectgetdoc).0ts     r1   	<setcomp>rD   \   s/       GN1  r3   )	type_name
base_classstring_formr*   lengthfile
definition	docstringsourceinit_definitionclass_docstringinit_docstringcall_defcall_docstringr'   r(   isclassr)   namec                  R    d t           D             }|                    |            |S )z1Make an object info dict with all fields present.c                     i | ]}|d S Nr:   )rB   ks     r1   
<dictcomp>zobject_info.<locals>.<dictcomp>{   s    ,,,1$,,,r3   )info_fieldsupdate)kwinfodicts     r1   object_infor]   y   s,    ,,,,,HOOBOr3   c                 .   t          |           }|dS |                    d          rdS t          j                            |          sdS t          j        |d          5 }t          j        |j	                  \  }}ddd           n# 1 swxY w Y   |S )znGet encoding for python source file defining obj

    Returns None if obj is not defined in a sourcefile.
    Nz.soz.dllz.pydrb)
	find_fileendswithospathisfile	stdlib_ioopenr   detect_encodingreadline)r,   ofilebufferencodingliness        r1   get_encodingrn      s    
 cNNE }t	/	0	0 
tW^^E"" t
 ^E4(( 	FF$4V_EEOHe	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	Fs   !B

BBreturnc                     	 |                                  }t          |t                    rt          j        |          S n# t
          $ r Y nw xY wt          j         |           }|S )a=  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.
    )rA   
isinstancer9   r@   cleandoc	Exception)r,   dsdocstrs      r1   rA   rA      sv    (ZZ\\ b# 	(#B'''	(    
 ^C  FMs   A   
AA c           	         t          | t                    rg }dD ]}t          | |          }|t          |          }|rd|z  nd}|                    d                    d||f                     t          j        |          r4t          |          }|r"|                    t          |                     |                    ||dt          |          d           |rd                    |          S dS t          |           } 	 t          j        |           }nP# t          $ r7 	 t          j        | j                  }n# t          t          f$ r Y Y dS w xY wY nt          $ r Y dS w xY w|S )al  Wrapper around inspect.getsource.

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

    Parameters
    ----------
    obj : object
        an object whose source code we will attempt to extract
    oname : str
        (optional) a name under which the object is known

    Returns
    -------
    src : unicode or None

    )fgetfsetfdelNz%s.rv   z# z = 
)rq   propertyr.   rn   appendjoinr@   
isfunction	getsourcer   r   _get_wrapped	TypeError	__class__OSError)	r,   onamesourcesattrnamefnrl   oname_prefix_srcsrcs	            r1   r   r      s   & #x   )0 	 	Hh''B~'++27?RrwwlH'EFFGGG%b)) 
$R==D 5vd||444 NN)5xxxL    	99W%%%4
 3
	#C((CC 	 	 	'66Y'   ttt   	 	 	44	 
s<   D" "
E/-EE/EE/EE/"	E/.E/c                     t          j        |           p=t          j        |           p)t          | t                    pt          | t
                    S )zTrue if obj is a function ())r@   r   ismethodrq   _builtin_func_type_builtin_meth_typer,   s    r1   is_simple_callabler      sQ    s## Ww'7'<'< Ws.//W3=cCU3V3VXr3   c                     t          j        dt          d           t          | d          rt	          |           s| j        } t          j        |           S )zWrapper around :func:`inspect.getfullargspec`

    In addition to functions and methods, this can also handle objects with a
    ``__call__`` attribute.

    DEPRECATED: Deprecated since 7.10. Do not use, will be removed.
    z]`getargspec` function is deprecated as of IPython 7.10and will be removed in future versions.   
stacklevel__call__)warningswarnDeprecationWarningr   r   r   r@   getfullargspecr   s    r1   
getargspecr      sh     M <=O\]_ _ _ _ C$$ -?-D-D l!#&&&r3   c                     t          j        dt          d           t          j        | d         | d         | d         | d                   S )a  Format argspect, convenience wrapper around inspect's.

    This takes a dict instead of ordered arguments and calls
    inspect.format_argspec with the arguments in the necessary order.

    DEPRECATED (since 7.10): Do not use; will be removed in future versions.
    za`format_argspec` function is deprecated as of IPython 7.10and will be removed in future versions.r   r   argsvarargsvarkwdefaults)r   r   r   r@   formatargspec)argspecs    r1   format_argspecr     sb     M <=O\]_ _ _ _  ')2D!(!17:3FH H Hr3   Tc                    t          j        dt          d           |                     d          }|d}nX	 |d         d         dk    }|r|d         d	d         |d<   n# t          t
          f$ r Y nw xY w| d
         t          |          z   }|                     d          }||                     d          }||                     dd          }||fS )z?DEPRECATED since 6.0. Extract call tip data from an oinfo dict.zZ`call_tip` function is deprecated as of IPython 6.0and will be removed in future versions.r   r   r   Nr   r   r/      rS   rQ   rO   rK   rv   )r   r   r   r2   KeyError
IndexErrorr   )oinfoformat_callr   	call_linehas_selfdocs         r1   call_tipr     s    M	2	    ii	""G		
	6vq)V3H  6")&/!"""5	 *% 	 	 	D	 &M."9"99	 ))$
%
%C
{ii())
{iiB''c>s   A   A43A4c                 v    | }d}t          | d          r$| j        } |dz  }|dk    r|S t          | d          $| S )aN  Get the original object if wrapped in one or more @decorators

    Some objects automatically construct similar objects on any unrecognised
    attribute access (e.g. unittest.mock.call). To protect against infinite loops,
    this will arbitrarily cut off after 100 levels of obj.__wrapped__
    attribute access. --TK, Jan 2016
    r   __wrapped__r   d   )r   r   )r,   orig_objis      r1   r   r   9  sY     H	A
sM
*
* o	Qs77O sM
*
*  Jr3   c                    t          |           } d}	 t          j        |           }nM# t          $ r5 	 t          j        | j                  }n# t
          t          f$ r Y nw xY wY nt
          $ r Y nw xY wt          |          S )a^  Find the absolute path to the file where an object was defined.

    This is essentially a robust wrapper around `inspect.getabsfile`.

    Returns None if no file can be found.

    Parameters
    ----------
    obj : any Python object

    Returns
    -------
    fname : str
        The absolute path to the file where the object was defined.
    N)r   r@   
getabsfiler   r   r   r   )r,   fnames     r1   ra   ra   K  s      s

CE"3''   	&s}55EE# 	 	 	D	     s8   ( 
A2AA2A!A2 A!!A2&	A21A2c                    t          |           } 	 t          j        |           d         }nV# t          $ r= 	 t          j        | j                  d         }n# t
          t          f$ r Y Y dS w xY wY nt
          $ r Y dS w xY w|S )aW  Find the line number in a file where an object was defined.

    This is essentially a robust wrapper around `inspect.getsourcelines`.

    Returns None if no file can be found.

    Parameters
    ----------
    obj : any Python object

    Returns
    -------
    lineno : int
        The line number where the object definition starts.
    r   N)r   r@   getsourcelinesr   r   r   )r,   linenos     r1   find_source_linesr   n  s      s

C	',,Q/   	+CM::1=FF# 	 	 	444	 F    tt Ms8   , 
A?AA?A-(A?,A--A?2	A?>A?c            	           e Zd Zeej        ddddf fd	Zd#deedf         fdZ	defdZ
d Zd	 Zd#d
Zed$d            Zd#dZd#dZd%dedefdZdedefdZdededefdZdefdZ	 	 	 	 	 d&dededee         defdZ	 	 	 	 	 	 d'dee         fdZd(dZd(deeef         fdZ e!d             Z"g d d fd d!d"Z# xZ$S ))r   Nr   c                     t          t          |                               ||           || _        t	          j        d| |          | _        | j        j        | _        || _        | 	                    |           d S )N)r+   configr9   )outr+   style)
superr   __init__color_tabler   Parserparserformatstr_detail_levelset_active_scheme)r/   r   code_color_tableschemer   r+   r   r   s          r1   r   zInspector.__init__  sw    
 	i''vf'EEE& 'E$fMMMk( 0v&&&&&r3   rv   ro   c                 p    t          |          sdS 	 t          t          |          |          S #  Y dS xY w)zReturn the call signature for any callable object.

        If any exception is generated, None is returned instead and the
        exception is suppressed.N)callable_render_signaturer   )r/   r,   r   s      r1   _getdefzInspector._getdef  sB    
 }} 	4	$Ys^^U;;;	44s   0 5c                 N    | j         j        j        || j         j        j        S )z*Return a header string with proper colors.)r   active_colorsheadernormal)r/   hs     r1   __headzInspector.__head  s0    +9@@+9@@B 	Br3   c                     |;| j                             |           | j        j                             |           d S d S rV   )r   r   r   )r/   r   s     r1   r   zInspector.set_active_scheme  sF    ..v666K#55f===== r3   c                 v    t          d|z  d           |rt          d|z             dS t                       dS )z-Generic message when no information is found.zNo %s found endzfor %sN)print)r/   msgr   s      r1   noinfozInspector.noinfo  sH    mc!s++++ 	(U"#####GGGGGr3   c                 F   t          |          st          d           dS d}t          j        |          r|                     d          }|                     ||          }||                     d|           dS t          ||                     |          d           dS )zwPrint the call signature for any callable object.

        If the object is a class, print the constructor information.zObject is not callable.Nrv   zClass constructor information:
zdefinition headerr   r   )r   r   r@   rR   _Inspector__headr   r   r   )r/   r,   r   r   outputs        r1   pdefzInspector.pdef  s    
 }} 	+,,,F?3 	E[[!CDDF c%((>KK+E22222&V,,#666666r3   c                 @   | j         }g }t          |          }|r ||                              d|          }|r@|                     |d                     |                    t	          |                     t          j        |          rgt          |d          rWt          |j                  }|@|                     |d                     |                    t	          |                     nft          |d          rVt          |j	                  }|r@|                     |d                     |                    t	          |                     |s| 
                    d|           dS t          j        d	                    |                     dS )
a  Print the docstring for any object.

        Optional:
        -formatter: a function to run the docstring through for specially
        formatted docstrings.

        Examples
        --------
        In [1]: class NoInit:
           ...:     pass

        In [2]: class NoDoc:
           ...:     def __init__(self):
           ...:         pass

        In [3]: %pdoc NoDoc
        No documentation found for NoDoc

        In [4]: %pdoc NoInit
        No documentation found for NoInit

        In [5]: obj = NoInit()

        In [6]: %pdoc obj
        No documentation found for obj

        In [5]: obj2 = NoDoc()

        In [6]: %pdoc obj2
        No documentation found for obj2
        z
plain/textzClass docstring:r   NzInit docstring:r   zCall docstring:documentationr{   )r   rA   r2   r}   r   r@   rR   hasattrr   r   r   r   r~   )	r/   r,   r   	formatterheadrm   rt   init_dscall_dss	            r1   pdoczInspector.pdoc  s   D {C[[ 	52""<44B 	%LL011222LL$$$?3 		.GC$<$< 		.S\**G"TT"344555VG__---S$$ 	.S\**G .TT"344555VG__--- 	(KK.....Idii&&'''''r3   c                     t          j                     	 t          ||          }n# t          $ r d}Y nw xY w||                     d|           dS t          j        |                     |                     dS )z$Print the source code for an object.)r   NrL   )	linecache
checkcacher   rs   r   r   r   )r/   r,   r   r   s       r1   psourcezInspector.psource	  s     		Cu---CC 	 	 	CCC	 ;KK%(((((Idkk#&&'''''s   ' 66c                    t          |          }||                     d|           dS t          |          }|                    d          rt	          d|z             dS t
          j                            |          st	          d|z             dS t          j        | 	                    t          j        |d                    |dz
             dS )	z0Show the whole file where an object was defined.NrI   r_   z File %r is binary, not printing.z%File %r does not exist, not printing.F)skip_encoding_cookier   )r   r   ra   rb   r   rc   rd   re   r   r   r   read_py_file)r/   r,   r   r   rj   s        r1   pfilezInspector.pfile  s     #3''>KK&&&F# >>122 	g4u<=====&& 	g9EABBBBB
 Idkk&"5eRW"X"X"XYY[ade[efffffr3   textc                     |dt          j        |           dd}||S  ||          }t          |t                    s	|d| ddS t          |fi |S )aR  Return a mime bundle representation of the input text.

        - if `formatter` is None, the returned mime bundle has
           a ``text/plain`` field, with the input text.
           a ``text/html`` field with a ``<pre>`` tag containing the input text.

        - if ``formatter`` is not None, it must be a callable transforming the
          input text into a mime bundle. Default values for ``text/plain`` and
          ``text/html`` representations are the ones described above.

        Note:

        Formatters returning strings are supported but this behavior is deprecated.

        z<pre>z</pre>
text/plain	text/html)htmlescaperq   dict)r/   r   r   r   	formatteds        r1   _mime_formatzInspector._mime_format/  s    " :T!2!2:::
 

 O!	$Ii.. 3 '0>Wi>W>W>WXXX H22	222r3   bundlec                 >   t          |d         t                    sJ |d         D ]}t          |t                    sJ i }g }t          d |d         D                       }|d         D ]h\  }}|                    d          }d|v rdnd}|                    |                     |dz              |t          |          z
  dz   | |            id                    |          |d<   d|v rt          |d         t                    sJ |d         D ]}t          |t                    sJ t          |d         t          t          f          r(d                    d |d         D                       |d<   |	                                D ]}	|	dv r||	         }|S )	zRFormat a mimebundle being created by _make_info_unformatted into a real mimebundler   c              3   :   K   | ]\  }}t          |          V  d S rV   len)rB   r   _s      r1   	<genexpr>z(Inspector.format_mime.<locals>.<genexpr>Z  s,      ;;da3q66;;;;;;r3   r{   r   :r   c              3   ,   K   | ]\  }}d | d| V  dS )z<h1>z</h1>
Nr:   )rB   r   bodys      r1   r   z(Inspector.format_mime.<locals>.<genexpr>m  s7      XXLT4/D////XXXXXXr3   )r   r   )
rq   listtuplemaxstripr}   r   r   r~   keys)
r/   r   itemnew_brm   _lenr   r  delimrW   s
             r1   format_mimezInspector.format_mimeQ  s    &.55555<( 	+ 	+DdE******;;f\&:;;;;; . 	 	JD$::d##D DLLDDcELL;;tCx((O4#d))+;S*@O%OOO    #ii..l&  f[1488888{+ / /!$......&-e}== %)YYXXF;DWXXX& &k"  	" 	"A///q	r3   titlekeyc                     ||v s||v rdS ||         }|^|                      ||          }|d                             ||d         f           |d                             ||d         f           dS dS )z^Append an info value to the unformatted mimebundle being constructed by _make_info_unformattedNr   r   )r   r}   )	r/   r   r  r  infoomit_sectionsr   r0   formatted_fields	            r1   _append_info_fieldzInspector._append_info_fieldw  s     M!!SM%9%9FS	"//yAAO< ''0M(NOOO;&&{/K'LMMMMM r3   c                     g g d}	 d+dt           dt          dt          f fd}dt          f fd}d	         r ||d
d           nd         r2|dk    r ||dd|           n ||dd|            ||dd           nRd         st          |          r} ||dd|            ||dd|            ||dd|           |dk    rd         r ||dd|           n ||dd|            ||dd            ||dd            ||dd           n ||dd|            ||dd |            ||dd            ||d!d           d"         d#k    r ||d$d"            ||d%d&            ||dd           |dk    rd         r ||dd|           n ||dd|            ||d'd(|            ||dd|            ||d)d*|           |S ),z;Assemble the mimebundle as unformatted lists of informationr   Nr   r  r  c                 >                         | |||           d S )N)r  r  r  r  r   )r  )r   r  r  r   r  r  r/   s       r1   append_fieldz6Inspector._make_info_unformatted.<locals>.append_field  s>     ##+# $     r3   ro   c                 N                         |           t          |           dS )Nr   )r   r>   )r   r/   s    r1   code_formatterz8Inspector._make_info_unformatted.<locals>.code_formatter  s*    "kk$//$T]]  r3   r(   ReprrG   r'   r   SourcerL   	DocstringrK   FilerI   rR   	SignaturerJ   zInit signaturerM   zInit docstringrO   TyperE   
Subclasses
subclasseszCall signaturerP   zString formr*   Interactive	NamespaceLengthrH   zClass docstringrN   zCall docstringrQ   rV   )r#   r9   r$   r   )	r/   r,   r  r   detail_levelr  r   r  r  s	   ` `  `   r1   _make_info_unformattedz Inspector._make_info_unformatted  s+   
 %
 %
 HL
	 
	%
	.1
	8;
	 
	 
	 
	 
	 
	 
	 
		F 	 	 	 	 	 	 	? /	PL7777)_ ,	PaVXxHHHHV[+yIIIL0000)_ %	P 23 7 7 %	PLlNKKKL!13DnUUULk9EEEaDNVXxHHHHV%57GSSSL000L555L|<<<< LlNKKKL!1:~NNNL555L>>> K M11V[+>>>L8444L000 aDNVXxHHHHV[+yIIIL!24EyQQQL!13CYOOOL!13CYOOOr3   r:   r,   r   r  c                     |                      ||||          }|                     |||||          }|                     |          S )a9  Retrieve an info dict and format it.

        Parameters
        ----------
        obj : any
            Object to inspect and return info from
        oname : str (default: ''):
            Name of the variable pointing to `obj`.
        formatter : callable
        info
            already computed information
        detail_level : integer
            Granularity of detail level, if set to 1, give more information.
        omit_sections : container[str]
            Titles or keys to omit from output (can be set, tuple, etc., anything supporting `in`)
        r   r  r$  )r$  r  )r  r%  r  )	r/   r,   r   r   r  r$  r  	info_dictr   s	            r1   	_get_infozInspector._get_info  s\    4 IIcTIUU	,,%' - 
 
 '''r3   Tc                 v    |J |                      ||||||          }|s|d= t          j        |           dS )a   Show detailed information about an object.

        Optional arguments:

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

        - formatter: callable (optional)
              A special formatter for docstrings.

              The formatter is a callable that takes a string as an input
              and returns either a formatted string or a mime type bundle
              in the form of a dictionary.

              Although the support of custom formatter returning a string
              instead of a mime type bundle is deprecated.

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

        - detail_level: if set to 1, more information is given.

        - omit_sections: set of section keys and titles to omit
        N)r  r   )r)  r   )	r/   r,   r   r   r  r$  enable_html_pagerr  info_bs	            r1   pinfozInspector.pinfo  s^    B 	4] ( 
 
 ! 	${#	&r3   c                 l    t          j        dt          d           |                     ||||          S )z
        Inspector.info() was likely improperly marked as deprecated
        while only a parameter was deprecated. We "un-deprecate" it.
        zThe `Inspector.info()` method has been un-deprecated as of 8.0 and the `formatter=` keyword removed. `Inspector._info` is now an alias, and you can just call `.info()` directly.r   r   r'  )r   r   r   r  )r/   r,   r   r  r$  s        r1   _infozInspector._info%  sG     	B 	
 	
 	
 	
 yyE<yPPPr3   c                 Z   |d}d}d}n|j         }|j        }|j        }|                    d          d         }d}	d}
|rQ|j        Jt          |j        t                    r0t          |j        t                    }|                    |d          }	t          |d||d          }|	r|	}nt|r\t          |          s&	 d|d	         z  }nV#  d
t          |          z   }Y n@xY wdt          |          z   }|j        r|d|j        z   z  }nt          |          }|d}n|}|
|z   }d}t          |dz
  dz            }|rd|d<   n|rd|d<   nt          |          j        |d<   	 |j        }t          |          |d<   n#  Y nxY w|| j        k    r	 t          |          }d}|st'          |          |k    rp|d|         dz   || d         z   }ddt'          |                                          z  z                       d |                    d          D                       }|||<   n#  Y nxY w|r||d<   	 t          t'          |                    |d<   n# t,          $ r Y nw xY wd}t/          |          }|d}nA|                    d          rd}n|                    d          rd}t3          |          |d<   |rgt5          j                     	 t9          |t:                    s|s+t=          ||          }||                                }||d <   n# t,          $ r Y nw xY w|r.|                      |                    d           |          s||d!<   tC          j"        |          rd|d"<   	 | #                    ||          }n# tH          $ r d}Y nw xY w	 |j%        }|(	 | #                    ||          }n# tH          $ r Y nw xY wt          |          }|tL          k    rd}n# tH          $ r d}Y nw xY w|r||d#<   |r||d$<   d% t          '                    |          D             }t'          |          d&k     rd'                    |          }n!d'                    |dd&         d(gz             }||d)<   n| #                    ||          }|r||d*<   |rB	 t          |d+          }t          |          }n	#  d}Y nxY w|tP          v rd}|r||k    r||d,<   	 t          |j%                  }|tL          k    rd}n# tH          $ r d}Y nw xY w|r||d$<   tS          |d-          rrtU          |          sc| #                    |j+        |          }|r||                    d*          k    r||d.<   t          |j+                  } | tX          k    rd} | r| |d/<   t[          d0i |S )1a  Compute a dict with detailed information about an object.

        Parameters
        ----------
        obj : any
            An object to find information about
        oname : str (default: '')
            Name of the variable pointing to `obj`.
        info : (default: None)
            A struct (dict like with attr access) with some information fields
            which may have been precomputed already.
        detail_level : int (default:0)
            If set to 1, more information is given.

        Returns
        -------
        An object info dict with known fields from `info_fields`. Keys are
        strings, values are string or None.
        NFrv   .T)rS   r)   r(   r'   r   z!Alias to the system command:
  %sr   zAlias: z	Alias to z
Docstring:
z<no docstring>      r   zMagic functionrE   zSystem aliasrF   rG   z <...> r{   r   c              3   >   K   | ]}|                                 V  d S rV   )r  )rB   qs     r1   r   z!Inspector.info.<locals>.<genexpr>  s*       E Eq E E E E E Er3   r*   rH   r_   z<string>z9Dynamically generated function. No source code available.rI   rL   rK   rR   rM   rO   c                     g | ]	}|j         
S r:   )r4   )rB   subs     r1   
<listcomp>z"Inspector.info.<locals>.<listcomp>  s    FFFcS\FFFr3   
   , z...r   rJ   r   rN   r   rP   rQ   r:   ).r'   r(   r*   splitr+   r   	HOOK_NAMEr.   r2   r   r   r9   __doc__rA   inttyper4   r   r   r   
expandtabsr~   rs   ra   rb   r   r   r   rq   r|   r   rstrip_source_contains_docstringr@   rR   r   AttributeErrorr   _object_init_docstring__subclasses___builtin_type_docstringsr   r   r   _func_call_docstringr]   )!r/   r,   r   r  r$  r'   r(   ospaceatt_nameparents_docspreludeparents_docs_dictr   rt   
ds_or_None
string_maxshalfbclassostrstr_headbinary_filer   r   init_defobj_initr   names	all_namesdeflnclsclass_dsrP   r   s!                                    r1   r  zInspector.info4  sD   * <GGFFlGlG^F ;;s##B' 	ADK+Y0O0O+ 'Y ? ?,004@@LdGWQU
 
 
  	 BB 	 C== 9.=AFBB."SXX-BBB 3s88+; 9*S[88BJ!%r\ 
Z!^q()) 	2/C 	2-C#Cyy1C	]F #FC	D 4000	3xx(# FD		*(<(<<)3dE677mCD 3X-@-@-B-B)C)C#CC D E EDJJt4D4D E E EEE  $H 	&%C	CMMCMM 	 	 	D	 #= KK~~566 T"
++ TS'..CK  	  """c8,, (K (#C//C!jjll$'CM     	"d55cggh6G6GLL 	"!C ?3 V	4!C	N <<U33!       #< ##'<<%#@#@)    **444"G "     2)1%& 0(/$%FFT-@-@-E-EFFFE5zzB IIe,,		 IIeCRCj%&899	 )C LLe,,E *$)L!  6+!#k22C  &c{{HH$#HHH 777#H 6h-5C)* ..444"G!    0(/$% C,, 45G5L5L 4<<e<< /SWW\-B-B!B!B '/C
O ..222"G 4,3C()!!S!!!s   <C C"E< <F BH+ +H/:I 
I'&I'AL 
L'&L'5N NNO- )O   
OO-O<;O<"S S$!T TTc                     	 t          j        t          |                     j        \  }t          j        |          |k    S # t
          $ r Y dS w xY w)z
        Check whether the source *src* contains the docstring *doc*.

        This is is helper function to skip displaying the docstring if the
        source already contains it, avoiding repetition of information.
        F)astparser   r  get_docstringrs   )r   r   def_nodes      r1   rC  z$Inspector._source_contains_docstring  s[    	)F3KK005KX$X..#55 	 	 	 55		s   ?A 
AAF)
list_typesc                   d}d}|r;t          j         d                    t          t                                         dS |                                }	t          |	          }
|
dk    r	|	d         }n|
dk    r|	\  }}nt          d|z            |D ]-}||vr't          d	|d
|                                          .t                      t                      }}|D ]g}||         }t          |          |v r|
                    t          |                     t          |||||          }|                    |           ht          j         d                    t          |                               dS )a  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.

          - list_types(False): list all available object types for object matching.
        allrv   r{   Nr   r   r   z)invalid argument string for psearch: <%s>zinvalid namespace <z>. Valid names: )ignore_caseshow_all)r   r~   sortedr   r<  r   
ValueErrorr  setidaddr   rZ   )r/   patternns_table	ns_searchrd  re  ra  type_patternfiltercmdslen_cmdsrS   search_resultnamespaces_seenns_namenstmp_ress                    r1   psearchzInspector.psearch'  s   4   	Idii| 4 455666F}}YYq==!WFF]]"&F<<H$% & & &  	9 	9D8## j"&$$x}}"8 9 9 9 $
 *-  	* 	*G'"B"vv((2'''$Rv0;hP P PG  ))))	$))F=112233333r3   rv   )rv   NrV   )rv   NNr   r:   )rv   NNr   Tr:   )rv   Nr   )%r4   r5   r6   r   r   ANSICodeColorsr   r   r9   r   r   r   r   r   r   r   r   r   r   r   r#   r$   r  r  r%  r   r	   r&   r)  r-  r/  r
   r  staticmethodrC  rw  __classcell__)r   s   @r1   r   r     s       #0",";"#T	
' 
' 
' 
' 
' 
'
 
eCHo 
 
 
 
B# B B B B
> > >
  7 7 7 7, 7( 7( 7( \7(r( ( ( (g g g g. 3  3  3  3  3  3  3D$"3 $ $ $ $ $LN!N N 	N N N N$L	L L L Ld  $"( "("( "(
 uo"( 
"( "( "( "(N  $' '
 uo' ' ' 'RQ Q Q Q`" `"S#X `" `" `" `"D   \  13!5@4@E@4 @4 @4 @4 @4 @4 @4 @4 @4r3   c                 d   g }d}d}| j                                         D ]}|j        t          j        j        k    rd}n|r|                    d           d}|j        t          j        j        k    rd}n3|j        t          j        j        k    r|r|                    d           d}|                    t          |                     |r|                    d           t          |          t          d |D                       z   dk    r4d                    |d                    d	 |D                                 }n)d
                    |d                    |                    }| j        t          j        ur1t          j        | j                  }|d                    |          z  }|S )z
    This was mostly taken from inspect.Signature.__str__.
    Look there for the comments.
    The only change is to add linebreaks when this gets too long.
    FT/*c              3   :   K   | ]}t          |          d z   V  dS )r   Nr   rB   rs     r1   r   z$_render_signature.<locals>.<genexpr>  s,      66!3q66A:666666r3   K   z{}(
{})rv   c              3   @   K   | ]}d                      |          V  dS )z    {},
N)r   r  s     r1   r   z$_render_signature.<locals>.<genexpr>  sA       73 73&'Kq!!73 73 73 73 73 73r3   z{}({})r;  z -> {})
parametersvalueskindr@   	ParameterPOSITIONAL_ONLYr}   VAR_POSITIONALKEYWORD_ONLYr9   r   sumr   r~   return_annotation_emptyformatannotation)obj_signatureobj_nameresultpos_onlykw_onlyparamrenderedannos           r1   r   r   j  s    FHG)0022 " ":*:::HH 	MM#H:*999GGZ7,999g9MM#Gc%jj!!!! c 8}}s66v666666;;$$Xrww 73 73+173 73 73 03 03 
 
 ??8TYYv->->??&gn<<'(GHHHOOD)))Or3   rx  )T)br>  __all__dataclassesr   r@   r   textwrapr   r]  r   iorf   r   rc   systypesr   typingr   r	   r
   r   r   r   r   IPython.corer   IPython.lib.prettyr   IPython.testing.skipdoctestr   IPython.utilsr   r   IPython.utils.dir2r   IPython.utils.pathr   IPython.utils.textr   IPython.utils.wildcardr   r   IPython.utils.coloransir   r   r   IPython.utils.py3compatr   IPython.utils.colorabler   IPython.utils.decoratorsr   pygmentsr   pygments.lexersr    pygments.formattersr!   r=  r9   r#   r8   r$   r&   r>   FunctionTyper   rH  objectr   rE  
ModuleType
MethodTyper|   rG  r@  rc  r   upperr   Colorsry  r   rY   r]   rn   rA   r   r   r   r   r   r   ra   r   r   r   r:   r3   r1   <module>r     s     
' " ! ! ! ! !             



           				 



   : : : : : : : : : : : : : : : :             % % % % % % 4 4 4 4 4 4 $ $ $ $ $ $             + + + + + + , , , , , , % % % % % % 1 1 1 1 1 1 / / / / / / M M M M M M M M M M 0 0 0 0 0 0 - - - - - - * * * * * *       ' ' ' ' ' ' - - - - - -'	  $CeCHo)>$>? 9 ? ? ?cN	 " " " $ $ $ $ $ $ $ $2I I I )2: 0   % 0%2B % 2H >   
 T#YY T#)__  
)      .5T?    *< <c$h < < < <~X X X
 ' ' '" H H H  " " " "J  $ c        F  >Z4 Z4 Z4 Z4 Z4	 Z4 Z4 Z4z(# ( ( ( ( ( (r3   