a
    J5d                  !   @   sf	  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ddl	Z	ej
dkr`d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&y0   dZ%Y n0 zddl'm(Z) W n  e&yb   ddl*m(Z) Y n0 g dZ+dZ,dZ-dZ.dZ/dZ0dZ1e%duZ2edg dZ3edg dZ4edg dZ5dd Z6d d! Z7d"d# Z8d$d% Z9d&d' Z:d(d) Z;dd*d+Z<dd,d-Z=d.d/d0d1d2d3d4d5d6d7d8d9d:Z>e>fd;d<Z?d=d> Z@e5e3dd?d@de3dd?d@dde3dd?d@de4dd@de4dd@dddAdBgde5dddde4dd@de4dd@dddde5e3dCd?dCdCe3dCdDdCdCe3dCd?dCdCe3dCd?dCdCe4dEdEdEe4dEdEdEdFdde5e3dGdHdIdJe3dKdHdLdMe3dNdOdPdQe3dRdHdSdTe4dUdUdUe4dUdUdUdFdde5e3dGdHdIdJe3dKdHdLdMde3dRdHdSdTe4dUdUdUe4dUdUdUdFdde5e3dEd?dEdEe3dEd?dEdEdde4dEdEdEe4dEdEdEdFdAgde5e7e7dde4dEdEdEe4dEdEdEdFdAgde5de3dEd?dCdEdde4dEdEdEe4dEdEdEdFdde5dddde4dVdVdVe4dEdEdEdFdde5de3dd?dCddde4ddEde4ddEddFdde5e3dCd?dCdCe3dCd?dCdCde3dCd?dCdCe4dEdEdEe4dEdEdEdFdde5e3dCd?dCdCe3dEd?dCdEde3dCd?dCdCe4dEdEdEe4dEdEdEdFdde5e3ddDd@de3ddDd@dde3ddDd@de4dd@de4dd@dddde5e3dWdddXe3dYddde3dYddde3dZdddee8d[ee8dEddde5ddddee<dVd\d]ee<dVdFdde5dddde4d^d_d_e4d`dadbdFdde5e:dde3dcdddee;dddee;dedddAgde5e:dde3dcdddee;dddfee;dedfddAgde5e=e3dgdddde3dhddde?e?dFdde5e=e3dgdddde3dhdddee?i diee?i didFdde5ee=dfdje3dkdddde3dlddde?e?dFdde5ee=dfdme3dndddde3doddde?e?dFdde5dddde4ddpde4ddpdddde5dddde4dqdrdEe9dFdddsZAeBeCeAD ZEdtdudvdwdxdydzd{d|d}d~dZFeGdZHeGdZIeGdZJeGdZKeGdZLdZMeGdZNdd ZOdd ZPdd ZQdd ZRefddZSdd ZTdddZUdd ZVdd ZWdd ZXdd ZYdd ZZdd Z[dd Z\dd Z]e^fddZ_dd Z`dd Zadd Zbe^fddZcdd ZddddZedd ZfdddZgdddZhdddZidd Zjdd ZkdddZldddZmddue/e1e1e0ddddf
ddńZnddǄ ZoddɄ Zpdd˄ Zqdd̈́ Zrddτ Zsddф Ztddӄ ZuddՄ Zvddׄ ZwG ddل deZxddۄ ZyG dd݄ de	jzZ{dd߄ Z|dd Z}e~dk	rbe|  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   D/var/www/html/django/DPS/env/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.10   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   )aligncolwidthwr   r   r   _pipe_segment_with_colons   s    r6   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   )r6   ).0ar5   r   r   r   
<listcomp>       z*_pipe_line_with_colons.<locals>.<listcomp>|)lenzipjoin)	colwidths	colalignssegmentsr   r   r   _pipe_line_with_colons   s    rB   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r7   cr8   	alignmentr   r   r9      s   z-_mediawiki_row_with_attrs.<locals>.<listcomp>r   )r=   r>   rstrip)	separatorcell_valuesr?   r@   values_with_attrsZcolsepr   rI   r   _mediawiki_row_with_attrs   s    
rO   c                    sH   | d  d7  < ddddd  fddt || D }d	d	| d	 S )
Nr   rD   z<.z>.z=.rC   c                 3   s"   | ]\}}  |d | V  qdS )r   NrE   )r7   r8   vrI   r   r   	<genexpr>   r:   z*_textile_row_with_attrs.<locals>.<genexpr>r;   r=   r>   )rM   r?   r@   valuesr   rI   r   _textile_row_with_attrs   s    rT   c                 C   s   dS )Nz<table>
<tbody>r   )Zcolwidths_ignoreZcolaligns_ignorer   r   r    _html_begin_table_without_header   s    rU   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;"rC   c              	      s&   g | ]\}}d   |d|qS z<{0}{1}>{2}</{0}>r   formatrF   rG   rJ   celltagr   r   r9      s   z(_html_row_with_attrs.<locals>.<listcomp>c              	      s*   g | ]"\}}d   |dt|qS rV   )rX   rF   
htmlescaperG   rY   r   r   r9      s   z<tr>{}</tr>thz#<table>
<thead>
{}
</thead>
<tbody>)r=   rX   r>   rK   )rZ   unsaferM   r?   r@   rN   Zrowhtmlr   rY   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;">rC   c              	      s.   g | ]&\}}d   |d|  qS )z{0}{1} {2} r   rW   rG   rJ   rZ   headerr   r   r9      s   z(_moin_row_with_attrs.<locals>.<listcomp>||rR   )rZ   rM   r?   r@   r`   rN   r   r_   r   _moin_row_with_attrs   s    rb   c                    sL   ddddd d  fdd|D }d |s2d	nd
| d |rDdndgS )NlrrH   rC   r   c                    s   g | ]}  |d qS )rc   rE   )r7   r8   rI   r   r   r9      r:   z-_latex_line_begin_tabular.<locals>.<listcomp>
z\begin{tabular}{z\begin{longtable}{}z\toprule\hline)r>   )r?   r@   booktabs	longtableZtabular_columns_fmtr   rI   r   _latex_line_begin_tabular   s    

rj   z\&z\%z\$z\#z\_z\^{}z\{z\}z\textasciitilde{}z\textbackslash{}z\ensuremath{<}z\ensuremath{>})&%$#_^{rf   ~\<>c                    s4   fdd  fdd| D }t ddd}t||S )Nc                    s     | | S r   rE   )rH   escrulesr   r   escape_char   s    z_latex_row.<locals>.escape_charc                    s   g | ]}d  t |qS )r   )r>   mapr7   cell)rx   r   r   r9     r:   z_latex_row.<locals>.<listcomp>r   rk   z\\)r"   _build_simple_row)rM   r?   r@   rw   Zescaped_valuesrowfmtr   )rx   rw   r   
_latex_row   s    r~   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   new_headersZnew_rowsrow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   │ra   z.{| class="wikitable" style="text-align: left;"z
|+ <!-- caption -->
|-z|-z|}!z''')r`   z|| z || z| z | z |z</tbody>
</table>r\   tdTrg   z\hline
\end{tabular}rv   )rh   z\midrulez\bottomrule
\end{tabular})ri   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
unsafehtml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\\z[0mz>^(([+-]?[0-9]{1,3})(?:,([0-9]{3}))*)?(?(1)\.[0-9]*|\.[0-9]+)?$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"   )rL   r   r   r   r   C  s    

r   c              	   C   s4   z|   } W n ttfy"   Y n0 ttt| S )a  
    >>> _isnumber_with_thousands_separator(".")
    False
    >>> _isnumber_with_thousands_separator("1")
    True
    >>> _isnumber_with_thousands_separator("1.")
    True
    >>> _isnumber_with_thousands_separator(".1")
    True
    >>> _isnumber_with_thousands_separator("1000")
    False
    >>> _isnumber_with_thousands_separator("1,000")
    True
    >>> _isnumber_with_thousands_separator("1,0000")
    False
    >>> _isnumber_with_thousands_separator("1,000.1234")
    True
    >>> _isnumber_with_thousands_separator(b"1,000.1234")
    True
    >>> _isnumber_with_thousands_separator("+1,000.1234")
    True
    >>> _isnumber_with_thousands_separator("-1,000.1234")
    True
    )decodeUnicodeDecodeErrorAttributeErrorboolrematch _float_with_thousands_separatorsstringr   r   r   "_isnumber_with_thousands_separatorW  s
    r   c              	   C   s,   z| | W dS  t tfy&   Y dS 0 d S )NTF)
ValueError	TypeError)convr   r   r   r   _isconvertiblex  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   mathisinfisnanlowerr   r   r   r   	_isnumber  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   _isint  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

    N	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   sf   t | st| r^t| rdS | d}|dk r<|  dn|}|dkrXt| | d S dS ndS dS )a  Symbols 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
    >>> _afterpoint("123,456.78")
    2

    .r   er/   N)r   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}rX   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   r   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   r   r   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.[
])maxry   r   splitZmultiline_sline_width_fnr   r   r   _multiline_widthB  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>P  r:   z"_choose_width_fn.<locals>.<lambda>r   r   r   r<   r   enable_widecharsis_multilinewidth_fnr   r   r   _choose_width_fnG  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   r7   r   r   r   r   r9   Y  r:   z._align_column_choose_padfn.<locals>.<listcomp>r1   c                 S   s   g | ]}|  qS r   r   r   r   r   r   r9   ]  r:   r-   c                 S   s   g | ]}t t|qS r   )r   r   r   r   r   r   r9   a  r:   c                 S   s   g | ]}t |qS r   )r   r   r   r   r   r9   c  r:   c                    s    g | ]\}}| | d   qS rD   r   )r7   r   ZdecsZmaxdecimalsr   r   r9   e  r:   c                 S   s   g | ]}|  qS r   r   r   r   r   r   r9   k  r:   )PRESERVE_WHITESPACEr   r   r   r=   r   r   )stringsrJ   r   padfnZdecimalsr   r   r   _align_column_choose_padfnV  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   x  r:   z/_align_column_choose_width_fn.<locals>.<lambda>r   r   r   r   r   _align_column_choose_width_fnp  s    r   c                 C   s   t t|td| S r   )r   ry   r   r   r   r   r   r   r   ~  s    r   c                 C   s<   g }| D ].}t |tr,|D ]}|| qq|| q|S r   )r   r   r   )Znested_listretitemsubitemr   r   r   
_flat_list  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 )re   c                    s   g | ]} |qS r   r   r   maxwidthr   r   r   r9     r:   ,_align_column.<locals>.<listcomp>.<listcomp>)r>   
splitlinesr7   msr   r   r   r9     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   r9     r:   r   r   )r   r   r   r   r   r   r9     r:   c                    s(   g | ] \}} fd dt ||D qS )c                    s   g | ]\}} ||  qS r   r   r7   r5   rc   r   r   r   r9     r:   r   )r=   )r7   mwmlr  r   r   r9     s   c                    s6   g | ].\}}d   fddt| p&||D qS )re   c                    s   g | ]\}} ||qS r   r   r7   r   r5   r   r   r   r9     r:   r   )r>   r=   r   )r7   r  r  r  r   r   r9     s   c                    s   g | ]} |qS r   r   r   r   r   r   r9     r:   c                    s   g | ]\}} ||  qS r   r   r  r  r   r   r9     r:   c                    s   g | ]\}} ||qS r   r   r  r  r   r   r9     r:   )r   r   r   ry   r   r   r=   r<   )r   rJ   Zminwidthr   r   r   r   Zs_widthsZpadded_stringsZs_lensZvisible_widthsr   r   r   _align_column  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   rF   )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   r9     r:   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   rX   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r7   hrJ   r   r   r   r   r9     s   z!_align_header.<locals>.<listcomp>re   r2   r1   r  N)	r   r   r   r>   r<   r   r   rX   r   )	r`   rJ   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   )r7   rP   r   r   r   r   r9   1  r:   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   _bool5  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keysrS   __call__r  )r   alwaysTr   c                 S   s   g | ]}t |qS r   r  r7   r   r   r   r   r9   z  r:   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   rE   r7   k)r   r   r   r9     r:   c                    s   g | ]}  ||qS r   rE   r(  )	firstdictr   r   r9     r:   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   rE   r(  r   r   r   r9     r:   z6_normalize_tabular_data.<locals>.<listcomp>.<listcomp>r   r7   )r   r+  r   r9     r:   descriptionZfetchoneZrowcountc                 S   s   g | ]}|d  qS )r   r   )r7   columnr   r   r   r9     r:   r   r"  neverr   )r   r   r   r
   rS   r   r   r  namer   ry   r   getattrr$  r%  r<   tupler&  setextendupdater   adddictr-  ranger   r   r  r   r  )tabular_datar   	showindexZis_headers2bool_brokenr  r   valsZ	uniq_keysr   r)  Zshowindex_is_a_strZnhsZncolsr   )r*  r   r   r   _normalize_tabular_data=  s    






.








r<  c                 C   s   t |t| d d}g }| D ]z}g }t|||D ]Z\}}}t|rR|rR|| q0|d urt|d}	|	|}
|d|
 q0|| q0|| q|S )Nr   T)r   re   )_expand_iterabler<   r=   r   r   _CustomTextWrapwrapr>   )list_of_listsr?   	numparsesresultr   r   r{   r   r   wrapperwrappedr   r   r   _wrap_text_to_colwidths  s    


rE  r   c                    s  | du rg } t | ||d\}}|
durnt|d }t|
trJt|
||
}
nt|
|d}
t||}t||
|d}|dkrt||\}}t|dkrdd}t	krdnt	krdnn t	krd	nt	krd
nd
d
tt|gdd |D  }tt|stt|tduo*t t|ts^|tv r^t|r^t||}dndt tt| }t|t|}dd t||D }t|trt||g }n6t|}t|t|k r|t|t| tg  t|tr
t||g }n6t|}t|t|k r@|t|t| tg  fddt||||D }fdd|D }|	durt|	tsJ t |	D ]\}}|||< q|rfdd|D ndgt| } fddt|||D }|r^|pd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st!|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.

    Column Widths and Auto Line Wrapping
    ------------------------------------
    Tabulate will, by default, set the width of each column to the length of the
    longest element in that column. However, in situations where fields are expected
    to reasonably be too long to look good as a single line, tabulate can help automate
    word wrapping long fields for you. Use the parameter `maxcolwidth` to provide a
    list of maximal column widths

    >>> print(tabulate(           [('1', 'John Smith',             'This is a rather long description that might look better if it is wrapped a bit')],           headers=("Issue Id", "Author", "Description"),           maxcolwidths=[None, None, 30],           tablefmt="grid"          ))
    +------------+------------+-------------------------------+
    |   Issue Id | Author     | Description                   |
    +============+============+===============================+
    |          1 | John Smith | This is a rather long         |
    |            |            | description that might look   |
    |            |            | better if it is wrapped a bit |
    +------------+------------+-------------------------------+


    N)r:  r   )rA  r   r   Tr1   r-   r2   r   c                 S   s   g | ]}d  tt|qS )r   )r>   ry   r   r#  r   r   r   r9   y  r:   ztabulate.<locals>.<listcomp>Fc                 S   s   g | ]\}}t ||d qS ))r   )r  )r7   colnpr   r   r   r9     r:   c                    s,   g | ]$\}  fd d|D qS )c                    s   g | ]}t | qS r   )r  )r7   rP   )ctfl_fmtr   miss_vr   r   r9     r:   z'tabulate.<locals>.<listcomp>.<listcomp>r   r7   rH   )r   )rH  rI  rJ  r   r9     s   
c                    s    g | ]}|t tfv r nqS r   )r   r   )r7   rH  )numalignstralignr   r   r9     r:   c                    s   g | ]}|  qS r   r   r  )min_paddingr   r   r   r9     r:   c              	      s$   g | ]\}}}t ||| qS r   )r	  )r7   rH   r8   minw)r   r   r   r   r   r9     s   r   c                    s,   g | ]$\}}t |t  fd d|D qS )c                 3   s   | ]} |V  qd S r   r   r7   clr   r   r   rQ     r:   &tabulate.<locals>.<listcomp>.<genexpr>r   )r7   rO  rH   rR  r   r   r9     s   c              	      s(   g | ] \}}}t |||| qS r   r  )r7   r  r8   rO  )r   r   r   r   r9     s   c                    s"   g | ]}t  fd d|D qS )c                 3   s   | ]} |V  qd S r   r   rP  rR  r   r   rQ     r:   rS  rT  rK  rR  r   r   r9     r:   r   )#r<  r<   r   r   r=  _expand_numparserE  r   MIN_PADDING_DEFAULT_ALIGNr>   ry   r   r   r   r   r   r   r   r#   multiline_formatsr   rF   r   r   r   r=   
basestringr4  _DEFAULT_FLOATFMT_DEFAULT_MISSINGVALr   	enumerate_table_formats_format_table)r9  r   tablefmtr  rL  rM  r  r:  disable_numparsecolalignZmaxcolwidthsr@  Znum_colsrA  
plain_textcolsZcoltypesZfloat_formatsZmissing_valsZalignsidxr3   Z	minwidthsZt_colsZt_alignsr   r   )r   r   r   rN  rL  rM  r   r   r      s      R




&


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`  column_countrA  r  r   r   r   rU    s    


rU  c                 C   s.   t | tr | |g|t|    S |g| S dS )aY  
    Expands the `original` argument to return a return a list of
    length `num_desired`. If `original` is shorter than `num_desired`, it will
    be padded with the value in `default`.
    If `original` is not a list to begin with (i.e. scalar value) a list of
    length `num_desired` completely populated with `default will be returned
    N)r   r   r<   )originalZnum_desiredr   r   r   r   r=    s    
r=  c                    s*   | r"d|   fdd| D }|S | S d S )NrD   c                    s   g | ]} |   qS r   r   rz   padr   r   r9     r:   z_pad_row.<locals>.<listcomp>r   )cellsr*   padded_cellsr   rg  r   _pad_row  s
    rk  c                 C   s    |\}}}|| |  |  S )z7Format row according to DataRow format without padding.)r>   rK   )rj  r}   r   r    r!   r   r   r   r|     s    
r|   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
   r|   )rj  r?   r@   r}   r   r   r   
_build_row  s
    
rm  c                 C   s   |  t|||| | S r   )r   rm  )linesrj  r?   r@   r}   r   r   r   _append_basic_row  s    ro  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   r7   r5   rg  r   r   r9     r:   z)_append_multiline_row.<locals>.<listcomp>c                 S   s   g | ]}|  qS r   )r   rK  r   r   r   r9     r:   c                    s*   g | ]"\}}|d | g t |   qS r   r  )r7   rQ  r5   )nlinesr   r   r9     s   c                    s   g | ]  fd dD qS )c                    s   g | ]}|  qS r   r   rP  ir   r   r9     r:   z4_append_multiline_row.<locals>.<listcomp>.<listcomp>r   r,  )cells_linesrs  r   r9     r:   )r   ry   r<   r=   r8  rk  ro  )
rn  Zpadded_multiline_cellspadded_widthsr@   r}   rh  r?   Zlines_cellslnZ	padded_lnr   )ru  rr  rh  r   _append_multiline_row  s    

rx  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   rq  fillr   r   r9     r:   z_build_line.<locals>.<listcomp>rl  )r?   r@   linefmtr   r    r!   ri  r   ry  r   _build_line  s    

r|  c                 C   s   |  t||| | S r   )r   r|  )rn  r?   r@   r{  r   r   r   _append_line!  s    r}  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   r  r   r   r   str-  s    zJupyterHTMLStr.strN)__name__
__module____qualname____doc__r  propertyr  r   r   r   r   r~  &  s   r~  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 rp  r   rq  rg  r   r   r9   :  r:   z!_format_table.<locals>.<listcomp>c                 S   s   | S r   r   )r   ro   r   r   r   r   <  r:   z_format_table.<locals>.<lambda>rg  c                    s   g | ]}| qS r   r   r#  rh  Zpad_rowr   r   r9   C  r:   r$   r%   r&   Nr   r'   re   r   )r+   r*   r(   r   rx  rk  ro  r$   r}  r%   r&   r)   r'   r>   rU   r~  )r   r   r   r?   r@   r   rn  Zhiddenr(   rv  Z
append_rowZpadded_headersZpadded_rowsr   outputr   r  r   r^  3  sB    

r^  c                   @   s<   e Zd ZdZdd Zedd Zdd Zdd	 Zd
d Z	dS )r>  a[  A custom implementation of CPython's textwrap.TextWrapper. This supports
    both wide characters (Korea, Japanese, Chinese)  - including mixed string.
    For the most part, the `_handle_long_word` and `_wrap_chunks` functions were
    copy pasted out of the CPython baseline, and updated with our custom length
    and line appending logic.
    c                 O   s*   g | _ d | _tjj| g|R i | d S r   )_active_codes	max_linestextwrapTextWrapper__init__)r  argskwargsr   r   r   r  m  s    z_CustomTextWrap.__init__c                 C   s"   t | }trt|S t|S dS )zqCustom len that gets console column width for wide
        and non-wide characters as well as ignores color codesN)r   r   r   r<   )r   strippedr   r   r   _lenr  s    
z_CustomTextWrap._lenc                 C   s~   dd t t|D }dd |D }d| j| }|D ] }|tkrR| j| q8g | _q8t| jdkrp|t }|| dS )a  Adds a new line to the list of lines the text is being wrapped into
        This function will also track any ANSI color codes in this string as well
        as add any colors from previous lines order to preserve the same formatting
        as a single unwrapped string.
        c                 S   s   g | ]}|qS r   r   )r7   xr   r   r   r9     r:   z1_CustomTextWrap._update_lines.<locals>.<listcomp>c                 S   s*   g | ]"}|j | d  | d  qS )r   r/   )r   span)r7   coder   r   r   r9     s   r   r   N)r   finditerr   r>   r  _ansi_color_reset_coder   r<   )r  rn  new_lineZcode_matchesZcolor_codesr  r   r   r   _update_lines|  s    z_CustomTextWrap._update_linesc                 C   s   |dk rd}n|| }| j rt|d }d}| |d| |krH|d }q(||d|d   ||d d |d< n|s||  dS )a	  _handle_long_word(chunks : [string],
                             cur_line : [string],
                             cur_len : int, width : int)
        Handle a chunk of text (most likely a word, not whitespace) that
        is too long to fit in any line.
        r/   r   N)break_long_wordsr  r   pop)r  reversed_chunkscur_linecur_lenr   
space_leftchunkrt  r   r   r   _handle_long_word  s    	
z!_CustomTextWrap._handle_long_wordc           	      C   s  g }| j dkrtd| j  | jdurf| jdkr8| j}n| j}| || | j  | j krftd|  |rg }d}|r| j}n| j}| j | | }| j	r|d 
 dkr|r|d= |r| |d }|| |kr||  ||7 }qqq|r2| |d |kr2| |||| tt| j|}| j	rj|rj|d 
 dkrj|| |d 8 }|d= |rn| jdu st|d | jk s|r| j	rt|dkr|d 
 s||kr| ||d|  qn|rF|d 
 r*|| | j |kr*|| j | ||d|  q|| |d 8 }|d= q|r|d  }| || | j | j kr|| j |d< q| ||| j   qqn|S )a  _wrap_chunks(chunks : [string]) -> [string]
        Wrap a sequence of text chunks and return a list of lines of
        length 'self.width' or less.  (If 'break_long_words' is false,
        some lines may be longer than this.)  Chunks correspond roughly
        to words and the whitespace between them: each chunk is
        indivisible (modulo 'break_long_words'), but a line break can
        come between any two chunks.  Chunks should not have internal
        whitespace; ie. a chunk is either all whitespace or a "word".
        Whitespace chunks will be removed from the beginning and end of
        lines, but apart from that whitespace is preserved.
        r   zinvalid width %r (must be > 0)Nr/   z#placeholder too large for max widthr   r   )r   r   r  subsequent_indentinitial_indentr  placeholderlstripreversedrop_whitespacer   r   r  r  sumry   r<   r  r>   rK   )	r  chunksrn  indentr  r  r   Z	chunk_len	prev_liner   r   r   _wrap_chunks  s    


 
 

	

z_CustomTextWrap._wrap_chunksN)
r  r  r  r  r  staticmethodr  r  r  r  r   r   r   r   r>  e  s   
	&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`   r  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--helpr5   )r   r_  r    r  filera  )getoptsysr  dedent_mainr  argvGetoptErrorr  exitrZ  r   r   stdinstdoutopenr   _pprint_file)r  r  r  usageoptsr  r   r   r  ra  r_  r    outfileoptvaluefilesoutr   Zfobjr   r   r   r  -  s     








r  c           	         s8   |   } fdd|D }tt|||||d|d d S )Nc                    s$   g | ]}|  rt | qS r   )r   r   r   rK   )r7   rd   r    r   r   r9     r:   z _pprint_file.<locals>.<listcomp>)r  ra  )r  )	readlinesr  r   )	Zfobjectr   r_  r    r  r  ra  r   tabler   r  r   r    s    r  __main__)r   )FF)TT)r   TFF)TT)r   T)FN)r   )T)r  
__future__r   r   collectionsr   r  r   r   r  version_infocollections.abcr   	itertoolsr   	functoolsr   r   r   r   r   r   Z	_int_typelongr   r   Z_float_typeunicoder   r  r   r   r   r   bytesrY  r   r   ImportErrorr   r   r[   cgi__all____version__rV  r   rZ  r[  rW  r   r   r"   r#   r6   rB   rO   rT   rU   r^   rb   rj   ZLATEX_ESCAPE_RULESr~   r   r]  r   sortedr   r   rX  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  r  r<  rE  r   rU  r=  rk  r|   rm  ro  rx  r|  r}  r~  r^  r  r>  r  r  r  r   r   r   r   <module>   sJ  


"	

	




























































  z

!
'    
1

% 

 -

   J	
2 I\	
