o
    ;Di|A                     @   sd  d dl mZmZmZ d dlZd dlmZ d dlmZ d dl	m
Z
mZ d dlmZ d dlmZ d dlmZ d d	lmZ 		d*d
dZee_G dd deZdd Zee_dd Zd+ddZee_dd Zee_ee_dd Zee_ee_dd Zdd Z dd Z!d,ddZ"G d d! d!eZ#e"e_"d"d# Z$			d-d$d%Z%e%e_&			d-d&d'Z'e'e_'d(d) Z(e(e_(dS ).    )absolute_importprint_functiondivisionN)islice)defaultdict)numeric_types	text_type)config)Table)MemorySource)tohtmlc              	   C   s\   |dkrt j}|du rt j}|du rt j}|du rt j}|du r#t j}t| ||||||dS )a  
    Format a portion of the table as text for inspection in an interactive
    session. E.g.::

        >>> import petl as etl
        >>> table1 = [['foo', 'bar'],
        ...           ['a', 1],
        ...           ['b', 2]]
        >>> etl.look(table1)
        +-----+-----+
        | foo | bar |
        +=====+=====+
        | 'a' |   1 |
        +-----+-----+
        | 'b' |   2 |
        +-----+-----+

        >>> # alternative formatting styles
        ... etl.look(table1, style='simple')
        ===  ===
        foo  bar
        ===  ===
        'a'    1
        'b'    2
        ===  ===

        >>> etl.look(table1, style='minimal')
        foo  bar
        'a'    1
        'b'    2

        >>> # any irregularities in the length of header and/or data
        ... # rows will appear as blank cells
        ... table2 = [['foo', 'bar'],
        ...           ['a'],
        ...           ['b', 2, True]]
        >>> etl.look(table2)
        +-----+-----+------+
        | foo | bar |      |
        +=====+=====+======+
        | 'a' |     |      |
        +-----+-----+------+
        | 'b' |   2 | True |
        +-----+-----+------+

    Three alternative presentation styles are available: 'grid', 'simple' and
    'minimal', where 'grid' is the default. A different style can be specified
    using the `style` keyword argument. The default style can also be changed
    by setting ``petl.config.look_style``.

    r   N)limitvreprindex_headerstyletruncatewidth)r	   
look_limit
look_vreprlook_index_header
look_style
look_widthLooktabler   r   r   r   r   r    r   F/var/www/Datamplify/venv/lib/python3.10/site-packages/petl/util/vis.pylook   s   7
r   c                   @   $   e Zd Zdd Zdd ZeZeZdS )r   c                 C   s.   || _ || _|| _|| _|| _|| _|| _d S Nr   )selfr   r   r   r   r   r   r   r   r   r   __init__[   s   
zLook.__init__c           	      C   s   t | j| j\}}| j}| j}| j}| j}| j}|dkr&t|||||d}n|dkr4t	|||||d}n	t
|||||d}|rC|d7 }|S )Nsimple)r   r   r   r   minimal...
)_vis_overflowr   r   r   r   r   r   r   _look_simple_look_minimal
_look_grid)	r    r   overflowr   r   r   r   r   outputr   r   r   __repr__e   s,   zLook.__repr__N__name__
__module____qualname__r!   r+   __str____unicode__r   r   r   r   r   Y   s
    
r   c                 C      t t| S r   strr   r   r   r   r   _table_repr      r6   c                 K   s   d|d< t | fi |S )z
    Format the entire table as text for inspection in an interactive session.

    N.B., this will load the entire table into memory.

    See also :func:`petl.util.vis.look` and :func:`petl.util.vis.see`.

    Nr   )r   r   kwargsr   r   r   lookall   s   
r:   c                 K   s   t |d< t| fd|i|S )z[Like :func:`petl.util.vis.look` but use str() rather than repr() for data
    values.

    r   r   r3   )r   r   r9   r   r   r   lookstr   s   r;   c                 C   r2   r   )r4   r;   r5   r   r   r   
_table_str   r7   r<   c                 K   s   t |d< t| fi |S )zc
    Like :func:`petl.util.vis.lookall` but use str() rather than repr() for data
    values.

    r   )r4   r:   r8   r   r   r   
lookallstr   s   r=   c                    sP  t | }zt|}W n
 ty   Y dS w ttt|}|r(dd t|D }n|}t|}	fdd|	D }
t|g}|dd |	D  t	|}t||k r\|dg|t|   |
D ]}t||k rr|dg|t|   q^ r fdd|D } fdd|
D }
dg| }t|D ]
\}}t|||< q|
D ]}t|D ]\}}t||| krt|||< qqd	}|D ]}|d
|d  7 }|d	7 }q|r|d | }|d7 }d	}|D ]}|d|d  7 }|d	7 }q|r|d | }|d7 }d}t|D ]\}}|| }|d| 7 }|d|t|  7 }|d7 }q|r!|d | }|d7 }t }t
|	|
D ]f\}}d}t|D ]H\}}|| }|t|k rjt|| trjt|| tsj|d|d t|  7 }||d 7 }q7|d| 7 }|d|t|  7 }|d7 }q7|r|d | }|d7 }|| q-|| | }|D ]	}||| 7 }q|S )N c                 S      g | ]
\}}d ||f qS %s|%sr   .0irr   r   r   
<listcomp>       z_look_grid.<locals>.<listcomp>c                       g | ]} fd d|D qS )c                       g | ]} |qS r   r   rC   vr   r   r   rF          )_look_grid.<locals>.<listcomp>.<listcomp>r   rC   rowrL   r   r   rF          c                 S      g | ]}t |qS r   lenrO   r   r   r   rF      rM   c                       g | ]}|d   qS r   r   rC   xr   r   r   rF          c                    rH   )c                    rU   r   r   rV   rX   r   r   rF      rY   rN   r   rC   valsreprrX   r   r   rF          r   +-   
=| z |   )iternextStopIterationlistmapr   	enumeraterT   extendmaxzip
isinstancer   boolappend)r   r   r   r   r   ithdrfldsfldsreprrowsrowsreprrowlens	maxrowlenr[   	colwidthsrD   frvrsepwhedsepfldslinefrowlinesvalsrowliner*   liner   r   r   r   r(      s   





r(   c                    s  t | }zt|}W n
 ty   Y dS w ttt|}|r(dd t|D }n|}t|}	fdd|	D }
t|g}|dd |	D  t	|}t||k r\|dg|t|   |
D ]}t||k rr|dg|t|   q^ r fdd|D } fdd|
D }
dg| }t|D ]
\}}t|||< q|
D ]}t|D ]\}}t||| krt|||< qqd	
d
d |D }|r|d | }|d7 }d	
dd t||D }|r|d | }|d7 }t }t|	|
D ]X\}}d}t|D ];\}}|| }|t|k rt|| trt|| ts|||7 }n|||7 }|t|d k r3|d	7 }q|r=|d | }|d7 }|| q|| | }|D ]}||7 }qO||7 }|S )Nr>   c                 S   r?   r@   r   rB   r   r   r   rF   2  rG   z _look_simple.<locals>.<listcomp>c                    rH   )c                    rI   r   r   rJ   rL   r   r   rF   8  rM   +_look_simple.<locals>.<listcomp>.<listcomp>r   rO   rL   r   r   rF   8  rQ   c                 S   rR   r   rS   rO   r   r   r   rF   <  rM   c                    rU   r   r   rV   rX   r   r   rF   H  rY   c                    rH   )c                    rU   r   r   rV   rX   r   r   rF   I  rY   r   r   rZ   rX   r   r   rF   I  r\   r     c                 s   s    | ]}d | V  qdS )ra   Nr   )rC   r}   r   r   r   	<genexpr>V  s    z_look_simple.<locals>.<genexpr>r`   c                 s       | ]
\}}| |V  qd S r   ljustrC   r   r}   r   r   r   r   \      rd   re   rf   rg   rh   ri   r   rj   rT   rk   rl   joinrm   rn   r   ro   rjustr   rp   )r   r   r   r   r   rq   rr   rs   rt   ru   rv   rw   rx   r[   ry   rD   rz   r{   r~   r   r   r   r   r}   r*   r   r   r   r   r&   (  s   


r&   c                    s~  t | }zt|}W n
 ty   Y dS w ttt|}|r(dd t|D }n|}t|}	fdd|	D }
t|g}|dd |	D  t	|}t||k r\|dg|t|   |
D ]}t||k rr|dg|t|   q^ r fdd|D } fdd|
D }
dg| }t|D ]
\}}t|||< q|
D ]}t|D ]\}}t||| krt|||< qqd	
d
d t||D }|r|d | }|d7 }t }t|	|
D ]X\}}d}t|D ];\}}|| }|t|k r	t|| tr	t|| ts	|||7 }n|||7 }|t|d k r|d	7 }q|r'|d | }|d7 }|| q|}|D ]}||7 }q5|S )Nr>   c                 S   r?   r@   r   rB   r   r   r   rF     rG   z!_look_minimal.<locals>.<listcomp>c                    rH   )c                    rI   r   r   rJ   rL   r   r   rF     rM   ,_look_minimal.<locals>.<listcomp>.<listcomp>r   rO   rL   r   r   rF     rQ   c                 S   rR   r   rS   rO   r   r   r   rF     rM   c                    rU   r   r   rV   rX   r   r   rF     rY   c                    rH   )c                    rU   r   r   rV   rX   r   r   rF     rY   r   r   rZ   rX   r   r   rF     r\   r   r   c                 s   r   r   r   r   r   r   r   r     r   z _look_minimal.<locals>.<genexpr>r`   rd   r   )r   r   r   r   r   rq   rr   rs   rt   ru   rv   rw   rx   r[   ry   rD   rz   r{   r   r   r   r   r}   r*   r   r   r   r   r'   ~  sx   


r'   c                 C   s:   |dkrt j}|du rt j}|du rt j}t| |||dS )aS  
    Format a portion of a table as text in a column-oriented layout for
    inspection in an interactive session. E.g.::

        >>> import petl as etl
        >>> table = [['foo', 'bar'], ['a', 1], ['b', 2]]
        >>> etl.see(table)
        foo: 'a', 'b'
        bar: 1, 2

    Useful for tables with a larger number of fields.


    r   N)r   r   r   )r	   	see_limit	see_vreprsee_index_headerSeer   r   r   r   r   r   r   see  s   r   c                   @   r   )r   c                 C   s   || _ || _|| _|| _d S r   r   )r    r   r   r   r   r   r   r   r!     s   
zSee.__init__c              
   C   s  t | j| j\}}| j}| j}d}t|}zt|}W n
 ty%   Y dS w tt	}|D ],}	t
|D ]%\}
}z|t|
 ||	|
  W q2 tyW   |t| d Y q2w q,t
|D ]&\}
}|rid|
|f }|d|d|t|
 f 7 }|r|d7 }q]|d7 }q]|S )Nr>   rA   z%s: %sz, r$   r`   )r%   r   r   r   r   re   rf   rg   r   rh   rj   r4   rp   
IndexErrorr   )r    r   r)   r   r   r*   rq   rs   colsrP   rD   r   r   r   r   r+     s6   

zSee.__repr__Nr,   r   r   r   r   r     s
    !r   c                 C   sD   d}|rt t| d|d } t| |d krd}| d d } | |fS )NFr   r_   rd   T)rh   r   rT   )r   r   r)   r   r   r   r%     s   r%   c
                 C   s   |dkrt j}|d u rt j}|d u rt j}|d u rt }t| |\} }
t }t| ||||||||d	 t	|
 |}|	rE|d|	 7 }|S |
rK|d7 }|S )Nr   )encodingr   r   captiontr_style	td_stylesr   z	<p>%s</p>z<p><strong>...</strong></p>)r	   display_limitdisplay_vreprdisplay_index_headerlocalegetpreferredencodingr%   r   r   r   getvalue)r   r   r   r   r   r   r   r   r   epiloguer)   bufr*   r   r   r   _display_html#  s*   
r   c
                 C   s8   ddl m}
 t| |||||||||	d
}|
|dd dS )z=
    Display a table inline within an IPython notebook.

    r   )display_html)	r   r   r   r   r   r   r   r   r   T)rawN)IPython.core.displayr   r   )r   r   r   r   r   r   r   r   r   r   r   htmlr   r   r   displayC  s   r   c                 K   s   d|d< t | fi | dS )z
    Display **all rows** from a table inline within an IPython notebook (use
    with caution, big tables will kill your browser).

    Nr   )r   r8   r   r   r   
displayallW  s   r   )r   NNNNN)r   )r   NN)	r   NNNNNNNN))
__future__r   r   r   r   	itertoolsr   collectionsr   petl.compatr   r   petlr	   petl.util.baser
   petl.io.sourcesr   petl.io.htmlr   r   objectr   r6   r+   r:   r;   r<   r0   r1   r=   r(   r&   r'   r   r   r%   r   _repr_html_r   r   r   r   r   r   <module>   sX    
F-

gV
O-


