Qc@sdZdZddlZddlZddlZddlmZmZm Z m Z ddl m Z ddl mZddlmZddlmZd efd YZd efd YZd efdYZdefdYZdS(s Directives for table elements. treStructuredTextiN(tiotnodest statemachinetutils(t SafeString(tSystemMessagePropagation(t Directive(t directivestTablecBsgeZdZdZeZiejd6ejd6Z eZ dZ dZ dZ dZdZRS( s# Generic table base class. itclasstnamecCsb|jrL|jd}|jj||j\}}tj|d|}n d}g}||fS(Nit(t argumentststatet inline_texttlinenoRttitletNone(tselft title_textt text_nodestmessagesR((sJ/usr/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyt make_title#s   cCs|jj|jd}g}d}d|jkru|j|jdjd|j|\}}|j|n||fS(Niitheaders (t state_machinet get_sourceRtoptionstparse_csv_data_into_rowstsplitt HeaderDialecttextend(Rtsourcet table_headtmax_header_colstrows((sJ/usr/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pytprocess_header_option.scCst||krj|jjjd|t||jftj|j|jd|j}t |nt||kodknr|jjjdt||jftj|j|jd|j}t |nx|D]}t||krX|jjjd|t||jftj|j|jd|j}t |nt||koudknr|jjjdt||jftj|j|jd|j}t |qqWdS(NsP%s header row(s) specified but only %s row(s) of data supplied ("%s" directive).tlineiseInsufficient data supplied (%s row(s)); no data remaining for table body, required by "%s" directive.sU%s stub column(s) specified but only %s columns(s) of data supplied ("%s" directive).siInsufficient data supplied (%s columns(s)); no data remaining for table body, required by "%s" directive.( tlenRtreporterterrorR Rt literal_blockt block_textRR(RR#t header_rowst stub_columnsR(trow((sJ/usr/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pytcheck_table_dimensions9s2 "   " cCsd|jkr|jd}t||kr|jjjd|j|ftj|j|jd|j }t |qnY|rd|g|}n?|jjjdtj|j|jd|j }t ||S(Ntwidthss="%s" widths do not match the number of columns in table (%s).R%ids#No table data detected in CSV file.( RR&RR'R(R RR)R*RR(Rtmax_colst col_widthsR(((sJ/usr/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pytget_column_widthsXs     cCsex^|D]V}xM|D]E}t||kr|jdddgfg|t|qqWqWdS(Ni(R&R(RtcolumnstpartstpartR-((sJ/usr/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyt"extend_short_rows_with_empty_cellsjs  (t__name__t __module__t__doc__toptional_argumentstTruetfinal_argument_whitespaceRt class_optiont unchangedt option_spect has_contentRR$R.R2R6(((sJ/usr/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyR s    tRSTTablecBseZdZRS(cCsH|jsJ|jjjd|jtj|j|jd|j}|gS|j \}}tj }|j j |j|j |t|dkst|dtj r|jjjd|jtj|j|jd|j}|gS|d}|dc|jjdg7<|j||r=|jd|n|g|S(Ns:Content block expected for the "%s" directive; none found.R%iisOError parsing content block for the "%s" directive: exactly one table expected.tclassesR (tcontentRR'twarningR RR)R*RRtElementRt nested_parsetcontent_offsetR&t isinstancettableR(Rtgettadd_nametinsert(RRDRRtnodeR(t table_node((sJ/usr/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pytrunss*    )    (R7R8RO(((sJ/usr/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyRAqstCSVTablecBs4eZi ejd6ejd6ejd6ejd6ejd6ejd6ejd6ej d6ejd6ej d 6ej d 6ej d 6ej d 6Z d ejfdYZdejfdYZdZdZdZejdkrdZdZndZdZeeZeeZdZRS(s header-rowss stub-columnsRR/tfileturltencodingR R tdelimt keepspacetquotetescapetDocutilsDialectcBsDeZdZdZdZeZeZeZdZ e j Z dZ RS(s&CSV dialect for `csv_table` directive.t,t"s cCsd|kr"t|d|_nd|kr:t|_nd|kr\t|d|_nd|krt|_t|d|_ntjj |dS(NRTRURVRW( tstrt delimitertFalsetskipinitialspacet quotechart doublequotet escapechartcsvtDialectt__init__(RR((sJ/usr/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyRds      (R7R8R9R\R_R;R`R^tstricttlineterminatorRbt QUOTE_MINIMALtquotingRd(((sJ/usr/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyRXs RcBsAeZdZdZdZdZeZeZ eZ dZ e j ZRS(s0CSV dialect to use for the "header" option data.RYRZs\s (R7R8R9R\R_RaR]R`R;R^ReRfRbRgRh(((sJ/usr/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyRscCsdS(N((R((sJ/usr/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pytcheck_requirementsscCs]yi|jjjj rud|jks4d|jkru|jjjd|jt j |j |j d|j }|gS|j |j\}}|j\}}|j\}}|j||j|j|\}} t| |} |jjdd} |jjdd} |j|| | |j|| || } |j| } |j| || fWnwtk r}|jdgStjk r}|jjjd|j|ft j |j |j d|j }|gSX| || f}|jj||j| }|d c|jjd g7<|j ||rR|j!d|n|g|S( NRQRRs9File and URL access deactivated; ignoring "%s" directive.R%s header-rowsis stub-columnss)Error with CSV data in "%s" directive: %sRBR ("Rtdocumenttsettingstfile_insertion_enabledRRR'RDR RR)R*RRiRt get_csv_dataR$RRXtmaxRJR.RR2R6RtargsRbtErrorR(t build_tableRGRKRL(RRDRRtcsv_dataR R!R"R#R0R+R,t table_bodyR1tdetailR(RIRN((sJ/usr/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyROsP   !     c Cs|jjd|jjjj}|jjjj}|jrd|jksZd|jkr|jj j d|j t j |j|jd|j}t|n|jjd}|j}nd|jkrAd|jkr(|jj j d|j t j |j|jd|j}t|ntjjtjj|jjj}tjjtjj||jd}tjd |}yM|jjjjj|tjd|d|d |}|j j!}Wqt"k r=}|jj j#d |j t$|ft j |j|jd|j}t|qXnMd|jkrHd d l%} |jd}y| j&|j } Wn~| j't"t(t)fk r}|jj j#d |j |jdt$|ft j |j|jd|j}t|nXtj*d| d|d|d |jjjj}|j j!}nF|jj j+d|j t j |j|jd|j}t|||fS(sr Get CSV data from the directive content, from an external file, or from a URL reference. RSRQRRsF"%s" directive may not both specify an external file and have content.R%isXThe "file" and "url" options may not be simultaneously specified for the "%s" directive.t source_patht error_handleru&Problems with "%s" directive path: %s.iNs*Problems with "%s" directive URL "%s": %s.R s3The "%s" directive requires content; none supplied.(,RRJRRjRktinput_encodingtinput_encoding_error_handlerRCRR'R(R RR)R*RRR tostpathtdirnametabspathtcurrent_sourcetnormpathtjoinRt relative_pathRtrecord_dependenciestaddRt FileInputtreadt splitlinestIOErrortsevereRturllib2turlopentURLErrortOSErrort ValueErrort StringInputRD( RRSRvR(R Rrt source_dirtcsv_fileRRtcsv_text((sJ/usr/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyRmsx                   icCs |jdS(Nsutf-8(tdecode(ts((sJ/usr/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pytdecode_from_csv>scCs |jdS(Nsutf-8(tencode(R((sJ/usr/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pytencode_for_csv@scCs|S(N((R((sJ/usr/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyRCscCs|S(N((R((sJ/usr/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyREsc Cstjg|D]}|j|d^q d|}g}d}x|D]}g} xQ|D]I} |j| } dddtj| jd|f} | j| q[W|j| t|t |}qHW||fS(Ns tdialectiR ( RbtreaderRRRt StringListRtappendRnR&( RRrRR R%t csv_readerR#R0R-trow_datatcellt cell_textt cell_data((sJ/usr/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyRJs #    (i(R7R8Rtnonnegative_intR>tpositive_int_listRzturiRSR=t$single_char_or_whitespace_or_unicodetflagtsingle_char_or_unicodeR?RbRcRXRRiRORmtsyst version_infoRRt staticmethodR(((sJ/usr/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyRPs4               * J      t ListTablecBsaeZdZiejd6ejd6ejd6ejd6ejd6ZdZ dZ dZ RS( s 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 s header-rowss stub-columnsR/R R cCs|jsJ|jjjd|jtj|j|jd|j}|gS|j \}}tj }|j j |j|j |y|j|\}}g|dD]&}g|dD]}|j^q^q} |jjdd} |jjdd} |j| | | Wntk r1} | jdgSX|j| || | } | dc|jjdg7<|j| |r| jd|n| g|S(Ns.The "%s" directive is empty; content required.R%is header-rowss stub-columnsRBR (RCRR'R(R RR)R*RRRERRFRGtcheck_list_contenttchildrenRRJR.RRotbuild_table_from_listRKRL(RR(RRRMtnum_colsR1trow_listtitemt table_dataR+R,RtRN((sJ/usr/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyROls2     4   c Cst|dks)t|dtj rr|jjjd|jtj|j |j d|j }t |n|d}x2t t|D]}||}t|dkst|dtj r|jjjd|j|dftj|j |j d|j }t |q|rt|d|kr|jjjd|j|dt|d|ftj|j |j d|j }t |qqt|d}qW|j |}||fS(NiisUError parsing content block for the "%s" directive: exactly one bullet list expected.R%sError parsing content block for the "%s" directive: two-level bullet list expected, but row %s does not contain a second-level bullet list.sError 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).(R&RHRt bullet_listRR'R(R R)R*RRtrangeR2(RRMR(t list_nodet item_indexRRR1((sJ/usr/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyRs6)    )  ! cCs7tj}tjdt|}||7}xJ|D]B}tjd|}|rmd|jd<|d8}n||7}q5Wg} xX|D]P} tj} x.| D]&} tj} | | 7} | | 7} qW| j| qW|r tj }|j | | ||7}ntj }|j | |||7}|S(Ntcolstcolwidthitstub( RRIttgroupR&tcolspect attributesR-tentryRttheadRttbody(RRR1R+R,RIRt col_widthRR#R-trow_nodeRRRR((sJ/usr/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyRs2              ( R7R8R9RRRR=R>R?RORR(((sJ/usr/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyR^s       '(R9t __docformat__Rtos.pathRyRbtdocutilsRRRRtdocutils.utils.error_reportingRtdocutils.utilsRtdocutils.parsers.rstRRR RARPR(((sJ/usr/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyts   "Z