a
    b0`                  !   @   s"	  d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlZej	dkrXddl
mZ nddlmZ ej	d dk rdd	lmZ dd
lmZ edZeZeZeZeZeZeZdd ZnPddlmZ ddlm Z mZ edZeZeZeZeZeZe!ZeZ"ddl#Z#dd Zzddl$Z$W n e%y(   dZ$Y n0 zddl&m'Z( W n  e%yZ   ddl)m'Z( Y n0 g dZ*dZ+dZ,dZ-dZ.dZ/dZ0e$duZ1edg dZ2edg dZ3edg dZ4dd Z5d d! Z6d"d# Z7d$d% Z8d&d' Z9d(d) Z:dd*d+Z;dd,d-Z<d.d/d0d1d2d3d4d5d6d7d8d9d:Z=e=fd;d<Z>d=d> Z?e4e2dd?d@de2dd?d@dde2dd?d@de3dd@de3dd@dddAdBgde4dddde3dd@de3dd@dddde4e2dCd?dCdCe2dCdDdCdCe2dCd?dCdCe2dCd?dCdCe3dEdEdEe3dEdEdEdFdde4e2dGdHdIdJe2dKdHdLdMe2dNdOdPdQe2dRdHdSdTe3dUdUdUe3dUdUdUdFdde4e2dGdHdIdJe2dKdHdLdMde2dRdHdSdTe3dUdUdUe3dUdUdUdFdde4e2dEd?dEdEe2dEd?dEdEdde3dEdEdEe3dEdEdEdFdAgde4e6e6dde3dEdEdEe3dEdEdEdFdAgde4de2dEd?dCdEdde3dEdEdEe3dEdEdEdFdde4dddde3dVdVdVe3dEdEdEdFdde4de2dd?dCddde3ddEde3ddEddFdde4e2dCd?dCdCe2dCd?dCdCde2dCd?dCdCe3dEdEdEe3dEdEdEdFdde4e2dCd?dCdCe2dEd?dCdEde2dCd?dCdCe3dEdEdEe3dEdEdEdFdde4e2ddDd@de2ddDd@dde2ddDd@de3dd@de3dd@dddde4e2dWdddXe2dYddde2dYddde2dZdddee7d[ee7dEddde4ddddee;dVd\d]ee;dVdFdde4dddde3d^d_d_e3d`dadbdFdde4e9dde2dcdddee:dddee:dedddAgde4e9dde2dcdddee:dddfee:dedfddAgde4e<e2dgdddde2dhddde>e>dFdde4e<e2dgdddde2dhdddee>i diee>i didFdde4ee<dfdje2dkdddde2dlddde>e>dFdde4ee<dfdme2dndddde2doddde>e>dFdde4dddde3ddpde3ddpdddde4dddde3dqdrdEe8dFdddsZ@eAeBe@C ZDdtdudvdwdxdydzd{d|d}d~dZEeFdZGeFdZHeFdZIeFdZJeFdZKdd ZLdd ZMdd ZNefddZOdd ZPdddZQdd ZRdd ZSdd ZTdd ZUdd ZVdd ZWdd ZXdd ZYeZfddZ[dd Z\dd Z]dd Z^eZfddZ_dd Z`dddZadd ZbdddZcdddZddddZedd Zfdd ZgdddZhddue.e0e0e/dddf	ddZidd ZjddÄ Zkddń ZlddǄ ZmddɄ Zndd˄ Zodd̈́ Zpddτ ZqG ddф deZrddӄ ZsddՄ Ztddׄ Zuevdk	ret  dS )zPretty-print tabular data.    )print_function)unicode_literals)
namedtupleN)   r   )Iterabler   )izip_longest)partialc                 C   s
   t | dS )Nread)hasattrf r   'lib/python3.9/site-packages/tabulate.py_is_file   s    r   )zip_longest)reducer   c                 C   s   t | tjS N)
isinstanceioIOBaser   r   r   r   r   1   s    )escape)tabulatetabulate_formatssimple_separated_formatz0.8.9   Fg defaultLine)beginZhlinesependDataRow)r   r    r!   TableFormat)	lineabovelinebelowheaderlinebetweenrows	linebelow	headerrowdatarowpaddingwith_header_hidec                 C   s\   |}| dv rd|d  d S | dkr8dd|d   d S | dkrPdd|d   S d| S dS )	z~Return a segment of a horizontal line with optional colons which
    indicate column's alignment (as in `pipe` output format).)rightdecimal-   :centerr   leftNr   )alignZcolwidthwr   r   r   _pipe_segment_with_colons   s    r5   c                 C   s8   |sdgt |  }dd t|| D }dd| d S )znReturn a horizontal line with optional colons to indicate column's
    alignment (as in `pipe` output format).r   c                 S   s   g | ]\}}t ||qS r   )r5   ).0ar4   r   r   r   
<listcomp>       z*_pipe_line_with_colons.<locals>.<listcomp>|)lenzipjoin)	colwidths	colalignsZsegmentsr   r   r   _pipe_line_with_colons   s    r@   c                    s@   ddddd  fddt ||D }| d }| ||  S )Nr   zalign="right"| zalign="center"| r2   r,   r1   r-   c                    s(   g | ] \}}d   |d | d  qS ) r   getr6   cr7   	alignmentr   r   r8      s   z-_mediawiki_row_with_attrs.<locals>.<listcomp>r   )r<   r=   rstrip)	separatorcell_valuesr>   r?   values_with_attrsZcolsepr   rG   r   _mediawiki_row_with_attrs   s    
rM   c                    sH   | d  d7  < ddddd  fddt || D }d	d	| d	 S )
Nr   rB   z<.z>.z=.rA   c                 3   s"   | ]\}}  |d | V  qdS )r   NrC   )r6   r7   vrG   r   r   	<genexpr>   r9   z*_textile_row_with_attrs.<locals>.<genexpr>r:   r<   r=   )rK   r>   r?   valuesr   rG   r   _textile_row_with_attrs   s    rR   c                 C   s   dS )Nz<table>
<tbody>r   )Zcolwidths_ignoreZcolaligns_ignorer   r   r    _html_begin_table_without_header   s    rS   c                    sr   ddddd |r. fddt ||D }n fddt ||D }dd| }d	krnd
|}|S )Nr   z style="text-align: right;"z style="text-align: center;"rA   c              	      s&   g | ]\}}d   |d|qS z<{0}{1}>{2}</{0}>r   formatrD   rE   rH   celltagr   r   r8      s   z(_html_row_with_attrs.<locals>.<listcomp>c              	      s*   g | ]"\}}d   |dt|qS rT   )rV   rD   
htmlescaperE   rW   r   r   r8      s   z<tr>{}</tr>thz#<table>
<thead>
{}
</thead>
<tbody>)r<   rV   r=   rI   )rX   ZunsaferK   r>   r?   rL   Zrowhtmlr   rW   r   _html_row_with_attrs   s     
r[   c                    s8   ddddd  fddt ||D }d|d S )Nr   z<style="text-align: right;">z<style="text-align: center;">rA   c              	      s.   g | ]&\}}d   |d|  qS )z{0}{1} {2} r   rU   rE   rH   rX   headerr   r   r8      s   z(_moin_row_with_attrs.<locals>.<listcomp>||rP   )rX   rK   r>   r?   r]   rL   r   r\   r   _moin_row_with_attrs   s    r_   c                    sL   ddddd d  fdd|D }d |s2d	nd
| d |rDdndgS )NlrrF   rA   r   c                    s   g | ]}  |d qS )r`   rC   )r6   r7   rG   r   r   r8      r9   z-_latex_line_begin_tabular.<locals>.<listcomp>
z\begin{tabular}{z\begin{longtable}{}z\toprule\hline)r=   )r>   r?   booktabs	longtableZtabular_columns_fmtr   rG   r   _latex_line_begin_tabular   s    

rg   z\&z\%z\$z\#z\_z\^{}z\{z\}z\textasciitilde{}z\textbackslash{}z\ensuremath{<}z\ensuremath{>})&%$#_^{rc   ~\<>c                    s4   fdd  fdd| D }t ddd}t||S )Nc                    s     | | S r   rC   )rF   escrulesr   r   escape_char   s    z_latex_row.<locals>.escape_charc                    s   g | ]}d  t |qS )r   )r=   mapr6   Zcell)ru   r   r   r8     r9   z_latex_row.<locals>.<listcomp>r   rh   z\\)r"   _build_simple_row)rK   r>   r?   rt   Zescaped_valuesrowfmtr   )ru   rt   r   
_latex_row   s    rz   c                 C   s`   dd }t |}g }|r(||d |d< | D ]*}t |}|rL||d |d< || q,||fS )Nc                 S   s"   t | ttfr|  sdS | S d S )Nz..)r   
_text_type_binary_typestripvalr   r   r   escape_empty  s    z._rst_escape_first_column.<locals>.escape_emptyr   )listappend)rowsheadersr   Znew_headersZnew_rowsrowZnew_rowr   r   r   _rst_escape_first_column  s    r   r.   z  r$   r'   +=r:   r/   u   ╒u   ═u   ╤u   ╕u   ╞u   ╪u   ╡u   ├u   ─u   ┼u   ┤u   ╘u   ╧u   ╛u   │r^   z.{| class="wikitable" style="text-align: left;"z
|+ <!-- caption -->
|-z|-z|}!z''')r]   z|| z || z| z | z |z</tbody>
</table>rZ   ZtdTrd   z\hline
\end{tabular}rs   )re   z\midrulez\bottomrule
\end{tabular})rf   z\hline
\endheadz\hline
\end{longtable}	z|_. z|_.)simpleplaingrid
fancy_gridZfancy_outlineZgithubpipeorgtbljiraprestoprettypsqlrstZ	mediawikiZmoinmoinZyoutrackhtmlZ
unsafehtmlZlatexZ	latex_rawZlatex_booktabsZlatex_longtableZtsvZtextiler   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   z
\r|\n|\r\ns   |
|
z:\x1b\[\d+[;\d]*m|\x1b\[\d*\;\d*\;\d*m|\x1b\]8;;(.*?)\x1b\\s3   \[\d+\[;\d]*m|\[\d*;\d*;\d*m|\x1b\]8;;(.*?)\x1b\\z;\x1B]8;[a-zA-Z0-9:]*;[^\x1B]+\x1B\\([^\x1b]+)\x1B]8;;\x1B\\c              
   C   s(   t ddddtd| dtd| ddddS )zConstruct a simple TableFormat with columns separated by a separator.

    >>> tsv = simple_separated_format("\t") ;         tabulate([["foo", 1], ["spam", 23]], tablefmt=tsv) == 'foo \t 1\nspam\t23'
    True

    Nr   r   )r(   r)   r*   r+   )r#   r"   )rJ   r   r   r   r   =  s    

r   c              	   C   s,   z| | W dS  t tfy&   Y dS 0 d S )NTF)
ValueError	TypeError)Zconvstringr   r   r   _isconvertibleQ  s
    r   c                 C   sH   t t| sdS t| ttfrDtt| s8tt| rD|  dv S dS )z
    >>> _isnumber("123.45")
    True
    >>> _isnumber("123")
    True
    >>> _isnumber("spam")
    False
    >>> _isnumber("123e45678")
    False
    >>> _isnumber("inf")
    True
    F)infz-infnanT)	r   floatr   r{   r|   mathZisinfZisnanlowerr   r   r   r   	_isnumberY  s    
r   c                 C   s*   t | |u p(t| ts t| to(t|| S )zG
    >>> _isint("123")
    True
    >>> _isint("123.45")
    False
    )typer   r|   r{   r   )r   Zinttyper   r   r   _isinto  s    r   c                 C   s"   t | tu p t| ttfo | dv S )zc
    >>> _isbool(True)
    True
    >>> _isbool("False")
    True
    >>> _isbool(1)
    False
    )TrueFalse)r   
_bool_typer   r|   r{   r   r   r   r   _isbool}  s    	r   c                 C   s   |r t | tst | tr t| } | du r,tS t| dr:tS t| rFtS t| rV|rVt	S t| t
rh|rht	S t| rx|rxtS t | trtS tS dS )a%  The least generic type (type(None), int, float, str, unicode).

    >>> _type(None) is type(None)
    True
    >>> _type("foo") is type("")
    True
    >>> _type("1") is type(1)
    True
    >>> _type('[31m42[0m') is type(42)
    True
    >>> _type('[31m42[0m') is type(42)
    True

    NZ	isoformat)r   r{   r|   _strip_invisible
_none_typer
   r   r   r   int
_long_typer   r   )r   has_invisiblenumparser   r   r   _type  s*    

r   c                 C   s^   t | rVt| rdS | d}|dk r4|  dn|}|dkrPt| | d S dS ndS dS )zSymbols after a decimal point, -1 if the string lacks the decimal point.

    >>> _afterpoint("123.45")
    2
    >>> _afterpoint("1001")
    -1
    >>> _afterpoint("eggs")
    -1
    >>> _afterpoint("123e45")
    2

    .r   er/   N)r   r   rfindr   r;   )r   posr   r   r   _afterpoint  s    
r   c                 C   s   d|  }| |S )uL   Flush right.

    >>> _padleft(6, 'яйца') == '  яйца'
    True

    z{0:>%ds}rV   widthsfmtr   r   r   _padleft  s    r   c                 C   s   d|  }| |S )uL   Flush left.

    >>> _padright(6, 'яйца') == 'яйца  '
    True

    z{0:<%ds}r   r   r   r   r   	_padright  s    r   c                 C   s   d|  }| |S )uN   Center string.

    >>> _padboth(6, 'яйца') == ' яйца '
    True

    z{0:^%ds}r   r   r   r   r   _padboth  s    r   c                 C   s   |S r   r   )Zignore_widthr   r   r   r   _padnone  s    r   c                 C   s8   t | tr&ttd| }ttd|S ttd| S dS )zRemove invisible ANSI color codes.

    >>> str(_strip_invisible('\x1B]8;;https://example.com\x1B\\This is a link\x1B]8;;\x1B\\'))
    'This is a link'

    z\1r   N)r   r{   resub_invisible_codes_link_invisible_codes_invisible_codes_bytes)r   Zlinks_removedr   r   r   r     s    
r   c                 C   sH   t durtrt j}nt}t| ts,t| tr8|t| S |t| S dS )zVisible width of a printed string. ANSI color codes are removed.

    >>> _visible_width('[31mhello[0m'), _visible_width("world")
    (5, 5)

    N)wcwidthWIDE_CHARS_MODEwcswidthr;   r   r{   r|   r   )r   Zlen_fnr   r   r   _visible_width   s    r   c                 C   s.   t | trttt| S ttt| S d S r   )r   r{   boolr   search_multiline_codes_multiline_codes_bytesr   r   r   r   _is_multiline  s    
r   c                 C   s   t t|td| S z1Visible width of a potentially multiline content.[
])maxrv   r   splitZmultiline_sline_width_fnr   r   r   _multiline_width  s    r   c                    s4   | r
t  n|rtj nt |r, fdd}n }|S )z2Return a function to calculate visible cell width.c                    s
   t |  S r   )r   r   r   r   r   <lambda>'  r9   z"_choose_width_fn.<locals>.<lambda>r   r   r   r;   r   enable_widecharsis_multilinewidth_fnr   r   r   _choose_width_fn  s    r   c                    s   |dkr t sdd | D } t}n|dkr@t s:dd | D } t}np|dkr|r\dd | D }ndd | D }t|  fd	dt| |D } t}n |st}nt sd
d | D } t}| |fS )Nr,   c                 S   s   g | ]}|  qS r   r}   r6   r   r   r   r   r8   0  r9   z._align_column_choose_padfn.<locals>.<listcomp>r1   c                 S   s   g | ]}|  qS r   r   r   r   r   r   r8   4  r9   r-   c                 S   s   g | ]}t t|qS r   )r   r   r   r   r   r   r8   8  r9   c                 S   s   g | ]}t |qS r   )r   r   r   r   r   r8   :  r9   c                    s    g | ]\}}| | d   qS rB   r   )r6   r   ZdecsZmaxdecimalsr   r   r8   <  r9   c                 S   s   g | ]}|  qS r   r   r   r   r   r   r8   B  r9   )PRESERVE_WHITESPACEr   r   r   r<   r   r   )stringsrH   r   padfnZdecimalsr   r   r   _align_column_choose_padfn-  s*    r   c                    s4   | r
t  n|rtj nt |r, fdd}n }|S )Nc                    s
   t |  S r   )_align_column_multiline_widthr   r   r   r   r   O  r9   z/_align_column_choose_width_fn.<locals>.<lambda>r   r   r   r   r   _align_column_choose_width_fnG  s    r   c                 C   s   t t|td| S r   )r   rv   r   r   r   r   r   r   r   U  s    r   c                 C   s<   g }| D ].}t |tr,|D ]}|| qq|| q|S r   )r   r   r   )Znested_listZretitemZsubitemr   r   r   
_flat_listZ  s    
r   c                    s   t | ||\} t|||}tt|| }ttt|| |r|s^|s^ fdd| D }qdd | D }	 fddt||	D }
fddt| |
D }n\|s|s fdd| D }n>ttt| }	 fddt||	D }
fddt| |
D }|S )	z[string] -> [padded_string]c                    s*   g | ]"}d   fdd| D qS )rb   c                    s   g | ]} |qS r   r   r   maxwidthr   r   r   r8   y  r9   ,_align_column.<locals>.<listcomp>.<listcomp>)r=   
splitlinesr6   msr   r   r   r8   x  s   z!_align_column.<locals>.<listcomp>c                 S   s"   g | ]}d d t d|D qS )c                 S   s   g | ]}t |qS r   r;   r   r   r   r   r8   ~  r9   r   r   )r   r   r   r   r   r   r8   ~  r9   c                    s(   g | ] \}} fd dt ||D qS )c                    s   g | ]\}} ||  qS r   r   r6   r4   r`   r   r   r   r8     r9   r   )r<   )r6   mwZmlr   r   r   r8     s   c                    s6   g | ].\}}d   fddt| p&||D qS )rb   c                    s   g | ]\}} ||qS r   r   r6   r   r4   r   r   r   r8     r9   r   )r=   r<   r   )r6   r   r   r   r   r   r8     s   c                    s   g | ]} |qS r   r   r   r   r   r   r8     r9   c                    s   g | ]\}} ||  qS r   r   r   r   r   r   r8     r9   c                    s   g | ]\}} ||qS r   r   r   r   r   r   r8     r9   )r   r   r   rv   r   r   r<   r;   )r   rH   Zminwidthr   r   r   r   Zs_widthsZpadded_stringsZs_lensZvisible_widthsr   r   r   _align_columne  s0    	

r   c                 C   sP   t dtdtdtdtdtdi}tttttt d}t|| d||d}|| S )Nr   r/   r   r         )r   r   r   r   r/   r   )r   r   r   r   r|   r{   r   rD   )Ztype1Ztype2typesZinvtypesZmoregenericr   r   r   _more_generic  s     	r   c                    s     fdd| D }t t|tS )u]  The least generic type all column values are convertible to.

    >>> _column_type([True, False]) is _bool_type
    True
    >>> _column_type(["1", "2"]) is _int_type
    True
    >>> _column_type(["1", "2.3"]) is _float_type
    True
    >>> _column_type(["1", "2.3", "four"]) is _text_type
    True
    >>> _column_type(["four", 'пять']) is _text_type
    True
    >>> _column_type([None, "brux"]) is _text_type
    True
    >>> _column_type([1, 2, None]) is _int_type
    True
    >>> import datetime as dt
    >>> _column_type([dt.datetime(1991,2,19), dt.time(17,35)]) is _text_type
    True

    c                    s   g | ]}t | qS r   )r   r   r   r   r   r   r8     r9   z _column_type.<locals>.<listcomp>)r   r   r   )r   r   r   r   r   r   r   _column_type  s    r   c                 C   s   | du r|S |t tfv r"d| S |tu rTzt| dW S  tyP   t|  Y S 0 nZ|tu r|olt| ttf}|rt| }tt||}| ||S tt| |S n
d| S dS )u  Format a value according to its type.

    Unicode is supported:

    >>> hrow = ['буква', 'цифра'] ;         tbl = [['аз', 2], ['буки', 4]] ;         good_result = '\u0431\u0443\u043a\u0432\u0430      \u0446\u0438\u0444\u0440\u0430\n-------  -------\n\u0430\u0437             2\n\u0431\u0443\u043a\u0438           4' ;         tabulate(tbl, headers=hrow) == good_result
    True

    N{0}ascii)	r   r{   rV   r|   r   r   r   r   replace)r   Zvaltypefloatfmt
missingvalr   Zis_a_colored_numberZraw_valZformatted_valr   r   r   _format  s&    
r   c           	         s   |r0t t| } fdd|D }d|S t| | }|7  dkrVt| S  dkrht| S  svd| S t| S dS )zIPad string header to width chars given known visible_width of the header.c                    s   g | ]}t | |qS r   _align_headerr6   hrH   r   r   r   r   r8     s   z!_align_header.<locals>.<listcomp>rb   r2   r1   r   N)	r   r   r   r=   r;   r   r   rV   r   )	r]   rH   r   Zvisible_widthr   r   Zheader_linesZpadded_linesZ
ninvisibler   r  r   r    s    



r  c                 C   sX   |du s|du r| S t |t | kr@td| td|  tddd t|| D } | S )zAdd a left-most index column.NFzindex=zrows=z0index must be as long as the number of data rowsc                 S   s   g | ]\}}|gt | qS r   r   )r6   rN   r   r   r   r   r8     r9   z&_prepend_row_index.<locals>.<listcomp>)r;   printr   r<   )r   indexr   r   r   _prepend_row_index   s    

r	  c                 C   s$   z
t | W S  ty   Y dS 0 dS )zDA wrapper around standard bool() which doesn't throw on NumPy arraysFN)r   r   r~   r   r   r   _bool  s    
r
  c                    s  zt  d}W n ty.   d}tY n0 d}t| drt| drt| jdrr|  tt|   }nt| drt| |dv r| jjdurt	| jjtr| jjdd	< n| jjgdd	< | j}t| j}d
d |D }ntddkrztt
tnlt| }dkr.|s.g nLdkr^t| dr^t| jdr^| jjndkrt|d	krt	|d	 trt|d	 drtt
t|d	 jnt|d	krt|d	 drt|d	 drt }g dkr.t|d	kr|d	 ni     | |dd }|D ]4}| D ]$}	|	|vr>|	 ||	 q>q2dkrxn|t	trfddD tt
tnNdkrt|d	kr fddD tt
tng nrtdfdd|D }nrdkrHt| drHt| drHt| drHdd | jD n2dkrzt|d	krztt
ttt|d	 dkrt|d	kr|dur|d	 gt|d	  |dd }n|d	 tt
t|dd }tt
ttt
t|}t|ttfv }
|dkr.|dur.t||}n|t	|trP|
sPt|t|}nZ|dksjt|r|
s|du rttt|}t||}n|dkst|s|
srt|d	krt}t|d	 }||k rdg||   |fS )a  Transform a supported data type to a list of lists, and a list of headers.

    Supported tabular data types:

    * list-of-lists or another iterable of iterables

    * list of named tuples (usually used with headers="keys")

    * list of dicts (usually used with headers="keys")

    * list of OrderedDicts (usually used with headers="keys")

    * 2D NumPy arrays

    * NumPy record arrays (usually used with headers="keys")

    * dict of iterables (usually used with headers="keys")

    * pandas.DataFrame (usually used with headers="keys")

    The first row can be used as headers if headers="firstrow",
    column indices can be used as headers if headers="keys".

    If showindex="default", show row indices of the pandas.DataFrame.
    If showindex="always", show row indices for all types of data.
    If showindex="never", don't show row indices for all types of data.
    If showindex is an iterable, show its values as row indices.

    FTNkeysrQ   __call__r  )r   alwaysTr   c                 S   s   g | ]}t |qS r   r  r6   r   r   r   r   r8   Q  r9   z+_normalize_tabular_data.<locals>.<listcomp>z7tabular data doesn't appear to be a dict or a DataFramedtypenames_fieldsfirstrowr/   c                    s   g | ]}  ||qS r   rC   r6   k)r   r   r   r8     r9   c                    s   g | ]}  ||qS r   rC   r  )	firstdictr   r   r8     r9   z6headers for a list of dicts is not a dict or a keywordc                    s   g | ]  fd dD qS )c                    s   g | ]}  |qS r   rC   r  r   r   r   r8     r9   z6_normalize_tabular_data.<locals>.<listcomp>.<listcomp>r   r6   )r  r  r   r8     r9   descriptionZfetchoneZrowcountc                 S   s   g | ]}|d  qS )r   r   )r6   columnr   r   r   r8     r9   r   r  neverr   )r   r   r   r
   rQ   r  r   r  namer   rv   r{   getattrr  r  r;   tupler  setextendupdater   adddictr  ranger   r|   r	  r   r
  )tabular_datar   	showindexZis_headers2bool_brokenr  r   ZvalsZ	uniq_keysr   r  Zshowindex_is_a_strZnhsZncolsr   )r  r   r  r   _normalize_tabular_data  s    






.








r&  r   c
                    sV  | du rg } t | ||d\}
}|dkr4t|
|\}
}t|dkrjdd}tkrTdntkrddnn tkrvdntkrd	nd
d
tt|gdd |
D  }tt	|stt
|tduot t|ts
|tv r
t|r
t||}dndt tt|
 }t|t|}dd t||D }t|trdt||g }n6t|}t|t|k r|t|t| tg  t|trt||g }n6t|}t|t|k r|t|t| tg  fddt||||D }fdd|D }|	durRt|	ts6J t|	D ]\}}|||< q>|rlfdd|D ndgt| } fddt|||D }|r
|pdggt| }|pƈgt| }fddt||D }fddt|||D }tt| }nfdd|D }tt| }t|tsDt|td }t|||||S )u,(  Format a fixed width table for pretty printing.

    >>> print(tabulate([[1, 2.34], [-56, "8.999"], ["2", "10001"]]))
    ---  ---------
      1      2.34
    -56      8.999
      2  10001
    ---  ---------

    The first required argument (`tabular_data`) can be a
    list-of-lists (or another iterable of iterables), a list of named
    tuples, a dictionary of iterables, an iterable of dictionaries,
    a two-dimensional NumPy array, NumPy record array, or a Pandas'
    dataframe.


    Table headers
    -------------

    To print nice column headers, supply the second argument (`headers`):

      - `headers` can be an explicit list of column headers
      - if `headers="firstrow"`, then the first row of data is used
      - if `headers="keys"`, then dictionary keys or column indices are used

    Otherwise a headerless table is produced.

    If the number of headers is less than the number of columns, they
    are supposed to be names of the last columns. This is consistent
    with the plain-text format of R and Pandas' dataframes.

    >>> print(tabulate([["sex","age"],["Alice","F",24],["Bob","M",19]],
    ...       headers="firstrow"))
           sex      age
    -----  -----  -----
    Alice  F         24
    Bob    M         19

    By default, pandas.DataFrame data have an additional column called
    row index. To add a similar column to all other types of data,
    use `showindex="always"` or `showindex=True`. To suppress row indices
    for all types of data, pass `showindex="never" or `showindex=False`.
    To add a custom row index column, pass `showindex=some_iterable`.

    >>> print(tabulate([["F",24],["M",19]], showindex="always"))
    -  -  --
    0  F  24
    1  M  19
    -  -  --


    Column alignment
    ----------------

    `tabulate` tries to detect column types automatically, and aligns
    the values properly. By default it aligns decimal points of the
    numbers (or flushes integer numbers to the right), and flushes
    everything else to the left. Possible column alignments
    (`numalign`, `stralign`) are: "right", "center", "left", "decimal"
    (only for `numalign`), and None (to disable alignment).


    Table formats
    -------------

    `floatfmt` is a format specification used for columns which
    contain numeric data with a decimal point. This can also be
    a list or tuple of format strings, one per column.

    `None` values are replaced with a `missingval` string (like
    `floatfmt`, this can also be a list of values for different
    columns):

    >>> print(tabulate([["spam", 1, None],
    ...                 ["eggs", 42, 3.14],
    ...                 ["other", None, 2.7]], missingval="?"))
    -----  --  ----
    spam    1  ?
    eggs   42  3.14
    other   ?  2.7
    -----  --  ----

    Various plain-text table formats (`tablefmt`) are supported:
    'plain', 'simple', 'grid', 'pipe', 'orgtbl', 'rst', 'mediawiki',
    'latex', 'latex_raw', 'latex_booktabs', 'latex_longtable' and tsv.
    Variable `tabulate_formats`contains the list of currently supported formats.

    "plain" format doesn't use any pseudographics to draw tables,
    it separates columns with a double space:

    >>> print(tabulate([["spam", 41.9999], ["eggs", "451.0"]],
    ...                 ["strings", "numbers"], "plain"))
    strings      numbers
    spam         41.9999
    eggs        451

    >>> print(tabulate([["spam", 41.9999], ["eggs", "451.0"]], tablefmt="plain"))
    spam   41.9999
    eggs  451

    "simple" format is like Pandoc simple_tables:

    >>> print(tabulate([["spam", 41.9999], ["eggs", "451.0"]],
    ...                 ["strings", "numbers"], "simple"))
    strings      numbers
    ---------  ---------
    spam         41.9999
    eggs        451

    >>> print(tabulate([["spam", 41.9999], ["eggs", "451.0"]], tablefmt="simple"))
    ----  --------
    spam   41.9999
    eggs  451
    ----  --------

    "grid" is similar to tables produced by Emacs table.el package or
    Pandoc grid_tables:

    >>> print(tabulate([["spam", 41.9999], ["eggs", "451.0"]],
    ...                ["strings", "numbers"], "grid"))
    +-----------+-----------+
    | strings   |   numbers |
    +===========+===========+
    | spam      |   41.9999 |
    +-----------+-----------+
    | eggs      |  451      |
    +-----------+-----------+

    >>> print(tabulate([["spam", 41.9999], ["eggs", "451.0"]], tablefmt="grid"))
    +------+----------+
    | spam |  41.9999 |
    +------+----------+
    | eggs | 451      |
    +------+----------+

    "fancy_grid" draws a grid using box-drawing characters:

    >>> print(tabulate([["spam", 41.9999], ["eggs", "451.0"]],
    ...                ["strings", "numbers"], "fancy_grid"))
    ╒═══════════╤═══════════╕
    │ strings   │   numbers │
    ╞═══════════╪═══════════╡
    │ spam      │   41.9999 │
    ├───────────┼───────────┤
    │ eggs      │  451      │
    ╘═══════════╧═══════════╛

    "pipe" is like tables in PHP Markdown Extra extension or Pandoc
    pipe_tables:

    >>> print(tabulate([["spam", 41.9999], ["eggs", "451.0"]],
    ...                ["strings", "numbers"], "pipe"))
    | strings   |   numbers |
    |:----------|----------:|
    | spam      |   41.9999 |
    | eggs      |  451      |

    "presto" is like tables produce by the Presto CLI:

    >>> print(tabulate([["spam", 41.9999], ["eggs", "451.0"]],
    ...                ["strings", "numbers"], "presto"))
     strings   |   numbers
    -----------+-----------
     spam      |   41.9999
     eggs      |  451

    >>> print(tabulate([["spam", 41.9999], ["eggs", "451.0"]], tablefmt="pipe"))
    |:-----|---------:|
    | spam |  41.9999 |
    | eggs | 451      |

    "orgtbl" is like tables in Emacs org-mode and orgtbl-mode. They
    are slightly different from "pipe" format by not using colons to
    define column alignment, and using a "+" sign to indicate line
    intersections:

    >>> print(tabulate([["spam", 41.9999], ["eggs", "451.0"]],
    ...                ["strings", "numbers"], "orgtbl"))
    | strings   |   numbers |
    |-----------+-----------|
    | spam      |   41.9999 |
    | eggs      |  451      |


    >>> print(tabulate([["spam", 41.9999], ["eggs", "451.0"]], tablefmt="orgtbl"))
    | spam |  41.9999 |
    | eggs | 451      |

    "rst" is like a simple table format from reStructuredText; please
    note that reStructuredText accepts also "grid" tables:

    >>> print(tabulate([["spam", 41.9999], ["eggs", "451.0"]],
    ...                ["strings", "numbers"], "rst"))
    =========  =========
    strings      numbers
    =========  =========
    spam         41.9999
    eggs        451
    =========  =========

    >>> print(tabulate([["spam", 41.9999], ["eggs", "451.0"]], tablefmt="rst"))
    ====  ========
    spam   41.9999
    eggs  451
    ====  ========

    "mediawiki" produces a table markup used in Wikipedia and on other
    MediaWiki-based sites:

    >>> print(tabulate([["strings", "numbers"], ["spam", 41.9999], ["eggs", "451.0"]],
    ...                headers="firstrow", tablefmt="mediawiki"))
    {| class="wikitable" style="text-align: left;"
    |+ <!-- caption -->
    |-
    ! strings   !! align="right"|   numbers
    |-
    | spam      || align="right"|   41.9999
    |-
    | eggs      || align="right"|  451
    |}

    "html" produces HTML markup as an html.escape'd str
    with a ._repr_html_ method so that Jupyter Lab and Notebook display the HTML
    and a .str property so that the raw HTML remains accessible
    the unsafehtml table format can be used if an unescaped HTML format is required:

    >>> print(tabulate([["strings", "numbers"], ["spam", 41.9999], ["eggs", "451.0"]],
    ...                headers="firstrow", tablefmt="html"))
    <table>
    <thead>
    <tr><th>strings  </th><th style="text-align: right;">  numbers</th></tr>
    </thead>
    <tbody>
    <tr><td>spam     </td><td style="text-align: right;">  41.9999</td></tr>
    <tr><td>eggs     </td><td style="text-align: right;"> 451     </td></tr>
    </tbody>
    </table>

    "latex" produces a tabular environment of LaTeX document markup:

    >>> print(tabulate([["spam", 41.9999], ["eggs", "451.0"]], tablefmt="latex"))
    \begin{tabular}{lr}
    \hline
     spam &  41.9999 \\
     eggs & 451      \\
    \hline
    \end{tabular}

    "latex_raw" is similar to "latex", but doesn't escape special characters,
    such as backslash and underscore, so LaTeX commands may embedded into
    cells' values:

    >>> print(tabulate([["spam$_9$", 41.9999], ["\\emph{eggs}", "451.0"]], tablefmt="latex_raw"))
    \begin{tabular}{lr}
    \hline
     spam$_9$    &  41.9999 \\
     \emph{eggs} & 451      \\
    \hline
    \end{tabular}

    "latex_booktabs" produces a tabular environment of LaTeX document markup
    using the booktabs.sty package:

    >>> print(tabulate([["spam", 41.9999], ["eggs", "451.0"]], tablefmt="latex_booktabs"))
    \begin{tabular}{lr}
    \toprule
     spam &  41.9999 \\
     eggs & 451      \\
    \bottomrule
    \end{tabular}

    "latex_longtable" produces a tabular environment that can stretch along
    multiple pages, using the longtable package for LaTeX.

    >>> print(tabulate([["spam", 41.9999], ["eggs", "451.0"]], tablefmt="latex_longtable"))
    \begin{longtable}{lr}
    \hline
     spam &  41.9999 \\
     eggs & 451      \\
    \hline
    \end{longtable}


    Number parsing
    --------------
    By default, anything which can be parsed as a number is a number.
    This ensures numbers represented as strings are aligned properly.
    This can lead to weird results for particular strings such as
    specific git SHAs e.g. "42992e1" will be parsed into the number
    429920 and aligned as such.

    To completely disable number parsing (and alignment), use
    `disable_numparse=True`. For more fine grained control, a list column
    indices is used to disable number parsing only on those columns
    e.g. `disable_numparse=[0, 2]` would disable number parsing only on the
    first and third columns.
    N)r%  r   r   r   Tr1   r-   r2   r   c                 S   s   g | ]}d  tt|qS )r   )r=   rv   r{   r  r   r   r   r8     r9   ztabulate.<locals>.<listcomp>Fc                 S   s   g | ]\}}t ||d qS ))r   )r   )r6   colZnpr   r   r   r8   (  r9   c                    s,   g | ]$\}  fd d|D qS )c                    s   g | ]}t | qS r   )r   )r6   rN   )ctfl_fmtr   miss_vr   r   r8   8  r9   z'tabulate.<locals>.<listcomp>.<listcomp>r   r6   rF   )r   )r(  r)  r*  r   r8   7  s   
c                    s    g | ]}|t tfv r nqS r   )r   r   )r6   r(  )numalignstralignr   r   r8   =  r9   c                    s   g | ]}|  qS r   r   r  )min_paddingr   r   r   r8   C  r9   c              	      s$   g | ]\}}}t ||| qS r   )r   )r6   rF   r7   minw)r   r   r   r   r   r8   E  s   r   c                    s,   g | ]$\}}t |t  fd d|D qS )c                 3   s   | ]} |V  qd S r   r   r6   clr   r   r   rO   O  r9   &tabulate.<locals>.<listcomp>.<genexpr>r   )r6   r/  rF   r2  r   r   r8   N  s   c              	      s(   g | ] \}}}t |||| qS r   r  )r6   r  r7   r/  )r   r   r   r   r8   R  s   c                    s"   g | ]}t  fd d|D qS )c                 3   s   | ]} |V  qd S r   r   r0  r2  r   r   rO   X  r9   r3  r4  r+  r2  r   r   r8   X  r9   r   ) r&  r   MIN_PADDING_DEFAULT_ALIGNr=   rv   r{   r   r   r   r   r   r   r   r#   multiline_formatsr   rD   r   r   r   _expand_numparser;   r<   
basestringr  _DEFAULT_FLOATFMT_DEFAULT_MISSINGVALr   	enumerate_table_formats_format_table)r$  r   tablefmtr   r,  r-  r   r%  disable_numparsecolalignZlist_of_listsZ
plain_textZcols	numparsesZcoltypesZfloat_formatsZmissing_valsZalignsidxr3   Z	minwidthsZt_colsZt_alignsr   r   )r   r   r   r.  r,  r-  r   r   r     s      8


&


r   c                 C   s:   t | tr*dg| }| D ]}d||< q|S |  g| S dS )aB  
    Return a list of bools of length `column_count` which indicates whether
    number parsing should be used on each column.
    If `disable_numparse` is a list of indices, each of those indices are False,
    and everything else is True.
    If `disable_numparse` is a bool, then the returned list is all the same.
    TFN)r   r   )r@  Zcolumn_countrB  r  r   r   r   r8  a  s    


r8  c                    s*   | r"d|   fdd| D }|S | S d S )NrB   c                    s   g | ]} |   qS r   r   rw   padr   r   r8   u  r9   z_pad_row.<locals>.<listcomp>r   )cellsr*   padded_cellsr   rD  r   _pad_rowr  s
    rH  c                 C   s    |\}}}|| |  |  S )z7Format row according to DataRow format without padding.)r=   rI   )rG  ry   r   r    r!   r   r   r   rx   {  s    
rx   c                 C   s,   |sdS t |dr|| ||S t| |S dS )z5Return a string which represents a row of data cells.Nr  r
   rx   )rG  r>   r?   ry   r   r   r   
_build_row  s
    
rJ  c                 C   s   |  t|||| | S r   )r   rJ  )linesrG  r>   r?   ry   r   r   r   _append_basic_row  s    rL  c           
         s   fdd|D }dd |D  t tt fddt |D   fddtD }|D ]}t|}	t| |	||| q`| S )Nc                    s   g | ]}|d    qS r   r   r6   r4   rD  r   r   r8     r9   z)_append_multiline_row.<locals>.<listcomp>c                 S   s   g | ]}|  qS r   )r   r+  r   r   r   r8     r9   c                    s*   g | ]"\}}|d | g t |   qS r   r   )r6   r1  r4   )nlinesr   r   r8     s   c                    s   g | ]  fd dD qS )c                    s   g | ]}|  qS r   r   r0  ir   r   r8     r9   z4_append_multiline_row.<locals>.<listcomp>.<listcomp>r   r  )cells_linesrP  r   r8     r9   )r   rv   r;   r<   r#  rH  rL  )
rK  Zpadded_multiline_cellspadded_widthsr?   ry   rE  r>   Zlines_cellsZlnZ	padded_lnr   )rR  rO  rE  r   _append_multiline_row  s    

rT  c                    sN   |sdS t |dr|| |S |\} }} fdd| D }t||||fS dS )z3Return a string which represents a horizontal line.Nr  c                    s   g | ]} | qS r   r   rN  Zfillr   r   r8     r9   z_build_line.<locals>.<listcomp>rI  )r>   r?   linefmtr   r    r!   rF  r   rU  r   _build_line  s    

rW  c                 C   s   |  t||| | S r   )r   rW  )rK  r>   r?   rV  r   r   r   _append_line  s    rX  c                   @   s$   e Zd ZdZdd Zedd ZdS )JupyterHTMLStrzUWrap the string with a _repr_html_ method so that Jupyter
    displays the HTML tablec                 C   s   | S r   r   selfr   r   r   _repr_html_  s    zJupyterHTMLStr._repr_html_c                 C   s   | S )z>add a .str property so that the raw string is still accessibler   rZ  r   r   r   str  s    zJupyterHTMLStr.strN)__name__
__module____qualname____doc__r\  propertyr]  r   r   r   r   rY    s   rY  c                    s  g }|r| j r| j ng }| j | j} fdd|D }	|rPdd tt d}
ntt}
| } fdd|D }| jrd|vrt||	|| j |r|
|||	|| | j	rd|vrt||	|| j	 |r*| j
r*d	|vr*|d
d D ]&}|
|||	|| j t||	|| j
 q|
||d |	|| j n|D ]}|
|||	|| j q.| jrjd|vrjt||	|| j |sv|rd|}| jtkrt|S |S ndS d
S )z1Produce a plain-text representation of the table.c                    s   g | ]}|d    qS rM  r   rN  rD  r   r   r8     r9   z!_format_table.<locals>.<listcomp>c                 S   s   | S r   r   )r   rl   r   r   r   r     r9   z_format_table.<locals>.<lambda>rD  c                    s   g | ]}| qS r   r   r  rE  Zpad_rowr   r   r8     r9   r$   r%   r&   Nr   r'   rb   r   )r+   r*   r(   r   rT  rH  rL  r$   rX  r%   r&   r)   r'   r=   rS   rY  )r   r   r   r>   r?   r   rK  Zhiddenr(   rS  Z
append_rowZpadded_headersZpadded_rowsr   outputr   rc  r   r>    sB    

r>  c                  C   s  ddl } ddl}ddl}|tj}z$|  |jdd dg d\}}W n@ | jy } z&t| t| |	d W Y d}~n
d}~0 0 g }t
}d}	d}
d}d	}|D ]\}}|d
v rd}q|dv r|}q|dv r|}q|dv r| }	q|dv r"|tvrtd|  t| |	d |}
q|dv r2|}q|dv rt| |	d q|s\|jgn|}|d	krp|jnt|d}|D ]x}|d	kr|j}t|rt|||
||||	d n@t|&}t|||
||||	d W d   n1 s0    Y  qW d   n1 s0    Y  dS )a      Usage: tabulate [options] [FILE ...]

    Pretty-print tabular data.
    See also https://github.com/astanin/python-tabulate

    FILE                      a filename of the file with tabular data;
                              if "-" or missing, read data from stdin.

    Options:

    -h, --help                show this message
    -1, --header              use the first row of data as a table header
    -o FILE, --output FILE    print table to FILE (default: stdout)
    -s REGEXP, --sep REGEXP   use a custom column separator (default: whitespace)
    -F FPFMT, --float FPFMT   floating point number format (default: g)
    -f FMT, --format FMT      set output table format; supported formats:
                              plain, simple, grid, fancy_grid, pipe, orgtbl,
                              rst, mediawiki, html, latex, latex_raw,
                              latex_booktabs, latex_longtable, tsv
                              (default: simple)
    r   Nr/   zh1o:s:F:A:f:)helpr]   rd  zsep=zfloat=zalign=zformat=r   r   z\s+r.   )z-1z--headerr  )z-oz--output)z-Fz--float)z-Cz
--colalign)z-fz--formatz"%s is not a supported table formatr   )z-sz--sep)z-hz--helpr4   )r   r?  r    r   filerA  )getoptsystextwrapdedent_mainra  argvZGetoptErrorr  exitr:  r   r   stdinstdoutopenr   _pprint_file)rg  rh  ri  ZusageZoptsargsr   r   r   rA  r?  r    ZoutfileZoptvaluefilesoutr   Zfobjr   r   r   rk    s     








rk  c           	         s8   |   } fdd|D }tt|||||d|d d S )Nc                    s$   g | ]}|  rt | qS r   )r}   r   r   rI   )r6   ra   r    r   r   r8   O  r9   z _pprint_file.<locals>.<listcomp>)r   rA  )rf  )	readlinesr  r   )	Zfobjectr   r?  r    r   rf  rA  r   tabler   rv  r   rq  M  s    rq  __main__)r   )FF)TT)r   TFF)TT)r   T)FN)r   )wra  Z
__future__r   r   collectionsr   rh  r   r   version_infocollections.abcr   	itertoolsr   	functoolsr   r   r   r   r   r   Z	_int_typeZlongr   r   Z_float_typeZunicoder{   r]  r|   r   r   r   bytesr9  r   r   ImportErrorr   r   rY   Zcgi__all____version__r5  r   r:  r;  r6  r   r   r"   r#   r5   r@   rM   rR   rS   r[   r_   rg   ZLATEX_ESCAPE_RULESrz   r   r=  r   sortedr  r   r7  compiler   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   r   r   r   r   r  r	  r
  r&  r   r8  rH  rx   rJ  rL  rT  rW  rX  rY  r>  rk  rq  r^  r   r   r   r   <module>   s4  


"	

	




























































  z


'    
1

% 

 /
   $	
2\	
