
    MhX                        U d Z 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mZ ddlmZmZmZmZmZmZmZmZmZ ddl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' ddl(m)Z) ddl*m+Z+ ddl,m-Z- ddl.m/Z/m0Z0 ddl1m2Z2 ddl3m4Z4 ddl5m6Z6 ddl7m8Z8 dZ9e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 Z?ej@        jA        j         ZBeCjD        j         ZEd ejF        ejG        ej@        eHfD             ZI eJeK          ZL eJe:jM                  ZN G d de          ZO ePeOj<        Q                                          ZRd ZSe G d  d!                      ZTe2d"d"d"d#d$e:d%eUd&eUd'eUd(eUd)eOfd*            ZVd+ ZWd)ee:df         fd,ZXd5d)ee:df         fd.ZYd/ ZZd0 Z[d)ee:         fd1Z\d2 Z] eC            Z^ G d3 de          Z_d)e:fd4Z`dS )6zTools 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    )	dataclass)	signature)dedentN)Token)	castAnyOptionalDictUnionList	TypedDict	TypeAliasTuple)Configurable)page)pretty)skip_doctest)
PyColorizeopenpy)safe_hasattr)compress_user)indent)list_namespacetypestr2type)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                 b    t          j        d| dt          d           t          | |          S )zGet a field from the object for backward compatibility with before 8.12

        see https://github.com/h5py/h5py/issues/2253
        zGOInfo dataclass with fields access since IPython 8.12 please use OInfo.z instead.OInfo used to be a dict but a dataclass provide static fields verification with mypy.This warning and backward compatibility `get()` method were added in 8.13.   
stacklevel)warningswarnDeprecationWarninggetattr)selffields     U/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/IPython/core/oinspect.pygetz	OInfo.getK   sR     	YV[ Y Y Y 	
 	
 	
 	
 tU###    N)	__name__
__module____qualname__bool__annotations__r
   strr	   r6    r7   r5   r$   r$   B   sb         MMMMMMKKK}KKK	HHH$ $ $ $ $r7   r$   c                 X    t          | t                      t          d                    S )NT)	noclasses)r   r   r   )codes    r5   pylightrB   ]   s#    T;==-$*G*G*GHHHr7   c                 6    h | ]}t          j        |          S r>   )inspectgetdoc).0ts     r5   	<setcomp>rH   c   s/       GN1  r7   c                      e Zd ZU ee         ed<   ee         ed<   ee         ed<   ee         ed<   ee         ed<   ee         ed<   ee         ed<   ee         ed<   ee         ed	<   ee         ed
<   ee         ed<   ee         ed<   ee         ed<   ee         ed<   ee         ed<   eed<   eed<   eed<   eed<   eed<   dS )InfoDict	type_name
base_classstring_formr(   lengthfile
definition	docstringsourceinit_definitionclass_docstringinit_docstringcall_defcall_docstring
subclassesr%   r&   isclassr'   nameN)r8   r9   r:   r
   r=   r<   r;   r>   r7   r5   rJ   rJ   r   s/        }#}SM
3-}SMc]"""c]"""SM!!!smSM!!! MMMMMMMMMKKK
IIIIIr7   rJ   c                     | dk    r#t          j        dt          d           t          S t	          dt
          d|           )Ninfo_fieldszfIPython.core.oinspect's `info_fields` is considered for deprecation and may be removed in the Future. r,   r-   zmodule z has no attribute )r/   r0   r1   _info_fieldsAttributeErrorr8   )rZ   s    r5   __getattr__r_      sV    }t	
 	
 	
 	

 
I8IIII
J
JJr7   c                   ^    e Zd ZU dZeed<   ee         ed<   eed<   e	ed<   e
e         ed<   dS )InspectorHookDatazData passed to the mime hookr*   info	info_dictdetail_levelomit_sectionsN)r8   r9   r:   __doc__r	   r<   r
   r$   rJ   intlistr=   r>   r7   r5   ra   ra      sY         &&	HHH
5/9r7   ra   F)rY   r&   r%   rZ   r'   rY   r&   r%   returnc                     t          |                              fdt          D                        | d<   |d<   |d<   |d<   |d<   t          di S )z1Make an object info dict with all fields present.c                     i | ]	}|v|d 
S Nr>   )rF   kinfodicts     r5   
<dictcomp>zobject_info.<locals>.<dictcomp>   s%    HHHax6G6GQ6G6G6Gr7   rZ   r'   rY   r&   r%   r>   )dictupdater]   rJ   )rZ   r'   rY   r&   r%   kwrn   s         @r5   object_infors      s}     BxxHOOHHHHlHHHIIIHVHW!HY!HY!HYhr7   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        r5   get_encodingr      s    
 cNNE }t	/	0	0 
tW^^E"" t
 ^E4(( 	GF%5foFFHf	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	Gs   !B

BBc                     	 |                                  }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.
    )rE   
isinstancer=   rD   cleandoc	Exception)r*   dsdocstrs      r5   rE   rE      sv    (ZZ\\ b# 	(#B'''	(    
 ^C  FMs   A   
AA c           	         t          | t                    rg }dD ]}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.r   z# z = 
)r   propertyr2   appendjoinrD   
isfunction	getsourcer   r   _get_wrapped	TypeError	__class__OSError)r*   onamesourcesattrnamefnoname_prefix_srcsrcs           r5   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 D87E 8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 ())rD   r   ismethodr   _builtin_func_type_builtin_meth_type)r*   s    r5   is_simple_callabler   &  sQ    s## Ww'7'<'< Ws.//W3=cCU3V3VXr7   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__   d   )r   r   )r*   orig_objis      r5   r   r   +  sY     H	A
sM
*
* o	Qs77O sM
*
*  Jr7   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|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   rD   
getabsfiler   r   r   )r*   fnames     r5   rw   rw   =  s      s

CE"3''   	&s}55EE# 	 	 	D	     Ls8   ( 
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   rD   getsourcelinesr   r   r   )r*   linenos     r5   find_source_linesr   `  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U  ej        dd                              d          Zeed<   ddddd	ef fd
Z	d Z
d/deedf         fdZdedefdZdefdZdefdZd Zd/dZed0d            Zd/dZd/dZd1dedefdZdedefdZdededed ee         fd!Zdefd"Z	 	 	 	 	 d2d$ed%ed&ee          d'e!d eee         e"d#         f         defd(Z#	 	 	 	 	 	 d3d&ee          fd)Z$d4de%fd*Z&e'd+             Z(g d,d,fd,d-d.Z) xZ*S )5r   TzKdictionary of mime to callable to add information into help mimebundle dict)confighelp)r   _theme_namer   N)str_detail_levelr)   r   
theme_namec                l   |dv rFt          j        d|                                 dt          d           |                                }|| _        t          t          |                               ||           t          j	        d|          | _
        || _        |                     |           d S )	N)LinuxLightBGNeutralNoColorz?Theme names and color schemes are lowercase in IPython 9.0 use z insteadr,   r-   )r)   r   r=   )outr   )r/   r0   lowerr1   r   superr   __init__r   Parserparserr   set_theme_name)r3   r   r   r)   r   r   s        r5   r   zInspector.__init__  s     CCCMnR\RbRbRdRdnnn"   
 $))++J%i''vf'EEE 'EjIII 0J'''''r7   c                 &     | j         j        |i |S rl   )r   format)r3   argskwargss      r5   r   zInspector.format  s    !t{!426222r7   r   ri   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   )r3   r*   r   s      r5   _getdefzInspector._getdef  sB    
 }} 	4	$Ys^^U;;;	44s   0 5hc                 p    t           j        | j                                     t          j        |fg          S )z*Return a header string with proper colors.)r   theme_tabler   r   r   Header)r3   r   s     r5   __headzInspector.__head  s+    %d&67>>q@Q?RSSSr7   rZ   c                     ||                                 k    sJ |t          j                                        v sJ || _        || j        _        d S rl   )r   r   r   keysr   r   r   )r3   rZ   s     r5   r   zInspector.set_theme_name  sS    tzz||####z-22444444!%r7   schemec                     t          j        dt          d           ||                                k    sJ | | j        |k    r|| _        || j        _        d S d S d S )NzPset_active_scheme is deprecated and replaced by set_theme_name as of IPython 9.0r,   r-   )r/   r0   r1   r   r   r   r   )r3   r   s     r5   set_active_schemezInspector.set_active_scheme  sx    ^	
 	
 	
 	

 ''''$"2f"<"<%D%+DK""" "<"<r7   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)r3   msgr   s      r5   noinfozInspector.noinfo  sH    mc!s++++ 	(U"#####GGGGGr7   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.Nr   zClass constructor information:
zdefinition headerr   r   )r   r   rD   rY   _Inspector__headr   r   r   )r3   r*   r   headeroutputs        r5   pdefzInspector.pdef  s    
 }} 	+,,,F?3 	E[[!CDDF c%((>KK+E22222&V,,#666666r7   c                 n   g }t          |          }|r ||                              d|          }|rJ|                    |                     d                     |                    t	          |                     t          j        |          rqt          |d          rat          |j                  }|J|                    |                     d                     |                    t	          |                     npt          |d          r`t          |j	                  }|rJ|                    |                     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:__call__zCall docstring:documentationr   )rE   r6   r   r   r   rD   rY   hasattrr   r   r   r   r   )r3   r*   r   	formatterlinesr   init_dscall_dss           r5   pdoczInspector.pdoc  s   D C[[ 	52""<44B 	%LL%788999LL$$$?3 		.GC$<$< 		.S\**G"T[[):;;<<<VG__---S$$ 	.S\**G .T[[):;;<<<VG__--- 	(KK.....Idii&&'''''r7   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   NrR   )	linecache
checkcacher   r   r   r   r   )r3   r*   r   r   s       r5   psourcezInspector.psource  s     		Cu---CC 	 	 	CCC	 ;KK%(((((Idkk#&&'''''s   ' 66c                    t          |          }||                     d|           dS t          |          }|t          d           dS |                    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.NrO   zCould not find file for objectru   z File %r is binary, not printing.z%File %r does not exist, not printing.F)skip_encoding_cookier   )r   r   rw   r   rx   ry   rz   r{   r   r   r   read_py_file)r3   r*   r   r   r   s        r5   pfilezInspector.pfile+  s     #3''>KK&&&F# =233333^^344 	g4u<=====&& 	g9EABBBBB
 Idkk&"5eRW"X"X"XYY[ade[efffffr7   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escaper   rp   )r3   r   r   defaults	formatteds        r5   _mime_formatzInspector._mime_formatD  s    " :T!2!2:::
 

 O!	$Ii.. 3 '0>Wi>W>W>WXXX H22	222r7   bundlec                 D   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 rl   len)rF   r   _s      r5   	<genexpr>z(Inspector.format_mime.<locals>.<genexpr>o  s,      ;;da3q66;;;;;;r7   r   r   :r   c              3   ,   K   | ]\  }}d | d| V  dS )z<h1>z</h1>
Nr>   )rF   headbodys      r5   r  z(Inspector.format_mime.<locals>.<genexpr>  sH       / /3?D$.4..../ / / / / /r7   )r   r   )
r   rh   tuplemaxstripr   r   r  r   r   )
r3   r   itemnew_br   _lenr  r  delimrm   s
             r5   format_mimezInspector.format_mimef  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 / /CI+CV/ / / & &k"  	% 	%A///!!9ar7   titlekeyre   c                     ||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   )	r3   r   r  r  rb   re   r   r4   formatted_fields	            r5   _append_info_fieldzInspector._append_info_field  s     M!!SM%9%9FS	"//yAAO< ''0M(NOOO;&&{/K'LMMMMM r7   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  rb   re   r   )r  )r   r  r  r   rb   re   r3   s       r5   append_fieldz6Inspector._make_info_unformatted.<locals>.append_field  s>     ##+# $     r7   ri   c                 N                         |           t          |           dS )Nr   )r   rB   )r   r3   s    r5   code_formatterz8Inspector._make_info_unformatted.<locals>.code_formatter  s*    "kk$//$T]]  r7   r&   ReprrM   r%   r   SourcerR   	DocstringrQ   FilerO   rY   	SignaturerP   zInit signaturerS   zInit docstringrU   TyperK   
SubclassesrX   zCall signaturerV   zString formr(   Interactive	NamespaceLengthrN   zClass docstringrT   zCall docstringrW   rl   )r!   r=   r"   r   )	r3   r*   rb   r   rd   re   r   r  r  s	   ` `  `   r5   _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r7   r>   r*   r   rb   rd   c                 *   |                      ||||          }t          |          }|                     |||||          }| j        rt	          |||||          }	| j                                        D ]\  }
}d t          j        |          j        	                                D             }t          |          dk    r ||	          }n(t          j        dt          d            |||          }||||
<   |                     |          S )	a4  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 : list[str]
            Titles or keys to omit from output (can be set, tuple, etc., anything supporting `in`)
        )r   rb   rd   )rd   re   )r*   rb   rc   rd   re   c                 F    g | ]}|j         t          j        j         k    |S r>   )defaultrD   	Parameter)rF   	parameters     r5   
<listcomp>z'Inspector._get_info.<locals>.<listcomp>  s6     ' ' '! (G,=,EEE EEEr7   r   zMIME hook format changed in IPython 8.22; hooks should now accept a single parameter (InspectorHookData); support for hooks requiring two-parameters (obj and info) will be removed in a future versionr,   r-   )rb   rh   r%  
mime_hooksra   itemsrD   r   
parametersvaluesr  r/   r0   r1   r  )r3   r*   r   r   rb   rd   re   rc   r   	hook_datar  hookrequired_parametersress                 r5   	_get_infozInspector._get_info  s^   4 IIcTIUU	]++,,%' - 
 
 ? 	&)#)+  I "_2244 & &	T' '%,%6t%<%<%G%N%N%P%P' ' '#
 *++q00$y//CCM] +#$    $sD//C?"%F3K'''r7   c                 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)re   r   )r4  r   )	r3   r*   r   r   rb   rd   enable_html_pagerre   info_bs	            r5   pinfozInspector.pinfo.  s^    B 	4] ( 
 
 ! 	${#	&r7   c           
      v   |d}d}d}n|j         }|j        }|j        }|                    d          d         }d}	d}
|rQ|j        Jt          |j        t                    r0t          |j        t                    }|                    |d          }	t          t          i d t          D             |d||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          |          }|st+          |          |k    rp|d|         dz   || d         z   }ddt+          d                                          z  z                       d |                    d          D                       }||d<   n#  Y nxY w|r||d<   	 t          t+          |                    |d<   n# t0          $ r Y nw xY wd}t3          |          }|d}nA|                    d          rd}n|                    d          rd}t7          |          |d <   |rgt9          j                     	 t=          |t>                    s|s+tA          ||          }||!                                }||d!<   n# t0          $ r Y nw xY w|r.| "                    |                    d!          |          s||d"<   tG          j$        |          rd|d#<   	 | %                    ||          }n# tL          $ r d}Y nw xY w	 |j'        }|(	 | %                    ||          }n# tL          $ r Y nw xY wt          |          }|tP          k    rd}n# tL          $ 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|tT          v rd}|r||k    r||d-<   	 t          |j'                  }|tP          k    rd}n# tL          $ r d}Y nw xY w|r||d%<   tW          |d.          rrtY          |          sc| %                    |j-        |          }|r||                    d+          k    r||d/<   t          |j-                  }|t\          k    rd}|r||d0<   |S )1as  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` (see `InfoDict`).
        NFr   .c                     i | ]}|d S rl   r>   )rF   r4   s     r5   ro   z"Inspector.info.<locals>.<dictcomp>~  s    99955$999r7   T)rZ   r'   r&   r%   rX   z!Alias to the system command:
  %sr   zAlias: z	Alias to z
Docstring:
z<no docstring>      r,   zMagic functionrK   zSystem aliasrL   z <...> r   r   rM   c              3   >   K   | ]}|                                 V  d S rl   )r  )rF   qs     r5   r  z!Inspector.info.<locals>.<genexpr>  sC       O O&'		O O O O O Or7   r(   rN   ru   z<string>z9Dynamically generated function. No source code available.rO   rR   rQ   rY   rS   rU   c                     g | ]	}|j         
S r>   )r8   )rF   subs     r5   r+  z"Inspector.info.<locals>.<listcomp>  s    FFFcS\FFFr7   
   , z...rX   rP   r   rT   r   rV   rW   )/r%   r&   r(   splitr)   r   	HOOK_NAMEr2   r6   r   rJ   r]   r   r=   rf   rE   rg   typer8   r   r   r  
expandtabsr   r   rw   rx   r   r   r   r   r   r   rstrip_source_contains_docstringrD   rY   r   r^   r   _object_init_docstring__subclasses___builtin_type_docstringsr   r   r   _func_call_docstring) r3   r*   r   rb   rd   r%   r&   ospaceatt_nameparents_docspreludeparents_docs_dictr   r   
ds_or_None
string_maxshalfbclassostrbinary_filer   r   init_defobj_initr   names	all_namesdeflnclsclass_dsrV   r   s                                    r5   rb   zInspector.infoW  st   ( <GGFFlGlG^F ;;s##B' 	ADK+Y0O0O+ 'Y ? ?,004@@L	99L999	 "!&&"& 	
 
  	 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# D		J(>(><)3dE677mCD !3]-E-E-G-G)H)H#HHNN O O+/::d+;+;O O O  D &*M"" 	&%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   C" "C8<F F)BI II2 2
I?>I?/AL2 2
L?>L?N$ $N32N37P O 
O%$O%PP: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_docstringr   )r   docdef_nodes      r5   rJ  z$Inspector._source_contains_docstringD  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.
        allr   r   Nr   r   r,   z)invalid argument string for psearch: <%s>zinvalid namespace <z>. Valid names: )ignore_caseshow_all)r   r   sortedr   rE  r  
ValueErrorr   setidaddr   rq   )r3   patternns_table	ns_searchrj  rk  rg  type_patternfiltercmdslen_cmdsrZ   search_resultnamespaces_seenns_namenstmp_ress                    r5   psearchzInspector.psearchU  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3r7   r   )r   Nrl   )r   NNr   r>   )r   NNr   Tr>   )r   Nr   )+r8   r9   r:   	traitletsr   tagr,  r=   r<   r   r   r   r   r   r   r   r   r   r   r   r   r   rp   r   r!   r"   r  r   r  r%  r	   r
   r$   rg   r   r4  r8  rJ   rb   staticmethodrJ  r}  __classcell__)r   s   @r5   r   r     s        Z   
cc 
  ( ( ( ( ( ( ( ( (*3 3 3
 
eCHo 
 
 
 
T T T T T T&3 & & & &	, 	, 	, 	, 	,  7 7 7 7, 6( 6( 6( \6(p( ( ( (g g g g2 3  3  3  3  3  3  3D$"3 $ $ $ $ $LN!N N 	N CyN N N N$L	L L L Ld  $57?( ?(?( ?(
 uo?( ?( T#Yb	12?( 
?( ?( ?( ?(H  $' '
 uo' ' ' 'Rk k k k k kZ   \  13!5@4@E@4 @4 @4 @4 @4 @4 @4 @4 @4r7   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  rF   rs     r5   r  z$_render_signature.<locals>.<genexpr>  s,      66!3q66A:666666r7   K   z{}(
{})r   c              3   @   K   | ]}d                      |          V  dS )z    {},
N)r   r  s     r5   r  z$_render_signature.<locals>.<genexpr>  sA       73 73&'Kq!!73 73 73 73 73 73r7   z{}({})rD  z -> {})r.  r/  kindrD   r)  POSITIONAL_ONLYr   VAR_POSITIONALKEYWORD_ONLYr=   r  sumr   r   return_annotation_emptyformatannotation)obj_signatureobj_nameresultpos_onlykw_onlyparamrenderedannos           r5   r   r     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)))Or7   r~  )arf   __all__dataclassesr   rD   r   textwrapr   rb  r   ior|   r   ry   typesr/   pygments.tokenr   typingr   r	   r
   r   r   r   r   r   r   r  traitlets.configr   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.decoratorsr   pygmentsr   pygments.lexersr   pygments.formattersr   rF  r=   r!   r<   r"   r$   rB   FunctionTyper   rN  objectr   rK  
ModuleType
MethodTyper   rM  rG  ri  r   upperr   rJ   rh   r   r]   r_   ra   r;   rs   r   rE   r   r   r   rw   r   	_sentinelr   r   r>   r7   r5   <module>r     s7     - " ! ! ! ! !             



           				              
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
     ) ) ) ) ) )       % % % % % % 4 4 4 4 4 4 , , , , , , , , + + + + + + , , , , , , % % % % % % ? ? ? ? ? ? ? ? * * * * * *       ' ' ' ' ' ' - - - - - -'	  $CeCHo)>$>? 9 ? ? ?cN	 " " " $ $ $ $ $ $ $ $4I I I )2: 0   % 0%2B % 2H >   
 T#YY T#)__     y   2 tH,113344	K 	K 	K         
      
    	 
            *  05d#    *; ;c$h ; ; ; ;|X X X
  $ hsm        F  @ FHH	R4 R4 R4 R4 R4 R4 R4 R4j(# ( ( ( ( ( (r7   