3 E\@sdZdZddlZddlZddlmZmZddlmZm Z m Z ddlm Z m Z ddl mZmZddlmZdd lmZddlZdd lmZmZmZmZdd lmZdd lmZmZmZdd lm Z m!Z!m"Z"ddlm#Z#Gddde Z$Gddde Z%Gddde Z&Gddde Z'Gddde(Z)GdddZ*GdddeZ+GdddeZ,Gdd d eZ-dSd"d#Z.Gd$d%d%Z/e0d&d'fd(d)Z1e0d*d'fd+d,Z2d-d.Z3Gd/d0d0e-Z4Gd1d2d2e4Z5Gd3d4d4e4Z6Gd5d6d6e6Z7Gd7d8d8e6Z8Gd9d:d:e6Z9Gd;d<dd>e6Z;Gd?d@d@e6e5ZGdEdFdFe6Z?GdGdHdHe4Z@GdIdJdJe-ZAGdKdLdLeAZBGdMdNdNeBZCGdOdPdPeBZDGdQdRdRe-ZEe4e7e8e9e:e;e>e=e?eAeCeDe@e5errrr:szNestedStateMachine.runN)T)rrrr(r:rrrrr?sr?c@seZdZdZeZgZd ddZddZddZ d d Z d d Z d!ddZ d idd d fddZ ddZddZddZddZddZddZddZd S)"RSTStatez` reStructuredText State superclass. Contains methods used by all State subclasses. FcCstdd|_tj|||dS)NBody) state_classes initial_state)rBnested_sm_kwargsr r')r& state_machinedebugrrrr's zRSTState.__init__cCsVtj||jj}||_|j|_|j|_|j|_|jj|_t |jdsR|jj |j_ dS)Nget_source_and_line) r runtime_initrEr6r+r0r*r9parenthasattrrG)r&r6rrrrHs   zRSTState.runtime_initc Cs*y|jj|Wntk r$YnXdS)zT Jump to input line `abs_line_offset`, ignoring jumps past the end. N)rE goto_lineEOFError)r&abs_line_offsetrrrrKszRSTState.goto_linecCs*|jjd|jj|||jjf|dgfS)zs Override `StateWS.no_match` to generate a system message. This code should never be run. zjInternal error: no transition pattern match. State: "%s"; transitions: %s; context: %s; current line: %r.N)r+severe __class__rrEline)r&context transitionsrrrno_matchs  zRSTState.no_matchcCsggfS)zCalled at beginning of file.r)r&rQrrrbofsz RSTState.bofNc Csd}|dkr|j}|d7}|dkr0|j}|d7}t|}d} |dkrhy|jj} Wntk rfYnX| s|fd|ji|} | j|||j||d|dkr|jj | n| j | j } |j rt||dkr|j jt||| S)zg Create a new StateMachine rooted at `node` and run it over the input `block`. rNrF)r6r9r3) nested_smrDlennested_sm_cachepop IndexErrorrFr:r6appendunlinkrMrIrE next_line) r&blockr=r9r3state_machine_classstate_machine_kwargsZ use_defaultZ block_lengthrEZ new_offsetrrr nested_parses4   zRSTState.nested_parsec Cs| dkr|j} | dkr |jj} || d<| fd|ji| } |dkrH|}|| j|_x*t|jD]\} } t| j|| | qbW| j |||j ||d| j|j}| j | j |fS)z Create a new StateMachine rooted at `node` and run it over the input `block`. Also keep track of optional intermediate blank lines and the required final one. NrCrF)r6r9r3) rWrDcopyrFZstates blank_finishlistitemssetattrr:r6r]rM)r&r_r=r9rCrdblank_finish_stateextra_settingsr3r`rarEkeyvaluerrrnested_list_parse&s"       zRSTState.nested_list_parsecCs |j|||r|j|||dS)z=Check for a valid subsection and create one if it checks out.N)check_subsectionnew_subsection)r&titler1stylelinenomessagesrrrsectionDszRSTState.sectionc Cs|j}|j}|j}y|j|d}WnJtk rnt||jkrP|j|dS|j|j||7_dSYnX||kr||_t|dkrd|_ |j j t|dt ||dkrdS|j|j||7_dSdS)a Check for a valid subsection header. Return 1 (true) or None (false). When a new section is reached that isn't a subsection of the current section, back up the line count (use ``previous_line(-x)``), then ``raise EOFError``. The current StateMachine will finish, then the calling StateMachine can re-examine the title. This will work its way back up the calling chain until the correct section level isreached. @@@ Alternative: Evaluate the title, store the title info & level, and back up the chain until that level is reached. Store in memo? Or return in results? :Exception: `EOFError` when a sibling or supersection encountered. rUNrVT) r6r-r.index ValueErrorrXr\rItitle_inconsistentr/rE previous_linerL)r&r1rprqr6r-mylevellevelrrrrmIs*    zRSTState.check_subsectioncCs|jjdtjd||d}|S)NzTitle level inconsistent:)rP)r+rNr literal_block)r&Z sourcetextrqerrorrrrrvrs zRSTState.title_inconsistentcCs|j}|j}|jd7_tj}|j|7_|j||\}}tj|df|} t| j} |dj | || 7}||7}||7}|j j |||j j d} |j jd} |j|j j| d| |dd} |j| |j|krt||_dS)z?Append new subsection to document tree. On return, check level.rUrznamesNT)r=r9r3)r6r.rrsrI inline_textronormalize_nameastextr\r*Znote_implicit_targetrE line_offsetrMrbr<rKrL)r&rorqrrr6rxZ section_node textnodesZtitle_messagesZ titlenodenameoffsetZ absoffsetZ newabsoffsetrrrrnxs,     zRSTState.new_subsectionc Csdj|j}tjd|r^t|dkr.gdfS|d dkrL|dd j}n |dd }d}n|}d}|j||\}}tj|d f|}|jj |\|_ |_ |g||fS) zW Return a list (paragraph & messages) & a boolean: literal_block next?  z(?%(or_group)s)%(suffix)s) typetupler\ build_regexprlocalsrcompileUNICODE) definitionrrprefixsuffixpartsZ part_stringspartZor_groupregexprrrrs     rc @seZdZdZddZddZddZdZd Zd Z d Z d Z d Z dZ dZdeZdZdZddZd=ddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd>d.d/Z d0d1Z!d2d3Z"d4d5Z#d6Z$d7d8Z%d9d:Z&eeeeeeee e!d; Z'd%s)(?P__?) footnotelabelz\[z(?P\]_)z[0-9]+z\#(%s)?z\*z(?P%s) backquotez(?P(:%s:)?)z`(?!`)z(\*)z(\*\*)a %(non_unescaped_whitespace_escape_before)s ( ` (?P (?P:%(simplename)s:)? (?P__?)? ) ) %(end_string_suffix)s a ( (?:[ \n]+|^) # spaces or beginning of line/string < # open bracket %(non_whitespace_after)s (([^<>]|\x00[<>])+) # anything but unescaped angle brackets %(non_whitespace_escape_before)s > # close bracket ) $ # end of string z(``)z(`)z (\|_{0,2})$a5 %(start_string_prefix)s (?P (?P # absolute URI (?P # scheme (http, ftp, mailto) [a-zA-Z][a-zA-Z0-9.+-]* ) : ( ( # either: (//?)? # hierarchical URI %(uric)s* # URI characters %(uri_end)s # final URI char ) ( # optional query \?%(uric)s* %(uri_end)s )? ( # optional fragment \#%(uric)s* %(uri_end)s )? ) ) | # *OR* (?P # email address z] ) ) %(end_string_suffix)s a %(start_string_prefix)s ( (pep-(?P\d+)(.txt)?) # reference to source file | (PEP\s+(?P\d+)) # reference by name ) %(end_string_suffix)sz{ %(start_string_prefix)s (RFC(-|\s+)?(?P\d+)) %(end_string_suffix)s) initialemphasisstronginterpreted_or_phrase_ref embedded_linkliteraltargetsubstitution_refemailuripeprfc)$getattrrZopeners delimitersZclosing_delimitersZclosersrrcr%varsrOnon_whitespace_after simplenamestart_string_prefixend_string_suffixrr#rrrnon_whitespace_escape_beforerVERBOSEnon_whitespace_before email_patternpatternsrr\rstandalone_uriZpep_referencesr pep_referenceZrfc_referencesr rfc_reference)r&r2rrargsrrrrr5s             zInliner.init_customizationscCs|j|_|j|_|j|_||_|jjj}|j}t|}g}g} g} x|r||} | r| j } || dp|| dp|| dp|| d} | || |\}}}}| j || |7} |r||j dj | |7}||7}g} qDPqDWdj | |}|r||j ||7}|| fS)a Return 2 lists: nodes (text and inline elements), and system_messages. Using `self.patterns.initial`, a pattern which matches start-strings (emphasis, strong, interpreted, phrase reference, literal, substitution reference, and inline target) and complete constructs (simple reference, footnote reference), search for a candidate. When one is found, check for validity (e.g., not a quoted '*' character). If valid, search for the corresponding end string if applicable, and check it for validity. If not found or invalid, generate a warning and ignore the start-string. Implicit inline markup (e.g. standalone URIs) is found last. rrrefendZfnendrz) r+r*r,rIrrrdispatchr groupdictr\implicit_inliner)r&rrqr6rIZpattern_searchr remaining processedZ unprocessedrrmatchgroupsmethodbeforeinlines sysmessagesrrrrds<  z Inliner.parsez(?]z[_~*/=+a-zA-Z0-9]z-(?:%(urilast)s|%(uric)s(?=%(uri_end_delim)s))z"[-_!~*'{|}/#?^`&=+$%a-zA-Z0-9\x00]z %(emailc)s+(?:\.%(emailc)s+)* # name (?-sz%Inliner.phrase_ref..z\_)refurizproblem with embedded link: %r)r__rr anonymousr}rrr)rrrrrrendswithrrrrrindirect_reference_namerr adjust_uriZ referencedr referencer r* note_refnamer\note_indirect_targetnote_explicit_targetrI)r&rafterrrrrZ aliastextZunderscore_escapedZ aliastypealiasrZ alias_partsrr node_listrrrrsd             zInliner.phrase_refcCs"|jjj|}|rd|S|SdS)Nzmailto:)rrr)r&rrrrrr\szInliner.adjust_uric Csntj||j||j\}}|r<||||||\}}|||fS|jjd||d} |j||| g|| gfSdS)Nz#Unknown interpreted text role "%s".)rP)rrr,r+r|r) r&rrrrqZrole_fnrrrZ messages2rrrrrcs   zInliner.interpretedcCs0|j|||jjtjdd\}}}}}||||fS)NT)r)rrrr)r&rrqrrrrrrrrrpszInliner.literalc Cs|j|||jjtj\}}}}}|rvt|dtjrvt|dksDt|d}t|j} |dj | |j j ||j ||||fS)NrrUr}) rrrr isinstancerXr;rrr\r*rrI) r&rrqrrrrrrrrrrinline_internal_targetvs zInliner.inline_internal_targetc Cs|j|||jjtj\}}}}}t|dkr|d}t|tjr|j} |jj || |d ddkrtj d| |fd} |d ddkrd| d<nt | | d <|jj | | |7} | g}||||fS) NrUrrz|%s%srzrVrrrrr) rrrrsubstitution_referencerXrrr*Znote_substitution_refrrr) r&rrqrrrrrZ subref_nodeZ subref_textZreference_noderrrrs$      zInliner.substitution_referencec Cs|jd}t|}|j}|d|jd}||jdd}|jdrttjd||d}|tj|7}|jj |ntj d|}|ddkr|d d}d |d <|jj |n0|d krd }d |d <|jj |n|tj|7}|r||d <|jj |tj|jjr|j}||g|gfS)ze Handles `nodes.footnote_reference` and `nodes.citation_reference` elements. rNrZ citationlabelz[%s]_)rr#rUauto*rzr)rrrrrrZcitation_referenceTextr*Znote_citation_reffootnote_referenceZnote_autofootnote_refZnote_symbol_footnote_refZnote_footnote_refrZget_trim_footnote_ref_spacer2r) r&rrqlabelrrrrZrefnoderrrrs6      zInliner.footnote_referencec Cs|jd}t|}tj||jd|t|d}|r>d|d<n||d<|jj||j}|jd}|j d} |d||g|| dgfS)Nrr)rrUrr) rrrrr r*rrrr) r&rrqrZ referencenamerZ referencenoderrrrrrrs      zInliner.referencecCs|j||ddS)NrU)r)r)r&rrqrrranonymous_referenceszInliner.anonymous_referencecCsl|jd s |jdjtjkrd|jdr0d}nd}|jd}t|d}tjt|d|||dgStdS) Nschemerzmailto:rzrrrU)r)rlowerrschemesrrrr")r&rrqZ addschemer unescapedrrrrs    zInliner.standalone_uricCs||jd}|jdr$t|jd}n|jdr>t|jd}nt|jjj|jjj|}t|d}t j t|d||dgS)Nrzpep-Zpepnum1ZPEPZpepnum2rU)r) r startswithintr"r*r2Z pep_base_urlZpep_file_url_templaterrr)r&rrqrZpepnumrefr rrrrs    zInliner.pep_referencez rfc%d.htmlcCs^|jd}|jdr8t|jd}|jjj|j|}ntt|d}t j t|d||dgS)NrZRFCrfcnumrU)r) rr rr*r2Z rfc_base_urlrfc_urlr"rrr)r&rrqrrrr rrrrs   zInliner.rfc_referencec Cs|sgSxp|jD]f\}}|j|}|ry:|j|d|j|||||j||jd|Stk rtYqXqWtjt|t|ddgS)a Check each of the patterns in `self.implicit_dispatch` for a match, and dispatch to the stored method for the pattern. Recursively check the text before and after the match. Return a list of `nodes.Text` and inline element nodes. NrU)r) rrrrrr"rrr)r&rrqpatternrrrrrrs   zInliner.implicit_inline) rz**`z``z_`z]_rrrN)F)F)(rrrr(r'r5rrrZ&non_unescaped_whitespace_escape_beforerrZuricZ uri_end_delimZurilastrZuri_endZemailcrrrrrrrrrrrrrrrrrrrrrrrrrrr4sZ3  4?  #   r4arUcCs t||S)N)ord)s_zerorrr_loweralpha_to_intsrAcCs t||S)N)r)rrrrr_upperalpha_to_intsrcCstj|jS)N)r fromRomanupper)rrrr_lowerroman_to_intsrc @seZdZdZejjZeZedddddedddddedddddd e_ e ej j e_ d d d d dge_ dddddde_eeeeejde_ie_x,ej D]"Zejejedejeje<qWejdZejdZejdZiZded<ded<ded<ded <d!ejed"<d#eed$<d%eed&<d'eed(<d)eed*<d+eed,<xDej D]:Zd-eej ej ej!ed"ej ej ej"fee<qZWd.d/ed0d1ed2d3eed4d5d6edd7 Z#dZ$dDdEZ%dFdGZ&ejdHejZ'dIdJZ(dKdLZ)dMdNZ*dOdPZ+dQdRZ,dSdTZ-ddVdWZ.dXdYZ/dZd[Z0d\d]Z1d^d_Z2d`daZ3dbdcZ4dddeZ5dfdgZ6dhdiZ7djdkZ8dldmZ9dndoZ:dpdqZ;drdsZdxdyZ?dzd{Z@d|d}ZAd~dZBdddZCdddZDddZEeZFeejdeGeHejIejBejdeGeHejIejBejdeGeHejIejBdeF_#ddZJddZKddZLddZMddZNddZOddZPddZQddZRddZSddZTddZUddZVddZWddZXddZYddZZeJejdeHj[ejIejBfeKejdeHj[ejIejBfeLejdejIejBfeQejdejIejBfeSejdeHj[ejIejBfgeF_\ddZ]ddZ^ddZ_ddZ`ddZaddZbddZcdUS)rAz: Generic classifier of the first line of a block. ()rU)rrrrrzr.)parensZrparenZperiodarabic loweralpha upperalpha lowerroman upperromanz[0-9]+z[a-z]z[A-Z]z [ivxlcdm]+z [IVXLCDM]+)r"r#r$r%r&rz\+-[-+]+-\+ *$z =+( +=+)+ *$z=+[ =]*$z[!-/:-@[-`{-~]Znonalphanum7bitz[a-zA-Z]alphaz [a-zA-Z0-9]alphanumz [a-zA-Z0-9_-]Z alphanumpluszJ(%(arabic)s|%(loweralpha)s|%(upperalpha)s|%(lowerroman)s|%(upperroman)s|#)enumz%(alphanum)s%(alphanumplus)s*optnamez%(%(alpha)s%(alphanumplus)s*|<[^<>]+>)optargz!(-|\+)%(alphanum)s( ?%(optarg)s)?Zshortoptz"(--|/)%(optname)s([ =]%(optarg)s)?Zlongoptz(%(shortopt)s|%(longopt)s)optionz(?P<%s>%s%s%s)u[-+*•‣⁃]( +|$)z((%(parens)s|%(rparen)s|%(period)s)( +|$)z#:(?![: ])([^:\\]|\\.)*(?>>( +|$)z\|( +|$)z \.\.( +|$)z__( +|$)z(%(nonalphanum7bit)s)\1* *$) bullet enumerator field_marker option_markerdoctest line_blockgrid_table_topsimple_table_topexplicit_markuprrPrr-r.r/r0r1r2r3r4r5rrPrc CsN|jj\}}}}|j||}|j|7_|sD|j|jd7_||gfS)z Block quote.z Block quote)rE get_indented block_quoterIr) r&rrQ next_stateindentedindentrrdelementsrrrr:zs  z Body.indentc Csg}x|r|j||\}}}}}tj}|j||||j||rd|j||\} } || 7}|| 7}|}x&|r|d r|dd}|d7}qjWqW|S)NrrU)split_attributionrr7rbr\parse_attribution) r&r9rr;Zblockquote_linesZattribution_linesZattribution_offsetnew_line_offset blockquote attributionrrrrrr7s    zBody.block_quoteu(---?(?!-)|—) *(?=[^ \n])c Csd}d}xtt|D]}||j}|r|r||dkr|jj|}|r|j||\}} |r|||} | j|jdd| j| dd|d|| |||d||fSd}q|}qW|ddddfSdS)a Check for a block quote attribution and split it off: * First line after a blank line must begin with a dash ("--", "---", em-dash; matches `self.attribution_pattern`). * Every line after that must have consistent indentation. * Attributions must be preceded by block quote content. Return a tuple of: (block quote content lines, content offset, attribution lines, attribution offset, remaining indented lines). NFrU)r)rT)rangerXrattribution_patternrcheck_attributionZ trim_leftr) r&r9rblankZ nonblank_seenirPrZattribution_endr:Za_linesrrrr<s(        zBody.split_attributioncCsd}|d}xnt|dt|D]P}||j}|s6P|dkrTt|t|j}q t|t|j|kr dSq W|d7}||pdfS)zt Check attribution shape. Return the index past the end of the attribution, and the indent. NrUr)NN)rArXrlstrip)r&r9Zattribution_startr:rErPrrrrCs zBody.check_attributioncCsZdj|j}|jj|}|j||\}}tj|df|}|jj|\|_|_ ||fS)Nrrz) rrrErr~rr@rGr1rP)r&r9rrrqrrrr9rrrr=s zBody.parse_attributionc Cstj}|jj\|_|_|j|7_|jd|d<|j|j \}}||7}|jj d}|j |jj |d|jj d|d|d\}}|j||s|j|jd7_g|gfS)zBullet list item.rr-rUN BulletList)r=r9rCrdz Bullet list)rZ bullet_listrErGr1rPrIr list_itemrrrlr<rMrKr) r&rrQr8Z bulletlistrErdrr>rrrr-s     z Body.bulletcCsd|jj|dr$|jj|\}}}n|jj|\}}}}tjdj|}|r\|j|||d||fS)Nr)r=r9)rErPZget_known_indentedget_first_known_indentedrrHrrb)r&r:r9rrdlistitemrrrrHszBody.list_itemc Cs@|j|\}}}}|j|||s*tjdtj}|j|7_|dkrRd|d<n||d<|jj|j |d<|jj|j |d<|dkr||d<|j j d ||f} |j| 7_|j |j\} } || 7}|jjd} |j|jj| d |jjd|d | |||dkd d \} } |j| | s6|j|jd7_g|gfS)zEnumerated List Itemrrr"enumtyperrrUrz      zBody.enumeratorNcCs>|j}d}x"|jjD]}||rPqWtd|||jj|j|jj|j}|dkrbd}n\|ry|jj|j|r~|}Wqt k rtd|YqXn|dkrd}n |dkrd}|sx,|jj D]}|jj|j|rPqWtd |dkrd }n2y|jj ||}Wnt j k r0d }YnX||||fS) aA Analyze an enumerator and return the results. :Return: - the enumerator format ('period', 'parens', or 'rparen'), - the sequence used ('arabic', 'loweralpha', 'upperroman', etc.), - the text of the enumerator, stripped of formatting, and - the ordinal value of the enumerator ('a' -> 1, 'ii' -> 2, etc.; ``None`` is returned for invalid enumerator text). The enumerator format has already been determined by the regular expression match. If `expected_sequence` is given, that sequence is tried first. If not, we check for Roman numeral 1. This way, single-character Roman numerals (which are also alphabetical) can be matched. If no sequence has been matched, all sequences are checked in order. rzzenumerator format not matchedrzunknown enumerator sequence: %srEr%Ir&zenumerator sequence not matchedrUN)rr)formatsr!rRrrsequenceregexpsrKeyError sequences convertersrZInvalidRomanNumeralError)r&rZexpected_sequencerrTrNrrUrrrrO!sB  zBody.parse_enumeratorcCs|dkr dSy|jj}Wntk r8|jjdSX|jj|ddjsXdS|j|d||}|r|\}}y|j|s|j|rdSWntk rYnXdS)z Check validity based on the ordinal value and the second line. Return true if the ordinal is valid and the second line is blank, indented, or starts with the next enumerator or an auto-enumerator. NrU)rEr^rLrwstripmake_enumeratorr  TypeError)r&rUrTrNr^resultnext_enumeratorauto_enumeratorrrrrPXs(    zBody.is_enumerated_list_itemc Cs|dkrd}n|dkr t|}n|jdrL|dkr6dSt|tdd}n>|jdr~ytj|}Wqtjk rzdSXn td ||jd r|j }n |jd r|j }n td ||j j |}|j ||jd }|j d|jd }||fS) z Construct and return the next enumerated list item marker, and an auto-enumerator ("#" instead of the regular enumerator). Return ``None`` for invalid (out of range) ordinals. rr"r'NrrUrz!unknown enumerator sequence: "%s"r rr)strrchrrrZtoRomanZ RomanErrorr!r r rr)rRrr)r&rUrTrNr.rRrarbrrrr^us2        zBody.make_enumeratorc Cstj}|j|7_|j|\}}||7}|jjd}|j|jj|d|jjd|d|d\}}|j ||s|j|j d7_g|gfS)zField list item.rUN FieldList)r=r9rCrdz Field list) r field_listrIfieldrErrlr<rMrKr) r&rrQr8rgrhrdrrVrrrr/s    zBody.field_markercCs|j|}|jj\}}|jj}|jj|j\}}}} tj} || _|| _ |j ||\} } | tj |df| 7} tj dj |f| } | | 7} |r|j||| | | fS)Nrzr)parse_field_markerrErGrrIrrrhr1rPr~ field_name field_bodyrparse_field_body)r&rrsrcsrclinerqr9r:rrdZ field_nodeZ name_nodesZ name_messagesrkrrrrhs  z Body.fieldcCs&|jdd}|d|jd}|S)z6Extract & return field name from a field marker match.rUN:)rrfind)r&rrhrrrriszBody.parse_field_markercCs|j|||ddS)N)r=r9)rb)r&r9rr9rrrrlszBody.parse_field_bodycCs:tj}|jj\|_|_y|j|\}}Wntk r}zr|jj d|}|j |7_ |jj |j \} } } }|j | | } |j | 7_ |s|j |jd7_ g|gfSd}~XnX|j |7_ ||7}|jjd} |j|jj| d|jjd|d|d\}}|j||s0|j |jd7_ g|gfS)zOption list item.zInvalid option list marker: %sz Option listNrU OptionList)r=r9rCrd)r option_listrErGr1rPoption_list_itemrr+r|rIrIrr7rrrlr<rMrK)r&rrQr8Z optionlistrJrdr|rr9r:rr;rrVrrrr0s4     zBody.option_markerc Cs|jj}|j|}|jj|j\}}}}|sD|j|tjdtj d|}tj dj |} tj d|| } |r|j ||| d| |fS)Nrrzr)r=r9)rz)rErMparse_option_markerrIrrKrrQr option_group descriptionrrsrb) r&rroptionsr9r:rrdrurvrsrrrrss    zBody.option_list_itemc Csg}|jjjd}x|D]x}|j}d}|djdd}t|dkr^||dd<d}nht|ddkr|djdr|djd  s|djd r|ddd|dddg|dd<d }t|dko|djd o|djd r dj|ddg|dd<dt|ko$dknrtj|}|tj |d|d7}t|dkrx|tj |d|d|d7}|j |qt dt||fqW|S)z Return a list of `node.option` and `node.option_argument` objects, parsed from an option marker match. :Exception: `MarkupError` for invalid option markers. z, rr=rUNrV-z--+rz<>) delimiterz;wrong number of option tokens (=%s), should be 1 or 2: "%s"r) rrrrXr rrrr,Z option_stringZoption_argumentr\r) r&rZoptlistZ optionstringsZ optionstringtokensr}Zfirstoptr,rrrrts:  (    zBody.parse_option_markercCs0dj|jj}|jtj||7_g|gfS)Nr)rrEget_text_blockrIrZ doctest_block)r&rrQr8rrrrr1sz Body.doctestc Cstj}|j|7_|jj}|j||\}}}||7}|j|7_|s|jjd} |j|jj| d|jj d|ddd\} }|j | |s|j|j j d|dd7_t |r|djdkrd|d_|j|g|gfS)zFirst line of a line block.rUN LineBlockr)r=r9rCrdz%Line block ends without a blank line.)rP)rr2rIrErline_block_linerrlr<rMrKr+rrXr:nest_line_block_lines) r&rrQr8r_rqrPrrrdrr>rrrr2&s.        zBody.line_blockc Cst|jj|jdd\}}}}dj|}|j||\}} tj|df|} |jjdkrjt |j dd| _ | | |fS)z(Return one line element of a line_block.T) until_blankrrzrrU) rErIrrr~rrPrrrXrr:) r&rrqr9r:rrdr text_nodesrrrPrrrr@s  zBody.line_block_linecCsNx>tdt|D],}t||dddkr||dj||_qW|j|dS)NrUr:)rArXrr:nest_line_block_segment)r&r_rtrrrrLszBody.nest_line_block_linescCsdd|D}t|}g}tj}xP|D]H}|j|krB|j|q(t|rf|j||j|tj}|j|q(Wt|r|j||j|||dd<dS)NcSsg|] }|jqSr)r:)ritemrrr Ssz0Body.nest_line_block_segment..)minrr2r:r\rXr)r&r_indentsZleastZ new_itemsZ new_blockrrrrrRs        zBody.nest_line_block_segmentcCs|j||||jtjS)zTop border of a full table.) table_topisolate_grid_tablerZGridTableParser)r&rrQr8rrrr3es zBody.grid_table_topcCs|j||||jtjS)zTop border of a simple table.)risolate_simple_tablerZSimpleTableParser)r&rrQr8rrrr4ks zBody.simple_table_topc CsT|j||\}}|j|7_|sJ|jjd|jjdd}|j|7_g|gfS)zTop border of a generic table.z Blank line required after table.rU)rP)tablerIr+rrEr) r&rrQr8isolate_function parser_classrrdrrrrrqszBody.table_topc Cs|\}}}|ry@|}|j|}|jjt|d}|j||} | g|} Wqtjk r} z$|j|dj| j | j d|} WYdd} ~ XqXn|} | |fS)zParse a table.rUr)rN) rrErrX build_tablerZTableMarkupErrormalformed_tablerrr) r&rrr_rrrdparser tabledata tablelinerrerrrrrr}s   "z Body.tablec Csg}d}y|jjdd}WnLtjk rf}z.|j\}}}|j|jjd||dd}WYdd}~XnX|j|j |j t |dj }xXt t |D]H}||j ||<||ddkrd}|jjt ||||d=PqW|jj|d spd}xrt t |ddd D]@}|jj||r|jjt ||d||dd=PqW|j|j|g||fSxTt t |D]D}t |||ks||d dkr~|j|j|g||fSq~W|||fS) NrUT) flush_leftzUnexpected indentation.)r1rPrz+|rVrrr)rErrUnexpectedIndentationErrorrr\r+r| disconnectpad_double_widthdouble_width_pad_charrXr]rArwgrid_table_top_patrextendr) r&rrrdr_rrmrnwidthrErrrrsB      $zBody.isolate_grid_tablecCs|jj}|jj}t|d}t||j}|jj}d}d}|d}x ||kr||} || } | rt| j|kr|jj|||j|||dd} g| ||kp||dj fS|d7}|}|dks||ks||dj r|} P|d7}qHW|r(d} |jj|||||d}n$d} |jj||d||d}|j|d| } g| | fS|jj| |||| d}|j |j |g| |kp|| dj fS)NrUrz5Bottom/header table border does not match top border.rVz$ or no blank line after table bottomrzzNo bottom table border found%s.) rErr<rXr]simple_table_border_patrr^rrr)r&rrlimitZtoplenZ pattern_matchfoundZfound_atrErPrrrrextrar_rrrrsJ   "     zBody.isolate_simple_tablecCsf|j|jddj|}d}|jjt|d}|rB|d|7}|jj|tj ||||d}|gS)NrzrzMalformed table.rU)rP) replacerrrErrXr+r|rr{)r&r_detailrrr startliner|rrrrs   zBody.malformed_tablecCs|\}}}tj}|dkr.|ddg7<n|rD|ddg7<tjt|d} || 7}x6|D].} tj| d} |rd| jd<|d8}| | 7} qbW|rtj} | | 7} x|D]} | |j| |7} qWtj}| |7} x|D]} ||j| |7}qW|S) Nrclasseszcolwidths-autozcolwidths-given)cols)colwidthrUZstub) rrtgrouprXcolspec attributestheadbuild_table_rowtbody)r&rrZ stub_columnsZwidthsZ colwidthsZheadrowsZbodyrowsrrrrrrowrrrrrs0       zBody.build_tablec Cs~tj}xp|D]h}|dkrq|\}}}}i} |r8|| d<|rD|| d<tjf| } || 7}dj|r|j|||| dqW|S)Nmorerowsmorecolsrz)r=r9)rrentryrrb) r&ZrowdatarrcellrrrZ cellblockrrrrrrs       zBody.build_table_rowa? ( _ # anonymous target | # *OR* (?!_) # no underscore at the beginning (?P`?) # optional open quote (?![ `]) # first char. not space or # backquote (?P # reference name .+? ) %(non_whitespace_escape_before)s (?P=quote) # close quote if open quote used ) (?%(simplename)s)_ | # *OR* ` # open backquote (?![ ]) # not space (?P.+?) # hyperlink phrase %(non_whitespace_escape_before)s `_ # close backquote, # reference mark ) $ # end of string a ( (?![ ]) # first char. not space (?P.+?) # substitution text %(non_whitespace_escape_before)s \| # close delimiter ) ([ ]+|$) # followed by whitespace )rr substitutionc Cs"|jj\}}|jj|j\}}}}|jd}t|} tjdj|} || _ || _ | ddkr| dd} d| d<| r| dj | |j j | nL| dkrd} d| d<|j j| n*| tjd|7} | dj | |j j| | r|j j| | n|j j| | |r|j||| d | g|fS) NrUrrrrr}rrz)r=r9)rErGrIrrrrfootnoterr1rPr\r*Znote_autofootnoteZnote_symbol_footnoterZ note_footnoterrrb) r&rrmrnr9r:rrdrrrrrrrHs4    z Body.footnotec Cs|jj\}}|jj|j\}}}}|jd}t|} tjdj|} || _ || _ | tj d|7} | dj | |j j| |j j| | |r|j||| d| g|fS)NrUrrzr})r=r9)rErGrIrrrrcitationrr1rPrr\r*Z note_citationrrb) r&rrmrnr9r:rrdrrrrrrrgs  z Body.citationc Cs |jjj}|jj}|jj|jddd\}}}}|jd|jdj|}dd|D}|d} d} xJ|j | } | rzP| d7} y| || 7} Wqjt k rt d YqjXqjW|d| =|dd | jt | ddj |d<|j|||| jd } | g|fS) NTF)r strip_indentrcSsg|] }t|qSr)r)rrPrrrrsz)Body.hyperlink_target..rrUzmalformed hyperlink target.rr)explicitrrrErrIrrrrr[rrXr] make_targetr) r&rrrqr_r:rrd blocktextr blockindexZ targetmatchrrrrhyperlink_targetxs,    ,  zBody.hyperlink_targetcCs|j|||\}}|dkrTtj|dt|d}||_|j|d|||jj||S|dkr|tj|d}|j|||||S|SdS)Nrrz)rr) parse_targetrrrr add_targetr*r)r&r_ block_textrqZ target_nameZ target_typerrrrrrs  zBody.make_targetcCsp|rF|d jd ddkrFdjdd|D}|j|}|rFd|fStdj|}djdd |D}d |fS) z Determine the type of reference of a target. :Return: A 2-tuple, one of: - 'refname' and the indirect reference name - 'refuri' and the URI - 'malformed' and a system_message node rUNrrcSsg|] }|jqSr)r])rrPrrrrsz%Body.parse_target..rcss |]}djt|jVqdS)rzN)rrr)rrrrrrsz$Body.parse_target..rrr)r]r is_referencer)r&r_rrqrrZ ref_partsrrrrs    zBody.parse_targetcCs4|jjjjt|}|sdSt|jdp0|jdS)Nsimplephrase)rrrrr rr)r&rrrrrrs   zBody.is_referencecCs||_|r`tt|}|dj||rN|jj|}|rB||d<n td||jj||j n |rl||d<d|d<|jj |dS)Nr}rzproblem with URI: %rrUr) rPrrr\r0rrr*rrIZnote_anonymous_target)r&Z targetnamerrrqrrrrrrs    zBody.add_targetc Cs|jjj}|jj\}}|jj|jdd\}}}}|jd|jdj|} |j t |dj } d} xV|j | } | r~P| d7} y| dt || j } Wqntk rtdYqnXqnW|d| =|dj d| jt| dd|d<|ds|d=|d7}x$|r6|dj r6|jqW| jd} tj| }||_||_|s|jjd | tj| | ||d }|g|fS|dj |d<|d jtj| |j|||d |d \}}d}xT|ddD]D}t|tjpt|tjs|j ||7_ ||=n|d7}qWx^|j!tj"D]N}|j#|r,tjd|j$j }|jj%d|tj| | ||d }|g|fSq,Wt|dkr|jjd| tj| | ||d }|g|fS|j&j'|| |j |g|fS)NF)rrrrUrz"malformed substitution definition.rz.Substitution definition "%s" missing contents.)r1rPr}SubstitutionDef)r=r9rCrdrzz1Substitution definition contains illegal element:z.Substitution definition "%s" empty or invalid.rr)(rrrrErGrIrrrrrrrr]r[rrXrZrrZsubstitution_definitionr1rPr+rr{r\r rlrZInlinerrIZtraverseElement*disallowed_inside_substitution_definitionspformatr|r*Znote_substitution_def)r&rrrmrnr_r:rrdrrrZ subdefmatchsubnameZsubstitution_nodernew_abs_offsetrEr9rrrrsubstitution_defs    ,              zBody.substitution_defcCs@|ds4t|tjr|jds4t|tjr8|jdr8dSdSdS)NidsrrrUr)rrrgetr)r&r9rrrrs z/Body.disallowed_inside_substitution_definitionscKsR|jd}tj||jj|j\}}|j|7_|rD|j||||S|j|SdS)z?Returns a 2-tuple: list of nodes, and a "blank finish" boolean.rUN) rr directiver6r,r*rI run_directiveunknown_directive)r&roption_presets type_nameZdirective_classrrrrrrs  zBody.directivec#Cst|ttfr"ddlm}||}|jj}|jj}|jj|j dd\}} } } dj |jj ||jjd} y|j || ||\} }}}WnPt k r}z4|jjd|dj |jftj| | |d}|g| fSd }~XnX||| ||||| ||j }y |j}WnVtjjjk rX}z2|jj|j|j|d}|tj| | 7}|g}WYd d }~XnXt|tsrtd |x>tt|D].}t||tjstd ||||fqW|| p|jj fS) a Parse a directive then run its directive function. Parameters: - `directive`: The class implementing the directive. Must be a subclass of `rst.Directive`. - `match`: A regular expression match object which matched the first line of the directive. - `type_name`: The directive name, as used in the source text. - `option_presets`: A dictionary of preset options, defaults for the directive options. Currently, only an "alt" option is passed by substitution definitions (value: the substitution name), which may be used by an embedded image directive. Returns a 2-tuple: list of nodes, and a "blank finish" boolean. r)convert_directive_function)Z strip_toprrUzError in "%s" directive: %s.r)rPNz+Directive "%s" must return a list of nodes.z6Directive "%s" returned non-Node object (index %s): %r)!rrrdocutils.parsers.rstrrErrrIrrr<parse_directive_blockrr+r|rrr{r:docutilsparsersZrstZDirectiveErrorZsystem_messageryrrer;rArXNodeis_next_line_blank)r&rrrrrrqZinitial_line_offsetr9r:rrdr argumentsrwcontentcontent_offsetrr|Zdirective_instancer`Zmsg_noderErrrr%sH       zBody.run_directivecCsz|j}|j}|r.|dj r.|j|d7}x|rL|dj rL|jq0W|r|jsb|jsb|rx&t|D]\}}|jslPqlW|d7}|d|} ||dd} ||d} n |} |} g} |r|j||| \} } ni} | o|jp|j r| ||d} |} g} x,| r4| dj r4| j| d7} q W|jsF|jrT|j || } ng} | rn| rnt d| | | | fS)NrrUzno content permittedr) option_spec has_contentr]Z trim_starttrim_endrequired_argumentsoptional_arguments enumerateparse_directive_optionsparse_directive_argumentsr)r&r9rrrrrrErP arg_blockrrrwrrrrrasN      zBody.parse_directive_blockc Cs|j}xDt|D]4\}}tjtjd|r||d}|d|}PqWg}|rz|j||\}} |rr|j| nt| ||fS)Nr/) rcrrrrArparse_extension_optionsr%r) r&rrrrwrErPZ opt_blocksuccessrrrrrs    zBody.parse_directive_optionscCs|j}|j}dj|}|j}t||kr@td|t|fnDt|||kr|jrl|jd||d}ntd||t|f|S)Nrz$%s argument(s) required, %s suppliedrUz+maximum %s argument(s) allowed, %s supplied)rrrrrXrZfinal_argument_whitespace)r&rrrequiredoptionalZarg_textrrrrrs  zBody.parse_directive_argumentscCstj}|j|d|ddd\}}|t|kr0d Sytj||}Wntk rn}zdd|jdfSd}~Xndtt fk r}zddd j |jfSd}~Xn2tj k r}zdd d j |jfSd}~XnX|rd |fSdSdS)a Parse `datalines` for a field list containing extension options matching `option_spec`. :Parameters: - `option_spec`: a mapping of option name to conversion function, which should raise an exception on bad input. - `datalines`: a list of input strings. :Return: - Success value, 1 or 0. - An option dictionary on success, an error string on failure. rExtensionOptionsT)rCrdinvalid option blockzunknown option: "%s"Nzinvalid option value: %srzinvalid option data: %srUoption data incompletely parsed)rr)rr) rrgrlrXrZextract_extension_optionsrZrrur_rZExtensionOptionError)r&rZ datalinesr9rVrdrwrrrrrs"   zBody.parse_extension_optionsc CsT|jj}|jjddd\}}}}dj|}|jjd|tj|||d}|g|fS)NrF)rrzUnknown directive type "%s".)rP)rErrIrr+r|rr{) r&rrqr9r:rrdrr|rrrrs  zBody.unknown_directivecCs|j|jdj r0|jjr0tjgdfS|jj|j\}}}}x|rf|dj rf|jqJWdj |}tj||g|fS)NrUrr) rrr]rErrcommentrIrr)r&rr9r:rrdrrrrrs   z Body.commenta \.\.[ ]+ # explicit markup start \[ ( # footnote label: [0-9]+ # manually numbered footnote | # *OR* \# # anonymous auto-numbered footnote | # *OR* \#%s # auto-number ed?) footnote label | # *OR* \* # auto-symbol footnote ) \] ([ ]+|$) # whitespace or end of line z \.\.[ ]+ # explicit markup start \[(%s)\] # citation label ([ ]+|$) # whitespace or end of line z \.\.[ ]+ # explicit markup start _ # target indicator (?![ ]|$) # first char. not space or EOL z \.\.[ ]+ # explicit markup start \| # substitution indicator (?![ ]|$) # first char. not space or EOL aK \.\.[ ]+ # explicit markup start (%s) # directive name [ ]? # optional space :: # directive delimiter ([ ]+|$) # whitespace or end of line cCs0|j|\}}|j|7_|j|g|gfS)z3Footnotes, hyperlink targets, directives, comments.)explicit_constructrI explicit_list)r&rrQr8rrdrrrr5 s zBody.explicit_markupc Csg}x|jjD]t\}}|j|j}|ry |||Stk r}z4|jj}dj|j}|j |j j ||dPWYdd}~XqXqW|j |\} } | || fS)z>Determine which explicit construct this is, parse & return it.r)rPN) r constructsrrrrErrrr\r+rr) r&rerrorsrrZexpmatchr|rqrrrdrrrr s    zBody.explicit_constructcCsh|jjd}|j|jj|d|jjd|jd||jjd\}}|j||sd|j|jd7_dS)z Create a nested state machine for a series of explicit markup constructs (including anonymous hyperlink targets). rUNExplicit)r=r9rCrdr3zExplicit markup) rErrlr<rMrIr3rKr)r&rdrrVrrrr+ s   zBody.explicit_listcCs0|j|\}}|j|7_|j|g|gfS)zAnonymous hyperlink targets.)anonymous_targetrIr)r&rrQr8rrdrrrr; s zBody.anonymousc Csj|jj}|jj|jdd\}}}}|jd|jdj|}dd|D}|j|||d}|g|fS)NT)rrcSsg|] }t|qSr)r)rrPrrrrH sz)Body.anonymous_target..rz)rErrIrrrr) r&rrqr_r:rrdrrrrrrB s  zBody.anonymous_targetcCs|jjr|jgdgfS|jjdkr0tjdnt|jjdkrr|jjd|jj d}|j |7_ tjdn@|jj }|jj dt j|||jj d}|j |7_ g|gfSdS) z,Section title overline or transition marker.Linez::rzeUnexpected possible title overline or transition. Treating it as ordinary text because it's so short.)rPz'Unexpected section title or transition.N)rEr3rr]rrQrXr+rSrrIrPrNrr{)r&rrQr8rrrrrrPL s"   z Body.linecCs|jgdgfS)z%Titles, definition lists, paragraphs.r)r)r&rrQr8rrrrb sz Body.textrrr) r-r.r/r0r1r2r3r4r5rrPr)N)rzr)rN)drrrr(rZ TableParserrr#r)rRrekeysrXr[Z sequencepatsrrrrrrr\rYrTrrrrZsimple_table_top_patrpatsrNescaperrrinitial_transitionsr:r7rBr<rCr=r-rHr.rOrPr^r/rhrirlr0rsrtr1r2rrrr3r4rrrrrrrrrr4rrrrrrrrrrrrrrrrrrrrr5rrrrrPrrrrrrAs(              & # # 7%)  &+   D <.!   rAc@sNeZdZdZejjZded<ddejDZejd ddd Z d d Z d S) RFC2822Bodyz RFC2822 headers are only valid as the first constructs in documents. As soon as anything else appears, the `Body` state should take over. z[!-9;-~]+:( +|$)rfc2822cCsg|] }|dfqS)rAr)rrrrrrp szRFC2822Body.rUrAc Cstjdgd}|j|7_|j|\}}||7}|jjd}|j|jj|d|jjd|d|d\}}|j ||s|j|j d7_g|gfS)zRFC2822-style field list item.r)rrUN RFC2822List)r=r9rCrdzRFC2822-style field list) rrgrI rfc2822_fieldrErrlr<rMrKr) r&rrQr8Z fieldlistrhrdrrVrrrrt s      zRFC2822Body.rfc2822c Cs~|jd|jjd}|jj|jdd\}}}}tj}|tj||7}tjdj |}||7}|rv|j |||d||fS)NroT)rr)r=r9) rfindrErIrrrhrjrkrrb) r&rrr9r:rrdZ fieldnodeZ fieldbodyrrrr s zRFC2822Body.rfc2822_fieldNr)rrA) rrrr(rArrcrinsertrrrrrrrg s   rc@sNeZdZdZdddZeZeZeZeZeZ eZ eZ eZ eZ eZeZeZeZdS)SpecializedBodya Superclass for second and subsequent compound element members. Compound elements are lists and list-like constructs. All transition methods are disabled (redefined as `invalid_input`). Override individual methods in subclasses to re-enable. For example, once an initial bullet list item, say, is recognized, the `BulletList` subclass takes over, with a "bullet_list" node as its container. Upon encountering the initial bullet list item, `Body.bullet` calls its ``self.nested_list_parse`` (`RSTState.nested_list_parse`), which starts up a nested parsing session with `BulletList` as the initial state. Only the ``bullet`` transition method is enabled in `BulletList`; as long as only bullet list items are encountered, they are parsed and inserted into the container. The first construct which is *not* a bullet list item triggers the `invalid_input` method, which ends the nested parse and closes the container. `BulletList` needs to recognize input that is invalid in the context of a bullet list, which means everything *other than* bullet list items, so it inherits the transition list created in `Body`. NcCs|jjtdS)z8Not a compound element member. Abort this state machine.N)rErwrL)r&rrQr8rrr invalid_input s zSpecializedBody.invalid_input)NNN)rrrr(rr:r-r.r/r0r1r2r3r4r5rrPrrrrrr s rc@seZdZdZddZdS)rGz-Second and subsequent bullet_list list_items.cCsL|jd|jdkr|j|j|j\}}|j|7_||_g|gfS)zBullet list item.rr-)rrIrrHrrd)r&rrQr8rJrdrrrr- s zBulletList.bulletN)rrrr(r-rrrrrG srGc@seZdZdZddZdS)DefinitionListz,Second and subsequent definition_list_items.cCs|jgdgfS)zDefinition lists. Definition)r)r&rrQr8rrrr szDefinitionList.textN)rrrr(rrrrrr src@seZdZdZddZdS)rLz1Second and subsequent enumerated_list list_items.c Cs|j||jd\}}}}||jks^|dkrN||jdks^|js^||jdks^|j||| rf|j|dkrtd|_|j|j\}} |j|7_| |_ ||_g|gfS)zEnumerated list item.rKrrU) rOrIrNrrMrPrrHrrd) r&rrQr8rNrTrrUrJrdrrrr. s zEnumeratedList.enumeratorN)rrrr(r.rrrrrL srLc@seZdZdZddZdS)rfz(Second and subsequent field_list fields.cCs,|j|\}}|j|7_||_g|gfS)zField list field.)rhrIrd)r&rrQr8rhrdrrrr/ szFieldList.field_markerN)rrrr(r/rrrrrf srfc@seZdZdZddZdS)rqz4Second and subsequent option_list option_list_items.c CsNy|j|\}}Wntk r.|jYnX|j|7_||_g|gfS)zOption list item.)rsrrrIrd)r&rrQr8rsrdrrrr0 szOptionList.option_markerN)rrrr(r0rrrrrq srqc@s*eZdZdZejZejZddZej Z dS)rz6Second and subsequent RFC2822-style field_list fields.cCs,|j|\}}|j|7_||_gdgfS)zRFC2822-style field list item.r)rrIrd)r&rrQr8rhrdrrrr szRFC2822List.rfc2822N) rrrr(rrrrrrrDrrrrr s rc@seZdZdZddZdS)rzz Parse field_list fields for extension options. No nested parsing is done (including inline markup parsing). cCsVg}xLt|dgD]:}|jr,|j|q|rdj|}|tj||7}g}qWdS)z5Override `Body.parse_field_body` for simpler parsing.rzrN)rer]r\rrr)r&r9rr9rrPrrrrrl% s  z!ExtensionOptions.parse_field_bodyN)rrrr(rlrrrrr src@seZdZdZejZddZdS)rz,Second and subsequent lines of a line_block.cCsJ|jj}|j||\}}}|j|7_|jj|7_||_g|gfS)zNew line of line block.)rErrrIrd)r&rrQr8rqrPrrrdrrrr27 s  zLineBlock.line_blockN)rrrr(rrrDr2rrrrr1 src@s&eZdZdZddZddZejZdS)rz0Second and subsequent explicit markup construct.cCs,|j|\}}|j|7_||_g|gfS)z3Footnotes, hyperlink targets, directives, comments.)rrIrd)r&rrQr8rrdrrrr5E szExplicit.explicit_markupcCs,|j|\}}|j|7_||_g|gfS)zAnonymous hyperlink targets.)rrIrd)r&rrQr8rrdrrrrL szExplicit.anonymousN) rrrr(r5rrrrDrrrrrA src@sBeZdZdZejdejejddZ ddgZ ddZ d d Z d S) rzG Parser for the contents of a substitution_definition element. z (%s)::( +|$)rz)embedded_directiverrrcCsB|j||jddd\}}|j|7_|jjs:||_tdS)Nr}r)Zalt)rrIrEat_eofrdrL)r&rrQr8rrdrrrrb s  z"SubstitutionDef.embedded_directivecCs|jjs|jj|_tdS)N)rErrrdrL)r&rrQr8rrrrj s  zSubstitutionDef.textN) rrrr(rrr4rrrrrrrrrrrV s rc@szeZdZdZejdddZddgZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZejdZddZdS)rzs Classifier of second line of a text block. Could be a paragraph, a definition list item, or a title. rPrz) underlinerrrArcCsH|j||jjd\}}|j|7_|r>|j|j7_gdgfS)zEnd of paragraph.rUrA)rrErrIr{)r&rrQr8rrrrrrD| s z Text.blankcCs|r|jd|dgS)N)rD)r&rQrrreof szText.eofc Cstj}|j|\}}||7}|j|7_|jjd}|j|jj|d|jjd|d|dd\}}|j ||s|j|j d7_gdgfS)zDefinition list item.rUNrr)r=r9rCrdrhzDefinition listrA) rZdefinition_listdefinition_list_itemrIrErrlr<rMrKr) r&rrQr8ZdefinitionlistZdefinitionlistitemrdrrVrrrr: s   z Text.indentcCsX|jj}|dj}|jj}|d|}g}t|t|krt|dkr~|jjrr|jjd|d} |j | 7_ t j dn8|dd|jj } |jj dtj| | |d} |j| |jjs$|dd|jj } |jj\} } |jjdtj| | | | d } |j |7_ |j | 7_ g|gfS|d} g|d d <|j||| |d |g|gfS) zSection title.rrrzfPossible title underline, too short for the title. Treating it as ordinary text because it's so short.)rPrzTitle underline too short.zUnexpected section title.)r1rPNrU)rErrrrrXr3r+rSrIrrQrPrrr{r\rGrNrs)r&rrQr8rqrorr1rrrrrmrnrprrrr s<            zText.underlinec Cs|jjd}d}y|jjdd}WnBtjk rf}z$|j\}}} |jjd|| d}WYdd}~XnX|t|} |j | |\} } |j | 7_ |j |7_ | ry|jj Wnt k rYnX|j |j 7_ g|gfS)z Paragraph.rUNT)rzUnexpected indentation.)r1rP)rErrrrrr+r|rerrIr^rLr{) r&rrQr8rrr_rrmrnrrrrrrr s&  z Text.textcCs||jj\}}}}x|r0|dj r0|jqW|s>|jSdj|}tj||}|d|_|g}|sx|j |j d|S)zReturn a list of nodes.rUrz Literal blockr) rEr6r]rquoted_literal_blockrrr{rPr\r)r&r9r:rrdrr{rrrrr{ s    zText.literal_blockcCsR|jj}|jj}tj}|j|jj|d||dtfddd}|j||j S)NFQuotedLiteralBlock)rBrC)r=r9r3ra) rErMrrrrbr<rrKchildren)r&rMrZ parent_noderrrrr s   zText.quoted_literal_blockc Cs|jj\}}}}tjdj|t|}|jjd}|jj|\|_|_ |j ||\}} ||7}tj d | } || 7}|dd ddkr| |j j d|dd7} |j||| d ||fS) NrrUrzrrVz::z`Blank line missing before literal block (after the "::")? Interpreted as a definition list item.)rP)r=r9)rzr)rEr6rrrrerrGr1rPtermrr+rSrb) r&Ztermliner9r:rrditemnoderqZtermlistrrrrrrr szText.definition_list_itemz +: +c Cst|dkst|j|d|\}}tj}|jj|\|_|_t |d|_ |g}xt t|D]}||}t |tj r|jj|j } t| dkr|d|7<nJ|dtj | dj7<x<| ddD]} tjd| } |j| qWqb|d|7<qbW||fS)z9Return a definition_list's term and optional classifiers.rUrNrzrrr)rXr;r~rr rErGr1rPrrrArrclassifier_delimiterrr classifierr\) r&rrqrrrZ term_noderrEr9rrZclassifier_noderrrr  s$   z Text.termN)rrA)rrA)rrrr(rArrrDrr:rrr{rrrrr r rrrrrp s (  rc@s2eZdZdZddZdddZeZeZeZeZ dS)SpecializedTextz Superclass for second and subsequent lines of Text-variants. All transition methods are disabled. Override individual methods in subclasses to re-enable. cCsgS)zIncomplete construct.r)r&rQrrrr/ szSpecializedText.eofNcCstdS)z8Not a compound element member. Abort this state machine.N)rL)r&rrQr8rrrr3 szSpecializedText.invalid_input)NNN) rrrr(rrrDr:rrrrrrr & s r c@s eZdZdZddZddZdS)rz.Second line of potential definition_list_item.cCs|jjdgS)zNot a definition.rV)rErw)r&rQrrrrA s zDefinition.eofcCs,|j|\}}|j|7_||_gdgfS)zDefinition list item.r)rrIrd)r&rrQr8r rdrrrr:F szDefinition.indentN)rrrr(rr:rrrrr= src@sLeZdZdZdZddZddZddZeZd d Z dd d Z dd dZ dS)rzO Second line of over- & underlined section title or transition marker. rUcCsv|dj}|jjrd|j_nt|dkr4|j||jrl|jjd}tj |dd}||_ |j |7_ d|_gS)z0Transition marker at end of section or document.rFrrU)r) r]r6r/rXstate_correctioneofcheckrErr transitionrPrI)r&rQmarkerrqrrrrrW s    zLine.eofcCsd|jj\}}|dj}t|dkr0|j|tj|d}||_|d|_|j |7_ gdgfS)zTransition marker.rr)rrUrA) rErGr]rXrrrr1rPrI)r&rrQr8rmrnrrrrrrDf s     z Line.blankc Csr|jjd}|d}|j}d}y|jj}Wnttk r|d|}t|jdkrl|j|||dn2|jj dt j |||d} |j | 7_ gd gfSYnXd |||f} |j}|j}|j d dj|sD|d|d|}t|jdkr|j|||dn2|jj d t j | | |d} |j | 7_ gd gfSnt||kr|d|d|}t|jdkr|j|||dn2|jj d t j | | |d} |j | 7_ gd gfS|j}g} t|t|kr2|d|d|}t|jdkr|j|||dn$|jjdt j | | |d} | j| |d|df} d|_|j|j| | |d| d|_gd gfS)z#Potential over- & underlined title.rUrrzrrrVzIncomplete section title.)rPrAz%s %s %srz6Missing matching underline for section title overline.z$Title overline & underline mismatch.zTitle overline too short.)rErrr^rLrXrshort_overliner+rNrr{rIrRrrrr\rrsrF) r&rrQr8rqoverlinerorrrr1rrrprrrrr sn         z Line.textcCsx|d}|d|jj}|jjd}t|jdkrF|j|||d|jjdtj |||d}|j |7_ gdgfS)NrrrUrz+Invalid section title or transition marker.)rPrA) rErPrrXrrr+r|rr{rI)r&rrQr8rrrqrrrrr s zLine.underlinecCs.|jjd|d}|j|7_|j||dS)Nz`Possible incomplete section title. Treating the overline as ordinary text because it's so short.)rP)r+rSrIr)r&rQrrqrrrrrr s zLine.short_overlinecCs(|jj|g|dd<tjdddS)NrAr)rErwrZStateCorrection)r&rQrrrrr s  zLine.state_correctionN)rU)rU) rrrr(rrrDrr:rrrrrrrrN s > rc@s^eZdZdZdejddZdZddd Zd d Z d d Z ddZ ddZ ddZ ddZdS)rz Nested parse handler for quoted (unindented) literal blocks. Special-purpose. Not for inclusion in `state_classes`. z(%(nonalphanum7bit)s)rz)initial_quotedrrrFcCstj|||g|_d|_dS)N)r@r'rrinitial_lineno)r&rErFrrrr' szQuotedLiteralBlock.__init__cCs|r tn ||gfSdS)N)rL)r&rrQr8rrrrD szQuotedLiteralBlock.blankcCs|rH|jj|j\}}dj|}tj||}||_||_|j|7_n*|j|j j d|jj d7_|jj |j|j 7_gS)Nrz#Literal block expected; none found.)rP)rErGrrrr{r1rPrIr+rrrwrr)r&rQrmrnrr{rrrr s     zQuotedLiteralBlock.eofcCs<|s td|jj|jjd|jjd|jjtdS)Nz7QuotedLiteralBlock.indent: context should not be empty!zUnexpected indentation.)rP) r;rrr\r+r|rErrwrL)r&rrQr8rrrr: s   zQuotedLiteralBlock.indentcCsZ|jd|jd}tjtj|tj}|jd||j|jj f|j j |_ |jg|gfS)z7Match arbitrary quote character on the first line only.rrquoted) Zremove_transitionrrrrradd_transitionrrOrrErr)r&rrQr8quoterrrrr s   z!QuotedLiteralBlock.initial_quotedcCs|j|j||gfS)z,Match consistent quotes on subsequent lines.)r\r)r&rrQr8rrrr s zQuotedLiteralBlock.quotedcCs4|r,|jj|jjd|jjd|jjtdS)Nz#Inconsistent literal block quoting.)rP)rrr\r+r|rErrwrL)r&rrQr8rrrr s  zQuotedLiteralBlock.textN)rr)F)rrrr(rArrrr'rDrr:rrrrrrrr s   r)T)Gr(Z __docformat__sysrtypesrrrrrrrrZdocutils.statemachiner r Zdocutils.nodesr rr rr rrrZdocutils.parsers.rst.languagesrZ_fallback_language_moduleZdocutils.utilsrrrrrrrrrr r! Exceptionr"r#r)r?r@rr4rrrrrArrrGrrLrfrqrrrrrrr rrrrBrrrres    'l LS.,  7K