U n^: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)Zargumentr/private/var/folders/sd/whlwsn6x1_qgglc0mjv25_695qk2gl/T/pip-install-4zq3fp6i/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).rrzeInsufficient 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_columnsr2rowrrrcheck_table_dimensionsCsb    zTable.check_table_dimensionscCsd|jkr|jd|d<dS)Nrr&get)r table_noderrrset_table_widthbs zTable.set_table_widthcCs|jddS)Nrrr9r 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).r/dz#No table data detected in CSV file.) typerlistr0rr1r2rrr3r4rr)r max_colsr2 col_widthsrrrget_column_widthsjs4zTable.get_column_widthscCsD|D]:}|D]0}t||kr |dddgfg|t|q qdS)Nr)r0r*)r columnspartspartr7rrr"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.r8r<propertyrrCrGrrrrrs(   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.r/rrzOError parsing content block for the "%s" directive: exactly one table expected.classesrrcSsg|]}|jdkr|qS)colspec)tagname).0childrrr s z RSTTable.run..colwidthrcolwidths-autocolwidths-given)contentrr1warningrrr3r4rr"Elementr nested_parsecontent_offsetr0 isinstancetabler2r&r:r<r?rr@childrenzipadd_nameinsert) r r^rr!noder2r;tgroupZcolspecsrU col_widthrrrrunsZ       z RSTTable.runN)rHrIrJrkrrrrrSsrSc@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)NrsrtFrurv) rlencode_for_csv delimiterskipinitialspace quotechar doublequote escapecharcsvDialect__init__)r r&rrrrsz!CSVTable.DocutilsDialect.__init__N)rHrIrJrKrzr|r}r{strictlineterminatorr QUOTE_MINIMALquotingrrrrrDocutilsDialectsrc@s2eZdZdZdZdZdZdZdZdZ dZ e j Z dS) zCSVTable.HeaderDialectz0CSV dialect to use for the "header" option data.rwrx\FTr$N)rHrIrJrKrzr|r~r}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)Nrprqz9File and URL access deactivated; ignoring "%s" directive.r/rnrroz1-character stringz1 with Python 2.x this must be an ASCII character.z)Error with CSV data in "%s" directive: %s)rrTrr)'rdocumentsettingsZfile_insertion_enabledr&rr1r^rrr3r4rrr" get_csv_datar.r'rmaxr:r8r*rCrGrargsrErrorstrsys version_infor2Z build_tablerarr<rfrg)r r^rr!csv_datarr+r,r-rAr5r6Z table_bodyrBdetailmessager2rcr;rrrrks               z CSVTable.runc Cs|jd|jjjj}|jjjj}|jrd|jks.)dialectr)r) rreaderrrZ StringListrappendrr0) r rrrZ csv_readerr-rAr7Zrow_datacellZ cell_textZ cell_datarr=rr'us&    z!CSVTable.parse_csv_data_into_rowsN)rHrIrJr nonnegative_intrMrNrOrPrurirrrLrZ$single_char_or_whitespace_or_unicodeflagZsingle_char_or_unicoderQrrrr)rrkrrrrry staticmethodr'rrrrrls> 0J  rlc@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 rm)rnrorrrrrc 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.r/cSsg|]}dd|dDqS)cSsg|] }|jqSr)rd)rWitemrrrrYsz,ListTable.run...rr)rWZrow_listrrrrYsz!ListTable.run..rrnrorrTr)r]rr1r2rrr3r4rr"r_rr`racheck_list_contentr&r:r8rrbuild_table_from_listr<rfrg) r r2rr!rhnum_colsrB table_datar5r6rr;rrrrks@ "    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.r/zError 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).)r0rbrZ bullet_listrr1r2rr3r4rrrangerC)r rhr2Z list_nodeZ item_indexrrrBrrrrsJ    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) NrrTr[r\)colsrZrZstub) rrcrrir0rU attributesr7entryrtheadr*tbody)r rrBr5r6rcrirjrUr-r7Zrow_noderrrrrrrrs>      zListTable.build_table_from_listN)rHrIrJrKr rrNrOrPrLrMrrQrkrrrrrrrs 'r)rKZ __docformat__ros.pathrrZdocutilsrrrrZdocutils.utils.error_reportingrZdocutils.utilsrZdocutils.parsers.rstrr rrrSrlrrrrrs    h*]