o
    
iu                     @   s  d dl Z d dlmZ d dlmZmZmZ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 dd	lmZ d
dddZ												d(de
eef dee dee dede
ee ed f dededee
eed  ed f  dededee dee d ee d!efd"d#Z						d)dede
e	e eed f dedee
e	ed  ef  dedee	 d ee	 d!efd$d%Zd&d' ZdS )*    N)zip_longest)
CollectionDictIterableListOptionalSequenceUnion)cast   )Literal)COLORS)color)supports_ansi<>^)lrcFauto      WASABIdataheaderfooterdividerwidthsmax_colspacingaligns)r   r   r   	multiline
env_prefixcolor_values	fg_colors	bg_colorsreturnc                    s  |dus|dur/t t |
dur |
 |dur" fdd|D }|dur/ fdd|D }t| t r:t|  } |rpg }t| D ]+\}}dd |D }|tt|ddi |t	| d k rm|
td	d |D  qB|} |d
kr{t| |||}||||	||d}tdd |D fi |}g }|r|
t|fi | |r|
| t| D ]\}}|
t|fi | q|r|r|
| |
t|fi | dd|S )a  Format tabular data.

    data (Union[Collection, Dict]): The data to render. Either a list of lists (one per
        row) or a dict for two-column tables.
    header (Optional[Iterable]): Optional header columns.
    footer (Optional[Iterable]): Optional footer columns.
    divider (bool): Show a divider line between header/footer and body.
    widths (Union[Iterable[int], Literal['auto']]): Column widths in order. If "auto", widths
        will be calculated automatically based on the largest value.
    max_col (int): Maximum column width.
    spacing (int): Spacing between columns, in spaces.
    aligns (Optional[Union[Iterable[str], str]]): Optional column alignments
        in order. 'l' (left, default), 'r' (right) or 'c' (center). If a string,
        value is used for all columns.
    multiline (bool): If a cell value is a list of a tuple, render it on
        multiple lines, with one value per line.
    env_prefix (str): Prefix for environment variables, e.g.
        WASABI_LOG_FRIENDLY.
    color_values (Optional[Dict]): Optional color values to add or overwrite, name mapped to value.
    fg_colors (Optional[Iterable]): Optional foreground colors, one per column. None can be specified
        for individual columns to retain the default foreground color.
    bg_colors (Optional[Iterable]): Optional background colors, one per column. None can be specified
        for individual columns to retain the default background color.
    RETURNS (str): The formatted table.
    Nc                       g | ]}  ||qS  get).0fg_colorcolorsr)   A/home/ubuntu/.local/lib/python3.10/site-packages/wasabi/tables.py
<listcomp>=       ztable.<locals>.<listcomp>c                    r(   r)   r*   )r,   bg_colorr.   r)   r0   r1   ?   r2   c                 S   s$   g | ]}t |ttfr|n|gqS r)   )
isinstancelisttuple)r,   vr)   r)   r0   r1   E   s   $ 	fillvalue r   c                 S   s   g | ]}d qS )r9   r)   )r,   ir)   r)   r0   r1   H       r   )r   r    r!   r#   r%   r&   c                 S   s   g | ]}d | qS )-r)   )r,   widthr)   r)   r0   r1   T   s    z
{}

)dictr   updater4   r5   items	enumerateextendr   lenappendr6   _get_max_widthsrowformatjoin)r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   zipped_datar:   itemvalssettingsdivider_rowrowsr)   r.   r0   table   sR   *



rP   c                    sT  t d|d}t o| o|dup|du}g }	t tr' fdd| D nttt  }
tdsIdkrIttt	 fddt
t| D t| D ]U\}}t|
r_|t|
k r_|
| nd	}dkrjt|nttt	 | }d
||f }|t|}|r|dur|| nd}|dur|| nd}t|||d}|	| qMd| |	S )a;  Format data as a table row.

    data (Collection): The individual columns to format.
    widths (Union[Sequence[int], int, Literal['auto']]): Column widths, either one integer for all
        columns or an iterable of values. If "auto", widths will be calculated
        automatically based on the largest value.
    spacing (int): Spacing between columns, in spaces.
    aligns (Optional[Union[Sequence[Literal['r', 'c', 'l']], str]]): Optional column
        alignments in order. 'l' (left, default), 'r' (right) or 'c' (center).
        If a string, value is used for all columns.
    env_prefix (str): Prefix for environment variables, e.g.
        WASABI_LOG_FRIENDLY.
    fg_colors (Optional[Sequence]): Optional foreground colors for the columns, in order. None can be
        specified for individual columns to retain the default foreground color.
    bg_colors (Optional[Sequence]): Optional background colors for the columns, in order. None can be
        specified for individual columns to retain the default background color.
    RETURNS (str): The formatted row.
    z{}_LOG_FRIENDLYFNc                       g | ]} qS r)   r)   r,   _)r!   r)   r0   r1      r;   zrow.<locals>.<listcomp>__iter__r   c                    rQ   r)   r)   rR   )r   r)   r0   r1      r;   r   z{:%s%d})fgbg )osgetenvrH   r   r4   strr
   r   hasattrintrangerD   rB   	ALIGN_MAPr+   _colorrE   rI   )r   r   r    r!   r#   r%   r&   env_log_friendlyshow_colorscols_alignsr:   colalign	col_widthtplrU   rV   r)   )r!   r   r0   rG   c   s,   ($""rG   c                    sL   t | }|r|| |r|| dd |D } fddt t| D S )Nc                 S   s   g | ]	}d d |D qS )c                 S   s   g | ]}t t|qS r)   )rD   rZ   )r,   rd   r)   r)   r0   r1      r2   z._get_max_widths.<locals>.<listcomp>.<listcomp>r)   )r,   rK   r)   r)   r0   r1          z#_get_max_widths.<locals>.<listcomp>c                    s   g | ]	}t t| qS r)   )minmax)r,   wr   r)   r0   r1      rh   )r5   rE   zip)r   r   r   r   all_datar   r)   rl   r0   rF      s   

rF   )NNFr   r   r   NFr   NNN)r   r   Nr   NN)rX   	itertoolsr   typingr   r   r   r   r   r   r	   r
   compatr   utilr   r   r_   r   r^   boolr\   rZ   rP   rG   rF   r)   r)   r)   r0   <module>   s    $
	

W
4