
    -Ph[                         d Z dZddlZddlmZ ddlmZ ddlZddlm	Z	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 Z G d de          Z G d de          Z G d de          Z G d de          ZdS )z 
Directives for table elements.
reStructuredText    N)urlopen)URLError)nodesstatemachine)	FileInputStringInput)	Directive)
directives)
adapt_path)SystemMessagePropagationc                 ,    t          j        | d          S )N)leftcenterright)r   choice)arguments    f/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/docutils/parsers/rst/directives/tables.pyalignr      s    X'BCCC    c                       e Zd ZdZdZdZej        ej        e	ej
         ej        dej                  dZdZd Zd Zd Zed	             Zd
 Zd ZdS )Tablez#
    Generic table base class.
       T)autogrid)classnamer   widthwidthsc                     | j         rp| j         d         }| j                            || j                  \  }}t	          j        |dg|R  }| j                            | j                  \  |_        |_	        nd }g }||fS )Nr    )
	argumentsstateinline_textlinenor   titlestate_machineget_source_and_linesourceline)self
title_text
text_nodesmessagesr&   s        r   
make_titlezTable.make_title-   s    > 		*J#':#9#9*:>+$G $G JK
B<<<<E-AA$+NNU\ZZEHhr   c           	         t          |          |k     ri| j                            |dt          |          d| j        dt	          j        | j        | j                  | j                  }t          |          t          |          |cxk    rdk    rjn ng| j                            dt          |           d| j         dt	          j        | j        | j                  | j                  }t          |          |D ]}t          |          |k     ri| j                            | d	t          |           d
| j         dt	          j        | j        | j                  | j                  }t          |          t          |          |cxk    rdk    rjn | j                            dt          |          d| j        dt	          j        | j        | j                  | j                  }t          |          d S )Nz" header row(s) specified but only z row(s) of data supplied ("z" directive).r*   r   zInsufficient data supplied (z9 row(s)); no data remaining for table body, required by "z" directive.z# stub column(s) specified but only z columns(s) of data supplied ("z= columns(s)); no data remaining for table body, required by ")	lenreportererrorr   r   literal_block
block_textr%   r   )r+   rowsheader_rowsstub_columnsr4   rows         r   check_table_dimensionszTable.check_table_dimensions:   sM   t99{""M'';;D				4999)6 #DOT_EE[	 ( " "E
 +5111t99''''a'''''M''8s4yy 8 8 $	8 8 8 #DOT_EE[ ( " "E +5111 	6 	6C3xx,&&++# 2 2 #C2 22 2 2 'II , & & /u5553xx<++++!++++++++ -0HHHHdiiiA 'II , & & /u555 ,	6 	6r   c                 V    d| j         v r| j                             d          |d<   d S d S )Nr   optionsget)r+   
table_nodes     r   set_table_widthzTable.set_table_width\   s7    dl"""&,"2"27";";Jw #"r   c                 8    | j                             dd          S )Nr   r!   r=   )r+   s    r   r   zTable.widths`   s    |"---r   c                    t          | j        t                    rzt          | j                  |k    rZ| j                            d| j        d|dt          j        | j	        | j	                  | j
                  }t          |          | j        }nZ|r
d|z  g|z  }nN| j                            dt          j        | j	        | j	                  | j
                  }t          |          |S )N"z6" widths do not match the number of columns in table ().r1   d   z#No table data detected in CSV file.)
isinstancer   listr2   r3   r4   r   r   r5   r6   r%   r   )r+   n_colsr4   
col_widthss       r   get_column_widthszTable.get_column_widthsd   s    dk4(( 	24;6))+++:>)))VVV-M'II , & & /u555JJ 	2-61JJM''(M#DOT_EE[ ( " "E +5111r   c           	          |D ]G}|D ]B}t          |          |k     r-|                    dddg fg|t          |          z
  z             CHd S )Nr   )r2   extend)r+   columnspartspartr:   s        r   "extend_short_rows_with_empty_cellsz(Table.extend_short_rows_with_empty_cellsw   st     	G 	GD G Gs88g%%JJAq"'CHH2DEFFFG	G 	Gr   N)__name__
__module____qualname____doc__optional_argumentsfinal_argument_whitespacer   class_option	unchangedr    length_or_percentage_or_unitlessvalue_orpositive_int_listoption_spechas_contentr/   r;   rA   propertyr   rK   rQ    r   r   r   r      s           $&3%/!&G0Z01A1;1MO O	P PK K   6  6  6D< < < . . X.  &G G G G Gr   r   c                       e Zd ZdZd ZdS )RSTTablez
    Class for the `"table" directive`__ for formal tables using rST syntax.

    __ https://docutils.sourceforge.io/docs/ref/rst/directives.html
    c                    | j         sJ| j                            d| j        z  t	          j        | j        | j                  | j                  }|gS |                                 \  }}t	          j	                    }| j
                            | j         | j        |           t          |          dk    s t          |d         t          j                  sJ| j                            d| j        z  t	          j        | j        | j                  | j                  }|gS |d         }|dxx         | j                            dg           z  cc<   |                     |           d| j        v r| j                            d          |d<   t          | j        t*                    rv|d         }	 |                     |d	                   }n%# t.          $ r}	|	j        d         gcY d }	~	S d }	~	ww xY wd
 |j        D             }
t5          |
|          D ]
\  }}||d<   | j        dk    r|dxx         dgz  cc<   n| j        r|dxx         dgz  cc<   |                     |           |r|                    d|           |g|z   S )Nz:Content block expected for the "%s" directive; none found.r1   r   r   zOError parsing content block for the "%s" directive: exactly one table expected.classesr   r   colsc                 (    g | ]}|j         d k    |S )colspec)tagname).0childs     r   
<listcomp>z RSTTable.run.<locals>.<listcomp>   s.     7 7 7% =I55 555r   colwidthr   colwidths-autocolwidths-given)contentr3   warningr   r   r5   r6   r%   r/   Elementr#   nested_parsecontent_offsetr2   rG   tabler4   r>   r?   rA   r   rH   rK   r   argschildrenzipadd_nameinsert)r+   rp   r&   r.   noder4   r@   tgrouprJ   detailcolspecsrg   	col_widths                r   runzRSTTable.run   s   | 	m++ -68<	-B#DOT_EE[ , " "G 9//++x}
d.A4HHHt99>>DGU[!A!A>M'' )>@D	)J#DOT_EE[ ( " "E 7N!W
9!1!1'2!>!>>Z(((dl"""&,"2"27";";Jwdk4(( 		0]F(!33F6NCC

+ ( ( (A'''''''(7 76? 7 7 7H&)(J&?&? 0 0"&/
##;&  y!!!&6%77!!!![ 	9y!!!&7%88!!!j!!! 	(a'''|h&&s   .G
 

G,G'!G,'G,N)rR   rS   rT   rU   r   r`   r   r   rb   rb   ~   s-         &' &' &' &' &'r   rb   c                      e Zd Zej        ej        ej        ej         ej        dej                  ej	        ej
        ej        ej        ej        eej        ej        ej        ej        dZ G d dej                  Z G d dej                  Zed             Zd Zd	 Zd
 Zed             Zed             Zd ZdS )CSVTabler   )header-rowsstub-columnsheaderr   r   fileurlencodingr   r   r   delim	keepspacequoteescapec                   H     e Zd ZdZdZdZdZdZdZdZ	e
j        Z fdZ xZS )CSVTable.DocutilsDialectz&CSV dialect for `csv_table` directive.,rD   T
c                     d|v r|d         | _         d|v rd| _        d|v r|d         | _        d|v rd| _        |d         | _        t                                                       d S )Nr   r   Fr   r   )	delimiterskipinitialspace	quotechardoublequote
escapecharsuper__init__)r+   r>   	__class__s     r   r   z!CSVTable.DocutilsDialect.__init__   s    '!!!(!1g%%(-%'!!!(!17""#( ")("3GGr   )rR   rS   rT   rU   r   r   r   r   strictlineterminatorcsvQUOTE_MINIMALquotingr   __classcell__r   s   @r   DocutilsDialectr      se        44		#
	 
	 
	 
	 
	 
	 
	 
	 
	r   r   c                   L     e Zd ZdZdZdZdZdZdZdZ	dZ
ej        Z fdZ xZS )	CSVTable.HeaderDialectzw
        CSV dialect used for the "header" option data.

        Deprecated. Will be removed in Docutils 0.22.
        r   rD   \FTr   c                     t          j        dt          d           t                                                       d S )Nz8CSVTable.HeaderDialect will be removed in Docutils 0.22.   
stacklevel)warningswarnPendingDeprecationWarningr   r   )r+   r   s    r   r   zCSVTable.HeaderDialect.__init__   sH    M .3C C C C GGr   )rR   rS   rT   rU   r   r   r   r   r   r   r   r   r   r   r   r   r   s   @r   HeaderDialectr      sp        	 	& 		
#	 	 	 	 	 	 	 	 	r   r   c                  >    t          j        dt          d           d S )NzaCSVTable.check_requirements() is not required with Python 3 and will be removed in Docutils 0.22.r   r   r   r   DeprecationWarningr`   r   r   check_requirementszCSVTable.check_requirements   s1     ? )Q	8 	8 	8 	8 	8 	8r   c                 2   | j                             | j        dz
            }g }d}d| j        v re|                     | j        d                             d          |                     | j                  |          \  }}|                    |           ||fS )Nr   r   r   r   )r'   
get_sourcer%   r>   parse_csv_data_into_rowssplitr   rM   )r+   r)   
table_headmax_header_colsr7   s        r   process_header_optionzCSVTable.process_header_option  s    #..t{Q??
t|##$($A$A(,X(>(D(DT(J(J(,(<(<T\(J(J(.%0 %0!D/ d###?**r   c                    	 | j         j        j        j        s\d| j        v s	d| j        v rJ| j                            d| j        z  t          j	        | j
        | j
                  | j                  }|gS |                                 \  }}|                                 \  }}|                                 \  }}|                     ||                     | j                  |          \  }}	t#          |	|          }	| j                            dd          }
| j                            dd          }|                     ||
|           |                    |d |
                    ||
d          }|                     |	          }|                     |	||f           n# t.          $ r}|j        d         gcY d }~S d }~wt2          j        $ rf}t7          |          }| j                            d| j        d	|t          j	        | j
        | j
                  | j                  }|gcY d }~S d }~ww xY w|||f}| j                             || j        || j        
          }|dxx         | j                            dg           z  cc<   d| j        v r| j                            d          |d<   |                      |           | !                    |           |r|"                    d|           |g|z   S )Nr   r   z9File and URL access deactivated; ignoring "%s" directive.r1   r   r   r   zError with CSV data in "z" directive:
)r   rd   r   r   )#r#   documentsettingsfile_insertion_enabledr>   r3   rp   r   r   r5   r6   r%   r/   get_csv_datar   r   r   maxr?   r;   rM   rK   rQ   r   ru   r   Errorstrr4   build_tablers   r   rA   rx   ry   )r+   rp   r&   r.   csv_datar)   r   r   r7   max_colsr8   r9   
table_bodyrJ   r|   messager4   rt   r@   s                      r   r   zCSVTable.run  sP   	J'0G !t|++---// 1<>Bi1H'II 0 & &  y "oo//OE8#0022Hf*.*D*D*F*F'J!::$..t|<<fF FND(8_55H,**=!<<K<++NA>>L''k<HHHd<K<0111kll+J//99J33H5?4LN N N N' 	$ 	$ 	$KN#######y 	 	 	&kkGM'''-1YYY)A#DOT_EE[ ( " "E 7NNNNNN	 Z4Z++E43F,8 , N N
9!1!1'2!>!>>dl"""&,"2"27";";JwZ(((j!!! 	(a'''|h&&s8   A1F 4D(F 
H2'F:4H2:H2AH-'H2-H2c           
      (   | j         j        j        }| j                            d|j                  }|j        }| j        rd| j        v s	d| j        v rV| j        	                    d| j
        z  t          j        | j        | j                  | j                  }t          |          | j                            d          }| j        }nd| j        v rPd| j        v rV| j        	                    d| j
        z  t          j        | j        | j                  | j                  }t          |          t#          | j        d         | j         j        j        |j                  }	 t)          |||          }|                                                                }|j                            |           n# t2          $ r_}| j                            d	| j
        d
|dt          j        | j        | j                  | j                  }t          |          d}~ww xY wd| j        v r| j        d         }	 t7          |          5 }	|	                                }
ddd           n# 1 swxY w Y   n# t8          t2          t:          f$ rm}| j                            d	| j
        d| j        d         d|dt          j        | j        | j                  | j                  }t          |          d}~ww xY wt=          |
|||          }|                                                                }nV| j                            d| j
        z  t          j        | j        | j                  | j                  }t          |          ||fS )zr
        Get CSV data from the directive content, from an external
        file, or from a URL reference.
        r   r   r   zF"%s" directive may not both specify an external file and have content.r1   r   zXThe "file" and "url" options may not be simultaneously specified for the "%s" directive.)source_pathr   error_handlerzProblems with "z" directive path:
.Nz" directive URL "z":
)r)   r   r   r   z3The "%s" directive requires content; none supplied.) r#   r   r   r>   r?   input_encodinginput_encoding_error_handlerro   r3   r4   r   r   r5   r6   r%   r   r)   r   current_sourceroot_prefixr   read
splitlinesrecord_dependenciesaddOSErrorseverer   r   
ValueErrorr	   rp   )r+   r   r   r   r4   r)   r   csv_filer   responsecsv_texts              r   r   zCSVTable.get_csv_data@  s   
 :&/<##J0GHH =< :	2%%$,)>)>++ -ACG9-M'II , & & /u555\((++F|HHt|##$$++ -.04	-: 'II	 , & &
 /u555V 4 $
 3 B ( 46 6F9$.63@B B B $==??5577 ,008888  7 7 7---yyy%%%)'II	 . & &
 /v6667 dl""\%(F	7V__ /'}}H/ / / / / / / / / / / / / / /gz2 7 7 7---DL$7$7$7@)$/4?KK;	 . ( (
 /v6667 #(,41>@ @ @H  }}1133HHM))E)#DOT_EE[	 * " "E
 +5111sV   %8F9 9
H"AHH"=I9 I-!I9 -I11I9 4I15I9 9K=A(K88K=c                 >    t          j        dt          d           | S )NzgCSVTable.decode_from_csv() is not required with Python 3 and will be removed in Docutils 0.21 or later.r   r   r   ss    r   decode_from_csvzCSVTable.decode_from_csv  /     D %	4 	4 	4 	4 r   c                 >    t          j        dt          d           | S )NzgCSVTable.encode_from_csv() is not required with Python 3 and will be removed in Docutils 0.21 or later.r   r   r   r   s    r   encode_for_csvzCSVTable.encode_for_csv  r   r   c           	      P   t          j        d |D             |          }g }d}|D ]|}g }|D ]C}	dddt          j        |	                                |          f}
|                    |
           D|                    |           t          |t          |                    }}||fS )Nc              3       K   | ]	}|d z   V  
dS )r   Nr`   )ri   r*   s     r   	<genexpr>z4CSVTable.parse_csv_data_into_rows.<locals>.<genexpr>  s&       B B B B B B B Br   )dialectr   )r)   )r   readerr   
StringListr   appendr   r2   )r+   r   r   r)   
csv_readerr7   r   r:   row_datacell	cell_datas              r   r   z!CSVTable.parse_csv_data_into_rows  s    Z B B B B B(/1 1 1
 	/ 	/CH + +1l&=OO%%f'6 '6 '6 7		****KK!!!8SXX..HHX~r   N)rR   rS   rT   r   nonnegative_intrY   rZ   r[   r\   pathurir   rX   r   $single_char_or_whitespace_or_unicodeflagsingle_char_or_unicoder]   r   Dialectr   r   staticmethodr   r   r   r   r   r   r   r`   r   r   r   r      sw       ","<#-#='1&G0Z01;1MO O%?$.)2&3%/!&K *&='>'@ @K*    #+   0! ! ! ! ! ! ! !F 8 8 \8
+ 
+ 
++' +' +'ZC  C  C J   \   \    r   r   c                       e Zd ZdZej        ej        ej         ej        dej                  ej	        ej
        edZd Zd Zd ZdS )	ListTablez
    Implement tables whose data is encoded as a uniform two-level bullet list.
    For further ideas, see
    https://docutils.sourceforge.io/docs/dev/rst/alternatives.html#list-driven-tables
    r   )r   r   r   r   r   r   r   c                    | j         sJ| j                            d| j        z  t	          j        | j        | j                  | j                  }|gS |                                 \  }}t	          j	                    }| j
                            | j         | j        |           	 |                     |          \  }}d |d         D             }| j                            dd          }| j                            dd          }	|                     |||	           n%# t"          $ r}
|
j        d         gcY d }
~
S d }
~
ww xY w|                     ||||	          }d| j        v r| j                            d          |d<   |dxx         | j                            d	g           z  cc<   |                     |           |                     |           |r|                    d|           |g|z   S )
Nz.The "%s" directive is empty; content required.r1   c                 2    g | ]}d  |d         D             S )c                     g | ]	}|j         
S r`   )rv   )ri   items     r   rk   z,ListTable.run.<locals>.<listcomp>.<listcomp>  s    AAAT4=AAAr   r   r`   )ri   row_lists     r   rk   z!ListTable.run.<locals>.<listcomp>  s;     3 3 3& BAXa[AAA 3 3 3r   r   r   r   r   rd   r   )ro   r3   r4   r   r   r5   r6   r%   r/   rq   r#   rr   rs   check_list_contentr>   r?   r;   r   ru   build_table_from_listrA   rx   ry   )r+   r4   r&   r.   rz   num_colsrJ   
table_datar8   r9   r|   r@   s               r   r   zListTable.run  s!   | 	M'' )$&*i)0#DOT_EE[ ( " "E 7N//++x}
d.A4HHH	$#'#:#:4#@#@ Hj3 3*.q'3 3 3J,**=!<<K<++NA>>L''
KNNNN' 	$ 	$ 	$KN#######	$//
J0;\K K
dl"""&,"2"27";";Jw9!1!1'2!>!>>Z(((j!!! 	(a'''|h&&s   #A7D 
D=%D82D=8D=c                    t          |          dk    s t          |d         t          j                  sV| j                            d| j        z  t          j        | j        | j                  | j	                  }t          |          |d         }d}t          t          |                    D ]C}||         }t          |          dk    s t          |d         t          j                  s]| j                            d| j        d|dz   dt          j        | j        | j                  | j	                  }t          |          |rt          |d                   |k    rv| j                            d| j        d|dz   d	t          |d                   d
|d	t          j        | j        | j                  | j	                  }t          |          .t          |d                   }E|                     |          }||fS )Nr   r   zUError parsing content block for the "%s" directive: exactly one bullet list expected.r1   z%Error parsing content block for the "z5" directive: two-level bullet list expected, but row z- does not contain a second-level bullet list.z=" directive: uniform two-level bullet list expected, but row z5 does not contain the same number of items as row 1 (z vs rE   )r2   rG   r   bullet_listr3   r4   r   r5   r6   r%   r   rangerK   )r+   rz   r4   	list_noder   
item_indexr   rJ   s           r   r   zListTable.check_list_content  s   t99>>DGU5F!G!G>M''46:i@#DOT_EE[	 ( " "E
 +5111G	I// 	( 	(JZ(D4yyA~~ZQ9J%K%K~+++ yyy*q...2 'II , & & /u555 (tAw<<8++ M///
  999j1nnnc$q'llllHHH	N
 +DOT_MM![ 0 * *E 35999 , tAw<<++H55
##r   c                    t          j                    }| j        dk    r|dxx         dgz  cc<   n| j        r|dxx         dgz  cc<   t          j        t	          |                    }||z  }|D ]7}t          j                    }|
||j        d<   |rd|j        d<   |dz  }||z  }8g }	|D ]L}
t          j                    }|
D ]}t          j                    }||z  }||z  } |		                    |           M|r5t          j
                    }|                    |	d |                    ||z  }t          j                    }|                    |	|d                     ||z  }|S )	Nr   rd   rm   rn   )re   rl   r   stub)r   rt   r   r{   r2   rg   
attributesr:   entryr   theadrM   tbody)r+   r   rJ   r8   r9   rt   r{   r~   rg   r7   r:   row_noder   r  r  r  s                   r   r   zListTable.build_table_from_list  s   ;&  )!1 22[ 	4)!2 333z??333# 	 	ImooG$1:":. "-."6*!gFF 	" 	"Cy{{H " "E!KK!!!! 	KMMELLl{l+,,,eOFT+,,'(((%r   N)rR   rS   rT   rU   r   r   rZ   r[   r\   rX   rY   r   r]   r   r   r   r`   r   r   r   r     s          #-"<#-#=&G0Z01;1MO O&3%/!# #K' ' '<$$ $$ $$L         r   r   )rU   __docformat__r   urllib.requestr   urllib.errorr   r   docutilsr   r   docutils.ior   r	   docutils.parsers.rstr
   r   $docutils.parsers.rst.directives.miscr   docutils.utilsr   r   r   rb   r   r   r`   r   r   <module>r     s  
  # 


 " " " " " " ! ! ! ! ! !  ( ( ( ( ( ( ( ( . . . . . . . . * * * * * * + + + + + + ; ; ; ; ; ; 3 3 3 3 3 3D D D^G ^G ^G ^G ^GI ^G ^G ^GB-' -' -' -' -'u -' -' -'`t t t t tu t t tnu u u u u u u u u ur   