
    N&iDY                         d Z dZddlZddlZddlZddlmZmZ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)ionodesstatemachineutils)
SafeString)SystemMessagePropagation)	Directive)
directivesc                 ,    t          j        | d          S )N)leftcenterright)r   choice)arguments    s/home/geonatureadmin/si_en_reseau/tutos/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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                 &   | j                             | j        dz
            }g }d}d| j        v r_|                     | j        d                             d          |                                 |          \  }}|                    |           ||fS )Nr   r   header
)r%   
get_sourcer#   optionsparse_csv_data_into_rowssplitHeaderDialectextend)r)   r'   
table_headmax_header_colsrowss        r   process_header_optionzTable.process_header_option8   s    #..t{Q??
t|##$($A$AX&,,T22D4F4F4H4H% %!D/ d###?**r   c           	      <   t          |          |k     rn| j        j                            |dt          |          d| j        dt          j        | j        | j                  | j                  }t          |          t          |          |cxk    rdk    ron nl| j        j                            dt          |          d| j        dt          j        | j        | j                  | j                  }t          |          |D ]}t          |          |k     rn| j        j                            |d	t          |          d
| j        dt          j        | j        | j                  | j                  }t          |          t          |          |cxk    rdk    ron | j        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 ")
lenr%   reportererrorr   r   literal_block
block_textr#   r	   )r)   r9   header_rowsstub_columnsr?   rows         r   check_table_dimensionszTable.check_table_dimensionsC   sT   t99{""&/55 ;;D				499967<7J82 828<	 6 E EE
 +5111t99''''a'''''&/555 t9999diii)*/*=+2 +28<	 6 E EE
 +5111 	6 	6C3xx,&&*399 "\\3s8888TYYY89>9LOT_:6 :6<@K	 : I I
 /u5553xx<++++!+++++*3999 3xxxx,-2-@OT_.6 .6<@K	 : I I
 /u555 ,	6 	6r   c                 V    d| j         v r| j                             d          |d<   d S d S )Nr   r2   get)r)   
table_nodes     r   set_table_widthzTable.set_table_widthb   s7    dl"""&,"2"27";";Jw #"r   c                 8    | j                             dd          S )Nr   r   rG   r)   s    r   r   zTable.widthsf   s    |"---r   c                    t          | j        t                    rt          | j                  |k    r_| j        j                            d| j        d|dt          j	        | j
        | j
                  | j                  }t          |          | j        }n_|r
d|z  g|z  }nS| j        j                            dt          j	        | j
        | j
                  | j                  }t          |          |S )N"z6" widths do not match the number of columns in table ().r<   d   z#No table data detected in CSV file.)
isinstancer   listr=   r%   r>   r?   r   r   r@   rA   r#   r	   )r)   n_colsr?   
col_widthss       r   get_column_widthszTable.get_column_widthsj   s   dk4(( 	24;6))*3999#yyy&&&2383FOT_46 46<@K : I I /u555JJ 	2-61JJ&/555u7J82 828< 6 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   )r=   r6   )r)   columnspartspartrD   s        r   "extend_short_rows_with_empty_cellsz(Table.extend_short_rows_with_empty_cells}   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:   rE   rJ   propertyr   rU   rZ    r   r   r   r      s           $&3%/!&G0Z01A1;1MO O	P PK K  	+ 	+ 	+6 6 6>< < < . . X.  &G G G G Gr   r   c                       e Zd Zd ZdS )RSTTablec                    | j         sO| j        j                            d| j        z  t          j        | j        | j                  | j                  }|gS | 	                                \  }}t          j
                    }| j                            | j         | j        |           t          |          dk    s t          |d         t
          j                  sO| j        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%# t0          $ r}	|	j        d         gcY d }	~	S d }	~	ww xY wd
 |j        D             }
t7          |
|          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.r<   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)contentr%   r>   warningr   r   r@   rA   r#   r-   Elementr!   nested_parsecontent_offsetr=   rQ   tabler?   r2   rH   rJ   r   rR   rU   r	   argschildrenzipadd_nameinsert)r)   ry   r$   r,   noder?   rI   tgrouprT   detailcolspecsrp   	col_widths                r   runzRSTTable.run   s   | 	(199L)"02 28< : E EG 9//++x}
d.A4HHHt99>>DGU[!A!A>&/55&(,	2383F42 428< 6 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   8G 
G6G1+G61G6N)r[   r\   r]   r   ri   r   r   rk   rk      s#        &' &' &' &' &'r   rk   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d Zd Zd	 Zej        d
k     rd Zd Znd Zd Z ee          Z ee          Zd ZdS )CSVTabler   )header-rowsstub-columnsr/   r   r   fileurlencodingr   r   r   delim	keepspacequoteescapec                   >    e Zd ZdZdZdZdZdZdZdZ	e
j        Zd ZdS )CSVTable.DocutilsDialectz&CSV dialect for `csv_table` directive.,rN   Tr0   c                 ^   d|v r%t                               |d                   | _        d|v rd| _        d|v r%t                               |d                   | _        d|v r,d| _        t                               |d                   | _        t          j        	                    |            d S )Nr   r   Fr   r   )
r   encode_for_csv	delimiterskipinitialspace	quotechardoublequote
escapecharcsvDialect__init__)r)   r2   s     r   r   z!CSVTable.DocutilsDialect.__init__   s    '!!!)!8!89I!J!Jg%%(-%'!!!)!8!89I!J!J7""#( "*"9"9'(:K"L"LK  &&&&&r   N)r[   r\   r]   r^   r   r   r   r   strictlineterminatorr   QUOTE_MINIMALquotingr   ri   r   r   DocutilsDialectr      sP        44		#
	' 
	' 
	' 
	' 
	'r   r   c                   <    e Zd ZdZdZdZdZdZdZdZ	dZ
ej        ZdS )	CSVTable.HeaderDialectz0CSV dialect to use for the "header" option data.r   rN   \FTr0   N)r[   r\   r]   r^   r   r   r   r   r   r   r   r   r   r   ri   r   r   r5   r      s@        >>		
#r   r5   c                     d S Nri   rL   s    r   check_requirementszCSVTable.check_requirements   s    r   c                 `   	 | j         j        j        j        sad| j        v s	d| j        v rO| j        j                            d| j        z  t          j
        | j        | j                  | j                  }|gS |                                  |                                 \  }}|                                 \  }}|                                 \  }}|                     ||                     | j                  |          \  }}	t'          |	|          }	| j                            dd          }
| j                            dd          }|                     ||
|           |                    |d |
                    ||
d          }|                     |	          }|                     |	||f           n# t2          $ r}|j        d         gcY d }~S d }~wt6          j        $ r}t;          |          }t<          j        dk     r	d	|v r|d
z  }| j        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.r<   r   r   r      r   z1-character stringz1
with Python 2.x this must be an ASCII character.zError with CSV data in "z" directive:
)r   rm   r   r   )'r!   documentsettingsfile_insertion_enabledr2   r%   r>   ry   r   r   r@   rA   r#   r   r-   get_csv_datar:   r3   r   maxrH   rE   r6   rU   rZ   r	   r~   r   Errorstrsysversion_infor?   build_tabler|   r   rJ   r   r   )r)   ry   r$   r,   csv_datar'   r7   r8   r9   max_colsrB   rC   
table_bodyrT   r   messager?   r}   rI   s                      r   r   zCSVTable.run   s   "	J'0G !t|++--,5==!#'9-.3.AOT_/6 /6<@K > I I  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&((-AW-L-LOO&/555999gg'(-(;)2 )28< 6 E EE 7NNNNNN	 Z4Z++E43F,8 , N N
9!1!1'2!>!>>dl"""&,"2"27";";JwZ(((j!!! 	(a'''|h&&s8   A6F6 9D<F6 6
I) GI)I)%A9I$I)$I)c                 	   | j                             d| j        j        j        j                  }| j        j        j        j        }| j        rd| j         v s	d| j         v r[| j        j	        
                    d| j        z  t          j        | j        | j                  | j                  }t!          |          | j                            d          }| j        }nd| j         v rd| j         v r[| j        j	        
                    d| j        z  t          j        | j        | j                  | j                  }t!          |          t$          j                            t$          j                            | j        j        j                            }t$          j                            t$          j                            || j         d                             }t3          j        d|          }	 | j        j        j        j                            |           t;          j        |||	          }|                                                                 }n!# tB          $ rq}| j        j	        "                    d
| j        dtG          |          dt          j        | j        | j                  | j                  }t!          |          d}~ww xY wd| j         v r>tH          j%        dk    rddl&m'}	 ddl(m)}
 nddl*m'}	m)}
 | j         d         }	  |	|                                          }n# |
tB          tV          tX          f$ r}| j        j	        "                    d
| j        d| j         d         dtG          |          dt          j        | j        | j                  | j                  }t!          |          d}~ww xY wt;          j-        |||| j        j        j        j                  }|                                                                 }n[| j        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.r<   r   zXThe "file" and "url" options may not be simultaneously specified for the "%s" directive.N)source_pathr   error_handlerzProblems with "z" directive path:
.r   )urlopen)URLError)r   r   z" directive URL "z":
)r'   r   r   r   z3The "%s" directive requires content; none supplied.)/r2   rH   r!   r   r   input_encodinginput_encoding_error_handlerrx   r%   r>   r?   r   r   r@   rA   r#   r	   r'   ospathdirnameabspathcurrent_sourcenormpathjoinr   relative_pathrecord_dependenciesaddr   	FileInputread
splitlinesIOErrorseverer   r   r   urllib.requestr   urllib.errorr   urllib2OSError
ValueErrorStringInputry   )r)   r   r   r?   r'   r   
source_dircsv_filer   r   r   csv_texts               r   r   zCSVTable.get_csv_data  s   
 <##
+4CE E
+4Q< D	2%%$,)>)>*399%'+y1272EOT_36 36<@K : I I /u555\((++F|HHt|##$$*399;=AYG)$/4?KK;	 : ( (
 /u555
 3 BCCE EJW%%bgll:37<3G'I 'I J JF(v66F7
#,@DDVLLL<F196CE E E $==??5577 7 7 7+4;;;yyy*U"3"3"3"35'II	 < & &
 /v6667 dl""
 6))222222111111155555555\%(F7"76??//11gw
; 7 7 7+4;;;DL$7$7$7E9J9J9J9JL)$/4?KK;	 < ( (
 /v6667 ~Vh#z2;;> > >H  }}1133HH&/77E)"02 28< 8 E EE +5111s3   4A&I 
K&A,KKL5 5OA:OOr   c                 ,    |                      d          S Nzutf-8)decodess    r   decode_from_csvzCSVTable.decode_from_csvp      88G$$$r   c                 ,    |                      d          S r   )encoder   s    r   r   zCSVTable.encode_for_csvr  r   r   c                     | S r   ri   r   s    r   r   zCSVTable.decode_from_csvu      Hr   c                     | S r   ri   r   s    r   r   zCSVTable.encode_for_csvw  r   r   c           	          t          j         fd|D             |          }g }d}|D ]}g }|D ]X}	                     |	          }
dddt          j        |
                                |          f}|                    |           Y|                    |           t          |t          |                    }||fS )Nc                 @    g | ]}                     |d z             S )r0   )r   )rr   r(   r)   s     r   rt   z5CSVTable.parse_csv_data_into_rows.<locals>.<listcomp>~  s;     !7 !7 !7%) "&!4!4TD[!A!A !7 !7 !7r   )dialectr   )r'   )	r   readerr   r   
StringListr   appendr   r=   )r)   r   r   r'   
csv_readerr9   r   rD   row_datacell	cell_text	cell_datas   `           r   r3   z!CSVTable.parse_csv_data_into_rows|  s    Z !7 !7 !7 !7-5!7 !7 !7(/1 1 1
  		/ 		/CH + + 0066	1l&=((**6'; '; '; <		****KK!!!8SXX..HHX~r   N)r[   r\   r]   r   nonnegative_intrb   rc   rd   re   r   urir   ra   r   $single_char_or_whitespace_or_unicodeflagsingle_char_or_unicoderf   r   r   r   r5   r   r   r   r   r   r   r   staticmethodr3   ri   r   r   r   r      s       ","<#-#='1&G0Z01;1MO O%?$.)2&3%/!&K *&='>'A AK*' ' ' ' '#+ ' ' '2$ $ $ $ $ $ $ $  .' .' .'`M  M  M ^ &  	% 	% 	%	% 	% 	% 	%	 	 		 	 	"l?33O!\.11N    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
    http://docutils.sf.net/docs/dev/rst/alternatives.html#list-driven-tables
    r   )r   r   r   r   r   r   r   c                    | j         sO| j        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.r<   c                 2    g | ]}d  |d         D             S )c                     g | ]	}|j         
S ri   )r   )rr   items     r   rt   z,ListTable.run.<locals>.<listcomp>.<listcomp>  s    AAAT4=AAAr   r   ri   )rr   row_lists     r   rt   z!ListTable.run.<locals>.<listcomp>  s;     3 3 3& BAXa[AAA 3 3 3r   r   r   r   r   rm   r   )rx   r%   r>   r?   r   r   r@   rA   r#   r-   rz   r!   r{   r|   check_list_contentr2   rH   rE   r	   r~   build_table_from_listrJ   r   r   )r)   r?   r$   r,   r   num_colsrT   
table_datarB   rC   r   rI   s               r   r   zListTable.run  s    | 	&/55@49L#DOT_EE[ 6 " "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   
E*D=7E=Ec                 :   t          |          dk    s t          |d         t          j                  s[| j        j                            d| j        z  t          j        | j	        | j	                  | j
                  }t          |          |d         }d}t          t          |                    D ]M}||         }t          |          dk    s t          |d         t          j                  sb| j        j                            d| j        d|dz   dt          j        | j	        | j	                  | j
                  }t          |          |rt          |d                   |k    r{| j        j                            d| j        d|dz   d	t          |d                   d
|d	t          j        | j	        | j	                  | j
                  }t          |          8t          |d                   }O|                     |          }||fS )Nr   r   zUError parsing content block for the "%s" directive: exactly one bullet list expected.r<   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 rO   )r=   rQ   r   bullet_listr%   r>   r?   r   r@   rA   r#   r	   rangerU   )r)   r   r?   	list_noder  
item_indexr   rT   s           r   r  zListTable.check_list_content  s   t99>>DGU5F!G!G>&/5546:i@#DOT_EE[	 6 " "E
 +5111G	I// 	( 	(JZ(D4yyA~~ZQ9J%K%K~*3999 yyy*q...2 493FOT_46 46<@K : I I /u555 (tAw<<8++ .7===
  999j1nnnc$q'llllHHH	N
 +DOT_MM![ > * *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   rm   rv   rw   )rn   ru   r   stub)r   r}   r   r   r=   rp   
attributesrD   entryr   theadr6   tbody)r)   r  rT   rB   rC   r}   r   r   rp   r9   rD   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)r[   r\   r]   r^   r   r   rc   rd   re   ra   rb   r   rf   r   r  r  ri   r   r   r   r     s          #-"<#-#=&G0Z01;1MO O&3%/!# #K' ' '<#$ #$ #$J    r   r   )r^   __docformat__r   os.pathr   r   docutilsr   r   r   r   docutils.utils.error_reportingr   docutils.utilsr	   docutils.parsers.rstr
   r   r   r   rk   r   r   ri   r   r   <module>r     s  
  # 


  



 3 3 3 3 3 3 3 3 3 3 3 3 5 5 5 5 5 5 3 3 3 3 3 3 * * * * * * + + + + + +D D DfG fG fG fG fGI fG fG fGR(' (' (' (' ('u (' (' ('V^ ^ ^ ^ ^u ^ ^ ^Bs s s s s s s s s sr   