ó È*Sc@sîdZdZddlZddlZddlZddlmZmZm Z m Z ddl m Z ddl mZddlmZddlmZd efd „ƒYZd efd „ƒYZd efd„ƒYZdefd„ƒYZdS(s Directives for table elements. treStructuredTextiÿÿÿÿN(tiotnodest statemachinetutils(t SafeString(tSystemMessagePropagation(t Directive(t directivestTablecBsgeZdZdZeZiejd6ejd6Z eZ d„Z d„Z d„Z d„Zd„ZRS( 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((sP/usr/local/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((sP/usr/local/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pytprocess_header_option.scCs×t|ƒ|krj|jjjd|t|ƒ|jftj|j|jƒd|jƒ}t |ƒ‚nt|ƒ|ko‡dknrá|jjjdt|ƒ|jftj|j|jƒd|jƒ}t |ƒ‚nxï|D]ç}t|ƒ|krX|jjjd|t|ƒ|jftj|j|jƒd|jƒ}t |ƒ‚nt|ƒ|koudknrè|jjjdt|ƒ|jftj|j|jƒd|jƒ}t |ƒ‚qèqèWdS(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((sP/usr/local/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pytcheck_table_dimensions9s2 "   " cCsÝd|jkr€|jd}t|ƒ|krÙ|jjjd|j|ftj|j|jƒd|j ƒ}t |ƒ‚qÙnY|ršd|g|}n?|jjjdtj|j|jƒd|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(((sP/usr/local/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-((sP/usr/local/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(((sP/usr/local/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyR s    tRSTTablecBseZd„ZRS(cCsH|jsJ|jjjd|jtj|j|jƒd|jƒ}|gS|j ƒ\}}tj ƒ}|j j |j|j |ƒt|ƒdks­t|dtjƒ rî|jjjd|jtj|j|jƒd|jƒ}|gS|d}|dc|jjdgƒ7<|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((sP/usr/local/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pytrunss*    )    (R7R8RO(((sP/usr/local/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyRAqstCSVTablecBs4eZi ejd6ejd6ejd6ejd6ejd6ejd6ejd6ej d6ejd6ej d 6ej d 6ej d 6ej d 6Z d ejfd„ƒYZdejfd„ƒYZd„Zd„Zd„Zejdkrÿd„Zd„Znd„Zd„ZeeƒZeeƒZd„ZRS(s header-rowss stub-columnsRR/tfileturltencodingR R tdelimt keepspacetquotetescapetDocutilsDialectcBsDeZdZdZdZeZeZeZdZ e j Z d„Z RS(s&CSV dialect for `csv_table` directive.t,t"s cCs¤d|kr%tj|dƒ|_nd|kr=t|_nd|krbtj|dƒ|_nd|krt|_tj|dƒ|_ntj j |ƒdS(NRTRURVRW( RPtencode_for_csvt delimitertFalsetskipinitialspacet quotechart doublequotet escapechartcsvtDialectt__init__(RR((sP/usr/local/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyRd«s      (R7R8R9R\R_R;R`R^tstricttlineterminatorRbt QUOTE_MINIMALtquotingRd(((sP/usr/local/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyRXŸs RcBsAeZdZdZdZdZeZeZ eZ dZ e j ZRS(s0CSV dialect to use for the "header" option data.RYRZs\s (R7R8R9R\R_RaR]R`R;R^ReRfRbRgRh(((sP/usr/local/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyR¸scCsdS(N((R((sP/usr/local/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pytcheck_requirementsÅscCs‘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| || fƒWn«tk r‰}|jdgStjk r}t|ƒ}tjdkrÏd |krÏ|d 7}n|jjj d |j|ft j |j |j ƒd|j ƒ}|gSX| || f}|jj!||j"| ƒ}|d c|jjd gƒ7<|j#|ƒ|r†|j$d|ƒn|g|S(NRQRRs9File and URL access deactivated; ignoring "%s" directive.R%s header-rowsis stub-columnsis1-character strings1 with Python 2.x this must be an ASCII character.s)Error with CSV data in "%s" directive: %sRBR (i(%Rtdocumenttsettingstfile_insertion_enabledRRR'RDR RR)R*RRiRt get_csv_dataR$RRXtmaxRJR.RR2R6RtargsRbtErrortstrtsyst version_infoR(t build_tableRGRKRL(RRDRRtcsv_dataR R!R"R#R0R+R,t table_bodyR1tdetailtmessageR(RIRN((sP/usr/local/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyROÈsV   !       c Cs˜|jjd|jjjjƒ}|jjjj}|jrÁd|jksZd|jkr£|jj j d|j t j |j|jƒd|jƒ}t|ƒ‚n|jjdƒ}|j}nÍd|jkrAd|jkr(|jj j d|j t j |j|jƒd|jƒ}t|ƒ‚ntjjtjj|jjjƒƒ}tjjtjj||jdƒƒ}tjd |ƒ}yM|jjjjj|ƒtjd|d|d |ƒ}|j ƒj!ƒ}WqŽt"k r=}|jj j#d |j t$|ƒft j |j|jƒd|jƒ}t|ƒ‚qŽXnMd|jkrHd d l%} |jd}y| j&|ƒj ƒ} Wn~| j't"t(t)fk r}|jj j#d |j |jdt$|ƒft j |j|jƒd|jƒ}t|ƒ‚nXtj*d| d|d|d |jjjjƒ}|j ƒj!ƒ}nF|jj j+d|j t j |j|jƒd|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.iÿÿÿÿNs*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( RRSRzR(R Rut source_dirtcsv_fileR‹RŒtcsv_text((sP/usr/local/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyRmõsx                   icCs |jdƒS(Nsutf-8(tdecode(ts((sP/usr/local/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pytdecode_from_csvAscCs |jdƒS(Nsutf-8(tencode(R–((sP/usr/local/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyR[CscCs|S(N((R–((sP/usr/local/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyR—FscCs|S(N((R–((sP/usr/local/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyR[Hsc CsØtjg|D]}|j|dƒ^q d|ƒ}g}d}xŠ|D]‚}g} xQ|D]I} |j| ƒ} dddtj| jƒd|ƒf} | j| ƒq[W|j| ƒt|t |ƒƒ}qHW||fS(Ns tdialectiR ( RbtreaderR[R—Rt StringListR‰tappendRnR&( RRuR™R R%t csv_readerR#R0R-trow_datatcellt cell_textt cell_data((sP/usr/local/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyRMs #    (i(R7R8Rtnonnegative_intR>tpositive_int_listR~turiRSR=t$single_char_or_whitespace_or_unicodetflagtsingle_char_or_unicodeR?RbRcRXRRiRORmRrRsR—R[t staticmethodR(((sP/usr/local/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyRP‹s4               - J      t ListTablecBsaeZdZiejd6ejd6ejd6ejd6ejd6Zd„Z d„Z d„Z 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|jƒd|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|jjdgƒ7<|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,RwRN((sP/usr/local/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyROos2     4   cCsÊt|ƒdks)t|dtjƒ rr|jjjd|jtj|j |j ƒd|j ƒ}t |ƒ‚n|d}x2t t|ƒƒD]}||}t|ƒdksÈt|dtjƒ r|jjjd|j|dftj|j |j ƒd|j ƒ}t |ƒ‚q|rt|dƒ|kr­|jjjd|j|dt|dƒ|ftj|j |j ƒd|j ƒ}t |ƒ‚q­qt|dƒ}qW|j |ƒ}||fS(NiisUError parsing content block for the "%s" directive: exactly one bullet list expected.R%s‹Error parsing content block for the "%s" directive: two-level bullet list expected, but row %s does not contain a second-level bullet list.s¥Error 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_indexR¯R­R1((sP/usr/local/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyRªŠs6)    )  ! cCs7tjƒ}tjdt|ƒƒ}||7}xJ|D]B}tjd|ƒ}|rmd|jd<|d8}n||7}q5Wg} xX|D]P} tjƒ} x.| D]&} tjƒ} | | 7} | | 7} q¡W| j| ƒqˆW|r tj ƒ}|j | | ƒ||7}ntj ƒ}|j | |ƒ||7}|S(Ntcolstcolwidthitstub( RRIttgroupR&tcolspect attributesR-tentryRœttheadRttbody(RR°R1R+R,RIR¸t col_widthR¹R#R-trow_nodeRŸR»R¼R½((sP/usr/local/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyR¬±s2              ( R7R8R9RR¢R£R=R>R?RORªR¬(((sP/usr/local/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyR©as       '(R9t __docformat__Rrtos.pathR}RbtdocutilsRRRRtdocutils.utils.error_reportingRtdocutils.utilsRtdocutils.parsers.rstRRR RARPR©(((sP/usr/local/lib/python2.7/site-packages/docutils/parsers/rst/directives/tables.pyts   "ZÖ