o
    Zh                     @   s  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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"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/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 dZ>dd Z?ej@jAj ZBeCjDj ZEdd ejFejGej@eHfD ZIeJeKZLeJe:jMZNe.ZOe"jPZQG d d! d!eZReSeRj<T ZUd"d# ZVeG d$d% d%ZWe2d&d&d&d'd(e:d)eXd*eXd+eXd,eXd-eRfd.d/ZYd0d1 ZZd-ee:df fd2d3Z[dId-ee:df fd5d6Z\d7d8 Z]e2d9d: Z^e2d;d< Z_e2dJd>d?Z`d@dA Zad-ee: fdBdCZbdDdE ZcG dFd de0Zdd-e:fdGdHZedS )KzTools 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)	castAnyOptionalDictUnionList	TypedDict	TypeAliasTuple)page)pretty)skip_doctest)
PyColorizeopenpy)safe_hasattr)compress_user)indent)list_namespacetypestr2type)
TermColors)	Colorable)undoc)	highlight)PythonLexer)HtmlFormatterZ__custom_documentations__UnformattedBundleBundlec                   @   sJ   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d Zd	S )
OInfoismagicisaliasfound	namespaceparentobjc                 C   s
   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field r,   L/var/www/html/lang_env/lib/python3.10/site-packages/IPython/core/oinspect.pygetK   s   
z	OInfo.getN)	__name__
__module____qualname__bool__annotations__r	   strr   r.   r,   r,   r,   r-   r"   B   s   
 r"   c                 C   s   t | t tddS )NT)Z	noclasses)r   r   r   )coder,   r,   r-   pylight\   s   r6   c                 C   s   h | ]}t |qS r,   )inspectgetdoc).0tr,   r,   r-   	<setcomp>b   s    
r;   c                   @   s   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)r/   r0   r1   r	   r4   r3   r2   r,   r,   r,   r-   r<   t   s*   
 r<   c                 C   s0   | dkrt jdtdd tS tdtd| )NZinfo_fieldszfIPython.core.oinspect's `info_fields` is considered for deprecation and may be removed in the Future.    
stacklevelzmodule z has no attribute )warningswarnDeprecationWarning_info_fieldsAttributeErrorr/   )rL   r,   r,   r-   __getattr__   s   rU   c                   @   sB   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)r/   r0   r1   __doc__r   r3   r	   r"   r<   intlistr4   r,   r,   r,   r-   rV      s   
 rV   F)rK   r$   r#   rL   r%   rK   r$   r#   returnc                    sL   |  fddt D  |  d< | d< | d< | d< | d< td	i  S )
z1Make an object info dict with all fields present.c                    s   i | ]	}| vr|d qS Nr,   )r9   kZinfodictr,   r-   
<dictcomp>   s    zobject_info.<locals>.<dictcomp>rL   r%   rK   r$   r#   Nr,   )rS   r<   )rL   r%   rK   r$   r#   kwr,   ra   r-   object_info   s   rd   c                 C   st   t | }|du r
dS |drdS tj|sdS t|d}t|j	\}}W d   |S 1 s3w   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_linesr,   r,   r-   get_encoding   s   

rt   c                 C   sB   z|   }W n	 ty   Y nw t|trt|S t | }|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.
    )r8   	Exception
isinstancer4   r7   cleandoc)r(   dsZdocstrr,   r,   r-   r8      s   



r8    c           	      C   s  t | trTg }dD ]A}t| |}|durJt|}|rd| nd}|dd||f t|r>t|}|r=|t	| q	|d||t
|f  q	|rRd|S dS t| } zt| }W |S  ty   z
t| j}W Y |S  ttfy~   Y Y dS w  ty   Y dS w )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.ry   z# z
%s%s = %s

)rv   propertyr)   rt   appendjoinr7   
isfunction	getsourcer   r   _get_wrapped	TypeError	__class__OSError)	r(   onamesourcesattrnamefnrr   Zoname_prefixZ_srcsrcr,   r,   r-   r      sD   



r   c                 C   s(   t | pt | pt| tpt| tS )zTrue if obj is a function ())r7   r   ismethodrv   _builtin_func_type_builtin_meth_typer(   r,   r,   r-   is_simple_callable)  s
   r   c                 C   s2   t jdtdd t| drt| s| j} t| 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.rM   rN   __call__)rP   rQ   rR   r   r   r   r7   getfullargspecr   r,   r,   r-   
getargspec.  s   

r   c                 C   s0   t jdtdd t| 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.rM   rN   argsvarargsvarkwdefaults)rP   rQ   rR   r7   formatargspec)argspecr,   r,   r-   format_argspec@  s   
r   Tc              	   C   s   t jdtdd | d}|du rd}n*z
|d d dk}W n ttfy)   Y nw |r6|d d	d |d< | d
 t| }| d}|du rL| d}|du rV| 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.rM   rN   r   Nr   r   r*      rL   rI   rG   rC   ry   )rP   rQ   rR   r.   KeyError
IndexErrorr   )ZoinfoZformat_callr   Z	call_lineZhas_selfdocr,   r,   r-   call_tipQ  s,   


r   c                 C   s:   | }d}t | dr| j} |d7 }|dkr|S t | ds	| 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(   Zorig_objir,   r,   r-   r   w  s   

r   c                 C   sn   t | } d}zt| }W |S  ty-   z
t| j}W Y |S  ttfy,   Y Y |S w  ty6   Y |S w )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   r7   
getabsfiler   r   r   )r(   fnamer,   r,   r-   rg     s"   rg   c                 C   sr   t | } z
t| d }W |S  ty/   zt| jd }W Y |S  ttfy.   Y Y dS w  ty8   Y dS w )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   r7   getsourcelinesr   r   r   )r(   linenor,   r,   r-   find_source_lines  s   
r   c                       s  e Zd ZejdddjddZeej	ddddf fdd	Z
d;d
eedf fddZd
efddZdd Zdd Zd;ddZed<ddZd;ddZd;ddZd=ded
efddZded
efdd Zded!ed"ed#ee fd$d%Zd
efd&d'Z						(d>d)ed*ed+ee  d,e!d#eee e"d( f d
efd-d.Z#							(d?d+ee  fd/d0Z$d@d1d2Z%d@d
e&fd3d4Z'e(d5d6 Z)g d7d7fd7d8d9d:Z*  Z+S )Ar   TzKdictionary of mime to callable to add information into help mimebundle dict)confighelp)r   Nr   c                    sJ   t t| j||d || _tjd| |d| _| jj| _|| _| 	| d S )N)r'   r   r4   )outr'   style)
superr   __init__color_tabler   Parserparserformatstr_detail_levelset_active_scheme)r*   r   Zcode_color_tableschemer   r'   r   r   r,   r-   r     s   	
zInspector.__init__ry   r^   c                 C   s*   t |sdS ztt||W S    Y dS )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   r,   r,   r-   _getdef  s   zInspector._getdefc                 C   s   d| j jj|| j jjf S )z*Return a header string with proper colors.z%s%s%s)r   Zactive_colorsheadernormal)r*   hr,   r,   r-   Z__head  s   zInspector.__headc                 C   s*   |d ur| j | | jj | d S d S r_   )r   r   r   )r*   r   r,   r,   r-   r     s   zInspector.set_active_schemec                 C   s.   t d| dd |rt d|  dS t   dS )z-Generic message when no information is found.zNo %s found endzfor %sN)print)r*   msgr   r,   r,   r-   noinfo  s   
zInspector.noinfoc                 C   sh   t |s
td dS d}t|r| d}| ||}|du r(| d| dS t|| |d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.Nry   zClass constructor information:
zdefinition headerr   r   )r   r   r7   rK   _Inspector__headr   r   r   )r*   r(   r   r   outputr,   r,   r-   pdef   s   

zInspector.pdefc           	      C   s   | j }g }t|}|r||d|}|r#||d |t| t|rEt|drEt|j}|durD||d |t| nt|dr_t|j	}|r_||d |t| |si| 
d| dS t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:Zdocumentationr}   )r   r8   r.   r   r   r7   rK   hasattrr   r   r   r   r   )	r*   r(   r   	formatterheadlinesrx   init_dscall_dsr,   r,   r-   pdoc  s,   "


zInspector.pdocc                 C   s\   t   zt||d}W n ty   d}Y nw |du r$| d| dS t| | dS )z$Print the source code for an object.)r   NrD   )	linecache
checkcacher   ru   r   r   r   )r*   r(   r   r   r,   r,   r-   psourceP  s   zInspector.psourcec                 C   s   t |}|du r| d| dS t|}|du rtd dS |dr+td|  dS tj|s9td|  dS t| 	t
j|dd|d	  dS )
z0Show the whole file where an object was defined.NrA   zCould not find file for objectre   z File %r is binary, not printing.z%File %r does not exist, not printing.F)Zskip_encoding_cookier   )r   r   rg   r   rh   ri   rj   rk   r   r   r   Zread_py_file)r*   r(   r   r   rp   r,   r,   r-   pfile_  s   
$zInspector.pfiletextc                 C   sX   |dt | dd}|du r|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/htmlN)htmlescaperv   dict)r*   r   r   r   	formattedr,   r,   r-   _mime_formatx  s   
zInspector._mime_formatbundlec           
      C   sB  t |d ts	J |d D ]	}t |tsJ qi }g }tdd |d D }|d D ])\}}|d}d|v r9dnd}|| |d  |t| d  | |  q*d||d< d|v rt |d tshJ |d D ]	}t |tsuJ qlt |d ttfrddd |d D |d< |	 D ]}	|	d	v rq||	 ||	< q|S )
zRFormat a mimebundle being created by _make_info_unformatted into a real mimebundler   c                 s   s    | ]	\}}t |V  qd S r_   len)r9   r   _r,   r,   r-   	<genexpr>      z(Inspector.format_mime.<locals>.<genexpr>r}   r   :r   c                 s   s$    | ]\}}d | d| V  qdS )z<h1>z</h1>
Nr,   )r9   r   bodyr,   r,   r-   r     s   " )r   r   )
rv   r]   tuplemaxstripr   r   r   r   keys)
r*   r   itemZnew_br   _lenr   r   delimr`   r,   r,   r-   format_mime  s4   
(zInspector.format_mimetitlekeyrZ   c           	      C   sd   ||v s||v r
dS || }|dur0|  ||}|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   rW   rZ   r   r+   Zformatted_fieldr,   r,   r-   _append_info_field  s   
zInspector._append_info_fieldc           	         s  g g d}	d-dt dtdtf fdd}dtffd	d
} d r+||dd |S  d rJ|dkr;||dd| n||dd| ||dd |S  d sRt|r||dd| ||dd| ||dd| |dkrw d rw||dd| n||dd| ||dd ||dd ||dd  |S ||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                    s   j | || |d d S )N)r   r   rW   rZ   r   )r   )r   r   r   r   rW   rZ   r*   r,   r-   append_field  s   
z6Inspector._make_info_unformatted.<locals>.append_fieldr^   c                    s     | t| dS )Nr   )r   r6   )r   )r*   r,   r-   code_formatter  s   z8Inspector._make_info_unformatted.<locals>.code_formatterr$   Reprr?   r#   r   ZSourcerD   Z	DocstringrC   FilerA   rK   	SignaturerB   zInit signaturerE   zInit docstringrG   Typer=   Z
SubclassesrJ   zCall signaturerH   zString formr&   Interactive	NamespaceZLengthr@   zClass docstringrF   zCall docstringrI   r_   )r    r4   r!   r   )	r*   r(   rW   r   rY   rZ   r   r   r   r,   r   r-   _make_info_unformatted  s^   /(z Inspector._make_info_unformattedr,   r(   r   rW   rY   c                 C   s   | j ||||d}t|}| j|||||d}| jrZt|||||d}	| j D ]1\}
}dd t|j	 D }t
|dkrD||	}ntjdtdd	 |||}|d
urY|||
< q(| |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   rW   rY   )rY   rZ   )r(   rW   rX   rY   rZ   c                 S   s   g | ]}|j tjj kr|qS r,   )defaultr7   	Parameter)r9   Z	parameterr,   r,   r-   
<listcomp>N  s
    z'Inspector._get_info.<locals>.<listcomp>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 versionrM   rN   N)rW   r]   r   
mime_hooksrV   itemsr7   r   
parametersvaluesr   rP   rQ   rR   r   )r*   r(   r   r   rW   rY   rZ   rX   r   	hook_datar   hookZrequired_parametersresr,   r,   r-   	_get_info!  sB   


zInspector._get_infoc           	      C   s:   |dusJ | j ||||||d}|s|d= t| 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)rZ   r   )r  r   )	r*   r(   r   r   rW   rY   Zenable_html_pagerrZ   Zinfo_br,   r,   r-   pinfob  s   !zInspector.pinfoc                 C   s"   t jdtdd | j||||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.rM   rN   r   )rP   rQ   rR   rW   )r*   r(   r   rW   rY   r,   r,   r-   _info  s   zInspector._infoc               	   C   s,  |du rd}d}d}n	|j }|j}|j}|dd }d}	d}
|r8|jdur8t|jtr8t|jt}||d}	t	t
i dd tD |d||dd	}|	rQ|	}n8|r|t|skzd
|d  }W n)   dt| }Y ndt| }|jr{|d|j 7 }nt|}|du rd}n|}|
| }d}t|d d }|rd|d< n|rd|d< nt|j|d< z|j}t||d< W n   Y || jkrz6t|}|st||kr|d| d || d  }ddtd   dd |dD }||d< W n   Y |r||d< z
tt||d< W n
 ty   Y nw d}t|}|du r&d}n|dr/d}n|d r7d!}t||d"< |rlt  zt|tsN|s`t ||}|dur\|! }||d#< W n
 tyk   Y nw |r}| "|d#|s}||d$< t#$|rd|d%< z| %||}W n t&y   d}Y nw z|j'}W n t&y   d}Y n$w |du rz| %||}W n
 t&y   Y nw t|}|t(krd}|r||d&< |r||d'< d(d) t)|D }t|d*k rd+|}nd+|dd* d,g }||d-< |S | %||}|r||d.< |r>zt|d/}W n   d}Y nt|}|t*v r2d}|r>||kr>||d0< zt|j'}|t(krKd}W n t&yX   d}Y nw |r`||d'< t+|d1rt,|s| %|j-|}|r||d.kr||d2< t|j-}|t.krd}|r||d3< |S )4as  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`).
        NFry   .c                 S   s   i | ]}|d qS r_   r,   )r9   r+   r,   r,   r-   rb         z"Inspector.info.<locals>.<dictcomp>T)rL   r%   r$   r#   rJ   z!Alias to the system command:
  %sr   zAlias: z	Alias to z
Docstring:
z<no docstring>      rM   zMagic functionr=   zSystem aliasr>   z <...> r}   r   r?   c                 s   s    | ]}|  V  qd S r_   )r   )r9   qr,   r,   r-   r     s    
z!Inspector.info.<locals>.<genexpr>r&   r@   re   z<string>z9Dynamically generated function. No source code available.rA   rD   rC   rK   rE   rG   c                 S   s   g | ]}|j qS r,   )r/   )r9   subr,   r,   r-   r   N  r  z"Inspector.info.<locals>.<listcomp>
   , z...rJ   rB   r   rF   r   rH   rI   )/r#   r$   r&   splitr'   r   	HOOK_NAMEr)   r.   r   r<   rS   r   r4   r[   r8   r\   typer/   r   r   r   
expandtabsr   ru   rg   rh   r   r   r   rv   r~   r   rstrip_source_contains_docstringr7   rK   r   rT   r   _object_init_docstring__subclasses___builtin_type_docstringsr   r   r   _func_call_docstring) r*   r(   r   rW   rY   r#   r$   ZospaceZatt_nameZparents_docsZpreludeZparents_docs_dictr   rx   Z
ds_or_NoneZ
string_maxZshalfZbclassZostrbinary_filer   r   Zinit_defZobj_initr   namesZ	all_namesZdeflnclsZclass_dsrH   r   r,   r,   r-   rW     s@  








2




zInspector.infoc                 C   s8   zt t| j\}t ||kW S  ty   Y dS 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_docstringru   )r   r   Zdef_noder,   r,   r-   r    s   z$Inspector._source_contains_docstringF)
list_typesc                C   s   d}d}|rt  dtt dS | }	t|	}
|
dkr#|	d }n|
dkr,|	\}}ntd| |D ]}||vrDtd	|| f q4t t }}|D ]"}|| }t	||v r[qN|
t	| t|||||d
}|| qNt  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.
        allry   r}   Nr   r   rM   z)invalid argument string for psearch: <%s>z'invalid namespace <%s>. Valid names: %s)ignore_caseshow_all)r   r   sortedr   r  r   
ValueErrorr   setidaddr   update)r*   patternZns_tableZ	ns_searchr  r   r  Ztype_patternfilterZcmdsZlen_cmdsrL   Zsearch_resultZnamespaces_seenZns_namensZtmp_resr,   r,   r-   psearch  s>   


zInspector.psearchry   )ry   Nr_   )ry   NNr   r,   )ry   NNr   Tr,   )ry   Nr   ),r/   r0   r1   	traitletsr
   tagr   r   r   ANSICodeColorsr   r   r4   r   r   r   r   r   r   r   r   r   r   r   r    r!   r   r   r   r   r   r	   r"   r\   r   r  r  r  r<   rW   staticmethodr  r*  __classcell__r,   r,   r   r-   r     s    

9
"&

R
D

) n
c                 C   s
  g }d}d}| j  D ]6}|jtjjkrd}n	|r |d d}|jtjjkr*d}n|jtjjkr:|r:|d d}|t	| q|rI|d t
|tdd |D  dkrgd|d	d
d |D }n	d|d|}| jtjurt| j}|d|7 }|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                 s   s    | ]	}t |d  V  qdS )rM   Nr   r9   rr,   r,   r-   r     r   z$_render_signature.<locals>.<genexpr>K   z{}(
{})ry   c                 s   s    | ]}d  |V  qdS )z    {},
N)r   r3  r,   r,   r-   r     s    

z{}({})r  z -> {})r   r   kindr7   r   POSITIONAL_ONLYr   VAR_POSITIONALKEYWORD_ONLYr4   r   sumr   r   return_annotation_emptyformatannotation)Zobj_signatureobj_nameresultZpos_onlykw_onlyparamrenderedannor,   r,   r-   r     s4   


r   r+  )T)fr[   __all__dataclassesr   r7   r   textwrapr   r  r   iorl   r   ri   typesrP   typingr   r   r	   r
   r   r   r   r   r   r,  ZIPython.corer   ZIPython.lib.prettyr   ZIPython.testing.skipdoctestr   ZIPython.utilsr   r   ZIPython.utils.dir2r   ZIPython.utils.pathr   ZIPython.utils.textr   ZIPython.utils.wildcardr   r   ZIPython.utils.coloransir   ZIPython.utils.colorabler   ZIPython.utils.decoratorsr   pygmentsr   Zpygments.lexersr   Zpygments.formattersr   r  r4   r    r3   r!   r"   r6   FunctionTyper   r  objectr   r  
ModuleType
MethodTyper~   r  r  r  r   upperr   ZColorsr.  r   r<   r]   r   rS   rU   rV   r2   rd   rt   r8   r   r   r   r   r   r   rg   r   r   r   r,   r,   r,   r-   <module>   s    , 


?

%#      