File: //lib/python3/dist-packages/__pycache__/texttable.cpython-310.pyc
o
    S��`YX  �                   @   s�  d Z ddlmZ ddgZdZdZdZdZdd	lZdd	l	Z	z
dd	l
Z
d
d� ZW n" eyH   z
dd	l
Z
dd� ZW n eyE   ej�d
� � w Y nw z
dd	lZdd� ZW n
 ey`   dd� ZY nw ddlmZ ejdkrqeZeZneZeZdd� Zdd� ZG dd� de�ZG dd� de�ZG dd� d�Ze dkr�e� Z!e!�"g d�� e!�#g d�� e!�$g d�g d�g d �g d!�g� e%e!�&� � e%�  e� Z!e!�'ej(� e!�)g d"�� e!�"g d#�� e!�$g d$�g d%�g d&�g d'�g d(�g� e%e!�&� � d	S d	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
Nc                 C   �   t �| |�S �N)�cjkwrap�wrap��txt�width� r
   �+/usr/lib/python3/dist-packages/texttable.py�textwrapperg   �   r   c                 C   r   r   )�textwrapr	   r
   r
   r
   r   r   l   r   zCan't import textwrap module!
c                 C   s   t dt�| ��S )�:Return the rendering width of a unicode character
        r   )�max�wcwidth��cr
   r
   r   �uchar_widthw   s   r   c                 C   s$   t �| �dv r	dS t �| �rdS dS )r   �WF�   r   �   )�unicodedata�east_asian_width�	combiningr   r
   r
   r   r   |   s
   
)�reduce)�   r   c              
   C   sr   t | t�r| S t | t�r5zt| d�W S  ty4 } ztj�d| |f � t| dd�W  Y d}~S d}~ww t| �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*   c                 C   s2   t | t�s
t | t�rtdd� t| �D ��S | �� S )zMRedefining len here so it will be able to work with non-ASCII characters
    c                 S   �   g | ]}t |��qS r
   )r   )�.0r   r
   r
   r   �
<listcomp>�   �    zlen.<locals>.<listcomp>)r!   r#   r"