o
    5cP>                     @  s&  d Z ddlmZ ddlZddlmZmZmZmZ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dKddZdLdMddZ	dNdOddZ	dNdPd d!Z			"	"	dQdRd*d+Z	-dSdTd1d2ZdUd5d6ZdVdWd7d8Z	9		9	"dXdYdAdBZdZdGdHZG dIdJ dJeeef ZdS )[z
Printing tools.
    )annotationsN)AnyCallableDictIterableMappingSequenceTypeVarUnion)
get_option)is_sequence_KT_VTspaceintlists	list[str]returnstrc                   s   | dt| dt}g }g } fdd|dd D }|ttt|d  ttt|}t|D ]"\}}	||	|| dd}
|
d	||  g|t|	   ||
 q5t| }|D ]
}|d
	| q^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   P/var/www/html/gps/gps/lib/python3.10/site-packages/pandas/io/formats/printing.py
<listcomp>0   s    zadjoin.<locals>.<listcomp>Nleft)mode  
)
poplenjustifyappendr   r   	enumerateextendzipjoin)r   r   kwargsr   	out_linesnewListslengthsmaxLenilstnltoJoinlinesr   r   r   adjoin   s    
r8   righttextsIterable[str]max_lenr"   c                   sF   |dkr fdd| D S |dkr fdd| D S  fdd| D S )zB
    Perform ljust, center, rjust against string or list-like
    r!   c                      g | ]}|  qS r   )ljustr   r<   r   r   r   C       zjustify.<locals>.<listcomp>centerc                   r=   r   )rA   r   r?   r   r   r   E   r@   c                   r=   r   rjustr   r?   r   r   r   G   r@   r   )r:   r<   r"   r   r?   r   r(   >   s
   r(   seqr   	_nest_lvlmax_seq_items
int | Nonec                   s   t | trd}n	t| drdnd}du rt| }n
p#tdp#t| }t|  fddtt|t| D }d	|}|t| k rK|d
7 }nt | t	rZt| dkrZ|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})FrF   c                   s*   g | ]}t t d  fdiqS )   rF   )pprint_thingnext)r   r3   rE   kwdsrF   sr   r   r   w   s    z_pprint_seq.<locals>.<listcomp>, , ...rI   ,)body)
isinstancesethasattrr'   r   iterrangeminr-   tupleformat)rD   rE   rF   rM   fmtnitemsrrR   r   rL   r   _pprint_seqb   s    
	


r^   r   c           
   	   K  s   d}g }d}|du rt | }n
|ptdpt | }t|  d| D ]$\}}	||jt||d fd|i|t|	|d fd|i|d q#|t | k rY|jd|d	 d
S |jd|d
S )zy
    internal. pprinter for iterables. you should probably use pprint_thing()
    rather than calling this directly.
    z{{{things}}}z{key}: {val}FrF   NrI   )keyvalrO   rP   )things)r'   r   listitemsr)   rZ   rJ   r-   )
rD   rE   rF   rM   r[   pairspfmtr\   kvr   r   r   _pprint_dict   s    
rh   Fthingr   escape_charsEscapeChars | Nonedefault_escapesboolquote_stringsc                   s   |fd fdd}t | d	rt| S t| tr'|td
k r't| |d|d}|S t| r<|td
k r<t| ||||d}|S t| trM|rMd||  d}|S || }|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
    ri   r   rj   rk   r   r   c                   sf   dddd}t |tr r|| n|}t| }n|pd}t| }|D ]
}|||| }q&|S )Nz\tz\nz\r)	r%   r   )rS   dictupdaterb   keysr   replace)ri   rj   	translateresultcrl   r   r   as_escaped_string   s   
z'pprint_thing.<locals>.as_escaped_string__next__zdisplay.pprint_nest_depthT)rn   rF   rj   rn   rF   'N)ri   r   rj   rk   r   r   )rU   r   rS   rq   r   rh   r   r^   )ri   rE   rj   rl   rn   rF   ry   rv   r   rx   r   rJ      s2    
rJ   utf-8rt   encodingerrorsbytesc                 C  s   t | }|||S N)rJ   encode)objectr~   r   valuer   r   r   pprint_thing_encoded   s   r   enableNonec                 C  s   dt jvrd S ddlm} | }|d u rd S |jj}d}| r<||vr5ddlm} G dd d|}| ||< d|| _d S ||v rGd	|| _d S d S )
NIPythonr   )get_ipythonz!application/vnd.dataresource+json)BaseFormatterc                   @  s   e Zd ZdZefZdS )z<enable_data_resource_formatter.<locals>.TableSchemaFormatter_repr_data_resource_N)__name__
__module____qualname__print_methodrq   _return_typer   r   r   r   TableSchemaFormatter  s    
r   TF)	sysmodulesr   r   display_formatter
formattersIPython.core.formattersr   enabled)r   r   ipr   mimetyper   r   r   r   r   enable_data_resource_formatter   s"   

r   c                 C  s   t | dd|dS )N)ro   rp   r%   Tr{   rJ   )ri   rF   r   r   r   default_pprint  s   r   T	formatterr   
is_justifyname
str | Noneindent_for_nameline_break_each_valuec                   s  ddl m} ddlm} | \}}	|du rtdpd}|du r$t| j}|r=t|}
dd|
d	   }dd|
d
   }nd}d}t| }|rPddt|  }nd}tdpW|}||k}|  d0 fdd}d1 fdd}d}|dkrzd| }|S |d	kr|s| d }d | d!| }|S |d
kr|s| d }| d" }d | d| d!| }|S |d	krg }fd#d$| d"d D }n2||krt|d
 d%}fd&d$| d| D }fd'd$| | d D }ng }fd(d$| D }|r5|rt	||\}}n2|std
||k rtd
||k s5t||||fd)d$|D }fd*d$|D }|rr|t| }|d }ttd	t|d	 D ]t|d+}t||k r^ nqMfd,d$|D }fd-d$|D }d.}|}tt|D ]| | d }||||||\}}q||r|| | d/ 7 }|}tt|d	 D ]| | d }||||||\}}q||||d" |d
 |\}}||7 }d!|d }||7 }t||ks|r||7 }n|d7 }d |t|d  }|S )2a  
    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.

        .. versionadded:: 0.25.0

    Returns
    -------
    summary string
    r   )get_console_size)get_adjustmentNzdisplay.widthP   r%   r#   rI      z
 z,
 rQ   zdisplay.max_seq_itemsrN   r   liner   display_widthr   next_line_prefixr   tuple[str, str]c                   s@     |   |  |kr| | 7 } |}||7 }| |fS r   )r'   rstrip)rN   r   r   r   r   adjr   r   _extend_linea  s
    z+format_object_summary.<locals>._extend_linevaluesr   c                   s   | rt  fdd| D S dS )Nc                 3  s    | ]}  |V  qd S r   r'   r   r   r   r   	<genexpr>m  s    z:format_object_summary.<locals>.best_len.<locals>.<genexpr>r   r   )r   r   r   r   best_lenk  s   z'format_object_summary.<locals>.best_lenrO   z[][]r    c                      g | ]} |qS r   r   r   r   r   r   r         z)format_object_summary.<locals>.<listcomp>
   c                   r   r   r   r   r   r   r   r     r   c                   r   r   r   r   r   r   r   r     r   c                   r   r   r   r   r   r   r   r     r   c                   r=   r   rB   r   
max_lengthr   r   r     r@   c                   r=   r   rB   r   r   r   r   r     r@   rF   c                      g | ]}t | d qS r   r^   r   	max_itemsr   r   r         c                   r   r   r   r   r   r   r   r     r   r$   z...)rN   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   )pandas.io.formats.consoler   pandas.io.formats.formatr   r   typer   r'   rX   _justifyr-   r   reversedrW   r^   r   )objr   r   r   r   r   r   r   r   _name_lenspace1space2nseprF   is_truncatedr   r   closesummaryfirstlastheadtail	max_spacer   pprinted_seqr   wordr   )r   r   r   r   r   format_object_summary  s   #



WTP
r   r   list[Sequence[str]]r   3tuple[list[tuple[str, ...]], list[tuple[str, ...]]]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     s    c                   $   g | ]}t d d t| D qS )c                 s      | ]
\}}| |V  qd S r   rB   r   r   r<   r   r   r   r         &_justify.<locals>.<listcomp>.<genexpr>rY   r,   r   rD   r   r   r   r         c                   r   )c                 s  r   r   rB   r   r   r   r   r     r   r   r   r   r   r   r   r     r   )r'   r,   )r   r   combined	inner_seqlengthr   r   r   r     s   

r   c                   @  s   e Zd ZdZ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   r   r   __doc__r   r   r   r   r   r     s    r   )r   r   r   r   r   r   )r9   )r:   r;   r<   r   r"   r   r   r   )r   N)rD   r   rE   r   rF   rG   r   r   )rD   r   rE   r   rF   rG   r   r   )r   NFFN)ri   r   rE   r   rj   rk   rl   rm   rn   rm   rF   rG   r   r   )r}   rt   )r~   r   r   r   r   r   )r   rm   r   r   r   )ri   r   rF   rG   r   r   )TNTF)r   r   r   rm   r   r   r   rm   r   rm   r   r   )r   r   r   r   r   r   ) r   
__future__r   r   typingr   r   r   r   r   r   r	   r
   pandas._configr   pandas.core.dtypes.inferencer   r   EscapeCharsr   r   r8   r(   r^   rh   rJ   r   r   r   r   r   r   r   r   r   r   <module>   sB    (
#%$!J
! 
1-