o
    F&h                     @   s   d dl mZ d dlmZmZmZmZmZmZ d dl	m
Z
mZmZ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 dd
lmZ ddlmZmZ dedefddZdedefddZ G dd deZ!dS )    )absolute_import)cleandocgetdocgetfileisclassismodule	signature)AnyIterableOptionalTuple   )RenderableTypeGroup)ReprHighlighter)JupyterMixin)Panel)Pretty)Table)TextTextTypedocreturnc                 C   s   |  d\}}}|S )z)Get the first paragraph from a docstring.z

)	partition)r   	paragraph_ r   L/var/www/html/venv/lib/python3.10/site-packages/pip/_vendor/rich/_inspect.py_first_paragraph   s   r   c                 C   s   t |  } | S )zReformat docstring.)r   strip)r   r   r   r   _reformat_doc   s   r    c                   @   s   e Zd ZdZdddddddddd	dedee ded	ed
ededededededdfddZdede	fddZ
defddZdededee	 fddZdee fddZdS )Inspecta  A renderable to inspect any Python Object.

    Args:
        obj (Any): An object to inspect.
        title (str, optional): Title to display over inspect result, or None use type. Defaults to None.
        help (bool, optional): Show full help text rather than just first paragraph. Defaults to False.
        methods (bool, optional): Enable inspection of callables. Defaults to False.
        docs (bool, optional): Also render doc strings. Defaults to True.
        private (bool, optional): Show private attributes (beginning with underscore). Defaults to False.
        dunder (bool, optional): Show attributes starting with double underscore. Defaults to False.
        sort (bool, optional): Sort attributes alphabetically. Defaults to True.
        all (bool, optional): Show all attributes. Defaults to False.
        value (bool, optional): Pretty print value of object. Defaults to True.
    NFT)	titlehelpmethodsdocsprivatedundersortallvalueobjr"   r#   r$   r%   r&   r'   r(   r)   r*   r   c       	         C   sd   t  | _|| _|p| || _|	rd } }}|| _|| _|p || _|p%|| _|| _	|| _
|
| _d S )NT)r   highlighterr+   _make_titler"   r#   r$   r%   r&   r'   r(   r*   )selfr+   r"   r#   r$   r%   r&   r'   r(   r)   r*   r   r   r   __init__+   s   


zInspect.__init__c                 C   s:   t |st|st|rt|ntt|}| |}|S )zMake a default title.)r   callabler   strtyper,   )r.   r+   	title_str
title_textr   r   r   r-   F   s   


zInspect._make_titlec                 C   s   t jt|   | jdddS )Nzscope.borderr   r   )r"   border_stylepadding)r   fitr   _renderr"   )r.   r   r   r   __rich__P   s   
zInspect.__rich__namec           	      C   s   z
t t|d }W n ty   d}Y n
 ty   Y dS w d}zt|}W n	 ty0   Y nw t|dd}|rA|d|  | |}|pMt|d|}t	d|df|}|S )	zGet a signature for a callable.:z(...)Nzinspect.callablestylezlink file://__qualname__)zdef zinspect.def)
r1   r   
ValueError	TypeErrorr   r   stylizer,   getattrassemble)	r.   r;   r+   
_signaturesource_filenamecallable_namesignature_textqualnamequal_signaturer   r   r   _get_signatureX   s,   

zInspect._get_signaturec                 #   s   dt ttf dt ttf fdd}dtdt ttf f fdd| j t }t|}| js6dd	 |D }| js@d
d	 |D }|t| }fdd	|D }| j	rX|j	|d t
jddd}|jdd |j}| j}t r| d }	|	dur|	V  dV  | jrt }
|
dur| jst|
}
tt|
dd}||}|V  dV  | jrt st st stt ddddddV  dV  |D ]\}\}}t||drdndfd}|dur| }|d  |||t | qt|rI| j!sq| ||}|du r||t||d! q| jrCt|}|durCtt|}
| js)t|
}
|"d"|
v r2d"nd# ||
}|d$ |"| ||| q||t||d! q|j#r\|V  dS t$d%| d&V  dS )'zRender object.itemr   c                 S   s"   | \}\}}t ||d fS )Nr   )r0   r   lower)rL   key_errorr*   r   r   r   
sort_itemsv   s   z#Inspect._render.<locals>.sort_items	attr_namec              
      s>   zdt  | fW S  ty } z
|dfW  Y d}~S d}~ww )zGet attribute or any exception.N)rC   	Exception)rQ   error)r+   r   r   safe_getattrz   s   z%Inspect._render.<locals>.safe_getattrc                 S      g | ]	}| d s|qS )__
startswith.0rN   r   r   r   
<listcomp>       z#Inspect._render.<locals>.<listcomp>c                 S   rU   )r   rW   rY   r   r   r   r[      r\   c                    s   g | ]}| |fqS r   r   rY   )rT   r   r   r[      s    )rN   r5   F)r7   expandright)justify Nzinspect.helpr=   T
   <   )indent_guides
max_length
max_stringzinspect.value.border)r6   rV   zinspect.attr.dunderzinspect.attr)z =zinspect.equalszinspect.error)r,   
 zinspect.docz[b cyan]za[/][i] attribute(s) not shown.[/i] Run [b][magenta]inspect[/]([not b]inspect[/])[/b] for options.)%r   r1   r	   boolr+   dirlenr'   r&   r(   r   grid
add_columnadd_rowr,   r0   rK   r%   r   r#   r   r   r    r*   r   r   r   r   rD   rX   copyrB   reprr$   append	row_countfrom_markup)r.   rP   keystotal_itemsnot_shown_countitemsitems_tablerm   r,   r   _docdoc_textrN   rS   r*   key_textwarning_signature_textr%   r   r   )r+   rT   r   r9   s   s   "








zInspect._render)__name__
__module__r?   __doc__r	   r   r   rh   r/   r   r-   r   r:   r1   rK   r
   r   r9   r   r   r   r   r!      sL    	


r!   N)"
__future__r   inspectr   r   r   r   r   r   typingr	   r
   r   r   consoler   r   r,   r   jupyterr   panelr   prettyr   tabler   textr   r   r1   r   r    r!   r   r   r   r   <module>   s     