
    ˀh                        d Z ddlmZ ddlZddlZddlmZ ddlmZ ddl	m
Z
 erddlmZ ddlmZ dd	lmZ dd
Z G d d      Z G d d      Z G d de      Zy)z*Module for formatting output data in HTML.    )annotationsN)dedent)TYPE_CHECKING)html)Iterable)TracebackType)	DataFramec                2    t        j                  dd |       S )z9Replace consecutive spaces with HTML non-breaking spaces.z( {2,})c                <    dt        | j                  d            z  S )Nz&nbsp;r   )lengroup)matchs    r/var/www/html/wine-match-dev/backend/winematch-backend/venv/lib/python3.12/site-packages/polars/dataframe/_html.py<lambda>z,replace_consecutive_spaces.<locals>.<lambda>   s    Hs5;;q>7J,J     )resub)ss    r   replace_consecutive_spacesr      s    66*JANNr   c                  J    e Zd ZdZ	 d	 	 	 	 	 	 	 ddZddZ	 	 	 	 	 	 	 	 d	dZy)
Tagz#Class for representing an HTML tag.Nc                .    || _         || _        || _        y N)tagelements
attributes)selfr   r   r   s       r   __init__zTag.__init__   s      $r   c                F   | j                   ld| j                   d}| j                   j                         D ]  \  }}|| d| dz  } |j                          d}| j                  j                  |       y | j                  j                  d| j                   d       y )N< z="z" >)r   r   itemsrstripr   append)r   r   kvs       r   	__enter__zTag.__enter__%   s    ??&DHH:QA--/ #1s"QCr]"#88:,a AMM  #MM  1TXXJa1r   c                V    | j                   j                  d| j                   d       y )Nz</r"   )r   r%   r   )r   exc_typeexc_valexc_tbs       r   __exit__zTag.__exit__/   s#     	r$((1-.r   r   )r   	list[str]r   strr   zdict[str, str] | NonereturnNoner0   r1   )r*   ztype[BaseException] | Noner+   zBaseException | Noner,   zTracebackType | Noner0   r1   )__name__
__module____qualname____doc__r   r(   r-    r   r   r   r      se    - -1	%% % *	%
 
%2/,/ &/ %	/
 
/r   r   c                  P    e Zd Zdddd	 	 	 	 	 	 	 	 	 ddZddZddZddZdd	Zy
)HTMLFormatterK   (   F)max_colsmax_rowsfrom_seriesc               N   || _         g | _        || _        || _        || _        |  |  ||j
                  k  r\t        |d      \  }}g t        t        ||z               dt        t        |j
                  |z
  |j
                              | _	        nt        |j
                        | _	        ||j                  k  rPg t        t        |dz              dt        t        |j                  |dz  z
  |j                              | _        y t        |j                        | _        y )N   )dfr   r<   r=   r>   heightdivmodlistrangerow_idxwidthcol_idx)r   rB   r<   r=   r>   halfrests          r   r   zHTMLFormatter.__init__9   s    #%  &bii!,JD$eD4K() eBII,bii89DL !+DLbhheHM*+ eBHHx1}4bhh?@DL !?DLr   c           
     \   t        | j                  d      5  t        t        t        j
                  j                  dd                  st        | j                  d      5  | j                  j                  }| j                  D ]s  }t        | j                  d      5  |dk(  r| j                  j                  d       n1| j                  j                  t        j                  ||                ddd       u 	 ddd       t        t        t        j
                  j                  d	d                  st        | j                  d      5  | j                  j                  j                         }| j                  D ]`  }t        | j                  d
      5  |dk(  r| j                  j                  d       n| j                  j                  ||          ddd       b 	 ddd       ddd       y# 1 sw Y   wxY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   8xY w# 1 sw Y   yxY w)z"Write the header of an HTML table.thead"POLARS_FMT_TABLE_HIDE_COLUMN_NAMES0trthrA   &hellip;N'POLARS_FMT_TABLE_HIDE_COLUMN_DATA_TYPEStd)r   r   boolintosenvirongetrB   columnsrI   r%   r   escape_dfdtype_strings)r   rZ   cdtypess       r   write_headerzHTMLFormatter.write_header[   s   ( 	@BJJNN+OQTUVW- N"ggooG!\\ N 5 N Bw $ 4 4Z @ $ 4 4T[[5L M	N NNN BJJNN#LcRS - @!WW[[668F!\\ @ 5 @ Bw $ 4 4Z @ $ 4 4VAY ?	@ @@@	@ 	@
N NN N@ @@ @	@ 	@sp   A	H" <G=AG0	/
G=:AH"
A
HA H
	
HH"0G:5G==H	H"
HHH	H""H+c                   t        t        j                  j                  dd            }t	        | j
                  d      5  | j                  D ]  }t	        | j
                  d      5  | j                  D ]  }t	        | j
                  d      5  |dk(  s|dk(  r| j
                  j                  d       nd| j                  d	d	|f   }| j
                  j                  t        t        j                  |j                  j                  ||                         d	d	d	        	 d	d	d	        	 d	d	d	       y	# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y	xY w)
z Write the body of an HTML table.POLARS_FMT_STR_LEN   )defaulttbodyrP   rT   rA   rR   N)rV   rW   rX   rY   r   r   rG   rI   r%   rB   r   r   r[   _sget_fmt)r   str_len_limitrr^   seriess        r   
write_bodyzHTMLFormatter.write_bodys   s#   BJJNN+?NLM( 	"\\ "- "!\\ 
" 5 	" Bw!r' $ 4 4Z @)-A $ 4 4$>(,FII4E4Ea4W(X%&!"	" 	"
"" ""	" 	"	" 	"" "	" 	"s=   &E'&EBD7
E#
E7E <EEEEc                :    | j                   j                  |       y)z&Append a raw string to the inner HTML.N)r   r%   )r   inners     r   writezHTMLFormatter.write   s    U#r   c                   t        t        t        j                  j	                  dd                  s\| j
                  j                  }| j                  r
d|d   ddnd|d   dd|d   dd	}| j                  j                  d
| d       t        | j                  dddd      5  | j                          | j                          ddd       | j                  S # 1 sw Y   | j                  S xY w)/Return the lines needed to render a HTML table.1POLARS_FMT_TABLE_HIDE_DATAFRAME_SHAPE_INFORMATIONrO   (r   _z,)z,    )z<small>shape: z</small>table1	dataframe)borderclassN)rU   rV   rW   rX   rY   rB   shaper>   r   r%   r   r`   rk   )r   r   r{   s      r   renderzHTMLFormatter.render   s    

RTWX
 A&*&6&6a!QxrNa!Qxr!A$qQR<SEMM  >%!AB MM[1
 	 OO	 }}	 }}s   )!CC2N)
rB   r	   r<   rV   r=   rV   r>   rU   r0   r1   r2   )rm   r/   r0   r1   r0   r.   )r3   r4   r5   r   r`   rk   rn   r|   r7   r   r   r9   r9   8   sX    
 ! + + 	 +
  +  + 
 +D@0"$$r   r9   c                  ,     e Zd ZdZddZd fdZ xZS )NotebookFormatterz
    Class for formatting output data in HTML for display in Jupyter Notebooks.

    This class is intended for functionality specific to DataFrame._repr_html_().
    c                <    d}| j                  t        |             y )Nz            <style>
            .dataframe > thead > tr,
            .dataframe > tbody > tr {
              text-align: right;
              white-space: pre-wrap;
            }
            </style>
        )rn   r   )r   styles     r   write_stylezNotebookFormatter.write_style   s     	

6%=!r   c                    t        | j                  d      5  | j                          t        |           ddd       | j                  S # 1 sw Y   | j                  S xY w)rp   divN)r   r   r   superr|   )r   	__class__s    r   r|   zNotebookFormatter.render   sO    & 	GN	 }}	 }}s   AAr2   r}   )r3   r4   r5   r6   r   r|   __classcell__)r   s   @r   r   r      s    
" r   r   )r   r/   r0   r/   )r6   
__future__r   rW   r   textwrapr   typingr   polars.dependenciesr   collections.abcr   typesr   polarsr	   r   r   r9   r   r7   r   r   <module>r      sP    0 " 	 	    $(# O
/ /@g gT r   