
    =e                        U d Z dZddlZddlZddlZej        rddlZej        d         Zde	d<   de
de
d	e
fd
ZdZde	d<   i Zde	d<   dZde	d<    G d dej        ej        edf         ef                   Z G d d          Z G d d          Z eed          Zde	d<   dZee	d<    G d d           Zd!Zde	d"<   d#Zde	d$<    G d% d&          Z G d' d(e          Z e                                eed)                              eeeed*                              eeeed*                              eed+                              eed+                              eed+          Zee	d,<   dS )-z$Utility to print tables to terminal.     N)<^>ztyping_extensions.TypeAlias	Alignmentleftrightreturnc                 X    | dk    rd} |dk    rd}| |z  t          j        | |          z  S )z.Find the least common multiple of two numbers.r      )mathgcd)r   r	   s     ;lib/python3.11/site-packages/binstar_client/utils/tables.pylcmr      s9    qyyzz%<48D%0000    *ztyping_extensions.Final[str]ANYzRtyping_extensions.Final[typing.Dict[int, typing.Sequence[typing.Tuple[int, ...]]]]COMBINATIONSu   ∅EMPTYc            	           e Zd ZdZdZdddej        ej        edf         ef         de	dej
        e         d	dfd
Zdej        edf         d	efdZd	ej        ej        edf                  fdZd	e	fdZdS )
ValuesViewa~  
    Helper view which allows parent collection to have patterns as its keys.

    Each key of the parent collection should be a tuple of strings of a particular length (defined via
    :code:`key_length` argument). In case you don't use patterns for your original collections keys - this view would
    return only full values for fully matched keys.

    For a key to become a pattern - it is enough to set any part to :code:`ANY` (or :code:`'*'`). Basically, this value
    means that on this particular place there might be any string value. If you request a value for some key tuple and
    everything matches except :code:`ANY` key parts - corresponding value might be returned to the user. Unless there is
    another value where key matches with less number of :code:`ANY` entries.

    .. warning::
        Patterns might be used only on the parent collection side. Each :code:`ANY` in your requested key would be
        treated as an exact value.

    :param content: Parent collection to look for values in.
    :param key_length: Length of a tuple keys used for this collection.
    :param default: Value to use on each lookup miss.
    )	__content	__default__key_lengthNdefaultcontent.
key_lengthr   r
   c                     | _         | _        | _        |t          vr- fdt	           j        dz             D             t          |<   dS dS )z-Initialize new :class:`~ValuesView` instance.c                 h    g | ].}t          j        t          j                  |          D ]}|/S r   )	itertoolscombinationsrange_ValuesView__key_length).0stepindexesselfs      r   
<listcomp>z'ValuesView.__init__.<locals>.<listcomp>D   sY     ( ( ((5eD<M6N6NPTUU( (  ( ( ( (r   r   N)_ValuesView__content_ValuesView__defaultr$   r   r#   )r(   r   r   r   s   `   r   __init__zValuesView.__init__7   ss     biJQ<F\))( ( ( (!$"3a"788( ( (L$$$ *)r   keyc                 J   t          |          | j        k    rt          d          t          | j                 D ]It	          fdt          |          D                       }	 | j        |         c S # t          $ r Y Fw xY w| j        | j        S t          d|           )z%Retrieve a value for the :code:`key`.zinvalid length of a keyc              3   8   K   | ]\  }}|v rt           n|V  d S N)r   )r%   indexvaluecombinations      r   	<genexpr>z)ValuesView.__getitem__.<locals>.<genexpr>Q   sI           E5 ,,5           r   Nzno value found for )	lenr$   
ValueErrorr   tuple	enumerater*   KeyErrorr+   )r(   r-   current_keyr3   s      @r   __getitem__zValuesView.__getitem__J   s    s88t(((6777 ((9: 	 	K        $-cNN       K~k2222    >%>!2S22333s   &A55
BBc                 *    t          | j                  S )z-Iterate through registered keys and patterns.)iterr*   r(   s    r   __iter__zValuesView.__iter___   s    DN###r   c                 *    t          | j                  S )z3Retrieve total number of records in the collection.)r5   r*   r>   s    r   __len__zValuesView.__len__c   s    4>"""r   )__name__
__module____qualname____doc__	__slots__typingMappingTuplestrintOptionalr,   r;   Iteratorr?   rA   r   r   r   r   r      s        * ;I -1  ^FLc$:C$?@ 
 _S) 
   &4v|CH5 4# 4 4 4 4*$&/&,sCx*@A $ $ $ $# # # # # # #r   r   .c                   *   e Zd ZdZdZd%dZedefd            Zedefd            Z	edefd            Z
d	ed
edededededd fdZdedededededd fdZded	ed
ededd f
dZdedededd fdZdedededededd fd Zd!ed"ededd fd#Zd&d$ZdS )'TableDesignz
    Definition of the design used for table borders.

    This design allows you to set borders between cells of different kinds. It is up to you to define cell kinds - no
    strict limitations here.
    )__horizontal__horizontal_view__intersection__intersection_view
__vertical__vertical_viewr
   Nc                     i | _         t          | j         dd          | _        i | _        t          | j        dd          | _        i | _        t          | j        dd          | _        dS )z.Initialize new :class:`~TableDesign` instance.    r      N)_TableDesign__horizontalr   _TableDesign__horizontal_view_TableDesign__intersection_TableDesign__intersection_view_TableDesign__vertical_TableDesign__vertical_viewr>   s    r   r,   zTableDesign.__init__v   sv    acHRSWSdfgqsHtHtHtceJTUYUhjkuwJxJxJx _aFPQUQ`bcmoFpFpFpr   c                     | j         S )z7Horizontal borders between cells above it and below it.)r[   r>   s    r   
horizontalzTableDesign.horizontal   s     %%r   c                     | j         S )z^Intersection between the cells on the top-left, top-right, bottom-left and bottom right of it.)r]   r>   s    r   intersectionzTableDesign.intersection   s     ''r   c                     | j         S )zAVertical borders between cells on the left of it and on the right)r_   r>   s    r   verticalzTableDesign.vertical   s     ##r   ra   re   	corner_nw	corner_ne	corner_se	corner_swc                    |                                  }||j        t          t          f<   ||j        t          t          f<   ||j        t          t          t          t          f<   ||j        t          t          t          t          f<   ||j        t          t          t          t          f<   ||j        t          t          t          t          f<   ||j        t          t          f<   ||j        t          t          f<   |S )z
        Define a style for an external border of the table.

        .. warning::

            This would create a new :class:`~TableDesign` with requested modifications. There would be no modifications
            to the original instance.
        )_TableDesign__copyrZ   r   r   r\   r^   )r(   ra   re   rf   rg   rh   ri   results           r   with_border_stylezTableDesign.with_border_style   s    $ !%*4E3J'*4CJ':CeUE367:CeUC67:CeS%67:Cc5%67(0%*%(0#u*%r   kindtopr	   bottomr   c                     |                                  }||j        t          t          ||f<   ||j        t          |t          |f<   ||j        |t          |t          f<   ||j        ||t          t          f<   |S )a  
        Define how external border should transition into borders of a :code:`kind`.

        .. warning::

            This would create a new :class:`~TableDesign` with requested modifications. There would be no modifications
            to the original instance.
        )rk   r\   r   )r(   rn   ro   r	   rp   r   rl   s          r   with_border_transitionz"TableDesign.with_border_transition   sn    " !%:=eUD$67:>eT5$67:?dE467:@dD%67r   rc   c                 z    |                                  }||j        ||f<   ||j        ||||f<   ||j        ||f<   |S )a  
        Define the borders between cells of the same :code:`kind`.

        .. warning::

            This would create a new :class:`~TableDesign` with requested modifications. There would be no modifications
            to the original instance.
        )rk   rZ   r\   r^   )r(   rn   ra   re   rc   rl   s         r   with_cell_stylezTableDesign.with_cell_style   sN      !%*4D$J'8DdD$45(0$*%r   top_kindbottom_kindr2   c                 F    |                                  }||j        ||f<   |S )z
        Define a single horizontal border rule.

        .. warning::

            This would create a new :class:`~TableDesign` with requested modifications. There would be no modifications
            to the original instance.
        )rk   rZ   )r(   ru   rv   r2   rl   s        r   with_horizontalzTableDesign.with_horizontal   s(     !%5:Hk12r   top_left_kindtop_right_kindbottom_left_kindbottom_right_kindc                 J    |                                  }||j        ||||f<   |S )z
        Define a single intersection border rule.

        .. warning::

            This would create a new :class:`~TableDesign` with requested modifications. There would be no modifications
            to the original instance.
        )rk   r\   )r(   ry   rz   r{   r|   r2   rl   s          r   with_intersectionzTableDesign.with_intersection   s.    " !%dim^=MO``ar   	left_kind
right_kindc                 F    |                                  }||j        ||f<   |S )z
        Define a single vertical border rule.

        .. warning::

            This would create a new :class:`~TableDesign` with requested modifications. There would be no modifications
            to the original instance.
        )rk   r^   )r(   r   r   r2   rl   s        r   with_verticalzTableDesign.with_vertical  s(     !%38)Z/0r   c                     t                      }|j                            | j                   |j                            | j                   |j                            | j                   |S )z
        Create a full copy of the current instance.

        Used for safe modifications without any changes to the original value.
        )rO   rZ   updater\   r^   )r(   rl   s     r   __copyzTableDesign.__copy  s_     !,""4#4555$$T%8999  111r   r
   N)r
   rO   )rB   rC   rD   rE   rF   r,   propertyr   ra   rc   re   rJ   rm   rr   rt   rx   r~   r   rk   r   r   r   rO   rO   h   sr        I	q 	q 	q 	q &J & & & X& (j ( ( ( X( $* $ $ $ X$  	
    
   :  	
   
   0  	
  
   ,  	
 
   &   "	
  #  
   *  	
 
   &     r   rO   c            	       V    e Zd ZdZdZdddedej        ddd	d
fdZd	efdZ	d	efdZ
d
S )	TableCellz
    General definition of a table cell.

    :param kind: Kind of the cell (used for styling purposes, see :class:`~TableDesign`).
    :param value: Exact content of the cell.
    :param alignment: How text should be aligned in the cell.
    )	alignmentrn   r2   r   )r   rn   r2   r   r   r
   Nc                R    |d}|| _         || _        t          |          | _        dS )z,Initialize new :class:`~TableCell` instance.NrX   )r   rn   rJ   r2   )r(   rn   r2   r   s       r   r,   zTableCell.__init__/  s-     =E&/	e**


r   c                 `    t          |           j         d| j        d| j        d| j        dS )0Prepare a string representation of the instance.z(kind=z, value=z, alignment=))typerB   rn   r2   r   r>   s    r   __repr__zTableCell.__repr__>  s:    t**%ooTYoo$*oo\`\joooor   c                     | j         S )r   r2   r>   s    r   __str__zTableCell.__str__B  s
    zr   )rB   rC   rD   rE   rF   rJ   rG   Anyr,   r   r   r   r   r   r   r   $  s          /I &)% % %% :%
 #% 
% % % %p# p p p p      r   r   rX   rn   r2   z"typing_extensions.Final[TableCell]
EMPTY_CELLz{{: {1}{0}.{0}s}}TEMPLATEc                      e Zd ZdZdZdeddfdZedefd            Z	edefd            Z
e
j        d	eddfd
            Z
edefd            Zdej        ej        e                  ddfdZdeddfdZdeddfdZdedej        e         fdZdddddedededej        ej        e         ej        e         f         fdZdej        ej        e                  dej        e         fdZdedej        e         fdZdej        ej        e                  dej        e         dedej        e         fdZdej        ej        e                  dej        ej        e                  dej        e         dedej        e         f
d Zd!ej        eef         ddfd"Z d!ej        eef         defd#Z!d!ej        eef         d	eddfd$Z"dS )%	TableCorez
    Core for any table implementation.

    It is used to store the whole table data and visualize it.

    :param default: What to show for cells with no values.
    )	__columnsr   r   __rowsr   r
   Nc                >    d| _         g | _        || _        d| _        dS )z,Initialize new :class:`~TableCore` instance.r   N)_TableCore__columns_TableCore__content_TableCore__default_TableCore__rows)r(   r   s     r   r,   zTableCore.__init__V  s"    /0jl$+,-r   c                 v    | j         ,t          t          t          | j                            | _         | j         S )z%Total number o columns in this table.)r   maxmapr5   r   r>   s    r   columnszTableCore.columns]  s/     >! S$.!9!9::DN~r   c                     | j         S )z-Default cell content to show for empty cells.r   r>   s    r   r   zTableCore.defaultd  s     ~r   r2   c                     || _         dS )zUpdate the `default` value.Nr   r(   r2   s     r   r   zTableCore.defaulti  s     r   c                 P    | j         t          | j                  | _         | j         S )z#Total number of rows in this table.)r   r5   r   r>   s    r   rowszTableCore.rowsn  s%     ;dn--DK{r   valuesc                     t          |          }| j                            |           | j        't	          | j        t          |                    | _        | j        | xj        dz  c_        dS dS )+Append new row to the bottom of this table.Nr   )listr   appendr   r   r5   r   )r(   r   rows      r   
append_rowzTableCore.append_rowu  sh    7;F||c""">% S::DN;"KK1KKKK #"r   columnc                 t    | j         D ]}	 ||= # t          $ r Y w xY w| j        | xj        dz  c_        dS dS )&Remove a single column from the table.Nr   )r   
IndexErrorr   )r(   r   r   s      r   remove_columnzTableCore.remove_column~  sg     > 	 	CKK   >%NNaNNNN &%s   
r   c                 l    	 | j         |= n# t          $ r Y nw xY w| j        | xj        dz  c_        dS dS )#Remove a single row from the table.Nr   )r   r   r   )r(   r   s     r   
remove_rowzTableCore.remove_row  sX    	s## 	 	 	D	;"KK1KKKK #"s    
designc              #   *  K   t           g| j        z  }|                     |          }|}| j        D ]A}|                     ||||          E d{V  |                     |||          E d{V  |}B|                     ||||          E d{V  dS )&Print table to the user (in terminal).)r   )	above_row	below_rowwidthsr   N)r   r   r   )r   r   _TableCore__render_analysisr   _TableCore__render_separator_TableCore__render_row)r(   r   	empty_rowr   previouscurrents         r   renderzTableCore.render  s      L4</	'+'='=V'='L'L AJ~ 	 	G..W]clr.sssssssss((WVF(SSSSSSSSSHH**X[ajp*qqqqqqqqqqqr   Fempty_columns
empty_rowsempty_valuesr   r   r   c                   g }d}g }d}d}|t          | j                  k     r|rd | j        |         D             | j        |<   | j        |         rR| j        |         d         ?| j        |                                          | j        |         r| j        |         d         ?| j        |         s5|r3|                     |           |                    ||z              |dz  }n|dz  }|t          | j                  k     | j        r6| j        d         s)|                     d           | j        r| j        d         )d}|rmd}	d}
| j        D ]"}	 |
||         duz  }
d}	# t
          $ r Y w xY w|	rn<|
r|dz  };|                     |           |                    ||z              |dz  }|md| _        d| _        ||fS )a  
        Remove trailing empty cells from each row.

        :param empty_columns: Also remove columns if all of their cells are empty.
        :param empty_rows: Also remove rows if all of their cells are empty
        :param empty_values: If any cell contains an empty value - convert it to empty cell.

                             This action is performed before anything else.

        :return: Lists of removed columns and rows
        r   c                 (    g | ]}|	|j         r|nd S r0   r   )r%   cells     r   r)   z"TableCore.trim.<locals>.<listcomp>  s8     ) ) ) "-4:-DD4) ) )r   Nr   TF)	r5   r   popr   r   LookupErrorr   r   r   )r(   r   r   r   removed_columnsremoved_columns_offsetremoved_rowsremoved_rows_offsetr1   	no_column	has_valuer   s               r   trimzTableCore.trim  sm   $ -/&')+#$c$.)))) ) ) $u 5) ) )u% .' ,T^E-B2-F-Nu%))+++ .' ,T^E-B2-F-N N5) z &&&##$7%$?@@@#q(##
% c$.))))* n 	 dnR&8 	 OOB n 	 dnR&8 	   	("I#I ~ & &&U4!77I !&II #   H
   
u%%%""#9E#ABBB"a'"+  	(0  ,,s   E!!
E.-E.c              #      K   t          j        t          j        |t          j        | j                            | j                  D ]}|p| j        V  dS )zz
        Iterate all cells in a single row.

        This may add trailing cells to ensure the number of columns.
        N)r!   islicechainrepeatr   r   )r(   r   r2   s      r   __iterate_rowzTableCore.__iterate_row  sa       %ioc9;KDN;[;[&\&\^b^lmm 	* 	*E)4>))))	* 	*r   c                 &   dgd| j         z  dz   z  }dgd| j         z  dz   z  }t          g| j         z  }| j        D ]}d}t          }t          }t	          |                     |          |                     |                    D ]\  }	}
t          ||         t          |j        ||	j	        ||
j	        f                   t          |j
        ||
j	        f                             ||<   |dz  }t          ||         t          |j        |	j	        |
j	        f                             ||<   t          ||         t          |
j                            ||<   |dz  }|	j	        }|
j	        }t          ||         t          |j        |t          |t          f                   t          |j
        |t          f                             ||<   |}d}t          }|                     |          D ]}	t          ||         t          |j        ||	j	        t          t          f                             ||<   |dz  }t          ||         t          |j        |	j	        t          f                             ||<   |dz  }|	j	        }t          ||         t          |j        |t          t          t          f                             ||<   t          t          |                    D ]2}||         ||         z  }|dk    r||xx         ||         |z
  z  cc<   3|S )z(Measure each column and vertical border.r   rW   r   )r   r   r   r   zip_TableCore__iterate_rowr   r5   rc   rn   re   r   ra   r2   r#   )r(   r   stepsr   prevcurrr1   	curr_prev	prev_prev	prev_cell	curr_celltemps               r   __render_analysiszTableCore.__render_analysis  s    $%#T\)9A)=">$%3!dl*:Q*>#? |dl*N 	 	DEII(+D,>,>t,D,DdFXFXY]F^F^(_(_ + +$	9 #5M+Iy~yR[R`,`abb	9>(ABCC! !u
 
"5<V5Fy~W`WeGe5f1g1ghhe #F5M3y3G3G H Hu
%N	%N		uF'	5)U(JKLLFOIu$4566 F5M DD	++D11 	' 	'Ius63FyR[R`bginGn3o/p/pqqF5MQJEuU|S1B9>SXCX1Y-Z-Z[[E%LQJE!IIF5M3v/B9eUZ\aCa/b+c+cddu 3v;;'' 	5 	5E%=5</Daxxuu!44 r   r   c              #     K   d}t           }t          |          }|                     |          D ]}|t                              t          |d          d                              |j        ||j        f                   z  }|t                              t          |d          |j                                      |j	                  z  }|j        }||j        |t           f         z   V  dS )zRender a row with values.rX   r   r   N)
r   r=   r   r   formatnextre   rn   r   r2   )r(   r   r   r   rl   previous_kindr   s          r   __render_rowzTableCore.__render_row:  s       "f&&s++ 	& 	&Dhood61oos;;BB6?S`bfbkSkClmmmFhood61oot~FFMMdjYYYF IMMv}e';<<<<<<<r   r   r   c           	   #      K   t           }t           }d}d}t          |          }t          |                     |          |                     |                    D ]\  }	}
|t                              t          |d          d                              |j        ||	j        ||
j        f                   z  }|j	        |	j        |
j        f         }|r)d}||t          |d          t          |          z  z  z  }n|dt          |d          z  z  }|	j        }|
j        }|r\|t                              t          |d          d                              |j        |t           |t           f                   z   V  dS dS )zIRender a string that contains of horizontal separators and intersections.FrX   r   r   T N)r   r=   r   r   r   r   r   rc   rn   ra   r5   )r(   r   r   r   r   
above_kind
below_kindgoodrl   
above_cell
below_cellr   s               r   __render_separatorzTableCore.__render_separatorK  s       

f&)$*<*<Y*G*GI[I[\eIfIf&g&g 	) 	)"J
hood61oos;;BB#J
Z_$\]  F $Z_jo%EFD 0$$vq//SYY">??#VQ//#J#JJ 	8??4??C@@GG#Jz5$HI       	 	r   r   c                 b    	 d| j         |d                  |d         <   dS # t          $ r Y dS w xY w)z6Remove a single cell from the table (set it to empty).Nr   r   )r   r   r(   r   s     r   __delitem__zTableCore.__delitem__k  sH    	/3DN47#DG,,, 	 	 	DD	s     
..c                 ~    	 | j         |d                  |d                  p| j        S # t          $ r
 | j        cY S w xY w)z&Retrieve a single cell from the table.r   r   )r   r   r   r   s     r   r;   zTableCore.__getitem__r  sQ    	">$q'*473Et~E 	" 	" 	">!!!	"s   %( <<c                    t          | j                  |d         k    r8| j                            g            t          | j                  |d         k    8t          | j        |d                            |d         k    rP| j        |d                                      d           t          | j        |d                            |d         k    P|| j        |d                  |d         <   | j        #t	          | j        |d         dz             | _        | j        %t	          | j        |d         dz             | _        dS dS )z Update a single cell in a table.r   r   N)r5   r   r   r   r   r   r(   r   r2   s      r   __setitem__zTableCore.__setitem__y  s   $.!!T!W,,N!!"%%% $.!!T!W,,$.a)**d1g55N47#**4000 $.a)**d1g55+0tAwQ(>% a1==DN;"dk47Q;77DKKK #"r   )#rB   rC   rD   rE   rF   r   r,   r   rK   r   r   setterr   rG   IterablerL   r   r   r   rO   rM   rJ   r   boolrI   Listr   r   Sequencer   r   r   r   r;   r   r   r   r   r   r   K  s         BI.9 . . . . .     X     X ^Y 4    ^ c    X1K!L QU    	 C 	 D 	  	  	  	 c d    r[ rV_S-A r r r r  #($!&N- N- N-  N- 	N-
 N- 
fk#&C(88	9N- N- N- N-`*1K!L *QWQ`ajQk * * * *@ @8L @ @ @ @D=!;<= OC(=  	=
 
	= = = ="vy'AB vy'AB OC(	
   
	   @S#X 6 4    "S#X 6 "9 " " " "8S#X 6 8y 8T 8 8 8 8 8 8r   r   HHEADINGCCELLc            	          e Zd ZdZdZ	 	 d&dededdfdZed'd
            Zej	        d(d            Zedefd            Z
edefd            Zdededd	ddfdZdedd	ddfdZdedd	ddfdZdej        ej                 ddfdZdeddfdZdeddfdZdedej        e         fdZdddddedededdfd Zd)d!Zd"ej        eef         ddfd#Zd"ej        eef         defd$Zd"ej        eef         deddfd%ZdS )*SimpleTablez
    Table with headings.

    :param heading_rows: How many rows should be used as a headings.
    :param heading_columns: How many columns should be used as a headings.
    )__alignment__clean__core__heading_columns__heading_rowsr   heading_rowsheading_columnsr
   Nc                     ddi| _         d| _        t          t          t          d                    | _        || _        || _        dS )z.Initialize new :class:`~SimpleTable` instance.r   r   r   TrX   r   r   N)_SimpleTable__alignment_SimpleTable__cleanr   r   r  _SimpleTable__core_SimpleTable__heading_columns_SimpleTable__heading_rows)r(   r  r  s      r   r,   zSimpleTable.__init__  sQ     OWX[_!<Ei]aikNlNlNl<m<m<mAP>Jr   r   c                     | j         d         S )z&Default alignment value for all cells.r  r  r>   s    r   r   zSimpleTable.alignment  s     ''r   r2   c                     || j         d<   dS )zUpdate default alignment value.r  Nr  r   s     r   r   zSimpleTable.alignment  s     $)   r   c                     | j         j        S )z Number of columns in this table.)r  r   r>   s    r   r   zSimpleTable.columns  s     {""r   c                     | j         j        S )zNumber of rows in this table.)r  r   r>   s    r   r   zSimpleTable.rows  s     {r   r   r   r   c                     |dk     rt          d|           |dk     rt          d|           || j        ||f<   d| _        dS )!Align a single cell in the table.r   z"row index must be at least 0, not z%column index must be at least 0, not FN)AttributeErrorr  r  )r(   r   r   r   s       r   
align_cellzSimpleTable.align_cell  s^    77 !Kc!K!KLLLA:: !Q!Q!QRRR(1f%r   c                 |    fd| j                                         D             }||df<   || _         d| _        dS )0Align each cell in a single column of the table.c                 4    i | ]\  }}|d          k    ||S )r   r   )r%   r-   r2   r   s      r   
<dictcomp>z,SimpleTable.align_column.<locals>.<dictcomp>  s;     K
 K
 K
U1v r   r   FNr  itemsr  )r(   r   r   new_alignments    `  r   align_columnzSimpleTable.align_column  sd    K
 K
 K
 K
".4466K
 K
 K

 %.b&j!(r   c                 |    fd| j                                         D             }||df<   || _         d| _        dS )z-Aline each cell in a single row of the table.c                 4    i | ]\  }}|d          k    ||S )r   r   )r%   r-   r2   r   s      r   r"  z)SimpleTable.align_row.<locals>.<dictcomp>  s7     K
 K
 K
U1v}} }}r   r   FNr#  )r(   r   r   r%  s    `  r   	align_rowzSimpleTable.align_row  sd    K
 K
 K
 K
".4466K
 K
 K

 "+c2g(r   r   c                 \    | j                             d |D                        d| _        dS )r   c                 :    g | ]}t          t          |           S )r   )r   r  )r%   r2   s     r   r)   z*SimpleTable.append_row.<locals>.<listcomp>  s%    VVVe	t5 A A AVVVr   FN)r  r   r  )r(   r   s     r   r   zSimpleTable.append_row  s2    VVvVVVWWWr   c                     | j                                        fd| j                                        D             }|| _        d| _        dS )r   c                 @    i | ]\  \  }}}|k    |||k    z
  f|S r   r   )r%   key_row
key_columnr2   r   s       r   r"  z-SimpleTable.remove_column.<locals>.<dictcomp>  sK     K
 K
 K
,%*uV## jJ$7895###r   FN)r  r   r  r$  r  )r(   r   r%  s    ` r   r   zSimpleTable.remove_column  sl    !!&)))K
 K
 K
 K
040@0F0F0H0HK
 K
 K

 )r   c                     | j                                        fd| j                                        D             }|| _        d| _        dS )r   c                 @    i | ]\  \  }}}|k    ||k    z
  |f|S r   r   )r%   r.  r/  r2   r   s       r   r"  z*SimpleTable.remove_row.<locals>.<dictcomp>  sF     K
 K
 K
,%*u#~~ #&
3U~~r   FN)r  r   r  r$  r  )r(   r   r%  s    ` r   r   zSimpleTable.remove_row  sl    s###K
 K
 K
 K
040@0F0F0H0HK
 K
 K

 )r   r   c                 ^    |                                   | j                            |          S )r   )
_normalizer  r   )r(   r   s     r   r   zSimpleTable.render  s(    {!!&)))r   Fr   r   r   r   c                    | j                             |||          \  fd| j                                        D             }|| _        d| _        dS )a  
        Remove trailing empty cells from each row.

        :param empty_columns: Also remove columns if all of their cells are empty.
        :param empty_rows: Also remove rows if all of their cells are empty
        :param empty_values: If any cell contains an empty value - convert it to empty cell.

                             This action is performed before anything else.
        r   c                     i | ]M\  \  }vvt          fd D                       z
  t          fdD                       z
  f|NS )c              3   $   K   | ]
}|k    V  d S r0   r   )r%   r   r.  s     r   r4   z.SimpleTable.trim.<locals>.<dictcomp>.<genexpr>	  s'      DDgmDDDDDDr   c              3   $   K   | ]
}|k    V  d S r0   r   )r%   r   r/  s     r   r4   z.SimpleTable.trim.<locals>.<dictcomp>.<genexpr>
  s(       S Sf!4 S S S S S Sr   )sum)r%   r2   r/  r.  r   r   s     @@r   r"  z$SimpleTable.trim.<locals>.<dictcomp>  s     K
 K
 K

 -%*u/11|8S8S	 #DDDD|DDDDDDS S S S S? S S SSSS 8S8S8Sr   FN)r  r   r  r$  r  )r(   r   r   r   r%  r   r   s        @@r   r   zSimpleTable.trim  s     )-(8(8'!% )9 )
 )
%K
 K
 K
 K
 K

 150@0F0F0H0HK
 K
 K
 )r   c                    | j         rdS t          | j        j                  D ]?}t          | j        j                  D ]!}|| j        k     s|| j        k     rt          }nt          }| j	        
                    ||fd          pV| j	        
                    |dfd          p9| j	        
                    d|fd          p| j	        
                    dd          pd}| j        ||f         }|j        |k    r|j        |k    s|j        s|| j        j        u r"t          ||j        |          | j        ||f<   || j        ||f         _        || j        ||f         _        #Ad| _         dS )zEApply table visualization preferences to the table (e.g. alignments).Nr   r  r   )rn   r2   r   T)r  r#   r  r   r   r  r  r  r  r  getrn   r   r2   r   r   )r(   r   r   rn   r   r   s         r   r3  zSimpleTable._normalize  s   < 	F)** 	9 	9C 344 9 9$---6D<R3R3R"DDD (,,c6]DAA (,,c2Y==(,,b&\4@@ (,,Xt<<   #'+c6k":I%%DNi,G,Gtz,G4;.../8d$*`i/j/j/jDKV,,9BDKV,648DKV,11194 r   r   c                     | j         |= dS z8Remove a single cell from the table (set it to default).N)r  r   s     r   r   zSimpleTable.__delitem__5  s    Kr   c                 &    | j         |         j        S z/Retrieve a value of a single cell in the table.)r  r2   r   s     r   r;   zSimpleTable.__getitem__9  s    {4 &&r   c                 P    t          t          |          | j        |<   d| _        dS )-Update a value of a single cell in the table.r   FN)r   r  r  r  r   s      r   r   zSimpleTable.__setitem__=  s&    %4u===Dr   r   r   )r
   r   )r2   r   r
   Nr   ) rB   rC   rD   rE   rF   rK   r,   r   r   r   r   r   r  r&  r)  rG   r   r   r   r   r   rO   rM   rJ   r   r   r   r3  rI   r   r;   r   r   r   r   r  r    s          \I !"#$
K 
K
K !
K 
	
K 
K 
K 
K ( ( ( X( ) ) ) ) # # # # X#  c       X c 3 ; 4    	3 	; 	4 	 	 	 		S 	[ 	T 	 	 	 	!<     
	C 	D 	 	 	 		c 	d 	 	 	 	*[ *V_S-A * * * *
 -2ebg   T t [_ lp    <       DS#X 6 4    'S#X 6 '3 ' ' ' 'S#X 6 s t      r   r  c            	           e Zd ZdZdZ	 	 ddej        ej        ej        eej	        eef         f                  ej
        eef         f         dededdf fd	Zd
edej        eef         ddddf fdZdej        eef         ddddf fdZdddej        ej        ej                 ej
        eej        f         f         deddf fdZdej        eef         ddf fdZdej	        eej        eef         f         dej	        eef         fdZdej	        eej        eef         f         ddf fdZdej	        eej        eef         f         def fdZdej	        eej        eef         f         deddf fdZ xZS )SimpleTableWithAliasesas  
    Extended version of the :class:`~SimpleTable` which allows columns to have aliases.

    :param aliases: Aliases for the columns in the table.

                    If at least a single alias is provided as tuple of alias and verbose name, or the whole aliases
                    value is a mapping - first row with verbose values would be added automatically to the table. In
                    case some column doesn't have a verbose name - its alias would be displayed.
    :param heading_rows: How many rows should be used as a headings.
    :param heading_columns: How many columns should be used as a headings.
    )	__aliasesr   aliasesr  r  r
   Nc                    t                                          ||           g }g }d}t          |t          j                  rqt          |                                 \  }}|                    t          t          |                     |                    t          t          |                     d}n|D ]}	t          |	t                    r+|
                    |	           |
                    |	           B|	\  }
}|
                    t          |
                     |
                    t          |                     d}|| _        |r#t                                          |           dS dS )z9Initialize new :class:`~SimpleTableWithAliases` instance.)r  r  FTN)superr,   
isinstancerG   rH   r   r$  extendr   rJ   r    _SimpleTableWithAliases__aliasesr   )r(   rE  r  r  column_aliasescolumn_titlescolumn_titles_readyraw_aliases
raw_titlesitemaliastitle	__class__s               r   r,   zSimpleTableWithAliases.__init__R  sq    	lOTTT+-*,$)gv~.. 	/ '*7==??&;#K!!#c;"7"7888  S*!5!5666"&   
/ 
/dC(( 	/"))$///!((.... $(LE5"))#e**555!((U444*.''FT 	.GG}-----	. 	.r   r   r   r   r   c                     t          |t                    r| j                            |          }t	                                          |||           dS )r  )r   r   r   N)rH  rJ   rJ  r1   rG  r  )r(   r   r   r   rS  s       r   r  z!SimpleTableWithAliases.align_cellz  sO    fc"" 	2^))&11Fs6YGGGGGr   c                     t          |t                    r| j                            |          }t	                                          ||           dS )r   )r   r   N)rH  rJ   rJ  r1   rG  r&  )r(   r   r   rS  s      r   r&  z#SimpleTableWithAliases.align_column  sM    fc"" 	2^))&11FFi@@@@@r   F)strictr   rV  c                
   t          |t          j                  rEt          |          fd| j        D             }|r!rt          dt                               t                                          |           dS )r   c                 <    g | ]}                     |d           S r0   )r   )r%   rQ  
old_valuess     r   r)   z5SimpleTableWithAliases.append_row.<locals>.<listcomp>  s'    NNNejnnUD11NNNr   zunexpected values: N)	rH  rG   rH   dictrJ  r6   r   rG  r   )r(   r   rV  rY  rS  s      @r   r   z!SimpleTableWithAliases.append_row  s     ffn-- 	K7;F||JNNNNt~NNNF K* K !ItJ7G7G!I!IJJJ6"""""r   c                     t          |t                    r| j                            |          }t	                                          |           dS )r   N)rH  rJ   rJ  r1   rG  r   )r(   r   rS  s     r   r   z$SimpleTableWithAliases.remove_column  sH    fc"" 	2^))&11Ff%%%%%r   r   c                 r    |\  }}t          |t                    r| j                            |          }||fS )z Normalize value of a cell index.)rH  rJ   rJ  r1   )r(   r   r   r   s       r   __normalize_cell_indexz-SimpleTableWithAliases.__normalize_cell_index  s>     Vfc"" 	2^))&11FF{r   c                 p    t                                          |                     |                     dS r<  )rG  r   -_SimpleTableWithAliases__normalize_cell_indexr(   r   rS  s     r   r   z"SimpleTableWithAliases.__delitem__  s/    D77==>>>>>r   c                 l    t                                          |                     |                    S r>  )rG  r;   r_  r`  s     r   r;   z"SimpleTableWithAliases.__getitem__  s)    ww""4#>#>t#D#DEEEr   r2   c                 r    t                                          |                     |          |           dS )r@  N)rG  r   r_  )r(   r   r2   rS  s      r   r   z"SimpleTableWithAliases.__setitem__  s1    D77==uEEEEEr   rA  )rB   rC   rD   rE   rF   rG   Unionr   rJ   rI   rH   rK   r,   r  r&  r   r   r   r   r_  r   r;   r   __classcell__)rS  s   @r   rC  rC  C  s+       
 
 I
 !"#$	&. &.\&/&,sFLQTVYQYDZ?Z2["\^d^lmprumu^v"vw&. &. !	&.
 
&. &. &. &. &. &.PHc H6<S+A Hk H^b H H H H H HA6<S#9 Ak AVZ A A A A A A !	# # #L!<fnSRXR\_>]!]^# 	#
 
# # # # # #&FLc$: &t & & & & & &6<V\#s(=S8S+T Y_YefiknfnYo    ?S&,sCx2H-H I ?d ? ? ? ? ? ?FS&,sCx2H-H I Fc F F F F F FFS&,sCx2H-H I FRU FZ^ F F F F F F F F F Fr   rC  -z-+-z | SIMPLE) rE   __all__r!   r   rG   TYPE_CHECKINGtyping_extensionsLiteralr   __annotations__rK   r   r   r   r   rH   rI   rJ   r   rO   r   r   r   r   r  r  r  rC  rx   r~   r   rf  r   r   r   <module>rl     s   + * *
      	 X/@/H/WI,WWW1c 1# 1# 1 1 1 1 '*# ) ) )egb g g g(-% - - -F# F# F# F# F#S#X 6 ;< F# F# F#Ry y y y y y y yx               F 4=9%r3R3R3R
0 R R R## # # #y8 y8 y8 y8 y8 y8 y8 y8x	 +.	' - - -'*$ * * *u u u u u u u upkF kF kF kF kF[ kF kF kF^ KMM_WdC((wtU;;w$>>]7GU++]7D%((]4u%%      r   