U C^:Y@sdZdZddlZddlZddlZddlmZmZm Z m Z ddl m Z ddl mZddlmZddlmZd d ZGd d d eZGd ddeZGdddeZGdddeZdS)z Directives for table elements. ZreStructuredTextN)ionodes statemachineutils) SafeString)SystemMessagePropagation) Directive) directivescCs t|dS)N)leftcenterright)r choice)argumentrL/tmp/pip-install-6_kvzl1k/docutils/docutils/parsers/rst/directives/tables.pyalignsrc@sxeZdZdZdZdZejeje ej e dej dZ dZddZdd Zd d Zd d ZeddZddZddZdS)Tablez# Generic table base class. T)autoZgrid)classnamerwidthwidthscCs^|jrN|jd}|j||j\}}tj|df|}|j|j\|_|_ nd}g}||fS)Nr) argumentsstateZ inline_textlinenortitle state_machineZget_source_and_linesourceline)selfZ title_textZ text_nodesmessagesrrrr make_title+s  zTable.make_titlecCsX|j|jd}g}d}d|jkrP||jdd||\}}||||fS)Nrrheader )r get_sourceroptionsparse_csv_data_into_rowssplit HeaderDialectextend)r!r table_headmax_header_colsrowsrrrprocess_header_option8s  zTable.process_header_optioncCsDt||krF|jjjd|t||jft|j|j|jd}t |t||kr^dkrnn8|jjjdt||jft|j|j|jd}t ||D]}t||kr|jjjd|t||jft|j|j|jd}t |t||krdkrnq|jjjdt||jft|j|j|jd}t |qdS)NzP%s header row(s) specified but only %s row(s) of data supplied ("%s" directive).r rzeInsufficient data supplied (%s row(s)); no data remaining for table body, required by "%s" directive.zU%s stub column(s) specified but only %s columns(s) of data supplied ("%s" directive).ziInsufficient data supplied (%s columns(s)); no data remaining for table body, required by "%s" directive.) lenrreportererrorrr literal_block block_textrr)r!r. header_rows stub_columnsr3rowrrrcheck_table_dimensionsCsb    zTable.check_table_dimensionscCsd|jkr|jd|d<dS)Nrr'get)r! table_noderrrset_table_widthbs zTable.set_table_widthcCs|jddS)Nrrr:r!rrrrfsz Table.widthscCst|jtkrXt|j|krP|jjjd|j|ft |j |j |j d}t ||j}n>|rld|g|}n*|jjjdt |j |j |j d}t ||S)Nz="%s" widths do not match the number of columns in table (%s).r0dz#No table data detected in CSV file.) typerlistr1rr2r3rrr4r5rr)r!max_colsr3 col_widthsrrrget_column_widthsjs4zTable.get_column_widthscCsD|D]:}|D]0}t||kr |dddgfg|t|q qdS)Nr)r1r+)r!columnspartspartr8rrr"extend_short_rows_with_empty_cells|s z(Table.extend_short_rows_with_empty_cellsN)__name__ __module__ __qualname____doc__Zoptional_argumentsZfinal_argument_whitespacer class_option unchangedr length_or_percentage_or_unitlessvalue_orpositive_int_list option_specZ has_contentr#r/r9r=propertyrrDrHrrrrrs(   rc@seZdZddZdS)RSTTablec Cs|js4|jjjd|jt|j|j|jd}|gS| \}}t }|j |j|j |t|dksxt|dtjs|jjjd|jt|j|j|jd}|gS|d}|d|jdg7<||d|jkr|jd|d<|d}t|jtkr4d d |jD}t||jD]\} } | | d <q |jd krT|dd g7<n|jrn|ddg7<|||r|d||g|S)Nz:Content block expected for the "%s" directive; none found.r0rrzOError parsing content block for the "%s" directive: exactly one table expected.classesrrcSsg|]}|jdkr|qS)colspec)tagname).0childrrr s z RSTTable.run..colwidthrcolwidths-autocolwidths-given)contentrr2warningrrr4r5rr#Elementr nested_parsecontent_offsetr1 isinstancetabler3r'r;r=r@rrAchildrenzipadd_nameinsert) r!r_rr"noder3r<tgroupZcolspecsrV col_widthrrrrunsZ       z RSTTable.runN)rIrJrKrlrrrrrTsrTc@seZdZejejejejedejej ej ej ej eje ejejejejdZGdddejZGdddejZddZd d Zd d Zejd krddZddZnddZddZeeZeeZddZdS)CSVTabler) header-rows stub-columnsr$rrfileurlencodingrrrdelim keepspacequoteescapec@s6eZdZdZdZdZdZdZdZdZ e j Z ddZ dS) zCSVTable.DocutilsDialectz&CSV dialect for `csv_table` directive.,"Tr%cCsld|krt|d|_d|kr&d|_d|kr>t|d|_d|kr\d|_t|d|_tj |dS)NrtruFrvrw) rmencode_for_csv delimiterskipinitialspace quotechar doublequote escapecharcsvDialect__init__)r!r'rrrrsz!CSVTable.DocutilsDialect.__init__N)rIrJrKrLr{r}r~r|strictlineterminatorr QUOTE_MINIMALquotingrrrrrDocutilsDialectsrc@s2eZdZdZdZdZdZdZdZdZ dZ e j Z dS) zCSVTable.HeaderDialectz0CSV dialect to use for the "header" option data.rxry\FTr%N)rIrJrKrLr{r}rr~r|rrrrrrrrrr*sr*cCsdSNrr>rrrcheck_requirementsszCSVTable.check_requirementsc CsFz|jjjjsTd|jks$d|jkrT|jjjd|jt |j |j |j d}|gWS| |\}}|\}}|\}}||||j|\}} t| |} |jdd} |jdd} ||| | ||d| || d} || } || || fWntk r<}z|jdgWYSd}~XYntjk r}z`t|}tjdkrvd |krv|d 7}|jjj d |j|ft |j |j |j d}|gWYSd}~XYnX| || f}|jj!||j"| |j#d }|d |jdg7<d|jkr|jd|d<|$||%||r<|&d||g|S)Nrqrrz9File and URL access deactivated; ignoring "%s" directive.r0rorrpz1-character stringz1 with Python 2.x this must be an ASCII character.z)Error with CSV data in "%s" directive: %s)rrUrr)'rdocumentsettingsZfile_insertion_enabledr'rr2r_rrr4r5rrr# get_csv_datar/r(rmaxr;r9r+rDrHrargsrErrorstrsys version_infor3Z build_tablerbrr=rgrh)r!r_rr"csv_datarr,r-r.rBr6r7Z table_bodyrCdetailmessager3rdr<rrrrls               z CSVTable.runc Cs|jd|jjjj}|jjjj}|jrd|jksrrrZwsz5CSVTable.parse_csv_data_into_rows..)dialectr)r) rreaderrrZ StringListrappendrr1) r!rrrZ csv_readerr.rBr8Zrow_datacellZ cell_textZ cell_datarr>rr(us&    z!CSVTable.parse_csv_data_into_rowsN)rIrJrKr nonnegative_intrNrOrPrQrurirsrMrZ$single_char_or_whitespace_or_unicodeflagZsingle_char_or_unicoderRrrrr*rrlrrrrrz staticmethodr(rrrrrms> 0J  rmc@sPeZdZdZejejejedejej ej e dZ ddZ ddZdd Zd 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 rn)rorprrrrrc CsT|js4|jjjd|jt|j|j|jd}|gS| \}}t }|j |j|j |zN||\}}dd|dD}|jdd}|jdd} |||| Wn2tk r} z| jdgWYSd} ~ XYnX||||| } d|jkr |jd| d<| d |jd g7<|| || |rJ| d|| g|S) Nz.The "%s" directive is empty; content required.r0cSsg|]}dd|dDqS)cSsg|] }|jqSr)re)rXitemrrrrZsz,ListTable.run...rr)rXZrow_listrrrrZsz!ListTable.run..rrorprrUr)r^rr2r3rrr4r5rr#r`rrarbcheck_list_contentr'r;r9rrbuild_table_from_listr=rgrh) r!r3rr"rinum_colsrC table_datar6r7rr<rrrrls@ "    z ListTable.runcCs@t|dkst|dtjsL|jjjd|jt|j |j |j d}t ||d}t t|D]}||}t|dkst|dtjs|jjjd|j|dft|j |j |j d}t |q`|r t|d|kr,|jjjd|j|dt|d|ft|j |j |j d}t |q`t|d}q`| |}||fS)NrrzUError parsing content block for the "%s" directive: exactly one bullet list expected.r0zError parsing content block for the "%s" directive: two-level bullet list expected, but row %s does not contain a second-level bullet list.zError parsing content block for the "%s" directive: uniform two-level bullet list expected, but row %s does not contain the same number of items as row 1 (%s vs %s).)r1rcrZ bullet_listrr2r3rr4r5rrrangerD)r!rir3Z list_nodeZ item_indexrrrCrrrrsJ    zListTable.check_list_contentcCs(t}|jdkr&|ddg7<n|jr>|ddg7<tjt|d}||7}|D]<}t}|dk rx||jd<|rd|jd<|d8}||7}qZg} |D]8} t} | D]} t} | | 7} | | 7} q| | q|rt }| | d|||7}t }| | |d||7}|S) NrrUr\r])colsr[rZstub) rrdrrjr1rV attributesr8entryrtheadr+tbody)r!rrCr6r7rdrjrkrVr.r8Zrow_noderrrrrrrrs>      zListTable.build_table_from_listN)rIrJrKrLr rrOrPrQrMrNrrRrlrrrrrrrs 'r)rLZ __docformat__ros.pathrrZdocutilsrrrrZdocutils.utils.error_reportingrZdocutils.utilsrZdocutils.parsers.rstrr rrrTrmrrrrrs    h*]