HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //proc/1233/cwd/lib/python3/dist-packages/__pycache__/texttable.cpython-310.pyc
o

S��`YX�@s�dZddlmZddgZdZdZdZdZdd	lZdd	l	Z	z
dd	l
Z
d
d�ZWn"eyHz
dd	l
Z
dd�ZWneyEej�d
��wYnwz
dd	lZdd�ZWn
ey`dd�ZYnwddlmZejdkrqeZeZneZeZdd�Zdd�ZGdd�de�ZGdd�de�ZGdd�d�Ze dkr�e�Z!e!�"gd��e!�#gd��e!�$gd�gd�gd �gd!�g�e%e!�&��e%�e�Z!e!�'ej(�e!�)gd"��e!�"gd#��e!�$gd$�gd%�gd&�gd'�gd(�g�e%e!�&��d	Sd	S))a�module for creating 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>�MITz1.6.4a�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
NcC�t�||�S�N)�cjkwrap�wrap��txt�width�r
�+/usr/lib/python3/dist-packages/texttable.py�textwrapperg�rcCrr)�textwrapr	r
r
r
rrlrzCan't import textwrap module!
cCstdt�|��S)�:Return the rendering width of a unicode character
        r)�max�wcwidth��cr
r
r�uchar_widthwsrcCs$t�|�dvr	dSt�|�rdSdS)r�WF�r�)�unicodedata�east_asian_width�	combiningrr
r
rr|s

)�reduce)�rc
Csrt|t�r|St|t�r5zt|d�WSty4}ztj�d||f�t|dd�WYd}~Sd}~wwt|�S)z7Return a unicode representation of a python object
    zutf-8z1UnicodeDecodeError exception for string '%s': %s
�replaceN)�
isinstance�unicode_type�
bytes_type�UnicodeDecodeError�sys�stderr�write)�obj�strerrorr
r
r�obj2unicode�s

��r*cCs2t|t�s
t|t�rtdd�t|�D��S|��S)zMRedefining len here so it will be able to work with non-ASCII characters
    cS�g|]}t|��qSr
)r)�.0rr
r
r�
<listcomp>��zlen.<locals>.<listcomp>)r!r#r"�sumr*�__len__)�iterabler
r
r�len�sr2c@s eZdZdZdd�Zdd�ZdS)rzEException raised when specified rows don't fit the required size
    cCs||_t�||d�dS)N�)�msg�	Exception�__init__)�selfr4r
r
rr6�szArraySizeError.__init__cCs|jSr)r4�r7r
r
r�__str__�szArraySizeError.__str__N)�__name__�
__module__�__qualname__�__doc__r6r9r
r
r
rr�sc@seZdZdZdS)�FallbackToTextz#Used for failed conversion to floatN)r:r;r<r=r
r
r
rr>�sr>c@sTeZdZdZdZdZdZdOdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdPd!d"�Zd#d$�Zed%d&��Zed'd(��Zed)d*��Zed+d,��Zed-d.��Zed/d0��Zd1d2�Zd3d4�Zd5d6�Zd7d8�Z d9d:�Z!d;d<�Z"d=d>�Z#d?d@�Z$dQdBdC�Z%dDdE�Z&dFdG�Z'dHdI�Z(dQdJdK�Z)dLdM�Z*dNS)Rrrr���PcCsD|�|�d|_tjtjBtjBtjB|_|�gd��|�	�dS)z�Constructor

        - 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�r7�	max_widthr
r
rr6�s
�zTexttable.__init__cCsd|_d|_g|_g|_|S)z<Reset the instance

        - reset rows and header
        N)�
_hline_string�	_row_size�_header�_rowsr8r
r
rrN�s
zTexttable.resetcCs|dkr	||_|Sd|_|S)z�Set 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
        rF)�
_max_widthrOr
r
rrF�s�zTexttable.set_max_widthcCsDt|�dkr
td��dd�dd�|D�D�}|\|_|_|_|_|S)z�Set the characters used to draw lines between rows and columns

        - the array should contain 4 fields:

            [horizontal, vertical, corner, header]

        - default is set to:

            ['-', '|', '+', '=']
        r?z!array should contain 4 characterscSsg|]}|dd��qS)Nrr
�r,�xr
r
rr-�sz'Texttable.set_chars.<locals>.<listcomp>cSr+r
)�str)r,�sr
r
rr-�r.)r2r�_char_horiz�
_char_vert�_char_corner�_char_header�r7�arrayr
r
rrM�s
�zTexttable.set_charscCs||_d|_|S)a�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)rLrQ)r7�decor
r
r�set_deco�szTexttable.set_decocC�|�|�||_|S)z�Set 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_alignr^r
r
r�set_header_align�

zTexttable.set_header_aligncCrb)z�Set 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
        )rc�_alignr^r
r
r�set_cols_alignrfzTexttable.set_cols_aligncCrb)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
        )rc�_valignr^r
r
r�set_cols_valign(rfzTexttable.set_cols_valigncCrb)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" or "i":

            * "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
            * a callable: should return formatted string for any value given

        - by default, automatic datatyping is used for each column
        )rc�_dtyper^r
r
r�set_cols_dtype6s
zTexttable.set_cols_dtypecCsV|�|�zttt|��}tt|�dkrt�Wnty%tj�	d��w||_
|S)z�Set the desired columns width

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

                [10, 20, 5]
        rz-Wrong argument in column width specification
)rc�list�map�intr�min�
ValueErrorr%r&r'�_widthr^r
r
r�set_cols_widthJs
	��zTexttable.set_cols_widthcCs&t|�tus
|dkrtd��||_|S)z�Set the desired precision for float/exponential formats

        - width must be an integer >= 0

        - default value is set to 3
        rz'width must be an integer greater then 0)�typerorqrG)r7rr
r
r�
set_precision^szTexttable.set_precisioncCs|�|�ttt|��|_|S)z(Specify the header of the table
        )rcrmrnr*rSr^r
r
r�headerks
zTexttable.headercCsZ|�|�t|d�sdg|j|_g}t|�D]
\}}|�|�||��q|j�|�|S)zSAdd a row in the rows stack

        - cells can contain newlines and tabs
        rk�a)rc�hasattrrRrk�	enumerate�append�_strrT)r7r_�cells�irWr
r
r�add_rowss

zTexttable.add_rowTcCsZ|r!t|d�rt|d�r|�|���n
|�|d�|dd�}|D]}|�|�q#|S)z�Add 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__�nextrrN)rxrvr�r~)r7�rowsrv�rowr
r
r�add_rows�szTexttable.add_rowscCs�|js|jsdS|��|��d}|��r||��7}|jr3||j|jdd�7}|��r3||��7}d}|jD]}|d7}||�|�7}|�	�rV|t
|j�krV||��7}q8|��ra||��7}|dd�S)zJDraw the table

        - the table is returned as a whole string
        Nr3T)�isheaderrr���)rSrT�_compute_cols_width�_check_align�_has_border�_hline�
_draw_line�_has_header�
_hline_header�_has_hlinesr2)r7�out�lengthr�r
r
r�draw�s*
�zTexttable.drawc	Cs2|durt��zt|�WSttfyt��wr)r>�float�	TypeErrorrq)�clsrWr
r
r�	_to_float�s
�zTexttable._to_floatcKs*t|�tkr
t|�Sttt|�|����S)z)Integer formatting class-method.
        )rtrorX�roundr��r�rW�kwr
r
r�_fmt_int�szTexttable._fmt_intcK�|�d�}d||�|�fS)z�Float 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�rWr�r�r
r
r�
_fmt_float��
	zTexttable._fmt_floatcKr�)z�Exponential 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�r
r
r�_fmt_exp�r�zTexttable._fmt_expcKst|�S)zString formatting class-method.)r*r�r
r
r�	_fmt_text�szTexttable._fmt_textcKs\|�|�}t|�dkr|j}n||kr|j}n|t|�dkr#|j}n|j}||fi|��S)zauto formatting class-method.g�חAr)r��absr�r�r�r�r�)r�rWr��f�fnr
r
r�	_fmt_auto�s
zTexttable._fmt_autocCsl|j|j|j|j|jd�}|j}|j|}zt|�r||�WS||||d�WSty5|�|�YSw)z�Handles string formatting of cell data

            i - index of the cell datatype in self._dtype
            x - cell data to format
        )rwr}r��e�t)r�)	r�r�r�r�r�rGrk�callabler>)r7r}rW�FMTr��dtyper
r
rr{�s�

�zTexttable._strcCs4|js
t|�|_dS|jt|�krtd|j��dS)zCCheck that the specified array fits the previous rows size
        z array should contain %d elementsN)rRr2rr^r
r
rrc	s��zTexttable._check_row_sizecC�|jtj@dkS)z8Return a boolean, if vlines are required or not
        r)rLrrHr8r
r
r�_has_vlines�zTexttable._has_vlinescCr�)z8Return a boolean, if hlines are required or not
        r)rLrrIr8r
r
rr�r�zTexttable._has_hlinescCr�)z7Return a boolean, if border is required or not
        r)rLrrJr8r
r
rr�r�zTexttable._has_bordercCr�)z<Return a boolean, if header line is required or not
        r)rLrrKr8r
r
rr�%r�zTexttable._has_headercCs
|�d�S)z'Print header's horizontal line
        T)�_build_hliner8r
r
rr�+s
zTexttable._hline_headercCs|js|��|_|jS)z!Print an horizontal line
        )rQr�r8r
r
rr�1s
zTexttable._hlineFcst|j�|r|j�d��|jg|���f}|��fdd�|jD��}|��r4d|j�|�|jf}|S|d7}|S)zTReturn a string used to separated rows or separate header from
        rows
        z%s%s%scsg|]}�|�qSr
r
)r,r���horizr
rr-Dr.z*Texttable._build_hline.<locals>.<listcomp>z%s%s%s%s%s
�
)rZr]r\r��joinrrr�)r7�	is_headerrY�lr
r�rr�9s���zTexttable._build_hlinec	Cs�|�d�}d}|D]5}d}|�d�}t|ttdt|�d���D]\}}|t|�}|t|�kr8|ddd}q t||�}q	|S)z�Return 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�	rr@)�split�ziprm�ranger2r)	r7�cell�
cell_lines�maxi�liner��parts�partr}r
r
r�	_len_cellMs

$�zTexttable._len_cellc
s\t�d�rdSg}�jr�fdd��jD�}�jD]3}t|ttt|����D]%\}}zt||��|��||<Wq&t	t
fyK|���|��Yq&wqt|�}t|�}d|dddg��
�}�jr�||�jkr�	�j||krytd	���j|}dg|}	d}|dkr�|	|||kr�|	|d7<|d8}|d|}|dks�|	}|�_dS)
aReturn 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.
        rrNcsg|]}��|��qSr
)r�rVr8r
rr-lsz1Texttable._compute_cols_width.<locals>.<listcomp>rrrr?z max_width too low to render data)rxrSrTr�rmr�r2rr�r��
IndexErrorrzr/r�rUrqrr)
r7r�r�r�r}�ncols�
content_width�
deco_width�available_width�newmaxir
r8rr�`s>

��

�
zTexttable._compute_cols_widthcCsPt|d�sdg|j|_t|d�sdg|j|_t|d�s&dg|j|_dSdS)zFCheck if alignment has been specified, set default one if not
        rdrrgr�rir�N)rxrRrdrgrir8r
r
rr��s


�zTexttable._check_aligncCs:|�||�}d}d}tt|d��D]�}|��r|d|j7}d}t||j|j�D]a\}}}	|d7}||}
|t|
�}|rE|j|d}	|	dkrR||||
7}n%|	dkro|t	|d�||
t	|d|d�|7}n||
||7}|t|�kr�|d	||jg|�
�7}q)|d
d||jg|��7}q|S)zPDraw a line

        Loop over a single cell length, over all the cells
        � r3rz%s r�rrrz %s z%s
)�_splititr�r2r�r[r�rrrgrdror�)r7r�r��spacer�r}r�r�r�align�	cell_line�fillr
r
rr��s2�� zTexttable._draw_linecCs"g}t||j�D]'\}}g}|�d�D]}|��dkr!|�d�q|�t||��q|�|�qttt	t
t|���}t||j�D]N\}}	|rHd}	|	dkrp|t|�}
dgt
|
d�|dd�<|�dgt
|
d|
d��q@|	dkr�dg|t|�|dd�<q@|�dg|t|��q@|S)	z�Split 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�r3r��mrNr�b)r�rrr��striprz�extendrrrrmrnr2riro)r7r�r��line_wrappedr�rr_r�max_cell_lines�valign�missingr
r
rr��s("zTexttable._splititN)rA)T)F)+r:r;r<rJrKrIrHr6rNrFrMrarerhrjrlrsrurvr~r�r��classmethodr�r�r�r�r�r�r{rcr�r�r�r�r�r�r�r�r�r�r�r�r
r
r
rr�s\
	










(
�__main__)r�r�r)r�r�r�)�Name�Age�Nickname)zMr
Xavier
Huon� zXav')zMr
Baptiste
Clementr�Baby)zMme
Louise
Bourgeau�z
Lou
 
Loue)r�r�r�r}rw)r�r�r�r�r�)�textr��expro�auto)�abcd�67i��Ygy�&1`@)�efghijkg_)���P@g!�rh���?gffffffV@g@��x��D)�lmn�ܐ�؆�/r�g�����YV@gV瞯B=)�opqrstugZd;�O��?g/'�%�EPgW@l�Zx^+)*r=�
__future__r�__all__�
__author__�__license__�__version__�__credits__r%rrr�ImportErrorrr&r'rr�	functoolsr�version_inforXr"�bytesr#�unicoder*r2r5rr>rr:�tablerhrjr��printr�rarKrlr
r
r
r�<module>s�8����
	
�
��