a
    OfF                  	   @  s  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 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dGdddddddZdHdddddddZdIdddddddZdJd dd!d"d"ddd#d$d%ZdKddd(d)d*d+Zd"d,d-d.d/ZdLd ddd0d1d2Z dMd4d"d5d"d"dd6d7d8Z!d9d9d:d;d<d=Z"G d>d? d?e#eef Z$G d@dA dAZ%G dBdC dCe%Z&dAdDdEdFZ'dS )Nz
Printing tools.
    )annotations)IterableMappingSequenceN)AnyCallableTypeVarUnion)east_asian_width)
get_option)is_sequence)get_console_size_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   S/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pandas/io/formats/printing.py
<listcomp>3       zadjoin.<locals>.<listcomp>Nleft)mode 
c                 s  s   | ]}d  |V  qdS ) N)join)r   linesr   r   r   	<genexpr><   r!   zadjoin.<locals>.<genexpr>)	poplen_adj_justifyappendr   r   	enumeratezipr(   )r   r   kwargsr   ZnewListslengthsZmaxLenilstnlZtoJoinr   r   r   adjoin   s    r6   right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   r;   r   r   r    D   r!   z _adj_justify.<locals>.<listcomp>centerc                   s   g | ]}|  qS r   r?   r   r>   r   r   r    F   r!   c                   s   g | ]}|  qS r   rjustr   r>   r   r   r    H   r!   Nr   )r:   r;   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})FrE   c                   s*   g | ]"}t t d  fdiqS )   rE   )pprint_thingnext)r   r3   rD   kwdsrE   sr   r   r    x   s   z_pprint_seq.<locals>.<listcomp>, , ...rG   ,)body)
isinstancesethasattrr,   r   iterrangeminr(   tupleformat)rC   rD   rE   rK   fmtnitemsrrP   r   rJ   r   _pprint_seqc   s     	



r\   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}FrE   NrG   )keyvalrM   rN   )things)r,   r   listitemsr.   rX   rH   r(   )
rC   rD   rE   rK   rY   pairsZpfmtrZ   kvr   r   r   _pprint_dict   s     
re   Fr   EscapeChars | Nonebool)thingrD   escape_charsdefault_escapesquote_stringsrE   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   rf   r   )rh   ri   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   )rQ   dictupdater`   keysr   replace)rh   ri   	translateresultcrj   r   r   as_escaped_string   s    
z'pprint_thing.<locals>.as_escaped_string__next__zdisplay.pprint_nest_depthT)rk   rE   ri   rk   rE   ')rS   r   rQ   rn   r   re   r   r\   )rh   rD   ri   rj   rk   rE   rv   rs   r   ru   r   rH      s,     
rH   utf-8rq   bytes)encodingerrorsr   c                 C  s   t | }|||S N)rH   encode)objectr|   r}   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_methodrn   _return_typer   r   r   r   TableSchemaFormatter	  s   r   TF)sysmodulesr   r   display_formatter
formattersIPython.core.formattersr   Z	traitletsr   enabled)r   r   ipr   mimetyper   r   r   r   r   enable_data_resource_formatter   s"    

r   )rh   rE   r   c                 C  s   t | dd|dS )N)rl   rm   r&   Trx   rH   )rh   rE   r   r   r   default_pprint  s    r   Tr   z
str | None)	formatter
is_justifynameindent_for_nameline_break_each_valuer   c                   s  t  \}}|du rtdpd}|du r0t| j}|rbt|}dd|d   }	dd|d   }
nd}	d}
t| }|rd	dt|  }nd
}tdp|}||k}t  ddddddd fdd}ddd fdd}d}|dkrd| }n |dkr |s | d }d| d| }n|dkrb|sb| 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 }|rr|rt||\}}nd|s<td||k r<td||k srt	||||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|rH|| |
 d( 7 }|
}|dd D ]&}|| d }||||||
\}}qT||||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
    Nzdisplay.widthP   r&   r%   rG      z
 z,
 rO   zdisplay.max_seq_itemsr   r   ztuple[str, str])rL   liner   display_widthnext_line_prefixr   c                   s@     |   |  |kr0| | 7 } |}||7 }| |fS r~   )r,   rstrip)rL   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 r~   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_lenrM   r   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   rA   r   
max_lengthr   r   r      r!   c                   s   g | ]}|  qS r   rA   r   r   r   r   r      r!   rE   c                   s   g | ]}t | d qS r   r\   r   	max_itemsr   r   r      r!   c                   s   g | ]}t | d qS r   r   r   r   r   r   r      r!   r'   z...)r   r   typer   r,   get_adjustmentrV   _justifyr(   r   reversedrU   r\   r   )objr   r   r   r   r   r   _Zname_lenZspace1Zspace2nseprE   Zis_truncatedr   r   closesummaryfirstlastheadtailZ	max_spacer   	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 r~   rA   r   r   r;   r   r   r   r*     r!   &_justify.<locals>.<listcomp>.<genexpr>rW   r0   r   rC   r   r   r   r      s   c                   s$   g | ]}t d d t| D qS )c                 s  s   | ]\}}| |V  qd S r~   rA   r   r   r   r   r*     r!   r   r   r   r   r   r   r      s   )r,   r0   )r   r   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 r~   r   selfr   r   r   __repr__  s    zPrettyDict.__repr__N)r   r   r   __doc__r   r   r   r   r   r     s   r   c                   @  sP   e Zd ZddddZddddd	ZddddddddZdddddZdS )_TextAdjustmentr   r   c                 C  s   t d| _d S )Nzdisplay.encoding)r   r|   r   r   r   r   __init__  s    z_TextAdjustment.__init__r   r   textr   c                 C  s   t |S r~   r   r   r   r   r   r   r,     s    z_TextAdjustment.lenr7   r   r   r9   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 )zJ
        Perform ljust, center, rjust against string or list-like
        r#   c                   s   g | ]}|  qS r   r<   r   r>   r   r   r      r!   z+_TextAdjustment.justify.<locals>.<listcomp>r?   c                   s   g | ]}|  qS r   r@   r   r>   r   r   r      r!   c                   s   g | ]}|  qS r   rA   r   r>   r   r   r    
  r!   Nr   r   r:   r;   r$   r   r>   r   justify  s
    z_TextAdjustment.justify)r   r   c                 O  s    t |g|R | j| jd|S )N)r   r   )r6   r,   r   )r   r   r   r1   r   r   r   r6     s    z_TextAdjustment.adjoinN)r7   )r   r   r   r   r,   r   r6   r   r   r   r   r     s   r   c                      sH   e Zd Zdd fddZddddd	ZddddddddZ  ZS )_EastAsianTextAdjustmentr   r   c                   s6   t    tdrd| _nd| _dddddd| _d S )Nz!display.unicode.ambiguous_as_wider   rG   )ZNaNWFH)superr   r   ambiguous_width_EAW_MAPr   	__class__r   r   r     s
    
z!_EastAsianTextAdjustment.__init__r   r   r   c                   s(   t |tst|S t fdd|D S )zN
        Calculate display width considering unicode East Asian Width
        c                 3  s"   | ]} j t| jV  qd S r~   )r   getr
   r   )r   rt   r   r   r   r*   $  s   z/_EastAsianTextAdjustment.len.<locals>.<genexpr>)rQ   r   r,   sumr   r   r   r   r,     s
    
z_EastAsianTextAdjustment.lenr7   r8   r   r9   c                   sX   fdd |dkr( fdd|D S |dkrB fdd|D S  fdd|D S d S )	Nc                   s     |  t |  S r~   r   )t)r;   r   r   r   _get_pad,  s    z2_EastAsianTextAdjustment.justify.<locals>._get_padr#   c                   s   g | ]}|  |qS r   r<   r   r   r   r   r    0  r!   z4_EastAsianTextAdjustment.justify.<locals>.<listcomp>r?   c                   s   g | ]}|  |qS r   r@   r   r   r   r   r    2  r!   c                   s   g | ]}|  |qS r   rA   r   r   r   r   r    4  r!   r   r   r   )r   r;   r   r   r   (  s    z _EastAsianTextAdjustment.justify)r7   )r   r   r   r   r,   r   __classcell__r   r   r   r   r     s    r   r   c                  C  s   t d} | rt S t S d S )Nz display.unicode.east_asian_width)r   r   r   )Zuse_east_asian_widthr   r   r   r   7  s    r   )r7   )r   N)r   N)r   NFFN)rz   rq   )N)TNTF)(r   
__future__r   collections.abcr   r   r   r   typingr   r   r   r	   unicodedatar
   Zpandas._configr   Zpandas.core.dtypes.inferencer   Zpandas.io.formats.consoler   r   ZEscapeCharsr   r   r6   r-   r\   re   rH   r   r   r   r   r   rn   r   r   r   r   r   r   r   r   <module>   sL    % $ !     J !     ,)'