
    <iY                       d Z ddlm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.
    )annotationsreStructuredTextN)urlopen)URLError)nodesstatemachine)	FileInputStringInput)	Directive)
directives)
adapt_path)SystemMessagePropagationc                ,    t          j        | d          S )N)leftcenterright)r   choice)arguments    /Users/kimhansen/Desktop/03 Workspace/ceo-agents/chl-effectiveness/mcp-servers/whoop/.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d
Zed             Zd Zd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_columnsr5   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   returnNonec                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.widthsa   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 ().r2   d   z#No table data detected in CSV file.)
isinstancer    listr3   r4   r5   r   r   r6   r7   r&   r   )r,   n_colsr5   
col_widthss       r   get_column_widthszTable.get_column_widthse   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   )r3   extend)r,   columnspartspartr;   s        r   "extend_short_rows_with_empty_cellsz(Table.extend_short_rows_with_empty_cellsx   st     	G 	GD G Gs88g%%JJAq"'CHH2DEFFFG	G 	Gr   Nr=   r>   )__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_contentr0   r<   rD   propertyr    rN   rT    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 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.r2   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)contentr4   warningr   r   r6   r7   r&   r0   Elementr$   nested_parsecontent_offsetr3   rJ   tabler5   rA   rB   rD   r    rK   rN   r   argschildrenzipadd_nameinsert)r,   rt   r'   r/   noder5   rC   tgrouprM   detailcolspecsrk   	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)rV   rW   rX   rY   r   rd   r   r   rf   rf      s-         &' &' &' &' &'r   rf   c                  X   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d	            Zd
 Zd Zd Zd ZdS )CSVTabler   )header-rowsstub-columnsheaderr   r    fileurlencodingr   r   r   delim	keepspacequoteescapec                  J     e Zd ZdZdZdZdZdZdZdZ	e
j        Zd	 fdZ xZS )
CSVTable.DocutilsDialectz&CSV dialect for `csv_table` directive.,rG   T
r=   r>   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,   rA   	__class__s     r   r   z!CSVTable.DocutilsDialect.__init__   s    '!!!(!1g%%(-%'!!!(!17""#( ")("3GGr   rU   )rV   rW   rX   rY   r   r   r   r   strictlineterminatorcsvQUOTE_MINIMALquotingr   __classcell__r   s   @r   DocutilsDialectr      sj        44		#
	 
	 
	 
	 
	 
	 
	 
	 
	 
	r   r   c                  N     e Zd ZdZdZdZdZdZdZdZ	dZ
ej        Zd 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   rG   \FTr   r=   r>   c                    t          j        dt          d           t                                                       d S )Nz6CSVTable.HeaderDialect will be removed in Docutils 1.0   
stacklevel)warningswarnDeprecationWarningr   r   )r,   r   s    r   r   zCSVTable.HeaderDialect.__init__   sD    M ,,< < < < GGr   rU   )rV   rW   rX   rY   r   r   r   r   r   r   r   r   r   r   r   r   r   s   @r   HeaderDialectr      su        	 	& 		
#	 	 	 	 	 	 	 	 	 	r   r   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   r   rd   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&   rA   parse_csv_data_into_rowssplitr   rP   )r,   r*   
table_headmax_header_colsr8   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.r2   r   r   r   zError with CSV data in "z" directive:
)r    rh   r   r   )#r$   documentsettingsfile_insertion_enabledrA   r4   rt   r   r   r6   r7   r&   r0   get_csv_datar   r   r   maxrB   r<   rP   rN   rT   r   ry   r   Errorstrr5   build_tablerw   r    rD   r|   r}   )r,   rt   r'   r/   csv_datar*   r   r   r8   max_colsr9   r:   
table_bodyrM   r   messager5   rx   rC   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.r2   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   rA   rB   input_encodinginput_encoding_error_handlerrs   r4   r5   r   r   r6   r7   r&   r   r*   r   current_sourceroot_prefixr	   read
splitlinesrecord_dependenciesaddOSErrorseverer   r   
ValueErrorr
   rt   )r,   r   r   r   r5   r*   r   csv_filer   responsecsv_texts              r   r   zCSVTable.get_csv_dataA  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           	     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   Nrd   )rm   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   r3   )r,   r   r   r*   
csv_readerr8   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   NrU   )rV   rW   rX   r   nonnegative_intr]   r^   r_   r`   pathurir   r\   r   $single_char_or_whitespace_or_unicodeflagsingle_char_or_unicodera   r   Dialectr   r   staticmethodr   r   r   r   r   rd   r   r   r   r      sF       ","<#-#='1&G0Z01;1MO O%?$.)2&3%/!&K *&='>'@ @K*    #+   0! ! ! ! ! ! ! !F 8 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.r2   c                2    g | ]}d  |d         D             S )c                    g | ]	}|j         
S rd   )rz   )rm   items     r   ro   z,ListTable.run.<locals>.<listcomp>.<listcomp>  s    AAAT4=AAAr   r   rd   )rm   row_lists     r   ro   z!ListTable.run.<locals>.<listcomp>  s;     3 3 3& BAXa[AAA 3 3 3r   r   r   r   r   rh   r   )rs   r4   r5   r   r   r6   r7   r&   r0   ru   r$   rv   rw   check_list_contentrA   rB   r<   r   ry   build_table_from_listrD   r|   r}   )r,   r5   r'   r/   r~   	_num_colsrM   
table_datar9   r:   r   rC   s               r   r   zListTable.run  s!   | 	M'' )$&*i)0#DOT_EE[ ( " "E 7N//++x}
d.A4HHH	$$($;$;D$A$A!Iz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.r2   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 rH   )r3   rJ   r   bullet_listr4   r5   r   r6   r7   r&   r   rangerN   )r,   r~   r5   	list_nodenum_cols
item_indexr   rM   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   rh   rq   rr   )ri   rp   Tstubr   )r   rx   r    r   r3   rk   
attributesr;   entryr   theadrP   tbody)r,   r   rM   r9   r:   rx   r   r   rk   r8   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:":. "-1"6*!gFF 	" 	"Cy{{H " "E!KK!!!! 	KMMELLl{l+,,,eOFT+,,'(((%r   N)rV   rW   rX   rY   r   r   r^   r_   r`   r\   r]   r   ra   r   r   r   rd   r   r   r   r     s          #-"<#-#=&G0Z01;1MO O&3%/!# #K' ' '<$$ $$ $$L         r   r   )rY   
__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   rf   r   r   rd   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 -' -' -'`d d d d du d d dNu u u u u u u u u ur   