o
    hF                     @  sj  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dTddZdUdVddZ	dWdXd d!Z	dWdYd#d$Z			%	%	dZd[d-d.Z	0d\d]d4d5Zd^d8d9Zd_d`d:d;Z 	<		<	%dadbdDdEZ!dcdJdKZ"G dLdM dMe#eef Z$G dNdO dOZ%G dPdQ dQe%Z&dddRdSZ'dS )ez
Printing tools.
    )annotations)IterableMappingSequenceN)AnyCallableTypeVarUnion)east_asian_width)
get_option)is_sequence)get_console_size_KT_VTspaceintlists	list[str]returnstrc                   s   | dt| dt}g } fdd|dd D }|ttt|d  ttt|}t|D ]!\}}|||| dd}	d	||  g|t|  |	 }	||	 q3t| }
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   n/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/pandas/io/formats/printing.py
<listcomp>3   s    zadjoin.<locals>.<listcomp>Nleft)mode 
c                 s  s    | ]}d  |V  qdS ) N)join)r   linesr   r   r   	<genexpr><       zadjoin.<locals>.<genexpr>)	poplen_adj_justifyappendr   r   	enumeratezipr'   )r   r   kwargsr   newListslengthsmaxLenilstnltoJoinr   r   r   adjoin   s   r9   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    D       z _adj_justify.<locals>.<listcomp>centerc                   r>   r   rC   r   rA   r   r   r    F   rB   c                   r>   r   rjustr   rA   r   r   r    H   rB   r   )r;   r=   r#   r   rA   r   r-   ?   
   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})FrJ   c                   s*   g | ]}t t d  fdiqS )   rJ   )pprint_thingnext)r   r5   rI   kwdsrJ   sr   r   r    x   s    z_pprint_seq.<locals>.<listcomp>, , ...rM   ,)body)
isinstancesethasattrr,   r   iterrangeminr'   tupleformat)rH   rI   rJ   rQ   fmtnitemsrrV   r   rP   r   _pprint_seqc   s    
	


rb   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}FrJ   NrM   )keyvalrS   rT   )things)r,   r   listitemsr.   r^   rN   r'   )
rH   rI   rJ   rQ   r_   pairspfmtr`   kvr   r   r   _pprint_dict   s    
rl   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
    rm   r   rn   ro   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   )rW   dictupdaterf   keysr   replace)rm   rn   	translateresultcrp   r   r   as_escaped_string   s   
z'pprint_thing.<locals>.as_escaped_string__next__zdisplay.pprint_nest_depthT)rr   rJ   rn   rr   rJ   'N)rm   r   rn   ro   r   r   )rY   r   rW   ru   r   rl   r   rb   )rm   rI   rn   rp   rr   rJ   r}   rz   r   r|   r   rN      s2    
rN   utf-8rx   encodingerrorsbytesc                 C  s   t | }|||S N)rN   encode)objectr   r   valuer   r   r   pprint_thing_encoded   s   r   enableNonec                   s   dt jvrd S ddlm} | }|d u rd S |jj}d}| rD||vr=ddlm} ddlm	  G  fddd|}| ||< d	|| _
d S ||v rOd
|| _
d S 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>.TableSchemaFormatter_repr_data_resource_N)__name__
__module____qualname__print_methodru   _return_typer   r   r   r   TableSchemaFormatter	  s    
r   TF)sysmodulesr   r   display_formatter
formattersIPython.core.formattersr   	traitletsr   enabled)r   r   ipr   mimetyper   r   r   r   r   enable_data_resource_formatter   s$   

r   c                 C  s   t | dd|dS )N)rs   rt   r%   Tr   rN   )rm   rJ   r   r   r   default_pprint  s   r   T	formatterr   
is_justifyname
str | Noneindent_for_nameline_break_each_valuec                   s  t  \}}|du rtdpd}|du rt| j}|r1t|}dd|d   }	dd|d   }
nd}	d}
t| }|rDd	dt|  }nd
}tdpK|}||k}t  d. fdd}d/ fdd}d}|dkrnd| }|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 }|r(|rt||\}}n2|std||k rtd||k s(t	||||fd'd"|D }fd(d"|D }|ri|t|
 }|d }dt
tdt|d D ]}t||d)}t||k rU| nqBfd*d"|D }fd+d"|D }d,}|
}|D ]}|| d }||||||
\}}qo|r|| |
 d- 7 }|
}|dd  D ]}|| d }||||||
\}}q||||d  |d |
\}}||7 }d|d }||7 }t||ks|r||	7 }n|d7 }d|t|
d  }|S )0a  
    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$   rM      z
 z,
 rU   zdisplay.max_seq_itemsrR   r   liner   display_widthr   next_line_prefixr   tuple[str, str]c                   s@     |   |  |kr| | 7 } |}||7 }| |fS r   )r,   rstrip)rR   r   r   r   r   adjr   r   _extend_line]  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   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_lenrS   r   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   rE   r   
max_lengthr   r   r      rB   c                   r>   r   rE   r   r   r   r   r      rB   rJ   c                      g | ]}t | d qS r   rb   r   	max_itemsr   r   r          c                   r   r   r   r   r   r   r   r      r   r&   z...)rR   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   )r   r   typer   r,   get_adjustmentr\   _justifyr'   r   reversedr[   rb   r   )objr   r   r   r   r   r   _name_lenspace1space2nseprJ   is_truncatedr   r   closesummaryfirstlastheadtail	max_spacer   	num_itemspprinted_seqr   
head_valueword	tail_itemr   )r   r   r   r   r   format_object_summary  s   
!
	
XUQ
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          c                   $   g | ]}t d d t| D qS )c                 s      | ]
\}}| |V  qd S r   rE   r   r   r=   r   r   r   r)         &_justify.<locals>.<listcomp>.<genexpr>r]   r0   r   rH   r   r   r   r          c                   r   )c                 s  r   r   rE   r   r   r   r   r)     r   r   r   r   r   r   r   r      r   )r,   r0   )r   r   combined	inner_seqlengthhead_tuplestail_tuplesr   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__     zPrettyDict.__repr__N)r   r   )r   r   r   __doc__r   r   r   r   r   r     s    r   c                   @  s6   e Zd ZdddZddd	ZddddZ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__textr   r   c                 C  s   t |S r   r   r   r   r   r   r   r,     r   z_TextAdjustment.lenr:   r;   r   r=   r#   r   c                   sF   |dkr fdd|D S |dkr fdd|D S  fdd|D S )zJ
        Perform ljust, center, rjust against string or list-like
        r"   c                   r>   r   r?   r   rA   r   r   r      rB   z+_TextAdjustment.justify.<locals>.<listcomp>rC   c                   r>   r   rD   r   rA   r   r   r      rB   c                   r>   r   rE   r   rA   r   r   r    
  rB   r   r   r;   r=   r#   r   rA   r   justify  rG   z_TextAdjustment.justifyr   c                 O  s    t |g|R | j| jd|S )N)r   r   )r9   r,   r   )r   r   r   r1   r   r   r   r9     s    z_TextAdjustment.adjoinN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   r9   r   r   r   r   r     s
    

r   c                      s6   e Zd Zd fddZddd	Z	
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   rM   )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   r{   r   r   r   r)   $  s    
z/_EastAsianTextAdjustment.len.<locals>.<genexpr>)rW   r   r,   sumr   r   r   r   r,     s
   
z_EastAsianTextAdjustment.lenr:   r;   r<   r=   r#   r   c                   sT   fdd |dkr fdd|D S |dkr! fdd|D S  fdd|D S )	Nc                   s     |  t |  S r   r   )t)r=   r   r   r   _get_pad,  s   z2_EastAsianTextAdjustment.justify.<locals>._get_padr"   c                      g | ]	}|  |qS r   r?   r   r  r   r   r    0  r   z4_EastAsianTextAdjustment.justify.<locals>.<listcomp>rC   c                   r  r   rD   r   r  r   r   r    2  r   c                   r  r   rE   r   r  r   r   r    4  r   r   r   r   )r  r=   r   r   r   (  s   z _EastAsianTextAdjustment.justifyr   r   r   r;   r<   r=   r   r#   r   r   r   )r   r   r   r   r,   r   __classcell__r   r   r
  r   r    s
    
r  c                  C  s   t d} | r	t S t S )Nz display.unicode.east_asian_width)r   r  r   )use_east_asian_widthr   r   r   r   7  s   r   )r   r   r   r   r   r   r   r  )r   N)rH   r   rI   r   rJ   rK   r   r   )rH   r   rI   r   rJ   rK   r   r   )r   NFFN)rm   r   rI   r   rn   ro   rp   rq   rr   rq   rJ   rK   r   r   )r   rx   )r   r   r   r   r   r   )r   rq   r   r   r   )rm   r   rJ   rK   r   r   )TNTF)r   r   r   rq   r   r   r   rq   r   rq   r   r   )r   r   r   r   r   r   )r   r   )(r   
__future__r   collections.abcr   r   r   r   typingr   r   r   r	   unicodedatar
   pandas._configr   pandas.core.dtypes.inferencer   pandas.io.formats.consoler   r   EscapeCharsr   r   r9   r-   rb   rl   rN   r   r   r   r   r   ru   r   r   r  r   r   r   r   r   <module>   sN    
 %$!J
! 
,)'