o
    5e%                     @   s<  d dl m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
mZmZ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 ddl m!Z!m"Z" de#de#fddZ$G dd deZ%dee&ee
 f dee'df fddZ(de&dee# fddZ)de&dee# de*fddZ+dS )    )absolute_importN)cleandocgetdocgetfileisclassismodule	signature)Any
CollectionIterableOptionalTupleTypeUnion   )GroupRenderableType)escape_control_codes)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                   @   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e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.   )r0   r-   	title_str
title_textr    r    r!   r/   B   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$   )r0   r    r    r!   __rich__L   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tfy2   Y nw t|dd}|rC|d|  | |}|pOt	|d|}t
|rXd}n
t
|r`d	}nd
}t| dd|dd f|df|}	|	S )zGet a signature for a callable.:z(...)Nzinspect.callablestylezlink file://__qualname__classz	async defdef zinspect.r   )r3   r   
ValueError	TypeErrorr   OSErrorr   stylizer.   getattrinspectr   iscoroutinefunctionassemblereplace)
r0   r=   r-   
_signaturesource_filenamecallable_namesignature_textqualnameprefixqual_signaturer    r    r!   _get_signatureT   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r|  }
|
durt|
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|r4| jsq| ||}|du r||t||d! q| jr.| |}|dur.|d"|v rd"nd# ||}|d$ || ||| q||t||d! q|j rG|V  dS |rVt!d%| d&V  dS dS )'zRender object.itemr   c                 S   s"   | \}\}}t ||d fS )Nr   )r2   striplower)rV   key_errorr,   r    r    r!   
sort_items~   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)rI   	Exception)r\   errorr-   r    r!   safe_getattr   s   z%Inspect._render.<locals>.safe_getattrc                 S      g | ]	}| d s|qS )__
startswith.0rY   r    r    r!   
<listcomp>       z#Inspect._render.<locals>.<listcomp>c                 S   ra   )r   rc   re   r    r    r!   rg      rh   c                    s   g | ]}| |fqS r    r    re   )r`   r    r!   rg      s    )rY   r7   F)r9   expandright)justify Nzinspect.helpr?   T
   <   )indent_guides
max_length
max_stringzinspect.value.border)r8   rb   zinspect.attr.dunderzinspect.attr)z =zinspect.equalszinspect.error)r.   
rD   zinspect.docz[b cyan]za[/][i] attribute(s) not shown.[/i] Run [b][magenta]inspect[/]([not b]inspect[/])[/b] for options.)"r   r3   r	   boolr-   dirlenr)   r(   r*   r   grid
add_columnadd_rowr.   r2   rU   r'   _get_formatted_docr   r,   r   r   r   r   rL   rd   copyrH   reprr&   append	row_countfrom_markup)r0   r[   keystotal_itemsnot_shown_countitemsitems_tablerx   r.   r   _docdoc_textrY   r^   r,   key_textwarning_signature_textr'   r   r    )r-   r`   r!   r;   {   s   "










zInspect._renderobject_c                 C   s6   t |}|du r
dS t| }| jst|}t|S )a  
        Extract the docstring of an object, process it and returns it.
        The processing consists in cleaning up the doctring's indentation,
        taking only its 1st paragraph if `self.help` is not True,
        and escape its control codes.

        Args:
            object_ (Any): the object to get the docstring from.

        Returns:
            Optional[str]: the processed docstring, or None if no docstring was found.
        N)r   r   rW   r%   r"   r   )r0   r   r'   r    r    r!   ry      s   zInspect._get_formatted_doc)__name__
__module__rA   __doc__r	   r   r   rs   r1   r   r/   r   r<   r3   rU   r   r   r;   ry   r    r    r    r!   r#      sN    	


']r#   r-   .c                 C   s   t | ds	t| } t| ddS )zNReturns the MRO of an object's class, or of the object itself if it's a class.__mro__r    )hasattrr4   rI   r_   r    r    r!   get_object_types_mro   s   
r   c                 C   s   dd t | D S )z
    Returns the MRO of an object's class as full qualified names, or of the object itself if it's a class.

    Examples:
        `object_types_mro_as_strings(JSONDecoder)` will return `['json.decoder.JSONDecoder', 'builtins.object']`
    c                 S   s*   g | ]}t |d d dt |dd qS )r   rl   .rA   )rI   )rf   type_r    r    r!   rg      s    z3get_object_types_mro_as_strings.<locals>.<listcomp>)r   r_   r    r    r!   get_object_types_mro_as_strings   s   r   fully_qualified_types_namesc                 C   s    t | D ]	}||v r dS qdS )z
    Returns `True` if the given object's class (or the object itself, if it's a class) has one of the
    fully qualified names in its MRO.
    TF)r   )r-   r   	type_namer    r    r!   is_object_one_of_types  s
   r   ),
__future__r   rJ   r   r   r   r   r   r   typingr	   r
   r   r   r   r   r   consoler   r   controlr   r.   r   jupyterr   panelr   prettyr   tabler   textr   r   r3   r"   r#   objectr4   r   r   rs   r   r    r    r    r!   <module>   s0     $ &X	