a
    dj=                  	   @  st  d Z ddlmZ ddlmZmZmZ ddlZddlm	Z	m
Z
mZmZ ddlmZ ddlmZ eeeef ee f ZedZed	Zd
dddddZd>dd
dddddZd?dd
dddddZd@dd
dddddZdAdd
dd d ddd!d"d#ZdBddd&d'd(d)Zd d*d+d,d-ZdCdddd.d/d0ZdDd2d d3d d dd4d5d6Zd7d7d8d9d:d;ZG d<d= d=eeef Z dS )Ez
Printing tools.
    )annotations)IterableMappingSequenceN)AnyCallableTypeVarUnion)
get_option)is_sequence_KT_VTint	list[str]str)spacelistsreturnc                   s   | dt| dt}g } fdd|dd D }|ttt|d  ttt|}t|D ]B\}}|||| dd}	d	||  g|t|  |	 }	||	 qft| }
d
dd |
D S )a  
    Glues together two sets of strings using the amount of space requested.
    The idea is to prettify.

    ----------
    space : int
        number of spaces for padding
    lists : str
        list of str which being joined
    strlen : callable
        function used to calculate the length of each str. Needed for unicode
        handling.
    justfunc : callable
        function used to justify str. Needed for unicode handling.
    strlenjustfuncc                   s   g | ]}t t|  qS  )maxmap.0xr   r   r   c/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/pandas/io/formats/printing.py
<listcomp>0       zadjoin.<locals>.<listcomp>Nleft)mode 
c                 s  s   | ]}d  |V  qdS ) N)join)r   linesr   r   r   	<genexpr>9   r   zadjoin.<locals>.<genexpr>)	poplenjustifyappendr   r   	enumeratezipr&   )r   r   kwargsr   ZnewListslengthsmaxLenilstnlZtoJoinr   r   r   adjoin   s    r5   rightzIterable[str])textsmax_lenr"   r   c                   sJ   |dkr fdd| D S |dkr4 fdd| D S  fdd| D S dS )zB
    Perform ljust, center, rjust against string or list-like
    r!   c                   s   g | ]}|  qS r   )ljustr   r8   r   r   r   A   r   zjustify.<locals>.<listcomp>centerc                   s   g | ]}|  qS r   )r;   r   r:   r   r   r   C   r   c                   s   g | ]}|  qS r   rjustr   r:   r   r   r   E   r   Nr   )r7   r8   r"   r   r:   r   r+   <   s
    r+   r   z
int | None)seq	_nest_lvlmax_seq_itemsr   c                   s   t | trd}nt| drdnd}du r4t| }npFtdpFt| }t|  fddtt|t| D }d	|}|t| k r|d
7 }nt | t	rt| dkr|d7 }|j
|dS )z
    internal. pprinter for iterables. you should probably use pprint_thing()
    rather than calling this directly.

    bounds length of printed sequence, depending on options
    z
{{{body}}}__setitem__z[{body}]z({body})Fr@   c                   s*   g | ]"}t t d  fdiqS )   r@   )pprint_thingnext)r   r2   r?   kwdsr@   sr   r   r   u   s   z_pprint_seq.<locals>.<listcomp>, , ...rB   ,)body)
isinstancesethasattrr*   r
   iterrangeminr&   tupleformat)r>   r?   r@   rF   fmtnitemsrrK   r   rE   r   _pprint_seq`   s     	



rW   r   c           
   	   K  s   d}g }d}|du rt | }n|p0tdp0t | }t|  d| D ]H\}}	||jt||d fd|i|t|	|d fd|i|d qF|t | k r|jd|d	 d
S |jd|d
S dS )zy
    internal. pprinter for iterables. you should probably use pprint_thing()
    rather than calling this directly.
    z{{{things}}}z{key}: {val}Fr@   NrB   )keyvalrH   rI   )Zthings)r*   r
   listitemsr,   rS   rC   r&   )
r>   r?   r@   rF   rT   pairsZpfmtrU   kvr   r   r   _pprint_dict   s     
r_   Fr   EscapeChars | Nonebool)thingr?   escape_charsdefault_escapesquote_stringsr@   r   c                   s   |fdddd fdd}t | dr,t| S t| trT|tdk rTt| |d	|d
}nPt| r||tdk r|t| ||||d}n(t| tr|rd||  d}n|| }|S )a  
    This function is the sanctioned way of converting objects
    to a string representation and properly handles nested sequences.

    Parameters
    ----------
    thing : anything to be formatted
    _nest_lvl : internal use only. pprint_thing() is mutually-recursive
        with pprint_sequence, this argument is used to keep track of the
        current nesting level, and limit it.
    escape_chars : list or dict, optional
        Characters to escape. If a dict is passed the values are the
        replacements
    default_escapes : bool, default False
        Whether the input escape characters replaces or adds to the defaults
    max_seq_items : int or None, default None
        Pass through to other pretty printers to limit sequence printing

    Returns
    -------
    str
    r   r`   r   )rb   rc   r   c                   sf   dddd}t |tr8 r&|| n|}t| }n|p>d}t| }|D ]}|||| }qL|S )Nz\tz\nz\r)	r$   r   )rL   dictupdaterZ   keysr   replace)rb   rc   	translateresultcrd   r   r   as_escaped_string   s    
z'pprint_thing.<locals>.as_escaped_string__next__zdisplay.pprint_nest_depthT)re   r@   rc   re   r@   ')rN   r   rL   rh   r
   r_   r   rW   )rb   r?   rc   rd   re   r@   rp   rm   r   ro   r   rC      s,     
rC   utf-8rk   bytes)encodingerrorsr   c                 C  s   t | }|||S N)rC   encode)objectrv   rw   valuer   r   r   pprint_thing_encoded   s    r|   None)enabler   c                   s   dt jvrd S ddlm} | }|d u r,d S |jj}d}| r||vrzddlm} ddlm	  G  fddd|}| ||< d	|| _
n||v rd
|| _
d S )NIPythonr   )get_ipythonz!application/vnd.dataresource+json)BaseFormatter
ObjectNamec                      s   e Zd Z dZefZdS )z<enable_data_resource_formatter.<locals>.TableSchemaFormatterZ_repr_data_resource_N)__name__
__module____qualname__Zprint_methodrh   Z_return_typer   r   r   r   TableSchemaFormatter  s   r   TF)sysmodulesr   r   Zdisplay_formatter
formattersZIPython.core.formattersr   Z	traitletsr   Zenabled)r~   r   ipr   mimetyper   r   r   r   r   enable_data_resource_formatter   s"    

r   )rb   r@   r   c                 C  s   t | dd|dS )N)rf   rg   r$   Trr   rC   )rb   r@   r   r   r   default_pprint  s    r   Tr   z
str | None)	formatter
is_justifynameindent_for_nameline_break_each_valuer   c           !        s  ddl m} ddlm} | \}}	|du r6tdp4d}|du rHt| j}|rzt|}
dd|
d	   }dd|
d
   }nd}d}t| }|rddt|  }nd}tdp|}||k}|  ddddddd fdd}ddd fdd}d}|dkr
d| }n |d	kr:|s:| d }d| d| }n|d
kr||s|| d }| d }d| d| d| }n|d	krg }fdd| dd D }nf||krt|d
 d }fd!d| d| D }fd"d| | d D }ng }fd#d| D }|r|r(t	||\}}nd|sVtd
||k rVtd
||k st||||fd$d|D }fd%d|D }|r|t| }|d }d	ttd	t|d	 D ]*}t||d&}t||k r| qqfd'd|D }fd(d|D }d)}|}|D ]&}|| d }||||||\}}q|rb|| | d* 7 }|}|dd D ]&} | | d }||||||\}}qn||||d |d
 |\}}||7 }d|d }||7 }t||ks|r||7 }n|d7 }d|t|d  }|S )+a  
    Return the formatted obj as a unicode string

    Parameters
    ----------
    obj : object
        must be iterable and support __getitem__
    formatter : callable
        string formatter for an element
    is_justify : bool
        should justify the display
    name : name, optional
        defaults to the class name of the obj
    indent_for_name : bool, default True
        Whether subsequent lines should be indented to
        align with the name.
    line_break_each_value : bool, default False
        If True, inserts a line break for each value of ``obj``.
        If False, only break lines when the a line of values gets wider
        than the display width.

    Returns
    -------
    summary string
    r   )get_console_size)get_adjustmentNzdisplay.widthP   r$   r#   rB      z
 z,
 rJ   zdisplay.max_seq_itemsr   r   ztuple[str, str])rG   liner{   display_widthnext_line_prefixr   c                   s@     |   |  |kr0| | 7 } |}||7 }| |fS rx   )r*   rstrip)rG   r   r{   r   r   adjr   r   _extend_line]  s
     z+format_object_summary.<locals>._extend_liner   )valuesr   c                   s"   | rt  fdd| D S dS d S )Nc                 3  s   | ]}  |V  qd S rx   r*   r   r   r   r   r(   h  r   z:format_object_summary.<locals>.best_len.<locals>.<genexpr>r   r   )r   r   r   r   best_lenf  s    z'format_object_summary.<locals>.best_lenrH   z[][]r    c                   s   g | ]} |qS r   r   r   r   r   r   r   {  r   z)format_object_summary.<locals>.<listcomp>
   c                   s   g | ]} |qS r   r   r   r   r   r   r   ~  r   c                   s   g | ]} |qS r   r   r   r   r   r   r     r   c                   s   g | ]} |qS r   r   r   r   r   r   r     r   c                   s   g | ]}|  qS r   r<   r   
max_lengthr   r   r     r   c                   s   g | ]}|  qS r   r<   r   r   r   r   r     r   r@   c                   s   g | ]}t | d qS r   rW   r   	max_itemsr   r   r     r   c                   s   g | ]}t | d qS r   r   r   r   r   r   r     r   r%   z...)Zpandas.io.formats.consoler   Zpandas.io.formats.formatr   r
   typer   r*   rQ   _justifyr&   r   reversedrP   rW   r   )!objr   r   r   r   r   r   r   r   _Zname_lenZspace1Zspace2nsepr@   Zis_truncatedr   r   closesummaryfirstlastheadtailZ	max_spacer{   Z	num_itemsZpprinted_seqr   Z
head_valuewordZ	tail_itemr   )r   r   r   r   r   format_object_summary  s    !

	




r   zlist[Sequence[str]]z3tuple[list[tuple[str, ...]], list[tuple[str, ...]]])r   r   r   c                   sr   | | }dgt |d   |D ]&}dd |D }dd t |D  q fdd| D } fdd|D }||fS )a  
    Justify items in head and tail, so they are right-aligned when stacked.

    Parameters
    ----------
    head : list-like of list-likes of strings
    tail : list-like of list-likes of strings

    Returns
    -------
    tuple of list of tuples of strings
        Same as head and tail, but items are right aligned when stacked
        vertically.

    Examples
    --------
    >>> _justify([['a', 'b']], [['abc', 'abcd']])
    ([('  a', '   b')], [('abc', 'abcd')])
    r   c                 S  s   g | ]}t |qS r   r   )r   itemr   r   r   r     r   z_justify.<locals>.<listcomp>c                 S  s   g | ]\}}t ||qS r   r   )r   r   yr   r   r   r     r   c                   s$   g | ]}t d d t| D qS )c                 s  s   | ]\}}| |V  qd S rx   r<   r   r   r8   r   r   r   r(     r   &_justify.<locals>.<listcomp>.<genexpr>rR   r.   r   r>   r   r   r   r     s   c                   s$   g | ]}t d d t| D qS )c                 s  s   | ]\}}| |V  qd S rx   r<   r   r   r   r   r(     r   r   r   r   r   r   r   r     s   )r*   r.   )r   r   ZcombinedZ	inner_seqlengthZhead_tuplesZtail_tuplesr   r   r   r     s    

r   c                   @  s   e Zd ZdZddddZdS )
PrettyDictz.Dict extension to support abbreviated __repr__r   )r   c                 C  s   t | S rx   r   )selfr   r   r   __repr__  s    zPrettyDict.__repr__N)r   r   r   __doc__r   r   r   r   r   r     s   r   )r6   )r   N)r   N)r   NFFN)rt   rk   )N)TNTF)!r   
__future__r   collections.abcr   r   r   r   typingr   r   r   r	   Zpandas._configr
   Zpandas.core.dtypes.inferencer   r   ZEscapeCharsr   r   r5   r+   rW   r_   rC   r|   r   r   r   r   rh   r   r   r   r   r   <module>   sB    % $ !     J !     /)