
    k7iY                        S r SSKJr  SrSSKrSSKJr  SSKJr  SSK	r	SSK
JrJr  SSKJrJr  SS	KJr  SS
KJr  SSKJr  SSKJr  S r " S S\5      r " S S\5      r " S S\5      r " S S\5      rg)z 
Directives for table elements.
    )annotationsreStructuredTextN)urlopen)URLError)nodesstatemachine)	FileInputStringInput)	Directive)
directives)
adapt_path)SystemMessagePropagationc                0    [         R                  " U S5      $ )N)leftcenterright)r   choice)arguments    `/home/james-whalen/.local/lib/python3.13/site-packages/docutils/parsers/rst/directives/tables.pyalignr      s    X'BCC    c                      \ rS rSrSrSrSr\R                  \R                  \
\R                  \R                  " S\R                  5      S.rSrS rS rSS	 jr\S
 5       rS rSS jrSrg)Table   z
Generic table base class.
   T)autogrid)classnamer   widthwidthsc                :   U R                   (       a  U R                   S   nU R                  R                  UU R                  5      u  p#[        R
                  " US/UQ76 nU R                  R                  U R                  5      u  Ul        Ul	        XC4$ S n/ nXC4$ )Nr    )
	argumentsstateinline_textlinenor   titlestate_machineget_source_and_linesourceline)self
title_text
text_nodesmessagesr(   s        r   
make_titleTable.make_title.   s    >>*J#'::#9#9*:>++$G JKK
B<<E--AA$++NU\Z  EHr   c           	     d   [        U5      U:  ax  U R                  R                  U< S[        U5      < SU R                  < S3[        R
                  " U R                  U R                  5      U R                  S9n[        U5      e[        U5      Us=:X  a  S:  av  O  OsU R                  R                  S[        U5       SU R                   S3[        R
                  " U R                  U R                  5      U R                  S9n[        U5      eU GH  n[        U5      U:  au  U R                  R                  U S	[        U5       S
U R                   S3[        R
                  " U R                  U R                  5      U R                  S9n[        U5      e[        U5      Us=:X  a  S:  d  M  O  M  U R                  R                  S[        U5      < SU R                  < S3[        R
                  " U R                  U R                  5      U R                  S9n[        U5      e   g )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_columnsr7   rows         r   check_table_dimensionsTable.check_table_dimensions;   s   t9{"MM''D	499)6 ##DOOT__E[[	 ( "E
 +511t9'a'MM''.s4yk :  $		{,8 ##DOOT__E[[ ( "E +511C3x,&++#n %  #Cz *=2 ''I , & /u553x<+!++++ -0HdiiA ''I , & /u55! r   c                b    SU R                   ;   a  U R                   R                  S5      US'   g g )Nr    optionsget)r-   
table_nodes     r   set_table_widthTable.set_table_width]   s,    dll""&,,"2"27";Jw #r   c                :    U R                   R                  SS5      $ )Nr!   r#   rA   )r-   s    r   r!   Table.widthsa   s    ||"--r   c                <   [        U R                  [        5      (       a  [        U R                  5      U:w  al  U R                  R                  SU R                  < SU< S3[        R                  " U R                  U R                  5      U R                  S9n[        U5      eU R                  nU$ U(       a  SU-  /U-  nU$ U R                  R                  S[        R                  " U R                  U R                  5      U R                  S9n[        U5      e)N"z6" widths do not match the number of columns in table ().r4   d   z#No table data detected in CSV file.)
isinstancer!   listr5   r6   r7   r   r   r8   r9   r'   r   )r-   n_colsr7   
col_widthss       r   get_column_widthsTable.get_column_widthse   s    dkk4((4;;6)++:>))V-M''I , & /u55J  -61J 	 MM''(M##DOOT__E[[ ( "E +511r   c           	         U HB  nU H9  n[        U5      U:  d  M  UR                  SSS/ 4/U[        U5      -
  -  5        M;     MD     g )Nr   )r5   extend)r-   columnspartspartr=   s        r   "extend_short_rows_with_empty_cells(Table.extend_short_rows_with_empty_cellsx   sF    Ds8g%JJAq"'CH2DEF  r    NreturnNone)__name__
__module____qualname____firstlineno____doc__optional_argumentsfinal_argument_whitespacer   class_option	unchangedr    length_or_percentage_or_unitlessvalue_orpositive_int_listoption_spechas_contentr1   r>   rE   propertyr!   rQ   rX   __static_attributes__rZ   r   r   r   r      s      $&33%//!&GG'001A1;1M1MO	PK K 6D< . .&Gr   r   c                      \ rS rSrSrS rSrg)RSTTable   z
Class for the `"table" directive`__ for formal tables using rST syntax.

__ https://docutils.sourceforge.io/docs/ref/rst/directives.html
c                   U R                   (       d^  U R                  R                  SU R                  -  [        R
                  " U R                  U R                  5      U R                  S9nU/$ U R                  5       u  p#[        R                  " 5       nU R                  R                  U R                   U R                  U5        [        U5      S:w  d"  [        US   [        R                  5      (       d^  U R                  R!                  SU R                  -  [        R
                  " U R                  U R                  5      U R                  S9nU/$ US   nUS==   U R"                  R%                  S/ 5      -  ss'   U R'                  U5        SU R"                  ;   a  U R"                  R%                  S5      US'   [        U R(                  [*        5      (       a`  US   n U R-                  US	   5      nUR2                   V
s/ s H  n
U
R4                  S
:X  d  M  U
PM     nn
[7        X5       H	  u  pXS'   M     U R(                  S:X  a  US==   S/-  ss'   OU R(                  (       a  US==   S/-  ss'   U R9                  U5        U(       a  UR;                  SU5        U/U-   $ ! [.         a  n	U	R0                  S   /s S n	A	$ S n	A	ff = fs  sn
f )Nz:Content block expected for the "%s" directive; none found.r4   r   r   zOError parsing content block for the "%s" directive: exactly one table expected.classesr   r   colscolspeccolwidthr   colwidths-autocolwidths-given)contentr6   warningr   r   r8   r9   r'   r1   Elementr%   nested_parsecontent_offsetr5   rM   tabler7   rB   rC   rE   r!   rN   rQ   r   argschildrentagnamezipadd_nameinsert)r-   ry   r(   r0   noder7   rD   tgrouprP   detailchildcolspecsrt   	col_widths                 r   runRSTTable.run   sn   ||mm++ -68<		-B##DOOT__E[[ , "G 9//+}}

d.A.A4Ht9>DGU[[!A!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 ?H 7&)(&?"&/
# '@;;& y!&6%77![[y!&7%88!j!a'|h&& , (A''(7s*   'J/ 	K!K/
K9KKKrZ   N)r^   r_   r`   ra   rb   r   rm   rZ   r   r   ro   ro      s    &'r   ro   c                     \ rS rSr\R
                  \R
                  \R                  \R                  \R                  " S\R                  5      \R                  \R                  \R                  \R                  \R                  \\R                  \R                   \R"                  \R"                  S.r " S S\R(                  5      r " S S\R(                  5      r\SS j5       rS	 rS
 rS rS rSrg)CSVTable   r   )header-rowsstub-columnsheaderr    r!   fileurlencodingr   r   r   delim	keepspacequoteescapec                  `   ^  \ rS rSrSrSrSrSrSrSr	Sr
\R                  rS	U 4S jjrSrU =r$ )
CSVTable.DocutilsDialect   z&CSV dialect for `csv_table` directive.,rJ   T
c                   > SU;   a
  US   U l         SU;   a  SU l        SU;   a
  US   U l        SU;   a  SU l        US   U l        [
        TU ]  5         g )Nr   r   Fr   r   )	delimiterskipinitialspace	quotechardoublequote
escapecharsuper__init__)r-   rB   	__class__s     r   r   !CSVTable.DocutilsDialect.__init__   sb    '!!(!1g%(-%'!!(!17"#( ")("3Gr   )r   r   r   r   r   r[   )r^   r_   r`   ra   rb   r   r   r   r   strictlineterminatorcsvQUOTE_MINIMALquotingr   rm   __classcell__r   s   @r   DocutilsDialectr      s:    4		##
	 
	r   r   c                  d   ^  \ rS rSrSrSrSrSrSrSr	Sr
Sr\R                  rSU 4S	 jjrS
rU =r$ )CSVTable.HeaderDialect   z_
CSV dialect used for the "header" option data.

Deprecated. Will be removed in Docutils 0.22.
r   rJ   \FTr   c                V   > [         R                  " S[        SS9  [        TU ]  5         g )Nz6CSVTable.HeaderDialect will be removed in Docutils 1.0   
stacklevel)warningswarnDeprecationWarningr   r   )r-   r   s    r   r   CSVTable.HeaderDialect.__init__   s&    MM ,,< Gr   rZ   r[   )r^   r_   r`   ra   rb   r   r   r   r   r   r   r   r   r   r   r   rm   r   r   s   @r   HeaderDialectr      sC    	& 		
##	 	r   r   c                 8    [         R                  " S[        SS9  g )NzaCSVTable.check_requirements() is not required with Python 3 and will be removed in Docutils 0.22.r   r   )r   r   r   rZ   r   r   check_requirementsCSVTable.check_requirements  s     ? )Q	8r   c                6   U R                   R                  U R                  S-
  5      n/ nSnSU R                  ;   a[  U R	                  U R                  S   R                  S5      U R                  U R                  5      U5      u  pCUR                  U5        X#4$ )Nr   r   r   r   )r)   
get_sourcer'   rB   parse_csv_data_into_rowssplitr   rT   )r-   r+   
table_headmax_header_colsr:   s        r   process_header_optionCSVTable.process_header_option  s    ##..t{{Q?
t||#$($A$A(,X(>(D(DT(J(,(<(<T\\(J(.%0!D d#**r   c                :    U R                   R                  R                  R                  (       d~  SU R                  ;   d  SU R                  ;   a^  U R
                  R                  SU R                  -  [        R                  " U R                  U R                  5      U R                  S9nU/$ U R                  5       u  p#U R                  5       u  pEU R                  5       u  pgU R                  X@R!                  U R                  5      U5      u  p[#        X5      n	U R                  R%                  SS5      n
U R                  R%                  SS5      nU R'                  XU5        UR)                  US U
 5        XS  nU R+                  U	5      nU R-                  U	Xl45        XU4nU R                   R;                  UU R<                  XR>                  S
9nUS==   U R                  R%                  S/ 5      -  ss'   SU R                  ;   a  U R                  R%                  S5      US'   U RA                  U5        U RC                  U5        U(       a  URE                  SU5        U/U-   $ ! [.         a  nUR0                  S   /s S nA$ S nAf[2        R4                   ax  n[7        U5      nU R
                  R9                  SU R                  < S	U< 3[        R                  " U R                  U R                  5      U R                  S9nU/s S nA$ S nAff = f)Nr   r   z9File and URL access deactivated; ignoring "%s" directive.r4   r   r   r   zError with CSV data in "z" directive:
)r!   rr   r   r   )#r%   documentsettingsfile_insertion_enabledrB   r6   ry   r   r   r8   r9   r'   r1   get_csv_datar   r   r   maxrC   r>   rT   rQ   rX   r   r~   r   Errorstrr7   build_tabler|   r!   rE   r   r   )r-   ry   r(   r0   csv_datar+   r   r   r:   max_colsr;   r<   
table_bodyrP   r   messager7   r}   rD   s                      r   r   CSVTable.run  s   	JJ''00GGt||+---// 1<>Bii1H''I 0 &  y "oo/OE#002H*.*D*D*F'J!::..t||<fFND85H,,**=!<K<<++NA>L''<Hd<K01l+J//9J33H5?4LN 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, /C4I, ,
L6JLL"A-LLLc           
     L   U R                   R                  R                  nU R                  R	                  SUR
                  5      nUR                  nU R                  (       a  SU R                  ;   d  SU R                  ;   af  U R                  R                  SU R                  -  [        R                  " U R                  U R                  5      U R                  S9n[        U5      eU R                  R!                  S5      nU R                  nXe4$ SU R                  ;   Ga   SU R                  ;   af  U R                  R                  SU R                  -  [        R                  " U R                  U R                  5      U R                  S9n[        U5      e[#        U R                  S   U R                   R                  R$                  UR&                  5      n [)        UUUS9nUR+                  5       R-                  5       nUR.                  R1                  U5        Xe4$ SU R                  ;   aa  U R                  S   n [7        U5       n	U	R+                  5       n
SSS5        [=        W
UUUS9nUR+                  5       R-                  5       nXe4$ U R                  R?                  SU R                  -  [        R                  " U R                  U R                  5      U R                  S9n[        U5      e! [2         aq  nU R                  R5                  S	U R                  < S
U< S3[        R                  " U R                  U R                  5      U R                  S9n[        U5      eSnAff = f! , (       d  f       GN = f! [8        [2        [:        4 a  nU R                  R5                  S	U R                  < SU R                  S   < SU< S3[        R                  " U R                  U R                  5      U R                  S9n[        U5      eSnAff = f)zZ
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.r4   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   rB   rC   input_encodinginput_encoding_error_handlerrx   r6   r7   r   r   r8   r9   r'   r   r+   r   current_sourceroot_prefixr	   read
splitlinesrecord_dependenciesaddOSErrorseverer   r   
ValueErrorr
   ry   )r-   r   r   r   r7   r+   r   csv_filer   responsecsv_texts              r   r   CSVTable.get_csv_dataA  s|   
 ::&&//<<##J0G0GH ==<<%$,,)>++ -ACG99-M''I , & /u55\\((+F||Hd c t||#$++ -.04		-: ''I	 , &
 /u55V 4 $

 3 3 B B ( 4 46F9$.63@B $==?557 ,,0080 / dll"\\%(F	7V_'}}H % #(,41>@H  }}113H  MM))E))##DOOT__E[[	 * "E
 +511?  7--yy%)''I	 . &
 /v667 %_gz2 7--DLL$7@))$//4??K;;	 . (
 /v667sP   )K< N M:!N <
M7A,M22M7:
N	N 	N P#!A=PP#c           
     ,   [         R                  " S U 5       US9n/ nSnU Hl  n/ nU H;  n	SSS[        R                  " U	R	                  5       US94n
UR                  U
5        M=     UR                  U5        [        U[        U5      5      nMn     XV4$ )Nc              3  *   #    U  H	  oS -   v   M     g7f)r   NrZ   ).0r,   s     r   	<genexpr>4CSVTable.parse_csv_data_into_rows.<locals>.<genexpr>  s      Bs   )dialectr   )r+   )r   readerr   
StringListr   appendr   r5   )r-   r   r   r+   
csv_readerr:   r   r=   row_datacell	cell_datas              r   r   !CSVTable.parse_csv_data_into_rows  s    ZZ B B(/1
CH1l&=&=OO%f'6 7		*  KK!8SX.H  ~r   rZ   Nr[   )r^   r_   r`   ra   r   nonnegative_intrf   rg   rh   ri   pathurir   re   r   $single_char_or_whitespace_or_unicodeflagsingle_char_or_unicoderj   r   Dialectr   r   staticmethodr   r   r   r   r   rm   rZ   r   r   r   r      s    ","<"<#-#=#='11&GG'001;1M1MO%??$..)22&33%//!&KK *&=='>>'@K*#++ 0! !F 8 8
++'ZC Jr   r   c                      \ rS rSrSr\R                  \R                  \R                  \R                  " S\R                  5      \R                  \R                  \S.rS rS rS rSrg	)
	ListTablei  z
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                h   U R                   (       d^  U R                  R                  SU R                  -  [        R
                  " U R                  U R                  5      U R                  S9nU/$ U R                  5       u  p#[        R                  " 5       nU R                  R                  U R                   U R                  U5         U R                  U5      u  pVUS    VVs/ s H"  nUS    Vs/ s H  oR                  PM     snPM$     n	nnU R                  R!                  SS5      n
U R                  R!                  SS5      nU R#                  XU5        U R)                  XX5      nSU R                  ;   a  U R                  R!                  S5      US'   US==   U R                  R!                  S/ 5      -  ss'   U R+                  U5        U R-                  U5        U(       a  UR/                  SU5        U/U-   $ s  snf s  snnf ! [$         a  nUR&                  S   /s S nA$ S nAff = f)	Nz.The "%s" directive is empty; content required.r4   r   r   r   r   rr   r   )rx   r6   r7   r   r   r8   r9   r'   r1   rz   r%   r{   r|   check_list_contentr   rB   rC   r>   r   r~   build_table_from_listrE   r   r   )r-   r7   r(   r0   r   	_num_colsrP   row_listitem
table_datar;   r<   r   rD   s                 r   r   ListTable.run  s   ||MM'' )$&*ii)0##DOOT__E[[ ( "E 7N//+}}

d.A.A4H	$$($;$;D$A!I*.q'3*1h 6>a[A[T==[A*1  3,,**=!<K<<++NA>L''
N //
0;K
dll""&,,"2"27";Jw9!1!1'2!>>Z(j!a'|h&&! B 3
 ( 	$KKN##	$sC   	H $H1HHAH HH 
H1H,&H1,H1c                B   [        U5      S:w  d"  [        US   [        R                  5      (       df  U R                  R                  SU R                  -  [        R                  " U R                  U R                  5      U R                  S9n[        U5      eUS   nSn[        [        U5      5       GHU  nX5   n[        U5      S:w  d"  [        US   [        R                  5      (       do  U R                  R                  SU R                  < SUS-   < S3[        R                  " U R                  U R                  5      U R                  S9n[        U5      eU(       a  [        US   5      U:w  a  U R                  R                  SU R                  < SUS-   < S	[        US   5      < S
U< S3	[        R                  " U R                  U R                  5      U R                  S9n[        U5      eGMG  [        US   5      nGMX     U R                  U5      nXG4$ )Nr   r   zUError parsing content block for the "%s" directive: exactly one bullet list expected.r4   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 rK   )r5   rM   r   bullet_listr6   r7   r   r8   r9   r'   r   rangerQ   )r-   r   r7   	list_nodenum_cols
item_indexr  rP   s           r   r  ListTable.check_list_content  s   t9>DGU5F5F!G!GMM''46:ii@##DOOT__E[[	 ( "E
 +511G	I/J(D4yA~ZQ9J9J%K%K++ yy*q.2 ''I , & /u55tAw<8+ MM//
  99j1nc$q'lH	N
 ++DOOT__M![[ 0 *E 3599 , tAw</ 00 ++H5
##r   c                   [         R                  " 5       nU R                  S:X  a  US==   S/-  ss'   OU R                  (       a  US==   S/-  ss'   [         R                  " [	        U5      S9nXV-  nU HH  n[         R
                  " 5       nUb  XxR                  S'   U(       a  SUR                  S'   US	-  nXh-  nMJ     / n	U HO  n
[         R                  " 5       nU
 H   n[         R                  " 5       nX-  nX-  nM"     U	R                  U5        MQ     U(       a-  [         R                  " 5       nUR                  U	S U 5        Xn-  n[         R                  " 5       nUR                  XS  5        Xo-  nU$ )
Nr   rr   rv   rw   )rs   ru   Tstubr   )r   r}   r!   r   r5   rt   
attributesr=   entryr   theadrT   tbody)r-   r  rP   r;   r<   r}   r   r   rt   r:   r=   row_noder   r  r  r  s                   r   r  ListTable.build_table_from_list  sO   ;;& )!1 22[[)!2 333z?3#ImmoG$1:"":.-1""6*!F $ Cyy{H!  KK!  KKMELLl{+,OFT,'(r   rZ   N)r^   r_   r`   ra   rb   r   r   rg   rh   ri   re   rf   r   rj   r   r  r  rm   rZ   r   r   r  r    sj     #-"<"<#-#=#=&GG'001;1M1MO&33%//!#K'<$$L r   r  )rb   
__future__r   __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   ro   r   r  rZ   r   r   <module>r"     ss   
 #" 
 " !  ( . * + ; 3D^GI ^GB-'u -'`du dNu ur   