
    iCY                     T   S r SSKJr  SS/rSrSrSrSrSS	KrSS	K	r	 SS	K
r
S
 r SS	KrS rSSKJr  \R(                  S:  a  \r\rO\r\rS rS r " S S\5      r " S S\5      r " S S5      r\ S:X  a  \" 5       r!\!RE                  / SQ5        \!RG                  / SQ5        \!RI                  / SQ/ SQ/ SQ/ SQ/5        \%" \!RM                  5       5        \%" 5         \" 5       r!\!RO                  \RP                  5        \!RS                  / SQ5        \!RE                  / SQ5        \!RI                  / S Q/ S!Q/ S"Q/ S#Q/ S$Q/5        \%" \!RM                  5       5        g	g	! \ a2     SS	KrS r GNK! \ a    \R                  R                  S5        e f = ff = f! \ a    S r GNyf = f)%a  module to create simple ASCII tables


Example:

    table = Texttable()
    table.set_cols_align(["l", "r", "c"])
    table.set_cols_valign(["t", "m", "b"])
    table.add_rows([["Name", "Age", "Nickname"],
                    ["Mr\nXavier\nHuon", 32, "Xav'"],
                    ["Mr\nBaptiste\nClement", 1, "Baby"],
                    ["Mme\nLouise\nBourgeau", 28, "Lou\n\nLoue"]])
    print(table.draw())
    print()

    table = Texttable()
    table.set_deco(Texttable.HEADER)
    table.set_cols_dtype(['t',  # text
                          'f',  # float (decimal)
                          'e',  # float (exponent)
                          'i',  # integer
                          'a']) # automatic
    table.set_cols_align(["l", "r", "r", "r", "l"])
    table.add_rows([["text",    "float", "exp", "int", "auto"],
                    ["abcd",    "67",    654,   89,    128.001],
                    ["efghijk", 67.5434, .654,  89.6,  12800000000000000000000.00023],
                    ["lmn",     5e-78,   5e-78, 89.4,  .000000000000128],
                    ["opqrstu", .023,    5e+78, 92.,   12800000000000000000000]])
    print(table.draw())

Result:

    +----------+-----+----------+
    |   Name   | Age | Nickname |
    +==========+=====+==========+
    | Mr       |     |          |
    | Xavier   |  32 |          |
    | Huon     |     |   Xav'   |
    +----------+-----+----------+
    | Mr       |     |          |
    | Baptiste |   1 |          |
    | Clement  |     |   Baby   |
    +----------+-----+----------+
    | Mme      |     |   Lou    |
    | Louise   |  28 |          |
    | Bourgeau |     |   Loue   |
    +----------+-----+----------+

    text   float       exp      int     auto
    ===========================================
    abcd   67.000   6.540e+02   89    128.001
    efgh   67.543   6.540e-01   90    1.280e+22
    ijkl   0.000    5.000e-78   89    0.000
    mnop   0.023    5.000e+78   92    1.280e+22
    )division	TexttableArraySizeErrorz%Gerome Fournier <jef(at)foutaise.org>MITz1.7.0a  Jeff Kowalczyk:
    - textwrap improved import
    - comment concerning header output

Anonymous:
    - add_rows method, for adding rows in one go

Sergey Simonenko:
    - redefined len() function to deal with non-ASCII characters

Roger Lew:
    - columns datatype specifications

Brian Peterson:
    - better handling of unicode errors

Frank Sachsenheim:
    - add Python 2/3-compatibility

Maximilian Hils:
    - fix minor bug for Python 3 compatibility

frinkelpi:
    - preserve empty lines
Nc                 .    [         R                  " X5      $ N)cjkwrapwraptxtwidths     M/home/kali/github-search/github-env/lib/python3.13/site-packages/texttable.pytextwrapperr   g   s    ||C''    c                 .    [         R                  " X5      $ r   )textwrapr
   r   s     r   r   r   l   s    ==,,r   zCan't import textwrap module!
c                 B    [        S[        R                  " U 5      5      $ ):Return the rendering width of a unicode character
        r   )maxwcwidthcs    r   uchar_widthr   w   s     1gooa())r   c                 r    [         R                  " U 5      S;   a  g[         R                  " U 5      (       a  gg)r   WF   r      )unicodedataeast_asian_width	combiningr   s    r   r   r   |   s1     ''*d2""1%%r   )reduce)   r   c                 "   [        U [        5      (       a  U $ [        U [        5      (       a   [        U S5      $ [        U 5      $ ! [         a?  n[        R
                  R                  SU < SU< S35        [        U SS5      s SnA$ SnAff = f)z7Return a unicode representation of a python object
    zutf-8z)UnicodeDecodeError exception for string 'z': 
replaceN)
isinstanceunicode_type
bytes_typeUnicodeDecodeErrorsysstderrwrite)objstrerrors     r   obj2unicoder/      s|     #|$$
	C	$	$	9W--
 C  	 " 	9JJUXZbcdWi88	9s   A 
B4B	B	Bc                     [        U [        5      (       d  [        U [        5      (       a.  [        [	        U 5       Vs/ s H  n[        U5      PM     sn5      $ U R                  5       $ s  snf )zMRedefining len here so it will be able to work with non-ASCII characters
    )r&   r(   r'   sumr/   r   __len__)iterabler   s     r   lenr4      sW     (J'':h+M+MK,AB,AqKN,ABCC!! Cs   A)c                   $    \ rS rSrSrS rS rSrg)r      zEException raised when specified rows don't fit the required size
    c                 <    Xl         [        R                  XS5        g )N )msg	Exception__init__)selfr9   s     r   r;   ArraySizeError.__init__   s    4b)r   c                     U R                   $ r   r9   r<   s    r   __str__ArraySizeError.__str__   s    xxr   r?   N)__name__
__module____qualname____firstlineno____doc__r;   rA   __static_attributes__ r   r   r   r      s    *r   c                       \ rS rSrSrSrg)FallbackToText   z#Used for failed conversion to floatrI   N)rC   rD   rE   rF   rG   rH   rI   r   r   rK   rK      s    -r   rK   c                   R   \ rS rSrSrSrSrSrS,S jrS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS-S jrS r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       rS rS r S r!S r"S  r#S! r$S" r%S# r&S.S$ jr'S% r(S& r)S' r*S.S( jr+S) r,S*r-g+)/r      r   r         c                 
   U R                  U5        SU l        [        R                  [        R                  -  [        R
                  -  [        R                  -  U l        U R                  / SQ5        U R                  5         g)zConstructor

- max_width is an integer, specifying the maximum width of the table
- if set to 0, size is unlimited, therefore cells won't be wrapped
r"   )-|+=N)
set_max_width
_precisionr   VLINESHLINESBORDERHEADER_deco	set_charsresetr<   	max_widths     r   r;   Texttable.__init__   s`     	9%%%	(8(889;K;KK
+,

r   c                 >    SU l         SU l        / U l        / U l        U $ )z,Reset the instance

- reset rows and header
N)_hline_string	_row_size_header_rowsr@   s    r   r^   Texttable.reset   s&     "
r   c                 0    US:  a  Xl         U $ SU l         U $ )zSet the maximum width of the table

- max_width is an integer, specifying the maximum width of the table
- if set to 0, size is unlimited, therefore cells won't be wrapped
r   F)
_max_widthr_   s     r   rV   Texttable.set_max_width   s#     (11}) ;@r   c                     [        U5      S:w  a  [        S5      eU Vs/ s H  n[        U5      PM     sn Vs/ s H  o3SS PM	     nnUu  U l        U l        U l        U l        U $ s  snf s  snf )zSet the characters used to draw lines between rows and columns

- the array should contain 4 fields:

    [horizontal, vertical, corner, header]

- default is set to:

    ['-', '|', '+', '=']
rO   z!array should contain 4 charactersNr   )r4   r   str_char_horiz
_char_vert_char_corner_char_header)r<   arraysxs       r   r]   Texttable.set_chars   sq     u:? !DEE38!:5a3q65!:<!:ABQ%!:<49	2	4?t0 ";<s
   A&A+c                      Xl         SU l        U $ )ag  Set the table decoration

- 'deco' can be a combination of:

    Texttable.BORDER: Border around the table
    Texttable.HEADER: Horizontal line below the header
    Texttable.HLINES: Horizontal lines between rows
    Texttable.VLINES: Vertical lines between columns

   All of them are enabled by default

- example:

    Texttable.BORDER | Texttable.HEADER
N)r\   rc   )r<   decos     r   set_decoTexttable.set_deco   s    " 
!r   c                 4    U R                  U5        Xl        U $ )zSet the desired header alignment

- the elements of the array should be either "l", "c" or "r":

    * "l": column flushed left
    * "c": column centered
    * "r": column flushed right
)_check_row_size_header_alignr<   rq   s     r   set_header_alignTexttable.set_header_align  s     	U#"r   c                 4    U R                  U5        Xl        U $ )zSet the desired columns alignment

- the elements of the array should be either "l", "c" or "r":

    * "l": column flushed left
    * "c": column centered
    * "r": column flushed right
)rz   _alignr|   s     r   set_cols_alignTexttable.set_cols_align  s     	U#r   c                 4    U R                  U5        Xl        U $ )a  Set the desired columns vertical alignment

- the elements of the array should be either "t", "m" or "b":

    * "t": column aligned on the top of the cell
    * "m": column aligned on the middle of the cell
    * "b": column aligned on the bottom of the cell
)rz   _valignr|   s     r   set_cols_valignTexttable.set_cols_valign(  s     	U#r   c                 4    U R                  U5        Xl        U $ )a  Set the desired columns datatype for the cols.

- the elements of the array should be either a callable or any of
  "a", "t", "f", "e", "i" or "b":

    * "a": automatic (try to use the most appropriate datatype)
    * "t": treat as text
    * "f": treat as float in decimal format
    * "e": treat as float in exponential format
    * "i": treat as int
    * "b": treat as boolean
    * a callable: should return formatted string for any value given

- by default, automatic datatyping is used for each column
)rz   _dtyper|   s     r   set_cols_dtypeTexttable.set_cols_dtype6  s    " 	U#r   c                     U R                  U5         [        [        [        U5      5      n[	        [
        U5      S::  a  [        e Xl
        U $ ! [         a!    [        R                  R                  S5        e f = f)zSet the desired columns width

- the elements of the array should be integers, specifying the
  width of each column. For example:

        [10, 20, 5]
r   z-Wrong argument in column width specification
)rz   listmapintr!   min
ValueErrorr*   r+   r,   _widthr|   s     r   set_cols_widthTexttable.set_cols_widthK  st     	U#	S%)Ec5!Q&   '
 	  	JJMN	s   3A +A:c                 X    [        U5      [        Ld  US:  a  [        S5      eXl        U $ )zvSet the desired precision for float/exponential formats

- width must be an integer >= 0

- default value is set to 3
r   z'width must be an integer greater then 0)typer   r   rW   )r<   r   s     r   set_precisionTexttable.set_precision_  s,     E{c!UQYFGGr   c                 d    U R                  U5        [        [        [        U5      5      U l        U $ )z(Specify the header of the table
        )rz   r   r   r/   re   r|   s     r   headerTexttable.headerl  s*     	U#CU34r   c                    U R                  U5        [        U S5      (       d  S/U R                  -  U l        / n[	        U5       H%  u  p4UR                  U R                  X45      5        M'     U R                  R                  U5        U $ )zCAdd a row in the rows stack

- cells can contain newlines and tabs
r   a)rz   hasattrrd   r   	enumerateappend_strrf   )r<   rq   cellsirs   s        r   add_rowTexttable.add_rowt  sr     	U#tX&&%$..0DKe$DALL1) %

% r   c                     U(       a[  [        US5      (       a1  [        US5      (       a   U R                  UR                  5       5        OU R                  US   5        USS nU H  nU R                  U5        M     U $ )zAdd several rows in the rows stack

- The 'rows' argument can be either an iterator returning arrays,
  or a by-dimensional array
- 'header' specifies if the first row should be used as the header
  of the table
__iter__nextr   r   N)r   r   r   r   )r<   rowsr   rows       r   add_rowsTexttable.add_rows  sh     tZ((WT6-B-BDIIK(DG$ABxCLL r   c                    U R                   (       d  U R                  (       d  gU R                  5         U R                  5         SnU R	                  5       (       a  XR                  5       -  nU R                   (       aC  XR                  U R                   SS9-  nU R                  5       (       a  XR                  5       -  nSnU R                   H_  nUS-  nXR                  U5      -  nU R                  5       (       d  M2  U[        U R                  5      :  d  MM  XR                  5       -  nMa     U R	                  5       (       a  XR                  5       -  nUSS $ )z:Draw the table

- the table is returned as a whole string
Nr8   T)isheaderr   r   )re   rf   _compute_cols_width_check_align_has_border_hline
_draw_line_has_header_hline_header_has_hlinesr4   )r<   outlengthr   s       r   drawTexttable.draw  s    ||DJJ  ";;= C<<??4<<$???C!!))++::CaKF??3''C!!fs4::&>{{}$	 
 ;;= C3Bxr   c                 p    Uc
  [        5       e [        U5      $ ! [        [        4 a    [        5       ef = fr   )rK   float	TypeErrorr   )clsrs   s     r   	_to_floatTexttable._to_float  s;    9 ""	#8O:& 	# ""	#s   
 5c           	          [        U5      [        :X  a  [        U5      $ [        [        [        U R	                  U5      5      5      5      $ )z)Integer formatting class-method.
        )r   r   rl   roundr   r   rs   kws      r   _fmt_intTexttable._fmt_int  s6     7c>q6Ms5q!12344r   c                 N    UR                  S5      nSX0R                  U5      4-  $ )zFloat formatting class-method.

- x parameter is ignored. Instead kw-argument f being x float-converted
  will be used.

- precision will be taken from `n` kw-argument.
nz%.*fgetr   r   rs   r   r   s       r   
_fmt_floatTexttable._fmt_float  (     FF3KMM!,---r   c                 N    UR                  S5      nSX0R                  U5      4-  $ )zExponential formatting class-method.

- x parameter is ignored. Instead kw-argument f being x float-converted
  will be used.

- precision will be taken from `n` kw-argument.
r   z%.*er   r   s       r   _fmt_expTexttable._fmt_exp  r   r   c                     [        U5      $ )zString formatting class-method.)r/   r   s      r   	_fmt_textTexttable._fmt_text  s     1~r   c                 *    [        [        U5      5      $ )zBoolean formatting class-method)rl   boolr   s      r   	_fmt_boolTexttable._fmt_bool  s     47|r   c                 *   U R                  U5      n[        U5      S:  a  U R                  nO^X3:w  a  U R                  nOLU[	        U5      -
  S:X  a.  [        U[        5      (       a  U R                  OU R                  nOU R                  nU" U40 UD6$ )zauto formatting class-method.g    חAr   )
r   absr   r   r   r&   r   r   r   r   )r   rs   r   ffns        r   	_fmt_autoTexttable._fmt_auto  sv     MM!q6C<BVBq\Q",Q"5"53<<BB!{r{r   c                 F   U R                   U R                  U R                  U R                  U R                  U R
                  S.nU R                  nU R                  U   n [        U5      (       a  U" U5      $ X5   " X$S9$ ! [         a    U R                  U5      s $ f = f)znHandles string formatting of cell data

i - index of the cell datatype in self._dtype
x - cell data to format
)r   r   br   et)r   )
r   r   r   r   r   r   rW   r   callablerK   )r<   r   rs   FMTr   dtypes         r   r   Texttable._str  s      OOA	%Qxz!)) 	%>>!$$	%s   "B :B B B c                     U R                   (       d  [        U5      U l         gU R                   [        U5      :w  a  [        SU R                   -  5      eg)zCCheck that the specified array fits the previous rows size
        z array should contain %d elementsN)rd   r4   r   r|   s     r   rz   Texttable._check_row_size  sG     ~~ ZDN^^s5z) !C.."! " " *r   c                 B    U R                   [        R                  -  S:  $ )z8Return a boolean, if vlines are required or not
        r   )r\   r   rX   r@   s    r   _has_vlinesTexttable._has_vlines       zzI,,,q00r   c                 B    U R                   [        R                  -  S:  $ )z8Return a boolean, if hlines are required or not
        r   )r\   r   rY   r@   s    r   r   Texttable._has_hlines   r   r   c                 B    U R                   [        R                  -  S:  $ )z7Return a boolean, if border is required or not
        r   )r\   r   rZ   r@   s    r   r   Texttable._has_border&  r   r   c                 B    U R                   [        R                  -  S:  $ )z<Return a boolean, if header line is required or not
        r   )r\   r   r[   r@   s    r   r   Texttable._has_header,  r   r   c                 $    U R                  S5      $ )z'Print header's horizontal line
        T)_build_hliner@   s    r   r   Texttable._hline_header2  s       &&r   c                 f    U R                   (       d  U R                  5       U l         U R                   $ )z!Print an horizontal line
        )rc   r   r@   s    r   r   Texttable._hline8  s*     !!!%!2!2!4D!!!r   c                 |   U R                   nU(       a  U R                  nU< X R                  /U R                  5          < U< 3nUR	                  U R
                   Vs/ s H  oBU-  PM	     sn5      nU R                  5       (       a(  U R                  < U< U< U< U R                  < S3nU$ US-  nU$ s  snf )zDReturn a string used to separated rows or separate header from
rows
r$   )rm   rp   ro   r   joinr   r   )r<   	is_headerhorizrr   r   ls         r   r   Texttable._build_hline@  s       %%E'8'89$:J:J:LM FFt{{3{!AI{34"&"3"3UAu!!#A  IA 4s    B9c                 6   UR                  S5      nSnU H  nSnUR                  S5      n[        U[        [        S[	        U5      S-   5      5      5       H/  u  pxU[	        U5      -   nU[	        U5      :  d  M$  US-  S-   S-  nM1     [        X55      nM     U$ )zReturn the width of the cell

Special characters are taken into account to return the width of the
cell, such like newlines and tabs
r$   r   	r   rP   )splitzipr   ranger4   r   )	r<   cell
cell_linesmaxiliner   partspartr   s	            r   	_len_cellTexttable._len_cellT  s     ZZ%
DFJJt$Eud5CJN+C&DE#d)+s5z>$ai!mq0F F t$D  r   c                 l   [        U S5      (       a  g/ nU R                  (       a*  U R                   Vs/ s H  o R                  U5      PM     nnU R                   HS  n[	        U[        [        [        U5      5      5      5       H%  u  pE [        X   U R                  U5      5      X'   M'     MU     [        U5      n[        U5      nSUS-
  -  SS/U R                  5          -   nU R                  (       az  Xx-   U R                  :  ah   U R                  Xh-   :  a  [        S5      eU R                  U-
  n	S/U-  n
SnU	S:  a+  X   X   :  a  X==   S-  ss'   U	S-  n	US-   U-  nU	S:  a  M+  U
nXl        gs  snf ! [        [        4 a%    UR                  U R                  U5      5         GM,  f = f)zReturn an array with the width of each column

If a specific width has been specified, exit. If the total of the
columns width exceed the table desired width, another width will be
computed to fit, and cells will be wrapped.
r   Nr"   r   r   rO   z max_width too low to render data)r   re   r	  rf   r  r   r  r4   r   r   
IndexErrorr   r1   r   ri   r   r   )r<   r  rs   r   r  r   ncolscontent_width
deco_widthavailable_widthnewmaxis              r   r   Texttable._compute_cols_widthg  s    4""<<04>1^^A&D>::Cc4c#h#896!$'4>>$+?@DG :  D	D	a[Aa5)9)9);#<<
?? :dooM %"45 !CDD"oo
:OcEkGA!A%:'J!OJ#q(OUeO	 "A%
 D5 ?
 ":. 6KKt 4556s   E9E>>0F32F3c                     [        U S5      (       d  S/U R                  -  U l        [        U S5      (       d  S/U R                  -  U l        [        U S5      (       d  S/U R                  -  U l        gg)zFCheck if alignment has been specified, set default one if not
        r{   r   r   r   r   r   N)r   rd   r{   r   r   r@   s    r   r   Texttable._check_align  sg     t_--"%!7DtX&&%$..0DKtY''54>>1DL (r   c           	         U R                  X5      nSnSn[        [        US   5      5       GH3  nU R                  5       (       a  USU R                  -  -  nSn[        XR                  U R                  5       H  u  pxn	US-  nXu   n
U[        U
5      -
  nU(       a  U R                  US-
     n	U	S:X  a  XKU-  U
-   -  nO?U	S:X  a0  U[        US-  5      U-  U
-   [        US-  US-  -   5      U-  -   -  nO	XJX-  -   -  nU[        U5      :  d  M  US	X0R                  /U R                  5          -  -  nM     US
SX0R                  -   /U R                  5          -  -  nGM6     U$ )z@Draw a line

Loop over a single cell length, over all the cells
 r8   r   z%s r   rr   r   z %s z%s
)_splititr  r4   r   rn   r  r   r   r{   r   r   )r<   r  r   spacer   r   r   r  r   align	cell_linefills               r   r   Texttable._draw_line  s|    }}T,s47|$A!!ut..F&)$T[[&I"U! G	s9~- ..vz:EC<%<)33Cc\CQK%/);!$q&46/2U:; <C t|33CCI%6UOO$<T=M=M=O$PPPC 'J 6R!89$:J:J:LMMMC' %( 
r   c           	         / n[        XR                  5       Hq  u  pE/ nUR                  S5       HD  nUR                  5       S:X  a  UR	                  S5        M*  UR                  [        Xu5      5        MF     UR	                  U5        Ms     [        [        [        [        [        U5      5      5      n[        X0R                  5       H  u  pIU(       a  Sn	U	S:X  aL  U[        U5      -
  n
S/[        U
S-  5      -  USS& UR                  S/[        U
S-  U
S-  -   5      -  5        M`  U	S:X  a  S/U[        U5      -
  -  USS& M}  UR                  S/U[        U5      -
  -  5        M     U$ )	zSplit each element of line to fit the column width

Each element is turned into a list, result of the wrapping of the
string to the desired width
r$   r8   r   mr   Nr   r   )r  r   r   stripr   extendr   r!   r   r   r   r4   r   r   )r<   r  r   line_wrappedr  r   rq   r   max_cell_linesvalignmissings              r   r  Texttable._splitit  sB    t[[1KDEZZ%779?LL$LLQ!67	 &
 & 2  T#c<*@%ABll;LD}(3t944#gk"22RaRD3w{Wq['@#AAB34>CI#=>RaRDNSY$>?@ < r   )r   ro   rp   rm   rn   r\   r   re   r{   rc   ri   rW   rd   rf   r   r   N)P   )T)F).rC   rD   rE   rF   rZ   r[   rY   rX   r;   r^   rV   r]   rw   r}   r   r   r   r   r   r   r   r   r   classmethodr   r   r   r   r   r   r   r   rz   r   r   r   r   r   r   r   r	  r   r   r   r  rH   rI   r   r   r   r      s4   FFFF
&**("*6 # # 5 5 	. 	. 	. 	.      %2"1111'"(&&P	2>r   __main__)r   r  r   )r   r  r   )NameAgeNickname)zMr
Xavier
Huon    zXav')zMr
Baptiste
Clementr   Baby)zMme
Louise
Bourgeau   z
Lou
 
Loue)r   r   r   r   r   )r   r  r  r  r   )textr   expr   auto)abcd67i  Y   gy&1 `@)efghijkg_)P@g!rh?gffffffV@g@xD)lmnܐ؆/r8  gYV@gV瞯B=)opqrstugZd;O?g/'%EPg      W@l      Zx^+)*rG   
__future__r   __all__
__author____license____version____credits__r*   r   r	   r   ImportErrorr   r+   r,   r   r   	functoolsr!   version_inforl   r'   bytesr(   unicoder/   r4   r:   r   rK   r   rC   tabler   r   r   printr   rw   r[   r   rI   r   r   <module>rG     s  6p  (
)4
6  (* vLJLJ!"	Y 		Y 	
\ \~ zKE	)	/*	NN/48AC D 
%**,	GKE	NN9##$	   
 
23	NN>?UHO	Q R
 
%**,1 _  	- 

:;$  		s.   E F F&E00#FF	F'&F'