U n^}@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@e5er?r8r;r5r@rrrr<szNestedStateMachine.runN)TrArrrrrBsrBc@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|_t|||dS)NBody state_classes initial_state)rFnested_sm_kwargsr r)r( state_machinedebugrrrr)szRSTState.__init__cCsVt||jj}||_|j|_|j|_|j|_|jj|_t |jdsR|jj |j_ dS)Nget_source_and_line) r runtime_initrJr8r-r2r,r;parenthasattrrL)r(r8rrrrMs   zRSTState.runtime_initcCs*z|j|Wntk r$YnXdS)zT Jump to input line `abs_line_offset`, ignoring jumps past the end. N)rJ goto_lineEOFError)r(abs_line_offsetrrrrPszRSTState.goto_linecCs*|jd|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__rrJline)r(context transitionsrrrno_matchs zRSTState.no_matchcCsggfS)zCalled at beginning of file.rr(rVrrrbofsz RSTState.bofNc Csd}|dkr|j}|d7}|dkr0|j}|d7}t|}d} |dkrhz|j} Wntk rfYnX| s|fd|ji|} | j|||j||d|dkr|j | n| | } |j rt||dkr|j t||| S)zg Create a new StateMachine rooted at `node` and run it over the input `block`. rNrKr8r;r5) nested_smrHlennested_sm_cachepop IndexErrorrKr<r8appendunlinkrRrNrJ next_line) r(blockr?r;r5state_machine_classstate_machine_kwargsZ use_defaultZ block_lengthrJZ new_offsetrrr nested_parses:  zRSTState.nested_parsec Cs| dkr|j} | dkr |j} || d<| fd|ji| } |dkrH|}|| j|_t|D]\} } t| j|| | q`| j |||j ||d| 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. NrGrKr]) r^rHcopyrKZstates blank_finishlistitemssetattrr<r8rdrR)r(rfr?r;rGrkblank_finish_stateextra_settingsr5rgrhrJkeyvaluerrrnested_list_parse&s(      zRSTState.nested_list_parsecCs ||||r||||dS)z=Check for a valid subsection and create one if it checks out.N)check_subsectionnew_subsection)r(titler3stylelinenomessagesrrrsectionDszRSTState.sectionc Cs|j}|j}|j}z||d}WnNtk rrt||jkrR||YdS|j|||7_YdSYnX||kr||_t|dkrd|_ |j t|dt ||dkrdS|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. r[Nr\T) r8r/r0index ValueErrorr_rcrNtitle_inconsistentr1rJ previous_linerQ)r(r3rwrxr8r/mylevellevelrrrrtIs*    zRSTState.check_subsectioncCs|jjdtd||d}|S)NzTitle level inconsistent:rU)r-rSr literal_block)r(Z sourcetextrxerrorrrrr}rs  zRSTState.title_inconsistentcCs|j}|j}|jd7_t}|j|7_|||\}}tj|df|} t| } |d | || 7}||7}||7}|j |||j j d} |j d} |j|j j| d| |dd} || |j|krt||_dS)z?Append new subsection to document tree. On return, check level.r[rnamesNT)r?r;r5)r8r0rrzrN inline_textrvnormalize_nameastextrcr,Znote_implicit_targetrJ line_offsetrRrir>rPrQ)r(rvrxryr8rZ section_node textnodesZtitle_messagesZ titlenodenameoffsetZ absoffsetZ newabsoffsetrrrruxs2    zRSTState.new_subsectionc Csd|}td|r^t|dkr.gdfS|ddkrL|dd}n |dd}d}n|}d }|||\}}tj|d f|}|j |\|_ |_ |g||fS) zW Return a list (paragraph & messages) & a boolean: literal_block next?  z(?%(or_group)s)%(suffix)s) typetuplerc 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\]_)[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_delimitersZclosersrrjr'varsrTnon_whitespace_after simplenamestart_string_prefixend_string_suffixrr$rrrnon_whitespace_escape_beforerVERBOSEnon_whitespace_before email_patternpatternsrrcrstandalone_uriZpep_referencesr pep_referenceZrfc_referencesr rfc_reference)r(r4rrargsrrrrr7s               V   zInliner.init_customizationscCs|j|_|j|_|j|_||_|jjj}|j}t|}g}g} g} |r||} | r| } || dpz| dpz| dpz| d} | || |\}}}}| || |7} |r|| d | |7}||7}g} qBqqBd | |}|r|| ||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. rrrefendZfnendr) r-r,r.rNrrrdispatchr groupdictrcimplicit_inliner)r(rrxr8rNZpattern_searchr remaining processedZ unprocessedrymatchgroupsmethodbeforeinlines sysmessagesrrrrfsF   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 (?2sz%Inliner.phrase_ref..refurizproblem with embedded link: %rr__rr anonymousr)rrrrrrendswithrrrrrindirect_reference_namerr adjust_uriZ referencedr referencer rr, note_refnamercnote_indirect_targetnote_explicit_targetrN)r(rafterrrrrZrawtextZ aliastextZ rawaliastextZunderscore_escapedZ aliastypealiasrZ alias_partsrr  node_listrrrr!st             zInliner.phrase_refcCs"|jj|}|rd|S|SdS)Nmailto:)rrr)r(rrrrrreszInliner.adjust_uric Cst||j||j\}}|rj||||||\}}zt|d|dd_Wntk r\YnX|||fS|jjd||d} |||| g|| gfSdS)NTrz#Unknown interpreted text role "%s".r) rrr.r-rrrbrr) r(rrrrxZrole_fnryrZ messages2rrrrrls"  zInliner.interpretedcCs0|j|||jjtjdd\}}}}}||||fS)NT)r)rrrrrrrrr}szInliner.literalc Cs||||jjtj\}}}}}|rvt|dtjrvt|dksDt|d}t|} |d | |j ||j ||||fS)Nrr[r) rrrr isinstancer_r=rrrcr,r rN) r(rrxrrrrrrrrrrinline_internal_targets zInliner.inline_internal_targetc Cs||||jjtj\}}}}}t|dkr|d}t|tjr|} |j || |dddkrt d| |fd} |dddkrd| d <nt | | d <|j | | |7} | g}||||fS) Nr[rrrz|%s%srrrrr) rrrrsubstitution_referencer_rrr,Znote_substitution_refr rr ) r(rrxrrrrrZ subref_nodeZ subref_textZreference_noderrrrs.      zInliner.substitution_referencec Cs|d}t|}|j}|d|d}||dd}|drttjd||d}|t|7}|j |nt d|}|ddkr|d d}d |d <|j |n0|d krd }d |d <|j |n|t|7}|r||d <|j |t|jjr|}||g|gfS)ze Handles `nodes.footnote_reference` and `nodes.citation_reference` elements. rNrZ citationlabelz[%s]_rr#r[auto*rr)rrrrrrZcitation_referenceTextr,Znote_citation_reffootnote_referenceZnote_autofootnote_refZnote_symbol_footnote_refZnote_footnote_refrZget_trim_footnote_ref_spacer4r) r(rrxlabelrrrrZrefnoderrrrs:      zInliner.footnote_referencec Cs|d}t|}tj||d|t|d}||d_|rHd|d<n||d<|j||j}| d}| d} |d||g|| dgfS)Nrrrrr[rr) rrrr r rr,r rrr) r(rrxrZ referencenamerZ referencenoderrrrrrr s        zInliner.referencecCs|j||ddS)Nr[)r)r )r(rrxrrranonymous_referenceszInliner.anonymous_referencecCsz|dr|dtjkrr|dr.d}nd}|d}t|}t|d}tj||||d}||d_|gStdS) NschemerrrrTrr) rlowerrschemesrrr rr#)r(rrxZ addschemer unescapedrr rrrrs     zInliner.standalone_uricCsz|d}|dr$t|d}n|dr>t|d}nt|jjj|jjj|}t|}t j t|d||dgS)Nrzpep-Zpepnum1ZPEPZpepnum2Tr) r startswithintr#r,r4Z pep_base_urlZpep_file_url_templaterrr )r(rrxrZpepnumrefrrrrrs    zInliner.pep_referencez rfc%d.htmlcCs\|d}|dr8t|d}|jjj|j|}ntt|}t j t|d||dgS)NrZRFCrfcnumTr) rrr r,r4Z rfc_base_urlrfc_urlr#rrr )r(rrxrr"r!rrrrrs  zInliner.rfc_referencec Cs|sgS|jD]l\}}||}|rz@||d||||||||d|WStk rxYqXqtjt|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. NTr) rrrrrr#rrr)r(rrxpatternrrrrrrs  zInliner.implicit_inline) rz**`rrz]_rrrN)F)F)(rrrr*r)r7rrrZ&non_unescaped_whitespace_escape_beforerrZuricZ uri_end_delimZurilastrZuri_endZemailcrrrrrrrrrrrrrrr rrrr#rrrrrrrr6s^3  4D #   r6ar[cCs t||Sr%ordsZ_zerorrr_loweralpha_to_int%sr,AcCs t||Sr%r(r*rrr_upperalpha_to_int(sr.cCst|Sr%)r fromRomanupper)r+rrr_lowerroman_to_int+sr1c @szeZdZdZejjZeZedddddedddddedd dddd e_ e ej e_ d d d ddge_ dddddde_eeeeejde_ie_ej D]"Zeejedejeje<qedZedZedZiZded<ded<ded<d ed!<d"ejed#<d$eed%<d&eed'<d(eed)<d*eed+<d,eed-<ej D]:Zd.ee ej ej!ed#e ej ej"fee<qTd/d0ed1d2ed3d4eed5d6d7edd8 Z#d8Z$d9d:Z%d;d<Z&ed=ejZ'd>d?Z(d@dAZ)dBdCZ*dDdEZ+dFdGZ,dHdIZ-ddKdLZ.dMdNZ/dOdPZ0dQdRZ1dSdTZ2dUdVZ3dWdXZ4dYdZZ5d[d\Z6d]d^Z7d_d`Z8dadbZ9dcddZ:dedfZ;dgdhZdmdnZ?dodpZ@dqdrZAdsdtZBddudvZCddwdxZDdydzZEeZFeed{eGeHejIejBed|eGeHejIejBed}eGeHejIejBd~eF_#ddZJddZKddZLddZMddZNddZOddZPddZQddZRddZSddZTddZUddZVddZWddZXddZYddZZeJedeHj[ejIejBfeKedeHj[ejIejBfeLedejIejBfeQedejIejBfeSedeHj[ejIejBfgeF_\ddZ]ddZ^ddZ_ddZ`ddZaddZbddZcdJS)rDz: Generic classifier of the first line of a block. ()r[r)rrrrrr.)parensZrparenZperiodarabic loweralpha upperalpha lowerroman upperromanrz[a-z]z[A-Z]z [ivxlcdm]+z [IVXLCDM]+)r6r7r8r9r:rz\+-[-+]+-\+ *$z =+( +=+)+ *$z=+[ =]*$z[!-/:-@[-`{-~]Znonalphanum7bitz[a-zA-Z]alphaz [a-zA-Z0-9]Zalphanumz [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)( +|$)z1:(?![: ])([^:\\]|\\.|:(?!([ `]|$)))*(?>>( +|$)z\|( +|$)z \.\.( +|$)z__( +|$)z(%(nonalphanum7bit)s)\1* *$) bullet enumerator field_marker option_markerdoctest line_blockgrid_table_topsimple_table_topexplicit_markuprrUrc CsN|j\}}}}|||}|j|7_|sD|j|d7_||gfS)z Block quote.z Block quote)rJ get_indented block_quoterNr) r(rrV next_stateindentedindentrrkelementsrrrrMs  z Body.indentc Csg}|r|||\}}}}}t}|||||||rb|||\} } || 7}|| 7}|}|r|ds|dd}|d7}qfq|S)Nrr[)split_attributionrrJrircparse_attribution) r(rLrrNZblockquote_linesZattribution_linesZattribution_offsetnew_line_offset blockquote attributionryrrrrJs.     zBody.block_quoteu(---?(?!-)|—) *(?=[^ \n])c Csd}d}tt|D]}||}|r|r||dkr|j|}|r|||\}} |r|||} | j|dd| j| dd|d|| |||d||fSd}q|}q|ddddfS)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). NFr[)r)rT)ranger_rattribution_patternrcheck_attributionZ trim_leftr) r(rLrblankZ nonblank_seenirUrZattribution_endrMZa_linesrrrrOs0      zBody.split_attributioncCsd}|d}t|dt|D]T}||}|s6q||dkrTt|t|}qt|t||krdSq|d7}||pdfS)zt Check attribution shape. Return the index past the end of the attribution, and the indent. Nr[)NNr)rTr_rlstrip)r(rLZattribution_startrMrXrUrrrrVs zBody.check_attributioncCsZd|}|j|}|||\}}tj|df|}|j|\|_|_ ||fS)Nrr) rrrJrrrrSrLr3rU)r(rLrrrxrryr;rrrrPs zBody.parse_attributionc Cst}|j\|_|_|j|7_|jd|d<|| \}}||7}|jj d}|j |jj |d|j d|d|d\}}|||s|j|d7_g|gfS)Bullet list item.rr@r[N BulletListr?r;rGrkz Bullet list)rZ bullet_listrJrLr3rUrNr list_itemrrrsr>rRrPr) r(rrVrKZ bulletlistrXrkrrQrrrr@s(    z Body.bulletcCsd|jj|dr$|j|\}}}n|j|\}}}}td|}|r\|j|||d||fS)Nrr?r;)rJrUZget_known_indentedget_first_known_indentedrr]rri)r(rMrLrrklistitemrrrr]s  zBody.list_itemc Cs@||\}}}}||||s*tdt}|j|7_|dkrRd|d<n||d<|jj|j |d<|jj|j |d<|dkr||d<|j d ||f} |j| 7_| |\} } || 7}|jjd} |j|jj| d |jd|d | |||dkd d \} } || | s6|j|d7_g|gfS)zEnumerated List Itemrrr6enumtyperrr[rzrRrPr)r(rrVrKrdsequencerordinalZenumlistrr`rkrnewline_offsetrrrrAsH      zBody.enumeratorNcCs8|}d}|jjD]}||rq.qtd|||jj|j|jj|j}|dkr`d}n\|rz|jj||r||}Wqt k rtd|YqXn|dkrd}n |dkrd}|s|jj D]}|jj||rqqtd |dkrd }n2z|jj ||}Wnt j k r*d }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. rzenumerator format not matchedrzunknown enumerator sequence: %srXr9Ir:zenumerator sequence not matchedr[N)rr<formatsr"rhrrsequenceregexpsrKeyError sequences convertersrZInvalidRomanNumeralError)r(rZexpected_sequencerrjrdrrkrrrre2sF    zBody.parse_enumeratorcCs|dkr dSz|j}Wn tk r:|jYdSX|j|ddsZdS||d||}|r|\}}z||s||rWdSWntk 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. Nr[)rJrerQr~stripmake_enumeratorr TypeError)r(rkrjrdreresultnext_enumeratorauto_enumeratorrrrrfis*    zBody.is_enumerated_list_itemcCs|dkrd}n|dkr t|}n|drL|dkr6dSt|tdd}n@|drzt|}Wqtjk r|YdSXn td ||d r| }n |d r| }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. rr6r;Nr'r[rz!unknown enumerator sequence: "%s"rr0r)strrchrr)rZtoRomanZ RomanErrorr"rrr0r<rhrr)r(rkrjrdrArhrwrxrrrrts:         zBody.make_enumeratorc Cst}|j|7_||\}}||7}|jjd}|j|jj|d|jd|d|d\}}| ||s|j| d7_g|gfS)zField list item.r[N FieldListr\z Field list) r field_listrNfieldrJrrsr>rRrPr) r(rrVrKr}r~rkrrlrrrrBs     zBody.field_markercCs||}|j\}}|j}|j|\}}}} t} || _|| _ | ||\} } | tj |df| 7} tj d |f| } | | 7} |r|||| | | fS)Nrr)parse_field_markerrJrLrr_rrr~r3rUr field_name field_bodyrparse_field_body)r(rrsrcsrclinerxrLrMrrkZ field_nodeZ name_nodesZ name_messagesrrrrr~s   z Body.fieldcCs&|dd}|d|d}|S)z6Extract & return field name from a field marker match.r[N:)rrfind)r(rr~rrrrszBody.parse_field_markercCs|j|||ddS)Nr^)ri)r(rLrr;rrrrszBody.parse_field_bodyc CsDt}|j\|_|_z||\}}Wntk r}zz|j d|}|j |7_ |j | \} } } }| | | } |j | 7_ |s|j |d7_ g|gfWYSd}~XYnX|j |7_ ||7}|jjd} |j|jj| d|jd|d|d\}}|||s:|j |d7_ g|gfS)Option list item.zInvalid option list marker: %sz Option listNr[ OptionListr\)r option_listrJrLr3rUoption_list_itemrr-rrNr_rrJrrrsr>rRrP)r(rrVrKZ optionlistr`rkrrrLrMrrNrrlrrrrCs<       zBody.option_markerc Cs|j}||}|j|\}}}}|sD||tdtj d|}t d |} t d|| } |r|j ||| d| |fS)Nrrrr^)r)rJrRparse_option_markerr_rrPrrgr option_group descriptionrrri) r(rroptionsrLrMrrkrrrrrrrs"     zBody.option_list_itemc Csg}|d}|D]z}|}d}|ddd}t|dkrZ||dd<d}nft|ddkr|ddr|dd r|dd r|ddd|dddg|dd<d }t|dkr |dd r |d dr d|ddg|dd<dt|kr&dkrnnXt|}|t |d|d7}t|dkrv|tj |d|d|d7}| |qt dt||fq|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=r[Nr\-z--+r) delimiterz;wrong number of option tokens (=%s), should be 1 or 2: "%s") rrrr_rrrrr?Z option_stringZoption_argumentrcr) r(rZoptlistZ optionstringsZ optionstringtokensrZfirstoptr?rrrrsH      (     zBody.parse_option_markercCs0d|j}|jt||7_g|gfS)Nr)rrJget_text_blockrNrZ doctest_block)r(rrVrKrrrrrD/sz Body.doctestc Cst}|j|7_|j}|||\}}}||7}|j|7_|s|jjd} |j|jj| d|j d|ddd\} }| | |s|j|j j d|dd7_t |r|djdkrd|d_||g|gfS)zFirst line of a line block.r[N LineBlockrr\z%Line block ends without a blank line.r)rrErNrJrline_block_linerrsr>rRrPr-rr_rMnest_line_block_lines) r(rrVrKrfrxrUryrkrrQrrrrE7s4         zBody.line_blockc Cst|jj|dd\}}}}d|}|||\}} tj|df|} |jdkrjt | dd| _ | | |fS)z(Return one line element of a line_block.T until_blankrrrr[) rJr_rrrrrUrrr_rrM) r(rrxrLrMrrkr text_nodesryrUrrrrQs   zBody.line_block_linecCsJtdt|D],}t||dddkr||dj||_q||dS)Nr[rM)rTr_rrMnest_line_block_segment)r(rfr{rrrr]szBody.nest_line_block_linescCsdd|D}t|}g}t}|D]H}|j|kr@||q&t|rd||||t}||q&t|r||||||dd<dS)NcSsg|] }|jqSr)rM)ritemrrr dsz0Body.nest_line_block_segment..)minrrErMrcr_r)r(rfindentsZleastZ new_itemsZ new_blockrrrrrcs        zBody.nest_line_block_segmentcCs|||||jtjS)zTop border of a full table.) table_topisolate_grid_tablerZGridTableParserr(rrVrKrrrrFvs zBody.grid_table_topcCs|||||jtjS)zTop border of a simple table.)risolate_simple_tablerZSimpleTableParserrrrrrG|s zBody.simple_table_topc CsT|||\}}|j|7_|sJ|jjd|jdd}|j|7_g|gfS)zTop border of a generic table.z Blank line required after table.r[r)tablerNr-rrJr) r(rrVrKisolate_function parser_classrrkrrrrrs zBody.table_topc Cs|\}}}|rz@|}||}|jt|d}|||} | g|} Wqtjk r} z"|j|d| j | j d|} W5d} ~ XYqXn|} | |fS)zParse a table.r[r)rN) rrJrr_ build_tablerZTableMarkupErrormalformed_tablerrr) r(rrrfryrkparser tabledata tablelinerrerrrrrrs$   z Body.tablec Csg}d}z|jjdd}WnLtjk rf}z,|j\}}}||jjd||dd}W5d}~XYnX|| |j t |d }t t |D]J}|| ||<||ddkrd}|jt ||||d=qq|j|dsnd}t t |d ddD]D}|j||r|jt ||d||dd=qnq|||g||fSt t |D]H}t |||ks||ddkrz|||g||fSqz|||fS) Nr[TZ flush_leftUnexpected indentation.r3rUrz+|rr\)rJrrUnexpectedIndentationErrorrrcr-r disconnectpad_double_widthdouble_width_pad_charr_rsrTr~grid_table_top_patrextendr) r(ryrkrfrrrwidthrXrrrrsF      $zBody.isolate_grid_tablecCs|jj}|jj}t|d}t||}|jj}d}d}|d}||kr||} || } | rt| |kr|j||||||dd} g| ||kp||d fS|d7}|}|dks||ks||ds|} qb|d7}qD|r"d} |j|||||d}n$d} |j||d||d}||d| } g| | fS|j| |||| d}| |j |g| |kp|| d fS)Nr[rz5Bottom/header table border does not match top border.r\z$ or no blank line after table bottomrzNo bottom table border found%s.) rJrr>r_rssimple_table_border_patrrerrr)r(rrlimitZtoplenZ pattern_matchfoundZfound_atrXrUrryrextrarfrrrrsR       zBody.isolate_simple_tablecCsf||jdd|}d}|jt|d}|rB|d|7}|jj|t ||||d}|gS)NrrzMalformed table.r[r) replacerrrJrr_r-rrr)r(rfdetailrrr startlinerrrrrs  zBody.malformed_tablecCs|\}}}t}|dkr.|ddg7<n|rD|ddg7<tjt|d} || 7}|D].} tj| d} |rd| jd<|d8}| | 7} q`|rt} | | 7} |D]} | || |7} qt}| |7} |D]} ||| |7}q|S) Nrclasseszcolwidths-autozcolwidths-given)cols)colwidthr[Zstub) rrtgroupr_colspec attributestheadbuild_table_rowtbody)r(rrZ stub_columnsZwidthsZ colwidthsZheadrowsZbodyrowsrrrrrrowrrrrrs0    zBody.build_tablec Cszt}|D]h}|dkrq |\}}}}i} |r6|| d<|rB|| d<tjf| } || 7}d|r |j|||| dq |S)Nmorerowsmorecolsrr^)rrentryrri) 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"|j\}}|j|\}}}}|d}t|} td|} || _ || _ | ddkr| dd} d| d<| r| d | |j | nL| dkrd} d| d<|j | n*| td|7} | d | |j | | r|j | | n|j | | |r|j||| d | g|fS) Nr[rrrrrrrr^)rJrLr_rrrrfootnoterr3rUrcr,Znote_autofootnoteZnote_symbol_footnoterZ note_footnoter rri) r(rrrrLrMrrkrrrrrrrYs6     z Body.footnotec Cs|j\}}|j|\}}}}|d}t|} td|} || _ || _ | t d|7} | d | |j | |j | | |r|j||| d| g|fS)Nr[rrrr^)rJrLr_rrrrcitationrr3rUrrcr,Z note_citationr ri) r(rrrrLrMrrkrrrrrrrxs   z Body.citationc Cs|jjj}|j}|jj|ddd\}}}}|jd|d|}dd|D}|d} d} | | } | rxq| d7} z| || 7} Wqht k rt d YqhXqh|d| =|dd | t | dd |d<||||| d } | g|fS) NTF)r strip_indentrcSsg|] }t|qSrrrrUrrrrsz)Body.hyperlink_target..rr[zmalformed hyperlink target.rr)explicitrrrJrr_rrrrrbrr_rs make_targetr) r(rr%rxrfrMrrk blocktextr blockindexZ targetmatchrrrrhyperlink_targets4     , zBody.hyperlink_targetcCs||||\}}|dkrTtj|dt|d}||_||d|||j||S|dkr|t|d}||||||S|SdS)Nrrrr) parse_targetrrrr add_targetr,r )r(rf block_textrxZ target_nameZ target_typerrrrrrs  zBody.make_targetcCsp|rF|ddddkrFddd|D}||}|rFd|fStd|}ddd |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 rNrrcSsg|] }|qSr)rsrrrrrsz%Body.parse_target..rcss |]}dt|VqdSrrrrrrrsz$Body.parse_target..r)rsr is_referencer)r(rfrrxr rZ ref_partsrrrrs   zBody.parse_targetcCs4|jjjt|}|sdSt|dp0|dS)Nsimplephrase)rrr rr rr)r(r rrrrrs  zBody.is_referencecCs||_|r`tt|}|d||rN|j|}|rB||d<n td||j||j n |rl||d<d|d<|j |dS)Nrrzproblem with URI: %rr[r) rUrrrcr2rrr,r rNZnote_anonymous_target)r(Z targetnamerrrxrrrrrrs    zBody.add_targetcCs|jjj}|j\}}|jj|dd\}}}}|jd|d|} | t |d } d} | | } | r|q| d7} z| dt ||  } Wqltk rtdYqlXql|d| =|d d| t| dd|d<|ds|d=|d7}|r.|d s.|q| d } t| }||_||_|s~|jjd | t| | ||d }|g|fS|d |d<|d t| |j|||d |d\}}d}|ddD]D}t|tjst|tjs|j ||7_ ||=n|d7}q|!tj"D]X}|#|rtd|$ }|jj%d|j&|t| | ||d }|g|fSqt|dkr|jjd| t| | ||d }|g|fS|j'(|| |j |g|fS)NFrrrr[rz"malformed substitution definition.rrz.Substitution definition "%s" missing contents.rrSubstitutionDefr\rz6Substitution definition contains illegal element <%s>:z.Substitution definition "%s" empty or invalid.))rrrrJrLr_rrrrrrrrsrbrr_rarrZsubstitution_definitionr3rUr-rrrcr rsrZInlinerrNZtraverseElement*disallowed_inside_substitution_definitionspformatrtagnamer,Znote_substitution_def)r(rr%rrrfrMrrkrrrZ subdefmatchsubnameZsubstitution_nodernew_abs_offsetrXr;rrrrsubstitution_defs     ,             zBody.substitution_defcCs@|ds4t|tjr|ds4t|tjr8|dr8dSdSdS)NidsrrTF)rrr getr)r(r;rrrr#s  z/Body.disallowed_inside_substitution_definitionscKsR|d}t||jj|j\}}|j|7_|rD|||||S||SdS)z?Returns a 2-tuple: list of nodes, and a "blank finish" boolean.r[N) rr directiver8r.r,rN run_directiveunknown_directive)r(roption_presets type_nameZdirective_classryrrrr+s zBody.directivec Cst|ttfr"ddlm}||}|j}|jj}|jj| dd\}} } } d |jj ||jjd} z| || ||\} }}}WnZt k r}z<|jjd|d |jft| | |d}|g| fWYSd }~XYnX||| ||||| ||j }z |}WnVtjjjk rb}z0|jj|j|j|d}|t| | 7}|g}W5d }~XYnXt|ts|td |tt|D].}t||tjstd ||||fq|| p|j 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_toprr[zError in "%s" directive: %s.rrNz+Directive "%s" must return a list of nodes.z6Directive "%s" returned non-Node object (index %s): %r)!rrrdocutils.parsers.rstrrJrrr_rrr>parse_directive_blockrr-rrrrr<docutilsparsersZrstZDirectiveErrorZsystem_messagerrrlr=rTr_Nodeis_next_line_blank)r(rrrrrrxZinitial_line_offsetrLrMrrkr argumentsrcontentcontent_offsetrrZdirective_instancervZmsg_noderXrrrr7sv           zBody.run_directivecCsb|j}|j}|r,|ds,||d7}|rF|dsF|q,|r|jsZ|jsZ|rt|D]\}}|sbqqb|d7}|d|} ||dd} ||d} n |} |} g} |r|||| \} } ni} | r|js|js| ||d} |} g} | r | ds | | d7} q|js0|jr>| || } ng} | rV|sVt d| | | | fS)Nrr[rzno content permitted) option_spec has_contentrsZ trim_starttrim_endrequired_argumentsoptional_arguments enumerateparse_directive_optionsparse_directive_argumentsr)r(rLrrrrrrXrU arg_blockrrrrrrrrss^       zBody.parse_directive_blockc Cs|}t|D]6\}}ttjd|r||d}|d|}qLqg}|rx|||\}} |rp|| nt| ||fS)NrB) rjrrrrDrparse_extension_optionsr'r) r(rrrrrXrUZ opt_blocksuccessrrrrrs   zBody.parse_directive_optionscCs|j}|j}d|}|}t||kr@td|t|fnDt|||kr|jrl|d||d}ntd||t|f|S)Nrz$%s argument(s) required, %s suppliedr[z+maximum %s argument(s) allowed, %s supplied)rrrrr_rZfinal_argument_whitespace)r(rrrequiredoptionalZarg_textrrrrrs"   zBody.parse_directive_argumentsc Cst}|j|d|ddd\}}|t|kr0dSzt||}Wntk rx}zdd|jdfWYSd}~XYnxtt fk r}zddd |jfWYSd}~XYn<tj k r}zdd d |jfWYSd}~XYnX|rd |fSd SdS) 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)rGrk)rzinvalid option blockzunknown option: "%s"Nzinvalid option value: %srzinvalid option data: %sr[)rzoption data incompletely parsed) rr}rsr_rZextract_extension_optionsrprr|rurZExtensionOptionError)r(rZ datalinesr;rlrkrrrrrrs*  &(*zBody.parse_extension_optionsc CsT|j}|jjddd\}}}}d|}|jjd|t|||d}|g|fS)NrFrrzUnknown directive type "%s".r)rJrr_rr-rrr) r(rrxrLrMrrkrrrrrrs    zBody.unknown_directivecCs||j|ds.|jr.tgdfS|j|\}}}}|r`|ds`|qFd |}t||g|fS)Nr[rr) rrrsrJrrcommentr_rr)r(rrLrMrrkrrrrrs   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|7_||g|gfSz3Footnotes, hyperlink targets, directives, comments.)explicit_constructrN explicit_listr(rrVrKrrkrrrrH& s zBody.explicit_markupc Csg}|jjD]\}}||j}|r z|||WStk r}z:|j}d|j}| |j j ||dWYqW5d}~XYq Xq | |\} } | || fS)z>Determine which explicit construct this is, parse & return it.rrN) r constructsrrrrJrrrrcr-rr) r(rerrorsrr%Zexpmatchrrxrrrkrrrr - s   zBody.explicit_constructcCsh|jjd}|j|jj|d|jd|jd||jjd\}}|||sd|j|d7_dS)z Create a nested state machine for a series of explicit markup constructs (including anonymous hyperlink targets). r[NExplicit)r?r;rGrkr5zExplicit markup) rJrrsr>rRrNr5rPr)r(rkrrlrrrr = s    zBody.explicit_listcCs0||\}}|j|7_||g|gfSzAnonymous hyperlink targets.)anonymous_targetrNr r rrrrM s zBody.anonymousc Csj|j}|jj|dd\}}}}|jd|d|}dd|D}||||d}|g|fS)NTrrcSsg|] }t|qSrrrrrrrZ sz)Body.anonymous_target..r)rJrr_rrrr) r(rrxrfrMrrkrrrrrrT s   zBody.anonymous_targetcCs|jjr|jgdgfS|jdkr0tdnt|jdkrr|jjd|j d}|j |7_ tdn@|jj }|jj dt |||j d}|j |7_ g|gfSdS) z,Section title overline or transition marker.Line::rzeUnexpected possible title overline or transition. Treating it as ordinary text because it's so short.rz'Unexpected section title or transition.N)rJr5rrsrrgr_r-rirrNrUrSrr)r(rrVrKrrrrrrU^ s&   z Body.linecCs|jgdgfS)z%Titles, definition lists, paragraphs.rrrrrrrt sz Body.text)N)rr)rN)drrrr*rZ TableParserrr$r<rhrlkeysrnrqZ sequencepatsr r,r.r1rr/rrrorjrrrrZsimple_table_top_patrpatsrdescaperrrinitial_transitionsrMrJrUrOrVrPr@r]rArerfrtrBr~rrrCrrrDrErrrrFrGrrrrrrrrrr6rrrrrrrrrrrrrrrrrrrr rHr r rrrUrrrrrrD/s`              # # 7%)  &+      -E <.!       , rDc@sNeZdZdZejZded<ddejDZedddd 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)rDr)rrrrrr szRFC2822Body.r)rrDc Cstjdgd}|j|7_||\}}||7}|jjd}|j|jj|d|jd|d|d\}}| ||s|j| d7_g|gfS)RFC2822-style field list item.r)rr[N RFC2822Listr\zRFC2822-style field list) rr}rN rfc2822_fieldrJrrsr>rRrPr) r(rrVrKZ fieldlistr~rkrrlrrrr s$     zRFC2822Body.rfc2822c Cs~|jd|jd}|jj|dd\}}}}t}|t||7}td |}||7}|rv|j |||d||fS)NrTrrr^) rfindrJr_rrr~rrrri) r(rrrLrMrrkZ fieldnodeZ fieldbodyrrrr s  zRFC2822Body.rfc2822_fieldN) rrrr*rDrrjrinsertrrrrrrry 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|jtdSz8Not a compound element member. Abort this state machine.N)rJr~rQrrrr invalid_input s zSpecializedBody.invalid_input)NNN)rrrr*r"rMr@rArBrCrDrErFrGrHrrUrrrrrr  s r c@seZdZdZddZdS)r[z-Second and subsequent bullet_list list_items.cCsL|jd|jdkr|||\}}|j|7_||_g|gfS)rZrr@)rrNr"r]rrk)r(rrVrKr`rkrrrr@ s zBulletList.bulletN)rrrr*r@rrrrr[ sr[c@seZdZdZddZdS)DefinitionListz,Second and subsequent definition_list_items.cCs|jgdgfS)zDefinition lists. Definitionrrrrrr szDefinitionList.textN)rrrr*rrrrrr# sr#c@seZdZdZddZdS)rbz1Second and subsequent enumerated_list list_items.c Cs|||jd\}}}}||jks\|dkrN||jdks\|js\||jdks\||||sd||dkrrd|_||\}} |j|7_| |_ ||_g|gfS)zEnumerated list item.rarr[) rerNrdrrcrfr"r]rrk) r(rrVrKrdrjrrkr`rkrrrrA s.     zEnumeratedList.enumeratorN)rrrr*rArrrrrb srbc@seZdZdZddZdS)r|z(Second and subsequent field_list fields.cCs,||\}}|j|7_||_g|gfS)zField list field.)r~rNrkr(rrVrKr~rkrrrrB szFieldList.field_markerN)rrrr*rBrrrrr| sr|c@seZdZdZddZdS)rz4Second and subsequent option_list option_list_items.cCsNz||\}}Wntk r.|YnX|j|7_||_g|gfS)r)rrr"rNrk)r(rrVrKrrkrrrrC szOptionList.option_markerN)rrrr*rCrrrrr src@s*eZdZdZejZejZddZej Z dS)rz6Second and subsequent RFC2822-style field_list fields.cCs,||\}}|j|7_||_gdgfS)rr)rrNrkr%rrrr% szRFC2822List.rfc2822N) rrrr*rrrrr r"rWrrrrr s rc@seZdZdZddZdS)rzz Parse field_list fields for extension options. No nested parsing is done (including inline markup parsing). cCsRg}t|dgD]:}|r*||q|rd|}|t||7}g}qdS)z5Override `Body.parse_field_body` for simpler parsing.rrN)rlrsrcrrr)r(rLrr;rrUrrrrr7 s  z!ExtensionOptions.parse_field_bodyN)rrrr*rrrrrr/ src@seZdZdZejZddZdS)rz,Second and subsequent lines of a line_block.cCsJ|j}|||\}}}|j|7_|jj|7_||_g|gfS)zNew line of line block.)rJrrrNrk)r(rrVrKrxrUryrkrrrrEI s  zLineBlock.line_blockN)rrrr*r r"rWrErrrrrC src@s&eZdZdZddZddZejZdS)rz0Second and subsequent explicit markup construct.cCs,||\}}|j|7_||_g|gfSr)r rNrkr rrrrHW szExplicit.explicit_markupcCs,||\}}|j|7_||_g|gfSr)rrNrkr rrrr^ szExplicit.anonymousN) rrrr*rHrr r"rWrrrrrS src@sBeZdZdZedejejddZ ddgZ ddZ d d Z d S) rzG Parser for the contents of a substitution_definition element. z (%s)::( +|$)r)embedded_directiverr&rcCsB|j||jddd\}}|j|7_|js:||_tdS)Nrr)Zalt)rrNrJat_eofrkrQr rrrr&t s  z"SubstitutionDef.embedded_directivecCs|js|j|_tdSr%)rJr'rrkrQrrrrr| s  zSubstitutionDef.textN) rrrr*rrr6rrrrr&rrrrrrh src@szeZdZdZejdddZddgZddZd d Zd d Z d dZ ddZ ddZ ddZ ddZedZddZdS)rzs Classifier of second line of a text block. Could be a paragraph, a definition list item, or a title. rUr) underliner)r(rD)rrDcCsH|||jd\}}|j|7_|r>|j|7_gdgfS)zEnd of paragraph.r[rD)rrJrrNr)r(rrVrKrrrrrrW s z Text.blankcCs|r|d|dgSr%)rWrYrrreof szText.eofc Cst}||\}}||7}|j|7_|jjd}|j|jj|d|jd|d|dd\}}| ||s|j| d7_gdgfS)Definition list item.r[Nr#r$)r?r;rGrkrozDefinition listrD) rZdefinition_listdefinition_list_itemrNrJrrsr>rRrPr) r(rrVrKZdefinitionlistZdefinitionlistitemrkrrlrrrrM s"    z Text.indentcCsX|j}|d}|j}|d|}g}t|t|krt|dkr~|jjrr|jjd|d} |j | 7_ t dn8|dd|jj } |jj dt| | |d} || |jjs$|dd|jj } |j\} } |jjdt| | | | d } |j |7_ |j | 7_ g|gfS|d} g|d d <|||| |d |g|gfS) zSection title.rrrzfPossible title underline, too short for the title. Treating it as ordinary text because it's so short.rrzTitle underline too short.zUnexpected section title.rNr[)rJrrrrr_r5r-rirNrrgrUrrrrcrLrSrz)r(rrVrKrxrvr(r3ryrrrrrwrrrr( sF            zText.underlinec Cs|jd}d}z|jjdd}WnBtjk rf}z"|j\}}} |jjd|| d}W5d}~XYnX|t|} | | |\} } |j | 7_ |j |7_ | rz|j Wnt k rYnX|j | 7_ g|gfS)z Paragraph.r[NTrrr)rJrrrrrr-rrlrrNrerQr) r(rrVrKrrrfrrrrrrrrrr s*  z Text.textcCs|j\}}}}|r,|ds,|q|s8|Sd|}t||}|j|d\|_ |_ |g}|s| | d|S)zReturn a list of nodes.rrr[z Literal block) rJrIrsrquoted_literal_blockrrrrLr3rUrcr)r(rLrMrrkrrrrrrr s    zText.literal_blockcCsR|j}|jj}t}|j|jj|d||dtfddd}|||j S)NFQuotedLiteralBlockrE)r?r;r5rh) rJrRrrrrir>r-rPchildren)r(rRrZ parent_noderrrrr, s  zText.quoted_literal_blockc Cs|j\}}}}td|t|}|jd}|j|\|_|_ | ||\}} ||7}tj d | } || 7}|ddddkr| |j j d|dd7} |j||| d ||fS) Nrr[rrrrz`Blank line missing before literal block (after the "::")? Interpreted as a definition list item.rr^)r)rJrIrr+rrlrrLr3rUtermrr-riri) r(ZtermlinerLrMrrkitemnoderxZtermlistryrrrrr+ s(  zText.definition_list_itemz +: +c Cst|dkst||d|\}}t|d}|j|\|_|_|g}t t|D]}||}t |tj r|j |} t| dkr|d|7<nX| d} t t| d} |d| 7<| ddD]} |tt| d| qqX|d|7<qX||fS)z9Return a definition_list's term and optional classifiers.r[rrTN)r_r=rrr/rJrLr3rUrTrrclassifier_delimiterrrrrrc classifier) r(rrxrryZ term_noderrXr;rrZtextnoderrrrr/ s,     z Text.termN)rrrr*rDrrrWr)rMr(rrr,r+rrr1r/rrrrr 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.rrYrrrr)B szSpecializedText.eofNcCstdSr!rQrrrrr"F szSpecializedText.invalid_input)NNN) rrrr*r)r"rWrMr(rrrrrr39 s r3c@s eZdZdZddZddZdS)r$z.Second line of potential definition_list_item.cCs|jdgS)zNot a definition.r\)rJr~rYrrrr)T s zDefinition.eofcCs,||\}}|j|7_||_gdgfS)r*r#)r+rNrk)r(rrVrKr0rkrrrrMY szDefinition.indentN)rrrr*r)rMrrrrr$P sr$c@sLeZdZdZdZddZddZddZeZd d Z dd d Z dd dZ dS)rzO Second line of over- & underlined section title or transition marker. r[cCsv|d}|jjrd|j_nt|dkr4|||jrl|jd}tj |dd}||_ |j |7_ d|_gS)z0Transition marker at end of section or document.rFrr[r$) rsr8r1r_state_correctioneofcheckrJrr transitionrUrN)r(rVmarkerrxr7rrrr)j s    zLine.eofcCsd|j\}}|d}t|dkr0||tj|d}||_|d|_|j |7_ gdgfS)zTransition marker.rrr$r[rD) rJrLrsr_r5rr7r3rUrN)r(rrVrKrrr8r7rrrrWy s     z Line.blankc Csv|jd}|d}|j}d}z|j}Wnxtk r|d|}t|dkrl||||dn6|jj dt |||d} |j | 7_ gd gfYSYnXd |||f} |}|}|j d d|sH|d|d|}t|dkr||||dn2|jj d t | | |d} |j | 7_ gd gfSnt||kr|d|d|}t|dkr||||dn2|jj d t | | |d} |j | 7_ gd gfS|}g} t|t|kr6|d|d|}t|dkr||||dn$|jjdt | | |d} | | |d|df} d|_||| | |d| d|_gd gfS)z#Potential over- & underlined title.r[rrrrr\zIncomplete section title.rrDz%s %s %sr(z6Missing matching underline for section title overline.z$Title overline & underline mismatch.zTitle overline too short.)rJrrrerQr_rshort_overliner-rSrrrNrWrrrrcr6rzrY) r(rrVrKrxoverlinervr(rrr3ryrwrrrr sv         z Line.textcCsx|d}|d|jj}|jd}t|dkrF||||d|jjdt |||d}|j |7_ gdgfS)Nrrr[rz+Invalid section title or transition marker.rrD) rJrUrr_rr9r-rrrrN)r(rrVrKr:rrxrrrrr( s zLine.underlinecCs.|jjd|d}|j|7_|||dS)Nz`Possible incomplete section title. Treating the overline as ordinary text because it's so short.r)r-rirNr5)r(rVrrxrrrrrr9 s zLine.short_overlinecCs(|j|g|dd<tdddS)NrDr)rJr~rZStateCorrection)r(rVrrrrr5 s  zLine.state_correctionN)r[)r[) rrrr*r6r)rWrrMr(r9r5rrrrra s > rc@s^eZdZdZdejddZdZdddZdd Z d d Z d d Z ddZ ddZ ddZdS)r-z Nested parse handler for quoted (unindented) literal blocks. Special-purpose. Not for inclusion in `state_classes`. z(%(nonalphanum7bit)s)r)initial_quotedrFcCst|||g|_d|_dSr%)rCr)ryinitial_linenorIrrrr) szQuotedLiteralBlock.__init__cCs|r tn ||gfSdSr%r4rrrrrW szQuotedLiteralBlock.blankcCs|rH|j|j\}}d|}t||}||_||_|j|7_n*|j|j j d|j d7_|j |j|j 7_gS)Nrz#Literal block expected; none found.r)rJrLr<rrrr3rUrNr-rrr~ry)r(rVrrrrrrrr) s      zQuotedLiteralBlock.eofcCs<|s td|j|jjd|jd|jtdS)Nz7QuotedLiteralBlock.indent: context should not be empty!rr) r=ryrcr-rrJrr~rQrrrrrM s  zQuotedLiteralBlock.indentcCsZ|d|jd}tt|tj}|d||j|jj f|j |_ |jg|gfS)z7Match arbitrary quote character on the first line only.r;rquoted) Zremove_transitionrrrrradd_transitionr=rTrrJrr<)r(rrVrKquoter%rrrr; s   z!QuotedLiteralBlock.initial_quotedcCs||j||gfS)z,Match consistent quotes on subsequent lines.)rcrrrrrr= s zQuotedLiteralBlock.quotedcCs4|r,|j|jjd|jd|jtdS)Nz#Inconsistent literal block quoting.r)ryrcr-rrJrr~rQrrrrr" s zQuotedLiteralBlock.textN)F)rrrr*rDrrrr)rWr)rMr;r=rrrrrr- s   r-)T)Gr*Z __docformat__sysrtypesrrrrrrrrZdocutils.statemachiner r Zdocutils.nodesr rr rr rrrZdocutils.parsers.rst.languagesrZ_fallback_language_moduleZdocutils.utilsrrrrrrrrr r!r" Exceptionr#r$r+rBrCrr6r)r,r.r1rDrr r[r#rbr|rrrrrrrr3r$rr-rFrrrrsb    'n [T.,  8K