o
    MEgkj                     @   s>  U 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	 d dl
mZmZm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mZmZ d dlmZ zd dlZW n e yb   dZY nw ded	e!fd
dZ"ded	ed fdd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l0m1Z1m2Z2 ddl3m4Z4 ddl5m6Z6 erddl7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z= 							dbded ddd e!d!e!d"ee> d#ee> d$e!d	dfd%d&Z?G d'd( d(e1Z@d)eeef d	eeAeAeAf fd*d+ZBd)d,d	eeAeAeAf fd-d.ZCejDd/d0 eeCeeBed1d0 ed2d0 eEd3d0 ed4d0 eFd5d0 eGd6d0 e	d7d0 eHd8d0 eId9d0 ed:d0 iZJeeKeegeeAeAeAf f f eLd;< eIeJM ZNeEejDeefZOded	e!fd<d=ZPeG d>d? d?ZQeG d@dA dAZR	dcd)ed"ee> d#ee> d	eQfdBdCZSdDdEddddFd)edGe>dHe>d"ee> d#ee> d$e!d	eAfdIdJZTddKddddLd)eded d!e!d"ee> d#ee> d$e!d	dfdMdNZUeVdOkrG dPdQ dQZWee>ZXdReXdS< ddTdUdVdWh dXgeFh dYeeGdZg d[ieg d\d]eW d^ZYeYdS ZeY d d_l[m\Z\ e\e@eYdKd`da dS dS )d    N)array)CounterdefaultdictdequeUserDictUserList)	dataclassfieldsis_dataclass)islice)DefaultDictTYPE_CHECKINGAnyCallableDictIterableListOptionalSetUnionTuple)MappingProxyTypeobjreturnc                 C   s   t duo
t t| S )z1Check if an object was created with attrs module.N)_attr_modulehastyper    r   e/var/www/eduai.edurigo.com/doc_train/edurigo_ai/Puru/venv/lib/python3.10/site-packages/rich/pretty.py_is_attr_object   s   r    z_attr_module.Attribute[Any]c                 C   s   t durt t| S g S )zGet fields for an attrs object.N)r   r	   r   r   r   r   r   _get_attr_fields"   s   r!      )ReprHighlighterget_console)	loop_last)	pick_bool)RichRenderablecell_len)JupyterMixinJupyterRenderable)Measurement)Text)ConsoleConsoleOptionsHighlighterTypeJustifyMethodOverflowMethodRenderResultignoreFconsoler/   overflowr3   cropindent_guides
max_length
max_string
expand_allc              	      s   ddl m} ddlm  p| dusJ dtddffdd	}dtddf fd
d}	zt }
ddlm} | }|jt	|	d ||
j
jd< W dS  tyc   |t_Y dS w )a  Install automatic pretty printing in the Python REPL.

    Args:
        console (Console, optional): Console instance or ``None`` to use global console. Defaults to None.
        overflow (Optional[OverflowMethod], optional): Overflow method. Defaults to "ignore".
        crop (Optional[bool], optional): Enable cropping of long lines. Defaults to False.
        indent_guides (bool, optional): Enable indentation guides. Defaults to False.
        max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation.
            Defaults to None.
        max_string (int, optional): Maximum length of string before truncating, or None to disable. Defaults to None.
        expand_all (bool, optional): Expand all containers. Defaults to False
    r   r$   r"   )ConsoleRenderableNvaluer   c              	      sT   | dur( dus
J dt _ jt| tr| n	t| dd | t _dS dS )z?Replacement sys.displayhook which prettifies objects with Rich.N)r7   r9   r:   r;   r<   r8   )builtins_print
isinstancer(   Prettyr>   )r6   r8   r<   r9   r:   r;   r7   r   r   display_hookY   s$   
zinstall.<locals>.display_hookc              
      s   d usJ t | ts| d u rd S jr!tdd t| D r!d S t| dr(d S t |  r1  jt | tr:| n
t	| ddd d S )Nc                 s   s    | ]}| d V  qdS )_repr_N)
startswith).0attrr   r   r   	<genexpr>s   s    z4install.<locals>.ipy_display_hook.<locals>.<genexpr>_repr_mimebundle_   )r7   r9   r:   r;   r<   marginr?   )
rC   r,   
is_jupyteranydirhasattrlinerB   r(   rD   rE   r=   r6   r8   r<   r9   r:   r;   r7   r   r   ipy_display_hookm   s.   

	
z!install.<locals>.ipy_display_hook)BaseFormatter)funcz
text/plain)richr%   r6   r=   r   get_ipythonIPython.core.formattersrV   for_typeobjectdisplay_formatter
formatters	Exceptionsysdisplayhook)r6   r7   r8   r9   r:   r;   r<   r%   rF   rU   iprV   rich_formatterr   rT   r   install=   s   
"$rd   c                   @   s   e Zd ZdZ	d#ddddddddddd
deded	 d
eded ded dee dedee dee dedededdfddZ						d$ddZ							 d%d!d"Z
dS )&rD   a  A rich renderable that pretty prints an object.

    Args:
        _object (Any): An object to pretty print.
        highlighter (HighlighterType, optional): Highlighter object to apply to result, or None for ReprHighlighter. Defaults to None.
        indent_size (int, optional): Number of spaces in indent. Defaults to 4.
        justify (JustifyMethod, optional): Justify method, or None for default. Defaults to None.
        overflow (OverflowMethod, optional): Overflow method, or None for default. Defaults to None.
        no_wrap (Optional[bool], optional): Disable word wrapping. Defaults to False.
        indent_guides (bool, optional): Enable indentation guides. Defaults to False.
        max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation.
            Defaults to None.
        max_string (int, optional): Maximum length of string before truncating, or None to disable. Defaults to None.
        expand_all (bool, optional): Expand all containers. Defaults to False.
        margin (int, optional): Subtrace a margin from width to force containers to expand earlier. Defaults to 0.
        insert_line (bool, optional): Insert a new line if the output has multiple new lines. Defaults to False.
    N   Fr   )
indent_sizejustifyr7   no_wrapr9   r:   r;   r<   rN   insert_line_objecthighlighterr1   rf   rg   r2   r7   r3   rh   r9   r:   r;   r<   rN   ri   r   c       
         C   sR   || _ |pt | _|| _|| _|| _|| _|| _|| _|	| _	|
| _
|| _|| _d S N)rj   r#   rk   rf   rg   r7   rh   r9   r:   r;   r<   rN   ri   )selfrj   rk   rf   rg   r7   rh   r9   r:   r;   r<   rN   ri   r   r   r   __init__   s   
zPretty.__init__r6   r/   optionsr0   r4   c                 c   s    t | j|j| j | j| j| j| jd}t|| j	p|j	| j
p |j
t| j|jdd}|r1| |ntt| j ddd}| jrK|jsK|j| jdd}| jrUd|v rUd	V  |V  d S )
N	max_widthrf   r:   r;   r<   pretty)rg   r7   rh   stylez.__repr__ returned empty stringz
dim italic)rs   zrepr.indent
 )pretty_reprrj   rq   rN   rf   r:   r;   r<   r.   rg   r7   r'   rh   rk   r   r9   
ascii_onlywith_indent_guidesri   )rm   r6   ro   
pretty_strpretty_textr   r   r   __rich_console__   s<   


	
zPretty.__rich_console__r-   c                 C   sD   t | j|j| j| j| jd}|rtdd | D nd}t||S )N)rq   rf   r:   r;   c                 s       | ]}t |V  qd S rl   r)   rI   rS   r   r   r   rK          z*Pretty.__rich_measure__.<locals>.<genexpr>r   )	rv   rj   rq   rf   r:   r;   max
splitlinesr-   )rm   r6   ro   ry   
text_widthr   r   r   __rich_measure__   s   
zPretty.__rich_measure__rl   )r6   r/   ro   r0   r   r4   )r6   r/   ro   r0   r   r-   )__name__
__module____qualname____doc__r   r   intboolrn   r{   r   r   r   r   r   rD      sn    	


"rD   rj   c                 C   s   d| j ddd| j dfS )Nzdefaultdict(z, {})z, {}))default_factoryrj   r   r   r   _get_braces_for_defaultdict   s   r   z
array[Any]c                 C   s   d| j dddfS )Nzarray(z, [])zarray({_object.typecode!r}))typecoder   r   r   r   _get_braces_for_array  s   r   c                 C      dS )N)z	environ({r   zenviron({})r   r   r   r   r   <lambda>      r   c                 C   r   )N)z	Counter({r   z	Counter()r   r   r   r   r   r   
  r   c                 C   r   )N)zdeque([r   zdeque()r   r   r   r   r   r     r   c                 C   r   N){}z{}r   r   r   r   r   r     r   c                 C   r   r   r   r   r   r   r   r     r   c                 C   r   )N)zfrozenset({r   zfrozenset()r   r   r   r   r   r     r   c                 C   r   N)[]z[]r   r   r   r   r   r     r   c                 C   r   r   r   r   r   r   r   r     r   c                 C   r   )N)r   r   zset()r   r   r   r   r   r     r   c                 C   r   )N)()()r   r   r   r   r   r     r   c                 C   r   )N)zmappingproxy({r   zmappingproxy({})r   r   r   r   r   r     r   _BRACESc                 C   s0   t | tpt| ot | t pt| dpt| S )z3Check if an object may be expanded by pretty print.__rich_repr__)rC   _CONTAINERSr
   r   rR   r    r   r   r   r   is_expandable  s   
r   c                	   @   s   e Zd ZU dZdZeed< dZeed< dZeed< dZ	eed< dZ
eed< dZeed	< dZeed
< dZeed   ed< dZedefddZdee fddZdededefddZdefddZ	d dedededefddZdS )!Nodez4A node in a repr tree. May be atomic or a container.ru   key_repr
value_repr
open_braceclose_braceemptyFlastis_tupleNchildrenz: r   c                 C   s   | j rdS dS )zGet separator between items.ru   ,)r   rm   r   r   r   	separator1  s   zNode.separatorc                 c   s    | j r| j V  | jV  | jr| jV  dS | jdurX| jrR| jV  | jr9t| jdkr9| jd  E dH  dV  n| jD ]}| E dH  |jsKdV  q<| j	V  dS | j
V  dS dS )zGenerate tokens for this node.Nr"   r   r   z, )r   key_separatorr   r   r   r   leniter_tokensr   r   r   )rm   childr   r   r   r   6  s(   

zNode.iter_tokensstart_lengthr:   c                 C   s0   |}|   D ]}|t|7 }||kr dS qdS )a*  Check the length fits within a limit.

        Args:
            start_length (int): Starting length of the line (indent, prefix, suffix).
            max_length (int): Maximum length.

        Returns:
            bool: True if the node can be rendered within max length, otherwise False.
        FT)r   r*   )rm   r   r:   total_lengthtokenr   r   r   check_lengthL  s   
zNode.check_lengthc                 C   s   d |  }|S Nru   )joinr   )rm   	repr_textr   r   r   __str__]  s   zNode.__str__P   re   rq   rf   r<   c                 C   s   t | ddg}d}|t|k r5|| }|jr+|js+|s ||s+|||||d < |d7 }|t|k sddd |D }|S )al  Render the node to a pretty repr.

        Args:
            max_width (int, optional): Maximum width of the repr. Defaults to 80.
            indent_size (int, optional): Size of indents. Defaults to 4.
            expand_all (bool, optional): Expand all levels. Defaults to False.

        Returns:
            str: A repr string of the original object.
        T)nodeis_rootr   r"   rt   c                 s   r|   rl   )strr}   r   r   r   rK   w  r~   zNode.render.<locals>.<genexpr>)_Liner   
expandableexpandedr   expandr   )rm   rq   rf   r<   linesline_norS   repr_strr   r   r   rendera  s   zNode.render)r   re   F)r   r   r   r   r   r   __annotations__r   r   r   r   r   r   r   r   r   r   r   propertyr   r   r   r   r   r   r   r   r   r   r   r   #  s4   
 r   c                   @   s   e Zd ZU dZdZeed< dZee	 ed< dZ
eed< dZeed< dZeed	< dZeed
< edefddZdedefddZdeded  fddZdefddZdS )r   zA line in repr output.Fr   Nr   ru   textsuffix
whitespacer   r   c                 C   s   t | jduo	| jjS )z"Check if the line may be expanded.N)r   r   r   r   r   r   r   r     s   z_Line.expandabler:   c                 C   s:   t | jt| j t| j }| jdusJ | j||S )z4Check this line fits within a given number of cells.N)r   r   r*   r   r   r   r   )rm   r:   r   r   r   r   r     s   z_Line.check_lengthrf   c           	      c   s    | j }|dus
J | j}|jsJ |jr&t|j |j |j |dV  nt|j|dV  | jd|  }|jo>t|jdk}|jD ]}|rHdn|j	}t|||d}|V  qBt|j
||ra| jsadn|j	dV  dS )z6Expand this line by adding children on their own line.N)r   r    r"   r   )r   r   r   )r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   )	rm   rf   r   r   child_whitespacetuple_of_oner   r   rS   r   r   r   r     s4   


z_Line.expandc                 C   s    | j  | j | jp
d | j S r   )r   r   r   r   r   r   r   r   r     s    z_Line.__str__)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   r   {  s   
 r   c                    s^   dt dtffddt jjddt dtdtf fdd  | d	d
}|S )a  Traverse object and generate a tree.

    Args:
        _object (Any): Object to be traversed.
        max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation.
            Defaults to None.
        max_string (int, optional): Maximum length of string before truncating, or None to disable truncating.
            Defaults to None.

    Returns:
        Node: The root of a tree structure which can be used to render a pretty repr.
    r   r   c              
      s    dur$t | ttfr$t|  kr$t|   }| d  d| }|S zt| }W |S  tyD } zd| d}W Y d}~|S d}~ww )z0Get repr string for an object, but catch errors.N+z<repr-error 'z'>)rC   bytesr   r   reprr_   )r   	truncatedobj_reprerror)r;   r   r   to_repr  s   
ztraverse.<locals>.to_reprFrootc              	      sx  t }tjjtjjf}dtdttttt	tf f  fdd}t
drt| }|rqg }|j}tjj dd||d}t|D ]*\}	}
t|
trc|
\}}|}|	|_||_d	|_|| qD|
}|	|_|| qDntjj d
g |d}ntrg }|j}t  rtjj dd||d}dttt	ttttgt	f  f  f fdd}t| D ]$\}	\}}}|rtt	||d}n|}|	|_||_d	|_|| qnUtjj d
g |d}nGtrStt sSdjjv s|dkrSt}|v rtddS | g }|j}tjj dd||d}ttD ]\}	}|j rLt!|j"}|j"|_|	|_d	|_|| q.| ntt#r,t#D ]}t|rg|} nq[t}|v rwtddS | t$| \}}}|jt jkrt|d}nr g }t||||d}|j}t%}|d }tt&rt'( }durt)|}t*|D ]\}\}}|}||_||k|_|| qn%t'}durt)|}t*|D ]\}}|}||k|_|| qdur|kr|td|  dd nt|g |d}| nt|d}tt|_+|S )zWalk the object depth first.	rich_argsr   c                 s   s    | D ]<}t |tr<t|dkr |\}}}||krq||fV  qt|dkr0|\}}||fV  qt|dkr;|d V  q|V  qd S )N      r"   r   )rC   tupler   )r   argkeyr   defaultr   r   r   iter_rich_args  s    


z3traverse.<locals>._traverse.<locals>.iter_rich_argsr   r   r   )r   r   r   r   =r   )r   r   r   c                  3   sx     D ]6} | j r9zt| j}W n ty) } z| j|dfV  W Y d}~qd}~ww | j|t| j r5| j ndfV  qdS )z$Iterate over attr fields and values.N)r   getattrnamer_   callable)rJ   r>   r   attr_fieldsr   r   r   
iter_attrs  s   z/traverse.<locals>._traverse.<locals>.iter_attrs)r   __create_fn__)r      z...)r   r   r"   Nz... +T)r   r   r   ),r   r`   version_infomajorminorr   r   r   r   r   rR   listr   appendr   	__class__r   r&   rC   r   r   r   r   r    r!   r   r   r
   __repr__r   idr	   r   r   r   r   r   r   _MAPPING_CONTAINERSiteritemsr   	enumerater   )r   r   obj_type
py_versionr   argsr   r   r   r   r   r   r   
child_noder   r   r>   repr_callableobj_idfieldcontainer_typer   r   r   	num_itemslast_item_index
iter_itemsindexiter_values)	_traverser:   pop_visitedpush_visitedr   visited_idsr   r   r     s  &




















ztraverse.<locals>._traverseT)r   N)F)r   r   setaddremover   r   )rj   r:   r;   r   r   )r   r:   r;   r   r   r   r  r   traverse  s   & 8r  r   re   rp   rq   rf   c                C   s2   t | tr| }nt| ||d}|j|||d}|S )a  Prettify repr string by expanding on to new lines to fit within a given width.

    Args:
        _object (Any): Object to repr.
        max_width (int, optional): Desired maximum width of repr string. Defaults to 80.
        indent_size (int, optional): Number of spaces to indent. Defaults to 4.
        max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation.
            Defaults to None.
        max_string (int, optional): Maximum length of string before truncating, or None to disable truncating.
            Defaults to None.
        expand_all (bool, optional): Expand all containers regardless of available width. Defaults to False.

    Returns:
        str: A possibly multi-line representation of the object.
    )r:   r;   )rq   rf   r<   )rC   r   r  r   )rj   rq   rf   r:   r;   r<   r   r   r   r   r   rv     s   
rv   T)r6   r9   r:   r;   r<   c             	   C   s4   |du rt  n|}|jt| ||||dddd dS )aw  A convenience function for pretty printing.

    Args:
        _object (Any): Object to pretty print.
        console (Console, optional): Console instance, or None to use default. Defaults to None.
        max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation.
            Defaults to None.
        max_string (int, optional): Maximum length of strings before truncating, or None to disable. Defaults to None.
        indent_guides (bool, optional): Enable indentation guides. Defaults to True.
        expand_all (bool, optional): Expand all containers. Defaults to False.
    Nr5   )r:   r;   r9   r<   r7   T)	soft_wrap)r%   rB   rD   )rj   r6   r9   r:   r;   r<   _consoler   r   r   pprint  s   
r  __main__c                   @   s   e Zd ZdefddZdS )
BrokenReprr   c                 C   s   dd  dS )Nr"   r   zthis will failr   r   r   r   r   r     s   zBrokenRepr.__repr__N)r   r   r   r   r   r   r   r   r   r
    s    r
     foozHello World!gZd;Y@gʡE3t@g    cA>   r"   r   r   re   r  r         >   r"   r   r   crumble)applerhubarbbuttersugarflour)r  orangepearkumquatr  X  duriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurianduriandurian)FTN)r  barr   counteratomicBroken)rB      )r9   r;   )Nr5   FFNNF)NN)]r@   osr`   r   collectionsr   r   r   r   r   dataclassesr   r	   r
   	itertoolsr   typingr   r   r   r   r   r   r   r   r   r   r   typesr   rJ   r   ImportErrorr   r    r!   rk   r#   ru   r%   _loopr&   _pickr'   abcr(   cellsr*   jupyterr+   r,   measurer-   r   r.   r6   r/   r0   r1   r2   r3   r4   r   rd   rD   r   r   r   _Environdict	frozensetr   r  r   r   r   r   keysr   r   r   r   r   r  rv   r  r   r
  ddatar   rX   rB   r   r   r   r   <module>   s0  
 4 
[$b
(
W:
 c
&

"

