
    dd]                         d Z dZddlZddlm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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y)z 
Directives for table elements.
reStructuredText    N)Path)ionodesstatemachineutils)SystemMessagePropagation)	Directive)
directives)urlopen)URLErrorc                 .    t        j                  | d      S )N)leftcenterright)r   choice)arguments    H/usr/lib/python3/dist-packages/docutils/parsers/rst/directives/tables.pyalignr      s    X'B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y)Tablez#
    Generic table base class.
       T)autogrid)classnamer   widthwidthsc                 4   | j                   r| j                   d   }| j                  j                  || j                        \  }}t	        j
                  |dg| }| j                  j                  | j                        \  |_        |_	        ||fS 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 JKK
B<<E--AA$++NU\Z h EHhr   c                    | j                   j                  | j                  dz
        }g }d}d| j                  v rt	        j
                         5  t	        j                  d       | j                         }d d d        | j                  | j                  d   j                  d      |      \  }}|j                  |       ||fS # 1 sw Y   PxY w)Nr   r   headerignore
)r'   
get_sourcer%   optionswarningscatch_warningssimplefilterHeaderDialectparse_csv_data_into_rowssplitextend)r+   r)   
table_headmax_header_colsheader_dialectrowss         r   process_header_optionzTable.process_header_option9   s     ##..t{{Q?
t||#((* 6%%h/!%!3!3!56 %)$A$AX&,,T2N%!D/ d#?**6 6s   &CCc           	      X   t        |      |k  rw| j                  j                  |dt        |      d| j                  dt	        j
                  | j                  | j                        | j                        }t        |      t        |      |cxk(  rdkD  rxn nu| j                  j                  dt        |       d| j                   dt	        j
                  | j                  | j                        | j                        }t        |      |D ]  }t        |      |k  rw| j                  j                  | d	t        |       d
| j                   dt	        j
                  | j                  | j                        | j                        }t        |      t        |      |cxk(  rdkD  sn | j                  j                  dt        |      d| j                  dt	        j
                  | j                  | j                        | j                        }t        |       y )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+   r@   header_rowsstub_columnsrF   rows         r   check_table_dimensionszTable.check_table_dimensionsL   s   t9{"MM''D	499)6 ##DOOT__E[[	 ( "E
 +511t9'a'MM''.s4yk :  $		{,8 ##DOOT__E[[ ( "E +511 	6C3x,&++#n %  #Cz *=2 ''I , & /u553x<+!+++ -0HdiiA ''I , & /u55!	6r   c                 ^    d| j                   v r| j                   j                  d      |d<   y y )Nr   r5   get)r+   
table_nodes     r   set_table_widthzTable.set_table_widthn   s,    dll""&,,"2"27";Jw #r   c                 :    | j                   j                  dd      S )Nr   r!   rN   )r+   s    r   r   zTable.widthsr   s    ||"--r   c                 *   t        | j                  t              rt        | j                        |k7  rl| j                  j                  d| j                  d|dt        j                  | j                  | j                        | j                        }t        |      | j                  }|S |rd|z  g|z  }|S | j                  j                  dt        j                  | j                  | j                        | j                        }t        |      )N"z6" widths do not match the number of columns in table ().rC   d   z#No table data detected in CSV file.)
isinstancer   listrD   rE   rF   r   r   rG   rH   r%   r	   )r+   n_colsrF   
col_widthss       r   get_column_widthszTable.get_column_widthsv   s    dkk4(4;;6)++:>))V-M''I , & /u55J  -61J 	 MM''(M##DOOT__E[[ ( "E +511r   c           	          |D ]=  }|D ]6  }t        |      |k  s|j                  dddg fg|t        |      z
  z         8 ? y )Nr   )rD   r<   )r+   columnspartspartrK   s        r   "extend_short_rows_with_empty_cellsz(Table.extend_short_rows_with_empty_cells   sT     	GD Gs8g%JJAq"'CH2DEF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/   rA   rL   rQ   propertyr   r[   r`    r   r   r   r      s      $&33%//!&GG0Z001A1;1M1MO	PK K+& 6D< . .&Gr   r   c                       e Zd ZdZd Zy)RSTTablez
    Class for the `"table" directive`__ for formal tables using rST syntax.

    __ https://docutils.sourceforge.io/docs/ref/rst/directives.html
    c                 x   | j                   s`| j                  j                  d| j                  z  t	        j
                  | j                  | j                        | j                        }|gS | j                         \  }}t	        j                         }| j                  j                  | j                   | j                  |       t        |      dk7  st        |d   t        j                        s`| j                  j!                  d| j                  z  t	        j
                  | j                  | j                        | j                        }|gS |d   }|dxx   | j"                  j%                  dg       z  cc<   | j'                  |       d| j"                  v r| j"                  j%                  d      |d<   t        | j(                  t*              r[|d   }	 | j-                  |d	         }|j2                  D 
cg c]  }
|
j4                  d
k(  r|
 }}
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<   | j9                  |       |r|j;                  d|       |g|z   S # t.        $ r}	|	j0                  d   gcY d }	~	S d }	~	ww xY wc c}
w )Nz:Content block expected for the "%s" directive; none found.rC   r   r   zOError parsing content block for the "%s" directive: exactly one table expected.classesr   r   colscolspeccolwidthr   colwidths-autocolwidths-given)contentrE   warningr   r   rG   rH   r%   r/   Elementr#   nested_parsecontent_offsetrD   rW   tablerF   r5   rO   rQ   r   rX   r[   r	   argschildrentagnamezipadd_nameinsert)r+   rz   r&   r.   noderF   rP   tgrouprZ   detailchildcolspecsru   	col_widths                 r   runzRSTTable.run   su   ||mm++ -68<		-B##DOOT__E[[ , "G 9//+x}}

d.A.A4Ht9>DGU[[!AMM'' )>@D		)J##DOOT__E[[ ( "E 7N!W
9!1!1'2!>>Z(dll""&,,"2"27";Jwdkk4(]F(!33F6NC
 ,2?? 7% ==I5  7H 7&)(J&? 0"&/
#0;;& y!&6%77![[y!&7%88!j!a'|h&& , (A''(7s$   J ;J7	J4J/)J4/J4N)ra   rb   rc   rd   r   ro   r   r   rq   rq      s    &'r   rq   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ed
        Zed        Zd Zy)CSVTabler   )header-rowsstub-columnsr1   r   r   fileurlencodingr   r   r   delim	keepspacequoteescapec                   R     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.,rT   Tr3   c                     d|v r
|d   | _         d|v rd| _        d|v r
|d   | _        d|v rd| _        |d   | _        t
        |           y )Nr   r   Fr   r   )	delimiterskipinitialspace	quotechardoublequote
escapecharsuper__init__)r+   r5   	__class__s     r   r   z!CSVTable.DocutilsDialect.__init__   sb    '!!(!1g%(-%'!!(!17"#( ")("3Gr   )ra   rb   rc   rd   r   r   r   r   strictlineterminatorcsvQUOTE_MINIMALquotingr   __classcell__r   s   @r   DocutilsDialectr      s:    4		##
	 
	r   r   c                   V     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   rT   \FTr3   c                 Z    t        j                  dt        d       t        |           y )Nz8CSVTable.HeaderDialect will be removed in Docutils 0.22.   
stacklevel)r6   warnPendingDeprecationWarningr   r   )r+   r   s    r   r   zCSVTable.HeaderDialect.__init__  s'    MM .3C Gr   )ra   rb   rc   rd   r   r   r   r   r   r   r   r   r   r   r   r   r   s   @r   r9   r      sC    	& 		
##	 	r   r9   c                  <    t        j                  dt        d       y )NzaCSVTable.check_requirements() is not required with Python 3 and will be removed in Docutils 0.22.r   r   r6   r   DeprecationWarningro   r   r   check_requirementszCSVTable.check_requirements  s     ? )Q	8r   c                 6   	 | j                   j                  j                  j                  s|d| j                  v sd| j                  v r`| j
                  j                  d| j                  z  t        j                  | j                  | j                        | j                        }|gS | j                         \  }}| j                         \  }}| j                         \  }}| j                  || j!                  | j                        |      \  }}	t#        |	|      }	| j                  j%                  dd      }
| j                  j%                  dd      }| j'                  ||
|       |j)                  |d |
        ||
d  }| j+                  |	      }| j-                  |	||f       |||f}| j                   j;                  || j<                  || j>                  
      }|dxx   | j                  j%                  dg       z  cc<   d| j                  v r| j                  j%                  d      |d<   | jA                  |       | jC                  |       |r|jE                  d|       |g|z   S # t.        $ r}|j0                  d   gcY d }~S d }~wt2        j4                  $ rx}t7        |      }| j
                  j9                  d| j                  d	|t        j                  | j                  | j                        | j                        }|gcY d }~S d }~ww xY w)Nr   r   z9File and URL access deactivated; ignoring "%s" directive.rC   r   r   r   zError with CSV data in "z" directive:
)r   rs   r   r   )#r#   documentsettingsfile_insertion_enabledr5   rE   rz   r   r   rG   rH   r%   r/   get_csv_datarA   r:   r   maxrO   rL   r<   r[   r`   r	   r   r   ErrorstrrF   build_tabler}   r   rQ   r   r   )r+   rz   r&   r.   csv_datar)   r=   r>   r@   max_colsrI   rJ   
table_bodyrZ   r   messagerF   r~   rP   s                      r   r   zCSVTable.run  s   	JJ''00GGt||+---// 1<>Bii1H''I 0 &  y "oo/OE8#002Hf*.*D*D*F'J!::$..t||<fFND(8_5H,,**=!<K<<++NA>L''k<Hd<K01kl+J//9J33H5?4LN Z4ZZ++E43F3F,8 , N
9!1!1'2!>>dll""&,,"2"27";JwZ(j!a'|h&&' ( 	$KKN##yy 	&kGMM''-1YY)A##DOOT__E[[ ( "E 7N	s8   B%I, (C=I, ,	L5J
L
L A-LLLc           
      Z	   | j                   j                  d| j                  j                  j                  j
                        }| j                  j                  j                  j                  }| j                  rd| j                   v sd| j                   v rh| j                  j                  d| j                  z  t        j                  | j                  | j                        | j                        }t        |      | j                  j!                  d      }| j                  }||fS d| j                   v rEd| j                   v rh| j                  j                  d| j                  z  t        j                  | j                  | j                        | j                        }t        |      | j                   d   }t#        | j                  j                  j$                        j&                  }t)        j*                  d||z        }	 t-        j.                  |||	      }|j1                         j3                         }| j                  j                  j                  j4                  j7                  |       ||fS d| j                   v r| j                   d   }	 t=        |      5 }	|	j1                         }
ddd       t-        jB                  
||| j                  j                  j                  j                        }|j1                         j3                         }||fS | j                  jE                  d| j                  z  t        j                  | j                  | j                        | j                        }t        |      # t8        $ rq}| j                  j;                  d
| j                  d|dt        j                  | j                  | j                        | j                        }t        |      d}~ww xY w# 1 sw Y   RxY w# t>        t8        t@        f$ r}| j                  j;                  d
| j                  d| j                   d   d|dt        j                  | j                  | j                        | j                        }t        |      d}~ww xY w)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.rC   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:
.z" directive URL "z":
)r)   r   r   r   z3The "%s" directive requires content; none supplied.)#r5   rO   r#   r   r   input_encodinginput_encoding_error_handlerry   rE   rF   r   r   rG   rH   r%   r	   r)   r   current_sourceparentr   relative_pathr   	FileInputread
splitlinesrecord_dependenciesaddOSErrorseverer   r   
ValueErrorStringInputrz   )r+   r   r   rF   r)   r   _basecsv_filer   responsecsv_texts              r   r   zCSVTable.get_csv_dataF  s   
 <<##

++44CCE

++44QQ<<%$,,)>++ -ACG99-M''I , & /u55\\((+F||Hh g t||#$++ -.04		-: ''I	 , &
 /u55\\&)F,,;;<CCE((uV|<FM<<F196CE $==?557 

##,,@@DDVL2 1 dll"\\%(F	7V_ /'}}H/ ~~Vh#zz22;;;;>H  }}113H  MM))E))##DOOT__E[[	 * "E
 +511A  7--yy%)''I	 . &
 /v667/ /gz2 7--DLL$7@))$//4??K;;	 . (
 /v667sJ   6N P 'P8P 	PA,P  PPP R*)A<R%%R*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 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           	      .   t        j                  d |D        |      }g }d}|D ]k  }g }|D ]<  }	dddt        j                  |	j	                         |      f}
|j                  |
       > |j                  |       t        |t        |            }m ||fS )Nc              3   &   K   | ]	  }|d z     yw)r3   Nro   ).0r*   s     r   	<genexpr>z4CSVTable.parse_csv_data_into_rows.<locals>.<genexpr>  s      B Bs   )dialectr   )r)   )r   readerr   
StringListr   appendr   rD   )r+   r   r   r)   
csv_readerr@   r   rK   row_datacell	cell_datas              r   r:   z!CSVTable.parse_csv_data_into_rows  s    ZZ B B(/1
 	/CH +1l&=&=OO%f'6 7		*+ KK!8SX.H	/ X~r   N)ra   rb   rc   r   nonnegative_intrh   ri   rj   rk   pathurir   rg   r   $single_char_or_whitespace_or_unicodeflagsingle_char_or_unicoderl   r   Dialectr   r9   staticmethodr   r   r   r   r   r:   ro   r   r   r   r      s   ","<"<#-#=#='11&GG0Z001;1M1MO%??$..)22&33%//!&KK *&=='>>'@K*#++ 0! !F 8 8+'ZE N    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y)	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                 P   | j                   s`| j                  j                  d| j                  z  t	        j
                  | j                  | j                        | j                        }|gS | j                         \  }}t	        j                         }| j                  j                  | j                   | j                  |       	 | j                  |      \  }}|d   D cg c]  }|d   D cg c]  }|j                   c}! }	}}| j                  j!                  dd      }
| j                  j!                  dd      }| j#                  |	|
|       | j)                  |	||
|      }d| j                  v r| j                  j!                  d      |d<   |dxx   | j                  j!                  dg       z  cc<   | j+                  |       | j-                  |       |r|j/                  d|       |g|z   S c c}w c c}}w # t$        $ r}|j&                  d   gcY d }~S d }~ww xY w)	Nz.The "%s" directive is empty; content required.rC   r   r   r   r   rs   r   )ry   rE   rF   r   r   rG   rH   r%   r/   r{   r#   r|   r}   check_list_contentr   r5   rO   rL   r	   r   build_table_from_listrQ   r   r   )r+   rF   r&   r.   r   num_colsrZ   row_listitem
table_datarI   rJ   r   rP   s                 r   r   zListTable.run  s   ||MM'' )$&*ii)0##DOOT__E[[ ( "E 7N//+x}}

d.A.A4H	$#'#:#:4#@ Hj*.q'3& 6>a[AT4==A 3J 3,,**=!<K<<++NA>L''
KN //
J0;\K
dll""&,,"2"27";Jw9!1!1'2!>>Z(j!a'|h&&! B 3
 ( 	$KKN##	$sC   H "G<.G7G<AH 7G<<H 	H%H H% H%c                    t        |      dk7  st        |d   t        j                        sh| j                  j                  d| j                  z  t        j                  | j                  | j                        | j                        }t        |      |d   }d}t        t        |            D ]E  }||   }t        |      dk7  st        |d   t        j                        so| j                  j                  d| j                  d|dz   dt        j                  | j                  | j                        | j                        }t        |      |rt        |d         |k7  s| j                  j                  d| j                  d|dz   d	t        |d         d
|d	t        j                  | j                  | j                        | j                        }t        |      t        |d         }H | j                  |      }||fS )Nr   r   zUError parsing content block for the "%s" directive: exactly one bullet list expected.rC   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 rU   )rD   rW   r   bullet_listrE   rF   r   rG   rH   r%   r	   ranger[   )r+   r   rF   	list_noder   
item_indexr   rZ   s           r   r   zListTable.check_list_content  s   t9>DGU5F5F!GMM''46:ii@##DOOT__E[[	 ( "E
 +511G	I/ 	(JZ(D4yA~ZQ9J9J%K++ yy*q.2 ''I , & /u55tAw<8+ MM//
  99j1nc$q'lH	N
 ++DOOT__M![[ 0 *E 3599tAw</	(0 ++H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 ]B  }t        j
                         }|||j                  d<   |rd|j                  d<   |dz  }||z  }D g }	|D ]L  }
t        j                         }|
D ]   }t        j                         }||z  }||z  }" |	j                  |       N |r-t        j                         }|j                  |	d |        ||z  }t        j                         }|j                  |	|d         ||z  }|S )	Nr   rs   rw   rx   )rt   rv   r   stub)r   r~   r   r   rD   ru   
attributesrK   entryr   theadr<   tbody)r+   r   rZ   rI   rJ   r~   r   r   ru   r@   rK   row_noder   r  r	  r
  s                   r   r   zListTable.build_table_from_list  sn   ;;& )!1 22[[)!2 333z?3# 	ImmoG$1:"":.-.""6*!gF	  	"Cyy{H "E!" KK!	" KKMELLl{+,eOFT+,'(%r   N)ra   rb   rc   rd   r   r   ri   rj   rk   rg   rh   r   rl   r   r   r   ro   r   r   r   r     sl     #-"<"<#-#=#=&GG0Z001;1M1MO&33%//!#K'<$$L r   r   )rd   __docformat__r   pathlibr   r6   docutilsr   r   r   r   docutils.utilsr	   docutils.parsers.rstr
   r   urllib.requestr   urllib.errorr   r   r   rq   r   r   ro   r   r   <module>r     sr   
 #    3 3 3 * + " !DqGI qGh-'u -'`ju jZu ur   