B “äî\ã@sòdZdZddlZddlZddlmZmZddlmZm Z m Z ddlm Z m Z ddl mZmZddlmZdd lmZddlZdd lmZmZmZmZdd lmZdd lmZmZmZdd lm Z m!Z!m"Z"ddlm#Z#Gdd„de ƒZ$Gdd„de ƒZ%Gdd„de ƒZ&Gdd„de ƒZ'Gdd„de(ƒZ)Gdd„dƒZ*Gdd„deƒZ+Gdd„deƒZ,Gdd „d eƒZ-dSd"d#„Z.Gd$d%„d%ƒZ/e0d&ƒd'fd(d)„Z1e0d*ƒd'fd+d,„Z2d-d.„Z3Gd/d0„d0e-ƒZ4Gd1d2„d2e4ƒZ5Gd3d4„d4e4ƒZ6Gd5d6„d6e6ƒZ7Gd7d8„d8e6ƒZ8Gd9d:„d:e6ƒZ9Gd;d<„d„d>e6ƒZ;Gd?d@„d@e6e5ƒZGdEdF„dFe6ƒZ?GdGdH„dHe4ƒZ@GdIdJ„dJe-ƒZAGdKdL„dLeAƒZBGdMdN„dNeBƒZCGdOdP„dPeBƒZDGdQdR„dRe-ƒZEe4e7e8e9e:e;e>e=e?eAeCeDe@e5errrr:·szNestedStateMachine.runN)T)rrrr(r:rrrrr?°sr?c@s˜eZdZdZeZgZd dd„Zdd„Zdd„Z d d „Z d d „Z d!dd„Z d idd d fdd„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd S)"ÚRSTStatez` reStructuredText State superclass. Contains methods used by all State subclasses. FcCstddœ|_t |||¡dS)NÚBody)Ú state_classesÚ initial_state)rBÚnested_sm_kwargsr r')r&Ú state_machineÚdebugrrrr'Õs zRSTState.__init__cCsVt |¡|jj}||_|j|_|j|_|j|_|jj|_t |jdƒsR|jj |j_ dS)NÚget_source_and_line) r Ú runtime_initrEr6r+r0r*r9ÚparentÚhasattrrG)r&r6rrrrHÚs   zRSTState.runtime_initcCs*y|j |¡Wntk r$YnXdS)zT Jump to input line `abs_line_offset`, ignoring jumps past the end. N)rEÚ goto_lineÚEOFError)r&Úabs_line_offsetrrrrKçszRSTState.goto_linecCs*|j d|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__rrEÚline)r&ÚcontextÚ transitionsrrrÚno_matchðs  zRSTState.no_matchcCsggfS)zCalled at beginning of file.r)r&rQrrrÚbofýsz RSTState.bofNc Csêd}|dkr|j}|d7}|dkr0|j}|d7}t|ƒ}d} |dkrhy|j ¡} Wntk rfYnX| s€|fd|ji|—Ž} | j|||j||d|dkr¬|j  | ¡n|   ¡|   ¡} |j ræt|ƒ|dkræ|j  t|ƒ|¡| S)zg Create a new StateMachine rooted at `node` and run it over the input `block`. rNéérF)r6r9r3)Ú nested_smrDÚlenÚnested_sm_cacheÚpopÚ IndexErrorrFr:r6ÚappendÚunlinkrMrIrEÚ next_line) r&Úblockr=r9r3Ústate_machine_classÚstate_machine_kwargsZ use_defaultZ block_lengthrEZ new_offsetrrrÚ nested_parses4   zRSTState.nested_parsec Cs¶| dkr|j} | dkr |j ¡} || d<| fd|ji| —Ž} |dkrH|}|| j|_x*t| ¡ƒD]\} } t| j|| | ƒqbW| 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. NrCrF)r6r9r3) rWrDÚcopyrFZstatesÚ blank_finishÚlistÚitemsÚsetattrr:r6r]rM)r&r_r=r9rCrdÚblank_finish_stateÚextra_settingsr3r`rarEÚkeyÚvaluerrrÚnested_list_parse&s"       zRSTState.nested_list_parsecCs | |||¡r| |||¡dS)z=Check for a valid subsection and create one if it checks out.N)Úcheck_subsectionÚnew_subsection)r&Útitler1ÚstyleÚlinenoÚmessagesrrrÚsectionDszRSTState.sectionc CsÖ|j}|j}|j}y| |¡d}WnJtk rnt|ƒ|jkrP| |¡dS|j| ||¡7_dSYnX||kr¨||_t|ƒdkrd|_ |j   t|ƒd¡t ‚||dkr¸dS|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\rIÚtitle_inconsistentr/rEÚ previous_linerL)r&r1rprqr6r-ÚmylevelÚlevelrrrrmIs*    zRSTState.check_subsectioncCs|jjdt d|¡|d}|S)NzTitle level inconsistent:Ú)rP)r+rNrÚ literal_block)r&Z sourcetextrqÚerrorrrrrvrs 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|krât‚||_dS)z?Append new subsection to document tree. On return, check level.rUrzÚnamesNT)r=r9r3)r6r.rrsrIÚ inline_textroÚnormalize_nameÚastextr\r*Znote_implicit_targetrEÚ line_offsetrMrbr<rKrL)r&rorqrrr6rxZ section_nodeÚ textnodesZtitle_messagesZ titlenodeÚnameÚoffsetZ absoffsetZ newabsoffsetrrrrnxs,     zRSTState.new_subsectionc Csªd |¡ ¡}t d|¡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) ÚtypeÚtupler\Ú build_regexprˆÚlocalsrŠÚcompileÚUNICODE) Ú definitionr›rƒÚprefixÚsuffixÚpartsZ part_stringsÚpartZor_groupÚregexprrrr™µs     r™c @seZdZdZdd„Zdd„Zdd„ZdZd Zd Z d Z d Z d Z dZ dZdeƒZdZdZdd„Zd=dd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„Zd,d-„Zd>d.d/„Z d0d1„Z!d2d3„Z"d4d5„Z#d6Z$d7d8„Z%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) ÚinitialÚemphasisÚstrongÚinterpreted_or_phrase_refÚ embedded_linkÚliteralÚtargetÚsubstitution_refÚemailÚuriÚpepÚrfc)$ÚgetattrrZopenersÚ delimitersZclosing_delimitersZclosersršrcr%ÚvarsrOÚnon_whitespace_afterÚ simplenameÚstart_string_prefixÚend_string_suffixr r#r™rŠr›Únon_whitespace_escape_beforerœÚVERBOSEÚnon_whitespace_beforeÚ email_patternÚpatternsr£r\r²Ústandalone_uriZpep_referencesr³Ú pep_referenceZrfc_referencesr´Ú rfc_reference)r&r2rºr»Úargsr rrrr5×s„             zInliner.init_customizationscCsþ|j|_|j|_|j|_||_|jjj}|j}t|ƒ}g}g} g} x|rÒ||ƒ} | rÎ|   ¡} || dp|| dp|| dp|| d} | || |ƒ\}}}}|   |¡| |7} |rÐ||  d  | ¡|¡7}||7}g} qDPqDWd  | ¡|}|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. r¤r§ÚrefendZfnendrz) r+r*r,rIrÀr©r‹ÚdispatchrÚ groupdictr\Úimplicit_inlinerˆ)r&rrqr6rIZpattern_searchrÆÚ remainingÚ processedZ unprocessedrrÚmatchÚgroupsÚmethodÚbeforeÚinlinesÚ sysmessagesrrrr’ds<  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ƒÚ__rërñÚ anonymousr})rÀr­r‹rr¤rÔÚendswithr²rËrrr¯Úindirect_reference_namerrˆÚ adjust_uriZ referencedrÚ referencer r*Ú note_refnamer\Únote_indirect_targetÚnote_explicit_targetrI)r&rÎÚafterrÜrérrËZ aliastextZunderscore_escapedZ aliastypeÚaliasr¯Z alias_partsrër÷Ú node_listrrrræsd             zInliner.phrase_refcCs"|jj |¡}|rd|S|SdS)Nzmailto:)rÀr±rË)r&r²rËrrrrö\szInliner.adjust_uric Csnt ||j||j¡\}}|r<||||||ƒ\}}|||fS|jjd||d} | ||| ¡g|| gfSdS)Nz#Unknown interpreted text role "%s".)rP)rrär,r+r|rÕ) r&rÜrrärqZrole_fnrrrZ messages2rÝrrrrçcs   zInliner.interpretedcCs0|j|||jjtjdd\}}}}}||||fS)NT)r×)rßrÀr®r)r&rËrqrÎrÏrÉrÐrãrrrr®pszInliner.literalc Cs‚| |||jjtj¡\}}}}}|rvt|dtjƒrvt|ƒdksDt‚|d}t| ¡ƒ} |d  | ¡|j   ||j ¡||||fS)NrrUr}) rßrÀr¯rÚ isinstancerXr;rr€r\r*rúrI) r&rËrqrÎrÏrÉrÐrãr¯rƒrrrÚinline_internal_targetvs zInliner.inline_internal_targetc CsÆ| |||jjtj¡\}}}}}t|ƒdkrº|d}t|tjƒrº| ¡} |j  || ¡|dd…dkrºt  d| |fd¡} |dd…dkr”d| d <nt | ƒ| d <|j  | ¡| |7} | g}||||fS) NrUrr‡råz|%s%srzrðròrórë) rßrÀr°rÚsubstitution_referencerXrþr€r*Znote_substitution_refr÷rrø) r&rËrqrÎrÏrÉrÐrãZ subref_nodeZ subref_textZreference_noderrrrs$      zInliner.substitution_referencec Cs| d¡}t|ƒ}|j}|d| d¡…}|| d¡d…}| d¡rttjd||d}|t |¡7}|j  |¡nœt  d|¡}|ddkr°|d d…}d |d <|j  |¡n0|d krÒd }d |d <|j  |¡n|t |¡7}|rø||d <|j  |¡t |jj¡r| ¡}||g|gfS)ze Handles `nodes.footnote_reference` and `nodes.citation_reference` elements. r¦Nr¥Z citationlabelz[%s]_)rërú#rUÚautoÚ*rzrë)rÔrrÑr¤rÒrZcitation_referenceÚTextr*Znote_citation_refÚfootnote_referenceZnote_autofootnote_refZnote_symbol_footnote_refZnote_footnote_refrZget_trim_footnote_ref_spacer2r‰) r&rËrqÚlabelrërÑrÎrÉZrefnoderrrr–s6      zInliner.footnote_referencec CsŠ| d¡}t|ƒ}tj|| d¡|t|ƒd}|r>d|d<n||d<|j |¡|j}| d¡}|  d¡} |d|…|g|| d…gfS)NrërÅ)rƒrUrór¥) rÔrrr÷r r*rørÑr¤rÒ) r&rËrqróZ referencenamerëZ referencenoderÑrØrÙrrrr÷¹s      zInliner.referencecCs|j||ddS)NrU)ró)r÷)r&rËrqrrrÚanonymous_referenceÉszInliner.anonymous_referencecCsj| d¡r| d¡ ¡tjkrb| d¡r.d}nd}| d¡}t|dƒ}tjt|dƒ|||dgSt‚dS) NÚschemer±zmailto:rzr¥rrU)rñ)rÔÚlowerrÚschemesrrr÷r")r&rËrqZ addschemerÚ unescapedrrrrÁÌs    zInliner.standalone_uricCs|| d¡}| d¡r$t| d¡ƒ}n| d¡r>t| d¡ƒ}nt‚|jjj|jjj|}t|dƒ}t j t|dƒ||dgS)Nrzpep-Zpepnum1ZPEPZpepnum2rU)rñ) rÔÚ startswithÚintr"r*r2Z pep_base_urlZpep_file_url_templaterrr÷)r&rËrqrZpepnumÚrefr rrrrÂÚs    zInliner.pep_referencez rfc%d.htmlcCs^| d¡}| d¡r8t| d¡ƒ}|jjj|j|}nt‚t|dƒ}t j t|dƒ||dgS)NrZRFCÚrfcnumrU)rñ) rÔr r r*r2Z rfc_base_urlÚrfc_urlr"rrr÷)r&rËrqrrrr rrrrÃés   zInliner.rfc_referencec Cs”|sgSxp|jD]f\}}| |¡}|ry:| |d| ¡…|¡|||ƒ| || ¡d…|¡Stk rtYqXqWtjt|ƒt|dƒdgS)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Ü) r£r‹rÈr¤rÒr"rrr)r&rrqÚpatternrÍrËrrrrÈós   zInliner.implicit_inline) rz**ú`z``z_`z]_r–råròN)F)F)(rrrr(r'r5r’r¾r¼Z&non_unescaped_whitespace_escape_beforer¸r¹ZuricZ uri_end_delimZurilastršZuri_endZemailcr¿rÓrßrÕrªr«r¬rærörçr®rÿrrr÷rrÁrÂrrÃrÈrÆrrrrr4ÌsZ3  4?  #   r4ÚarUcCs t|ƒ|S)N)Úord)ÚsÚ_zerorrrÚ_loweralpha_to_intsrÚAcCs t|ƒ|S)N)r)rrrrrÚ_upperalpha_to_intsrcCst | ¡¡S)N)rÚ fromRomanÚupper)rrrrÚ_lowerroman_to_intsrc @s‚eZdZdZejjZeƒZedddddedddddedd dddd œe_ e ej   ¡ƒe_ d d d ddge_ ddddddœe_eeeeejdœe_ie_x,ej D]"Ze ejedej¡eje<q We d¡Ze d¡Ze d¡ZiZded<ded<ded<d ed!<d"ejed#<d$eed%<d&eed'<d(eed)<d*eed+<d,eed-<xDej D]:Zd.ee  ej ej!¡ed#e  ej ej"¡fee<qZWd/d0ed1d2ed3d4eed5d6d7edd8œ Z#d8Z$d9d:„Z%d;d<„Z&e d=ej¡Z'd>d?„Z(d@dA„Z)dBdC„Z*dDdE„Z+dFdG„Z,dHdI„Z-d´dKdL„Z.dMdN„Z/dOdP„Z0dQdR„Z1dSdT„Z2dUdV„Z3dWdX„Z4dYdZ„Z5d[d\„Z6d]d^„Z7d_d`„Z8dadb„Z9dcdd„Z:dedf„Z;dgdh„Zdmdn„Z?dodp„Z@dqdr„ZAdsdt„ZBdµdudv„ZCd¶dwdx„ZDdydz„ZEeƒZFee d{eGeHƒejIejB¡e d|eGeHƒejIejB¡e d}eGeHƒejIejB¡d~eF_#dd€„ZJdd‚„ZKdƒd„„ZLd…d†„ZMd‡dˆ„ZNd‰dŠ„ZOd‹dŒ„ZPddŽ„ZQdd„ZRd‘d’„ZSd“d”„ZTd•d–„ZUd—d˜„ZVd™dš„ZWd›dœ„ZXddž„ZYdŸd „ZZeJe d¡eHj[ejIejB¡feKe d¢eHj[ejIejB¡feLe d£ejIejB¡feQe d¤ejIejB¡feSe d¥eHj[ejIejB¡fgeF_\d¦d§„Z]d¨d©„Z^dªd«„Z_d¬d­„Z`d®d¯„Zad°d±„Zbd²d³„ZcdJS)·rAz: Generic classifier of the first line of a block. ú(ú)rUr‡)ržrŸr¤rÒrzrÚ.)ÚparensZrparenZperiodÚarabicÚ loweralphaÚ upperalphaÚ lowerromanÚ upperromanz[0-9]+z[a-z]z[A-Z]z [ivxlcdm]+z [IVXLCDM]+)r!r"r#r$r%r¨z\+-[-+]+-\+ *$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)( +|$)z#:(?![: ])([^:\\]|\\.)*(?>>( +|$)z\|( +|$)z \.\.( +|$)z__( +|$)z(%(nonalphanum7bit)s)\1* *$) ÚbulletÚ enumeratorÚ field_markerÚ option_markerÚdoctestÚ line_blockÚgrid_table_topÚsimple_table_topÚexplicit_markuprórPrc CsN|j ¡\}}}}| ||¡}|j|7_|sD|j| d¡7_||gfS)z Block quote.z Block quote)rEÚ get_indentedÚ block_quoterIr•) r&rËrQÚ next_stateÚindentedÚindentrrdÚelementsrrrr8zs  z Body.indentc Cs–g}xŒ|r| ||¡\}}}}}t ¡}| |||¡| |¡|rd| ||¡\} } || 7}|| 7}|}x$|rŒ|dsŒ|dd…}|d7}qjWqW|S)NrrU)Úsplit_attributionrr5rbr\Úparse_attribution) r&r7rr9Zblockquote_linesZattribution_linesZattribution_offsetÚnew_line_offsetÚ blockquoteÚ attributionrrrrrr5„s    zBody.block_quoteu(---?(?!-)|—) *(?=[^ \n])c CsÌd}d}x¾tt|ƒƒD] }|| ¡}|r²|r¬||dkr¬|j |¡}|r¬| ||¡\}} |r¬|||…} | j| ¡dd| 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Ò)r¤T)ÚrangerXr‰Úattribution_patternrËÚcheck_attributionZ trim_leftrÒ) r&r7rÚblankZ nonblank_seenÚirPrËZattribution_endr8Za_linesrrrr:žs(        zBody.split_attributioncCsˆd}|d}xnt|dt|ƒƒD]P}|| ¡}|s6P|dkrTt|ƒt| ¡ƒ}q t|ƒt| ¡ƒ|kr dSq W|d7}||p„dfS)zt Check attribution shape. Return the index past the end of the attribution, and the indent. NrU)NNr)r?rXr‰Úlstrip)r&r7Zattribution_startr8rCrPrrrrAÁs zBody.check_attributioncCsZd |¡ ¡}|j ¡|}| ||¡\}}tj|df|žŽ}|j |¡\|_|_ ||fS)Nr…rz) rˆr‰rEr“r~rr>rGr1rP)r&r7rrrqr‚rrr9rrrr;Õs zBody.parse_attributionc Cs¶t ¡}|j ¡\|_|_|j|7_|jd|d<| |  ¡¡\}}||7}|jj d}|j |jj |d…|j  ¡d|d|d\}}| |¡|s¬|j| d¡7_g|gfS)zBullet list item.rr+rUNÚ BulletList)r=r9rCrdz Bullet list)rZ bullet_listrErGr1rPrIrÑÚ list_itemrÒrrlr<rMrKr•) r&rËrQr6Z bulletlistrCrdr„r<rrrr+Ýs     z Body.bulletcCsd|jj|d…r$|j |¡\}}}n|j |¡\}}}}t d |¡¡}|r\|j|||d||fS)Nr…)r=r9)rErPZget_known_indentedÚget_first_known_indentedrrFrˆrb)r&r8r7rrdÚlistitemrrrrFñszBody.list_itemc Cs@| |¡\}}}}| |||¡s*t d¡‚t ¡}|j|7_|dkrRd|d<n||d<|jj|j |d<|jj|j |d<|dkr°||d<|j   d ||f¡} |j| 7_|  | ¡¡\} } || 7}|jjd} |j|jj| d …|j ¡d|d | |||dkd œd \} } | | ¡| s6|j| d¡7_g|gfS)zEnumerated List Itemrrr!ÚenumtyperžrŸrUr¤z      zBody.enumeratorNcCs<| ¡}d}x"|jjD]}||rPqWtdƒ‚|||jj|j|jj|j…}|dkrbd}n\|r¤y|jj| |¡r~|}Wq¾t k r td|ƒ‚Yq¾Xn|dkr²d}n |dkr¾d}|sðx,|jj D]}|jj| |¡rÌPqÌWtd ƒ‚|dkrþd }n2y|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. rzzenumerator format not matchedrzunknown enumerator sequence: %srCr$ÚIr%zenumerator sequence not matchedrUN)rÇr'Úformatsr!rPr¤rÒÚsequenceregexpsrËÚKeyErrorÚ sequencesÚ convertersrZInvalidRomanNumeralError)r&rËZexpected_sequencerÇrRrLrrSrrrrM!sB zBody.parse_enumeratorcCs¬|dkr dSy|j ¡}Wntk r8|j ¡dSX|j ¡|dd… ¡sXdS| |d||¡}|r¨|\}}y| |¡sŒ| |¡rdSWntk r¦YnXdS)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^rLrwÚstripÚmake_enumeratorr Ú TypeError)r&rSrRrLr^ÚresultÚnext_enumeratorÚauto_enumeratorrrrrNXs(    zBody.is_enumerated_list_itemcCsú|dkrd}n°|dkr t|ƒ}nž| d¡rL|dkr6dSt|tdƒdƒ}n>| d¡r~yt |¡}WqŠtjk rzdSXn 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. rr!r&éNrrUrz!unknown enumerator sequence: "%s"r rrì)ÚstrrôÚchrrrZtoRomanZ RomanErrorr!r r rr'rPržrŸ)r&rSrRrLr,rPr_r`rrrr\us2        zBody.make_enumeratorc Cs’t ¡}|j|7_| |¡\}}||7}|jjd}|j|jj|d…|j ¡d|d|d\}}|  |¡|sˆ|j|  d¡7_g|gfS)zField list item.rUNÚ FieldList)r=r9rCrdz Field list) rÚ field_listrIÚfieldrErrlr<rMrKr•) r&rËrQr6rerfrdr„rTrrrr-šs    zBody.field_markercCs¬| |¡}|j ¡\}}|j ¡}|j | ¡¡\}}}} t ¡} || _|| _ |  ||¡\} } | tj |df| žŽ7} tj d  |¡f| žŽ} | | 7} |r¤| ||| ¡| | fS)Nrzr…)Úparse_field_markerrErGr“rGrÒrrfr1rPr~Ú field_nameÚ field_bodyrˆÚparse_field_body)r&rËrƒÚsrcÚsrclinerqr7r8rrdZ field_nodeZ name_nodesZ name_messagesrirrrrf«s  z Body.fieldcCs&| ¡dd…}|d| d¡…}|S)z6Extract & return field name from a field marker match.rUNú:)rÔÚrfind)r&rËrfrrrrg¼szBody.parse_field_markercCs|j|||ddS)N)r=r9)rb)r&r7r„r9rrrrjÂszBody.parse_field_bodyc Cs<t ¡}|j ¡\|_|_y| |¡\}}Wntk r¼}zr|j  d|¡}|j |7_ |j  |  ¡¡\} } } }|  | | ¡} |j | 7_ |s¦|j | d¡7_ g|gfSd}~XYnX|j |7_ ||7}|jjd} |j|jj| d…|j ¡d|d|d\}}| |¡|s2|j | d¡7_ g|gfS)zOption list item.zInvalid option list marker: %sz Option listNrUÚ OptionList)r=r9rCrd)rÚ option_listrErGr1rPÚoption_list_itemrr+r|rIrGrÒr5r•rrlr<rMrK)r&rËrQr6Z optionlistrHrdr|rÝr7r8rr9r„rTrrrr.Ås4     zBody.option_markerc CsŒ|j ¡}| |¡}|j | ¡¡\}}}}|sD| |¡t d¡‚tj d|žŽ}t  d  |¡¡} t  d|| ¡} |r„|j ||| d| |fS)Nrrzr…)r=r9)rz)rErMÚparse_option_markerrGrÒrKrrOrÚ option_groupÚ descriptionrˆrqrb) r&rËr„Úoptionsr7r8rrdrsrtrqrrrrqäs    zBody.option_list_itemc Cs¢g}| ¡ ¡ d¡}x„|D]z}| ¡}d}|d dd¡}t|ƒdkr^||dd…<d}nft|dƒdkrÄ|d d¡rŠ|d d ¡r˜|d d ¡rÄ|ddd…|ddd…g|dd…<d }t|ƒdkr|d d ¡r|d  d¡rd |dd…¡g|dd…<dt|ƒkr*dkr†nnXt |¡}|t  |d|d¡7}t|ƒdkrz|tj |d|d|d7}|  |¡qt dt|ƒ|fƒ‚qW|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, rìrú=rUNrVú-z--ú+rzú)Ú delimiterz;wrong number of option tokens (=%s), should be 1 or 2: "%s") rÔr‰rírXr rôrˆrr*Z option_stringZoption_argumentr\r) r&rËZoptlistZ optionstringsZ optionstringÚtokensr{Zfirstoptr*rrrrrõs:  (    zBody.parse_option_markercCs0d |j ¡¡}|jt ||¡7_g|gfS)Nr…)rˆrEÚget_text_blockrIrZ doctest_block)r&rËrQr6rŽrrrr/sz Body.doctestc Csæt ¡}|j|7_|j ¡}| ||¡\}}}||7}|j|7_|s|jjd} |j|jj| d…|j  ¡d|ddd\} }|  | ¡|s²|j|j j d|dd7_t |ƒrÜ|djdkrÒd|d_| |¡g|gfS)zFirst line of a line block.rUNÚ LineBlockr)r=r9rCrdz%Line block ends without a blank line.)rP)rr0rIrEr“Úline_block_linerrlr<rMrKr+r”rXr8Únest_line_block_lines) r&rËrQr6r_rqrPrrrdr„r<rrrr0&s.        zBody.line_blockc Cst|jj| ¡dd\}}}}d |¡}| ||¡\}} tj|df|žŽ} |j ¡dkrjt |  d¡ƒd| _ | | |fS)z(Return one line element of a line_block.T)Ú until_blankr…rzr–rU) rErGrÒrˆr~rrPrÑr‰rXrÔr8) r&rËrqr7r8rrdrÚ text_nodesrrrPrrrr@s  zBody.line_block_linecCsNx>tdt|ƒƒD],}t||ddƒdkr||dj||_qW| |¡dS)NrUr8)r?rXrµr8Únest_line_block_segment)r&r_rtrrrr€LszBody.nest_line_block_linescCs dd„|Dƒ}t|ƒ}g}t ¡}xP|D]H}|j|krB| |¡q(t|ƒrf| |¡| |¡t ¡}| |¡q(Wt|ƒr| |¡| |¡||dd…<dS)NcSsg|] }|j‘qSr)r8)rîÚitemrrrú Ssz0Body.nest_line_block_segment..)Úminrr0r8r\rXrƒ)r&r_ÚindentsZleastZ new_itemsZ new_blockr„rrrrƒRs        zBody.nest_line_block_segmentcCs| ||||jtj¡S)zTop border of a full table.)Ú table_topÚisolate_grid_tablerZGridTableParser)r&rËrQr6rrrr1es zBody.grid_table_topcCs| ||||jtj¡S)zTop border of a simple table.)rˆÚisolate_simple_tablerZSimpleTableParser)r&rËrQr6rrrr2ks zBody.simple_table_topc CsT| ||¡\}}|j|7_|sJ|jjd|j ¡dd}|j|7_g|gfS)zTop border of a generic table.z Blank line required after table.rU)rP)ÚtablerIr+r”rEr“) r&rËrQr6Úisolate_functionÚ parser_classrêrdrÝrrrrˆqszBody.table_topc Cs¢|ƒ\}}}|r–y@|ƒ}| |¡}|j ¡t|ƒd}| ||¡} | g|} Wqštjk r’} z"|j|d | j ¡| j d|} Wdd} ~ XYqšXn|} | |fS)zParse a table.rUrì)r„N) r’rEr“rXÚ build_tablerZTableMarkupErrorÚmalformed_tablerˆrÄr„) r&rŒrr_rrrdÚparserÚ tabledataÚ tableliner‹rêÚerrrrrr‹}s   "z Body.tablec CsÐg}d}y|jjdd}WnLtjk rf}z,|j\}}}| |jjd||d¡d}Wdd}~XYnX| ¡|  |j ¡t |d  ¡ƒ}xXt t |ƒƒD]H}||  ¡||<||ddkršd}|j t |ƒ|¡||d…=PqšW|j |d¡spd}xrt t |ƒd ddƒD]@}|j ||¡r|j t |ƒ|d¡||dd…=PqW| | |¡¡g||fSxTt t |ƒƒD]D}t ||ƒ|ks¦||ddkr~| | |¡¡g||fSq~W|||fS) NrUT)Ú flush_leftzUnexpected indentation.)r1rPrz+|r‡rV)rEr}rÚUnexpectedIndentationErrorrÄr\r+r|Ú disconnectÚpad_double_widthÚdouble_width_pad_charrXr[r?rwÚgrid_table_top_patrËÚextendr) r&rrrdr_r“rkrlÚwidthrCrrrr‰sB      $zBody.isolate_grid_tablecCs´|jj}|jj}t|ƒd}t|| ¡ƒ}|jj}d}d}|d}x||krø||} || ƒ} | rît|  ¡ƒ|kr¼|j ||¡| |||d…d¡} g| ||kp¸||d ¡ fS|d7}|}|dksè||ksè||d ¡sî|} P|d7}qHW|r&d} |j ||¡|||d…}n$d} |j ||d¡||d…}| |d| ¡} g| | fS|j | |¡||| d…}|  |j ¡|g| |kp°|| d ¡ 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_patrËr^rr—r˜)r&r¤rÚlimitZtoplenZ pattern_matchÚfoundZfound_atrCrPrËrrrÒÚextrar_rrrrŠµsJ         zBody.isolate_simple_tablecCsf| |jd¡d |¡}d}|j ¡t|ƒd}|rB|d|7}|jj|t  ||¡||d}|gS)Nrzr…zMalformed table.rU)rP) Úreplacer˜rˆrEr“rXr+r|rr{)r&r_Údetailr„rŽráÚ startliner|rrrràs   zBody.malformed_tablecCsø|\}}}t ¡}|dkr.|ddg7<n|rD|ddg7<tjt|ƒd} || 7}x6|D].} tj| d} |rˆd| jd<|d8}| | 7} qbW|rÆt ¡} | | 7} x|D]} | | | |¡7} q®Wt ¡}| |7} x|D]} || | |¡7}qÜW|S) NrÚclasseszcolwidths-autozcolwidths-given)Úcols)ÚcolwidthrUZstub) rr‹ÚtgrouprXÚcolspecÚ attributesÚtheadÚbuild_table_rowÚtbody)r&r‘r’Z stub_columnsZwidthsZ colwidthsZheadrowsZbodyrowsr‹r¦r¥r§r©Úrowr«rrrrŽës0       zBody.build_tablec Cs~t ¡}xp|D]h}|dkrq|\}}}}i} |r8|| d<|rD|| d<tjf| Ž} || 7}d |¡r|j|||| dqW|S)NÚmorerowsÚmorecolsrz)r=r9)rr¬Úentryrˆrb) r&Zrowdatar’r¬Zcellr­r®r„Z cellblockr¨r¯rrrrªs       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 )r¯r÷Ú substitutionc Cs"|j ¡\}}|j | ¡¡\}}}}| d¡}t|ƒ} t d |¡¡} || _ || _ | ddkr”| dd…} d| d<| r†| d  | ¡|j   | ¡nL| dkr¶d} d| d<|j  | ¡n*| t d|¡7} | d  | ¡|j  | ¡| rô|j  | | ¡n|j  | | ¡|r|j||| d | g|fS) NrUr…rrrr}rrz)r=r9)rErGrGrÒrÔrrÚfootnoterˆr1rPr\r*Znote_autofootnoteZnote_symbol_footnoterZ note_footnoterúràrb) r&rËrkrlr7r8r„rdrrƒr±rrrr±Hs4    z Body.footnotec Csª|j ¡\}}|j | ¡¡\}}}}| d¡}t|ƒ} t d |¡¡} || _ || _ | t  d|¡7} | d  | ¡|j  | ¡|j  | | ¡|r |j||| d| g|fS)NrUr…rzr})r=r9)rErGrGrÒrÔrrÚcitationrˆr1rPrr\r*Z note_citationrúrb) r&rËrkrlr7r8r„rdrrƒr²rrrr²gs  z Body.citationc Cs |jjj}|j ¡}|jj| ¡ddd\}}}}|jd| ¡…d |¡}dd„|Dƒ}|d} d} xJ|  | ¡} | rzP| d7} y| || 7} Wqjt k r®t d ƒ‚YqjXqjW|d| …=|dd |  ¡t | ƒdd…  ¡|d<| ||||  d ¡¡} | g|fS) NTF)rÚ strip_indentr…cSsg|] }t|ƒ‘qSr)r)rîrPrrrr…sz)Body.hyperlink_target..rrUzmalformed hyperlink target.rìrƒ)ÚexplicitrÀr¯rEr“rGrÒrÑrˆrËr[rrXr[Ú make_targetrÔ) r&rËrrqr_r8r„rdÚ blocktextréÚ blockindexZ targetmatchr¯rrrÚhyperlink_targetxs,    ,  zBody.hyperlink_targetcCs„| |||¡\}}|dkrTtj|dt|ƒd}||_| |d||¡|j |¡|S|dkr|t |d¡}| ||||¡|S|SdS)Nrërz)rërñ)Ú parse_targetrr¯rrõÚ add_targetr*rù)r&r_Ú block_textrqZ target_nameZ target_typerŽr¯rrrrµ‘s  zBody.make_targetcCsp|rF|d ¡dd…dkrFd dd„|Dƒ¡}| |¡}|rFd|fStd |¡ƒ}d dd „|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 r‡NrårìcSsg|] }| ¡‘qSr)r[)rîrPrrrr…«sz%Body.parse_target..rëcss |]}d t|ƒ ¡¡VqdS)rzN)rˆrrí)rîr¡rrrrï°sz$Body.parse_target..rñ)r[rˆÚ is_referencer)r&r_r»rqr÷rëZ ref_partsrrrr¹ s    zBody.parse_targetcCs4|jjj t|ƒ¡}|sdSt| d¡p0| d¡ƒS)NÚsimpleÚphrase)r´rÀr÷rËr rrÔ)r&r÷rËrrrr¼´s   zBody.is_referencecCs„||_|r`tt|ƒƒ}|d |¡|rN|j |¡}|rB||d<n td|ƒ‚|j ||j ¡n |rl||d<d|d<|j  |¡dS)Nr}rñzproblem with URI: %rrUró) rPrrr\r0rörr*rúrIZnote_anonymous_target)r&Z targetnamerñr¯rqrƒr²rrrrº»s    zBody.add_targetcCsÐ|jjj}|j ¡\}}|jj| ¡dd\}}}}|jd| ¡…d |¡} |  ¡t |d  ¡ƒ} d} xV|  | ¡} | r~P| d7} y| dt ||   ¡ƒ} Wqntk r¾tdƒ‚YqnXqnW|d| …=|d  ¡d|  ¡t| ƒdd…|d<|ds|d=|d7}x"|r4|d  ¡s4| ¡qW|  d ¡} t | ¡}||_||_|s†|jjd | t | | ¡||d }|g|fS|d  ¡|d<|d  t | ¡¡|j|||d |d\}}d}xT|dd…D]D}t|tjƒst|tjƒs|j ||7_ ||=n|d7}qÔWx^| !tj"¡D]N}| #|¡r*t d| $¡  ¡¡}|jj%d|t | | ¡||d }|g|fSq*Wt|ƒdkr´|jjd| t | | ¡||d }|g|fS|j& '|| |j ¡|g|fS)NF)r³r…rrUrìz"malformed substitution definition.r‡rƒz.Substitution definition "%s" missing contents.)r1rPr}ÚSubstitutionDef)r=r9rCrdrzz1Substitution definition contains illegal element:z.Substitution definition "%s" empty or invalid.)(r´rÀr°rErGrGrÒrÑrˆr–rr‰rËr[r[rrXrZrÔrZsubstitution_definitionr1rPr+r”r{r\r rlrþZInlinerrIZtraverseÚElementÚ*disallowed_inside_substitution_definitionsÚpformatr|r*Znote_substitution_def)r&rËrrkrlr_r8r„rdr¶rér·Z subdefmatchÚsubnameZsubstitution_noderÝÚnew_abs_offsetrCr9rÂrrrÚsubstitution_defÍs€    ,              zBody.substitution_defcCs@|ds4t|tjƒr| d¡s4t|tjƒr8| d¡r8dSdSdS)NÚidsrórrUr)rþrr÷Úgetr)r&r9rrrrÁ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.rUN) rÔr Ú directiver6r,r*rIÚ run_directiveÚunknown_directive)r&rËÚoption_presetsÚ type_nameZdirective_classrrrrrrÈs  zBody.directivec CsÈt|ttfƒr"ddlm}||ƒ}|j ¡}|jj}|jj|  ¡dd\}} } } d  |jj ||jjd…¡} y|  || ||¡\} }}}WnRt k rÜ}z4|jjd|d  |j¡ft | | ¡|d}|g| fSd }~XYnX||| ||||| ||jƒ }y | ¡}WnVtjjjk rZ}z0|jj|j|j|d}|t | | ¡7}|g}Wd d }~XYnXt|tƒsttd |ƒ‚x>tt|ƒƒD].}t||tjƒs‚td ||||fƒ‚q‚W|| 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_topr…rUzError in "%s" directive: %s.rì)rPNz+Directive "%s" must return a list of nodes.z6Directive "%s" returned non-Node object (index %s): %r)!rþrrÚdocutils.parsers.rstrÍrEr“rrGrÒrˆr<Úparse_directive_blockrr+r|rÄrr{r:ÚdocutilsÚparsersZrstZDirectiveErrorZsystem_messageryrÝrer;r?rXÚNodeÚis_next_line_blank)r&rÈrËrÌrËrÍrqZinitial_line_offsetr7r8rrdr»Ú argumentsruÚcontentÚcontent_offsetr¡r|Zdirective_instancer^Zmsg_noderCrrrrÉ%sH       zBody.run_directivecCst|j}|j}|r,|d ¡s,| ¡|d7}x|rH|d ¡sH| ¡q.W|r°|js^|js^|r°x&t|ƒD]\}}| ¡shPqhW|d7}|d|…} ||dd…} ||d} n |} |} g} |rÔ| ||| ¡\} } ni} | r|js|js| ||d…} |} g} x*| r0| d ¡s0|  ¡| d7} qW|jsB|jrP|  || ¡} ng} | rh|sht dƒ‚| | | | fS)NrrUr‡zno content permitted) Ú option_specÚ has_contentr[Z trim_startÚtrim_endÚrequired_argumentsÚoptional_argumentsÚ enumerateÚparse_directive_optionsÚparse_directive_argumentsr)r&r7rrÈrËr×rØrCrPÚ arg_blockrÕrÖrurÔrrrrÏasN     zBody.parse_directive_blockc Cs‚| ¡}xDt|ƒD]4\}}t tjd|¡r||d…}|d|…}PqWg}|rz| ||¡\}} |rr| | ¡nt| ƒ‚||fS)Nr-) rcrÜrŠrËrArÀÚparse_extension_optionsr%r) r&rËr×rßrurCrPZ opt_blockÚsuccessrŽrrrrÝs    zBody.parse_directive_optionscCsˆ|j}|j}d |¡}| ¡}t|ƒ|kr@td|t|ƒfƒ‚nDt|ƒ||kr„|jrl| d||d¡}ntd||t|ƒfƒ‚|S)Nr…z$%s argument(s) required, %s suppliedrUz+maximum %s argument(s) allowed, %s supplied)rÚrÛrˆrírXrZfinal_argument_whitespace)r&rÈrßÚrequiredÚoptionalZarg_textrÔrrrrÞ¡s  zBody.parse_directive_argumentsc Csìt ¡}|j|d|ddd\}}|t|ƒkr0dSyt ||¡}Wn–tk rp}zdd|jdfSd}~XYnhtt fk r¤}zddd   |j¡fSd}~XYn4tj k rÖ}zdd d   |j¡fSd}~XYnX|räd |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. rÚExtensionOptionsT)rCrd)rzinvalid option blockzunknown option: "%s"Nzinvalid option value: %srìzinvalid option data: %srU)rzoption data incompletely parsed) rrerlrXrZextract_extension_optionsrXrÄrur]rˆZExtensionOptionError)r&r×Z datalinesr9rTrdrur¡rrrrà²s"   "zBody.parse_extension_optionsc CsT|j ¡}|jjddd\}}}}d |¡}|jjd|t ||¡|d}|g|fS)NrF)r³r…zUnknown directive type "%s".)rP)rEr“rGrˆr+r|rr{) r&rÌrqr7r8r„rdrr|rrrrÊÓs  zBody.unknown_directivecCs€|j| ¡d… ¡s.|j ¡r.t ¡gdfS|j | ¡¡\}}}}x|rb|d ¡sb| ¡qHWd  |¡}t ||¡g|fS)NrUr‡r…) rÑrÒr[rErÓrÚcommentrGrÙrˆ)r&rËr7r8r„rdrrrrråÝs   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|gfS)z3Footnotes, hyperlink targets, directives, comments.)Úexplicit_constructrIÚ explicit_list)r&rËrQr6rêrdrrrr3 s zBody.explicit_markupc Cs g}x€|jjD]t\}}| |j¡}|ry |||ƒStk r€}z2|j ¡}d |j¡}|  |j j ||d¡PWdd}~XYqXqW|  |¡\} } | || fS)z>Determine which explicit construct this is, parse & return it.rì)rPN) r´Ú constructsrËrÑrrEr“rˆrÄr\r+r”rå) r&rËÚerrorsrÍrZexpmatchr|rqrárêrdrrrræ s    zBody.explicit_constructcCsh|jjd}|j|jj|d…|j ¡d|jd||jjd\}}| |¡|sd|j| d¡7_dS)z‹ Create a nested state machine for a series of explicit markup constructs (including anonymous hyperlink targets). rUNÚExplicit)r=r9rCrdr3zExplicit markup) rErrlr<rMrIr3rKr•)r&rdr„rTrrrrç+ s   zBody.explicit_listcCs0| |¡\}}|j|7_| |¡g|gfS)zAnonymous hyperlink targets.)Úanonymous_targetrIrç)r&rËrQr6rêrdrrrró; s zBody.anonymousc Csj|j ¡}|jj| ¡dd\}}}}|jd| ¡…d |¡}dd„|Dƒ}| |||d¡}|g|fS)NT)rr…cSsg|] }t|ƒ‘qSr)r)rîrPrrrr…H sz)Body.anonymous_target..rz)rEr“rGrÒrÑrˆrµ) r&rËrqr_r8r„rdr¶r¯rrrrëB s  zBody.anonymous_targetcCs¶|jjr|jgdgfS|j ¡dkr0t d¡‚n‚t|j ¡ƒdkrr|jjd|j  ¡d}|j |7_ t d¡‚n@|jj }|jj dt  ||¡|j  ¡d}|j |7_ g|gfSdS) z,Section title overline or transition marker.ÚLinez::rézeUnexpected possible title overline or transition. Treating it as ordinary text because it's so short.)rPz'Unexpected section title or transition.N)rEr3rÑr[rrOrXr+rQr“rIrPrNrr{)r&rËrQr6rÝr¶rrrrPL s"   z Body.linecCs|jgdgfS)z%Titles, definition lists, paragraphs.r)rÑ)r&rËrQr6rrrrb sz Body.text)N)rzr)rN)drrrr(rZ TableParserr˜r#r'rPreÚkeysrVrYZ sequencepatsr rrrrrrZrWrRrŠr›rœr™Zsimple_table_top_patrœÚpatsrLÚescaperžrŸrÀÚinitial_transitionsr8r5r@r:rAr;r+rFr,rMrNr\r-rfrgrjr.rqrrr/r0rr€rƒr1r2rˆr‹r‰rŠrrŽrªr´r·r4r½r±r²r¸rµr¹r¼rºrÅrÁrÈrÉrÏrÝrÞràrÊrår¹rèr3rærçrórërPrrrrrrAs              &  # # 7%)  &+   D <.!   rAc@sNeZdZdZej ¡Zded<dd„ejDƒZe dd¡dd „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|] }|df‘qS)rAr)rîrƒrrrr…p szRFC2822Body.r‡)rórAc Cs˜tjdgd}|j|7_| |¡\}}||7}|jjd}|j|jj|d…|j ¡d|d|d\}}|  |¡|sŽ|j|  d¡7_g|gfS)zRFC2822-style field list item.ró)r£rUNÚ RFC2822List)r=r9rCrdzRFC2822-style field list) rrerIÚ rfc2822_fieldrErrlr<rMrKr•) r&rËrQr6Z fieldlistrfrdr„rTrrrrót s      zRFC2822Body.rfc2822c Cs~|jd|j d¡…}|jj| ¡dd\}}}}t ¡}|t ||¡7}t d  |¡¡}||7}|rv|j |||d||fS)NrmT)rr…)r=r9) rÑÚfindrErGrÒrrfrhrirˆrb) r&rËrƒr7r8rrdZ fieldnodeZ fieldbodyrrrrõ† s zRFC2822Body.rfc2822_fieldN) rrrr(rArÀrcrñÚinsertrórõrrrrròg s   ròc@sNeZdZdZddd„ZeZeZeZeZeZ 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|j ¡t‚dS)z8Not a compound element member. Abort this state machine.N)rErwrL)r&rËrQr6rrrÚ invalid_input­ s zSpecializedBody.invalid_input)NNN)rrrr(rùr8r+r,r-r.r/r0r1r2r3rórPrrrrrrø• s røc@seZdZdZdd„ZdS)rEz-Second and subsequent bullet_list list_items.cCsL|jd|jdkr| ¡| | ¡¡\}}|j|7_||_g|gfS)zBullet list item.rr+)rÑrIrùrFrÒrd)r&rËrQr6rHrdrrrr+Å s zBulletList.bulletN)rrrr(r+rrrrrEÁ srEc@seZdZdZdd„ZdS)ÚDefinitionListz,Second and subsequent definition_list_items.cCs|jgdgfS)zDefinition lists.Ú Definition)rÑ)r&rËrQr6rrrrÔ szDefinitionList.textN)rrrr(rrrrrrúÐ srúc@seZdZdZdd„ZdS)rJz1Second and subsequent enumerated_list list_items.c Cs¨| ||jd¡\}}}}||jks\|dkrN||jdks\|js\||jdks\| |||¡sd| ¡|dkrrd|_| | ¡¡\}} |j|7_| |_ ||_g|gfS)zEnumerated list item.rIrrU) rMrIrLrrKrNrùrFrÒrd) r&rËrQr6rLrRrrSrHrdrrrr,Ý s zEnumeratedList.enumeratorN)rrrr(r,rrrrrJÙ srJc@seZdZdZdd„ZdS)rdz(Second and subsequent field_list fields.cCs,| |¡\}}|j|7_||_g|gfS)zField list field.)rfrIrd)r&rËrQr6rfrdrrrr-õ szFieldList.field_markerN)rrrr(r-rrrrrdñ srdc@seZdZdZdd„ZdS)roz4Second and subsequent option_list option_list_items.cCsNy| |¡\}}Wntk r.| ¡YnX|j|7_||_g|gfS)zOption list item.)rqrrùrIrd)r&rËrQr6rqrdrrrr. szOptionList.option_markerN)rrrr(r.rrrrroý sroc@s*eZdZdZejZejZdd„Zej Z dS)rôz6Second and subsequent RFC2822-style field_list fields.cCs,| |¡\}}|j|7_||_gdgfS)zRFC2822-style field list item.rô)rõrIrd)r&rËrQr6rfrdrrrró szRFC2822List.rfc2822N) rrrr(ròrÀrñrórørùrBrrrrrô s rôc@seZdZdZdd„ZdS)räzz Parse field_list fields for extension options. No nested parsing is done (including inline markup parsing). cCsVg}xLt|ƒdgD]:}| ¡r,| |¡q|rd |¡}|t ||¡7}g}qWdS)z5Override `Body.parse_field_body` for simpler parsing.rzr…N)rer[r\rˆrrŒ)r&r7r„r9rrPrrrrrj% s  z!ExtensionOptions.parse_field_bodyN)rrrr(rjrrrrrä sräc@seZdZdZejZdd„ZdS)r~z,Second and subsequent lines of a line_block.cCsJ|j ¡}| ||¡\}}}|j|7_|jj|7_||_g|gfS)zNew line of line block.)rEr“rrIrd)r&rËrQr6rqrPrrrdrrrr07 s  zLineBlock.line_blockN)rrrr(rørùrBr0rrrrr~1 sr~c@s&eZdZdZdd„Zdd„ZejZdS)rêz0Second and subsequent explicit markup construct.cCs,| |¡\}}|j|7_||_g|gfS)z3Footnotes, hyperlink targets, directives, comments.)rærIrd)r&rËrQr6rêrdrrrr3E szExplicit.explicit_markupcCs,| |¡\}}|j|7_||_g|gfS)zAnonymous hyperlink targets.)rërIrd)r&rËrQr6rêrdrrrróL szExplicit.anonymousN) rrrr(r3rórørùrBrrrrrêA srêc@sBeZdZdZe dejej¡ddœZ ddgZ dd„Z d d „Z d S) r¿zG Parser for the contents of a substitution_definition element. z (%s)::( +|$)rz)Úembedded_directiverrürcCsB|j||jddd\}}|j|7_|j ¡s:||_t‚dS)Nr}r)Zalt)rÈrIrEÚat_eofrdrL)r&rËrQr6rêrdrrrrüb s  z"SubstitutionDef.embedded_directivecCs|j ¡s|j ¡|_t‚dS)N)rErýrÓrdrL)r&rËrQr6rrrrj s  zSubstitutionDef.textN) rrrr(rŠr›r4r¹rœrÀrñrürrrrrr¿V s r¿c@szeZdZdZejdddœZddgZdd„Zd d „Zd d „Z d d„Z dd„Z dd„Z dd„Z dd„Ze d¡Zdd„ZdS)rzs Classifier of second line of a text block. Could be a paragraph, a definition list item, or a title. rPrz)Ú underliner)rþrA)rrAcCsH| ||j ¡d¡\}}|j|7_|r>|j| ¡7_gdgfS)zEnd of paragraph.rUrA)rŒrEr“rIr{)r&rËrQr6rŒrrrrrB| s z Text.blankcCs|r| d|d¡gS)N)rB)r&rQrrrÚeof† szText.eofc Cs”t ¡}| |¡\}}||7}|j|7_|jjd}|j|jj|d…|j ¡d|d|dd\}}|  |¡|sŠ|j|  d¡7_gdgfS)zDefinition list item.rUNrúrû)r=r9rCrdrhzDefinition listrA) rZdefinition_listÚdefinition_list_itemrIrErrlr<rMrKr•) r&rËrQr6ZdefinitionlistZdefinitionlistitemrdr„rTrrrr8‹ s   z Text.indentcCsX|j ¡}|d ¡}|j ¡}|d|}g}t|ƒt|ƒkr¶t|ƒdkr~|jjrr|jjd|d} |j | 7_ t   d¡‚n8|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.rr…rízfPossible 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)rEr“r‰rÑrrXr3r+rQrIrrOrPr”rr{r\rGrNrs)r&rËrQr6rqrorþr1rrrÝr¶rkrlrprrrrþœ s<            zText.underlinec Csä|j ¡d}d}y|jjdd}WnBtjk rf}z"|j\}}} |jjd|| d}Wdd}~XYnX|t|ƒ} |  | |¡\} } |j | 7_ |j |7_ | rÚy|j  ¡Wnt k rÆYnX|j |  ¡7_ g|gfS)z Paragraph.rUNT)r”zUnexpected indentation.)r1rP)rEr“r}rr•rÄr+r|rerŒrIr^rLr{) r&rËrQr6r¢rÝr_r“rkrlrrŒrrrrrÄ s&  z Text.textcCsz|j ¡\}}}}x|r.|d ¡s.| ¡qW|s<| ¡Sd |¡}t ||¡}|d|_|g}|sv|  |  d¡¡|S)zReturn a list of nodes.r‡r…rUz Literal block) rEr4r[rÙÚquoted_literal_blockrˆrr{rPr\r•)r&r7r8r„rdrŽr{rêrrrr{Ú s    zText.literal_blockcCsR|j ¡}|jj}t ¡}|j|jj|d…||dtfddœd}| |¡|j S)NFÚQuotedLiteralBlock)rBrC)r=r9r3ra) rErMrrrÀrbr<rrKÚchildren)r&rMr„Z parent_noderÄrrrrê s   zText.quoted_literal_blockc Cs¾|j ¡\}}}}t d |t|ƒ¡¡}|j ¡d}|j |¡\|_|_ |  ||¡\}} ||7}tj d | žŽ} || 7}|ddd…dkr¦| |j j d|dd7} |j||| d ||fS) Nr…rUrzrrðz::z`Blank line missing before literal block (after the "::")? Interpreted as a definition list item.)rP)r=r9)rz)rEr4rrrˆrer“rGr1rPÚtermrr+rQrb) r&Ztermliner7r8rrdÚitemnoderqZtermlistrrrrrrrö szText.definition_list_itemz +: +c Cst|ƒdkst‚| |d|¡\}}t ¡}|j |¡\|_|_t |dƒ|_ |g}x°t t|ƒƒD] }||}t |tj ƒrò|j |j ¡} t| ƒdkr¦|d|7<nJ|dt  | d ¡¡7<x<| dd…D]} t d| ¡} | | ¡qÒWqb|d|7<qbW||fS)z9Return a definition_list's term and optional classifiers.rUrr‡Nrz)rXr;r~rrrErGr1rPrrÜr?rþrÚclassifier_delimiterrír‰Ú classifierr\) r&rrqr‚rrZ term_noderýrCr9r r¡Zclassifier_noderrrr s$   z Text.termN)rrrr(rArÀrñrBrÿr8rþrr{rrrŠr›rrrrrrrp s (  rc@s2eZdZdZdd„Zddd„ZeZeZeZeZ 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.eofNcCst‚dS)z8Not a compound element member. Abort this state machine.N)rL)r&rËrQr6rrrrù3 szSpecializedText.invalid_input)NNN) rrrr(rÿrùrBr8rþrrrrrr& s rc@s eZdZdZdd„Zdd„ZdS)rûz.Second line of potential definition_list_item.cCs|j d¡gS)zNot a definition.rV)rErw)r&rQrrrrÿA s zDefinition.eofcCs,| |¡\}}|j|7_||_gdgfS)zDefinition list item.rú)rrIrd)r&rËrQr6rrdrrrr8F szDefinition.indentN)rrrr(rÿr8rrrrrû= srûc@sLeZdZdZdZdd„Zdd„Zdd„ZeZd d „Z dd d „Z dd d„Z dS)rìzO Second line of over- & underlined section title or transition marker. rUcCsv|d ¡}|jjrd|j_nt|ƒdkr4| |¡|jrl|j ¡d}tj |dd}||_ |j |7_ d|_gS)z0Transition marker at end of section or document.rFrírU)rÜ) r[r6r/rXÚstate_correctionÚeofcheckrEr“rÚ transitionrPrI)r&rQÚmarkerrqr rrrrÿW s    zLine.eofcCsd|j ¡\}}|d ¡}t|ƒdkr0| |¡tj|d}||_|d|_|j |7_ gdgfS)zTransition marker.rrí)rÜrUrA) rErGr[rXr rr r1rPrI)r&rËrQr6rkrlr r rrrrBf s     z Line.blankc Csr|j ¡d}|d}|j}d}y|j ¡}Wnttk r¢|d|}t| ¡ƒdkrl| |||d¡n2|jj dt   ||¡|d} |j | 7_ gd gfSYnXd |||f} | ¡}| ¡}|j d d |¡sD|d|d|}t| ¡ƒdkr| |||d¡n2|jj d t   | | ¡|d} |j | 7_ gd gfSnt||kr¸|d|d|}t| ¡ƒdkr†| |||d¡n2|jj d t   | | ¡|d} |j | 7_ gd gfS| ¡}g} t|ƒt|ƒkr2|d|d|}t| ¡ƒdkr| |||d¡n$|jjdt   | | ¡|d} |  | ¡|d|df} d|_| | ¡| | |d| ¡d|_gd gfS)z#Potential over- & underlined title.rUrrzr…rírVzIncomplete section title.)rPrAz%s %s %srþz6Missing matching underline for section title overline.z$Title overline & underline mismatch.zTitle overline too short.)rEr“rÑr^rLrXr‰Úshort_overliner+rNrr{rIrRrËrr”r\r rsrD) r&rËrQr6rqÚoverlinerorþr¶rÝr1rrrprrrrr sn         z Line.textcCsx|d}|d|jj}|j ¡d}t| ¡ƒdkrF| |||d¡|jjdt  ||¡|d}|j |7_ gdgfS)Nrr…rUríz+Invalid section title or transition marker.)rPrA) rErPr“rXr‰r r+r|rr{rI)r&rËrQr6rr¶rqrÝrrrrþ² s zLine.underlinecCs.|jjd|d}|j|7_| ||¡dS)Nz`Possible incomplete section title. Treating the overline as ordinary text because it's so short.)rP)r+rQrIr )r&rQr¶rqrrÝrrrr ¿ s zLine.short_overlinecCs(|j |¡g|dd…<t dd¡‚dS)NrAr)rErwrZStateCorrection)r&rQrrrrr Ç s  zLine.state_correctionN)rU)rU) rrrr(r rÿrBrr8rþr r rrrrrìN s > rìc@s^eZdZdZdejddœZdZddd„Zdd „Z d d „Z d d „Z dd„Z dd„Z dd„ZdS)rzƒ Nested parse handler for quoted (unindented) literal blocks. Special-purpose. Not for inclusion in `state_classes`. z(%(nonalphanum7bit)s)rz)Úinitial_quotedrFcCst |||¡g|_d|_dS)N)r@r'rrÚinitial_lineno)r&rErFrrrr'Ù szQuotedLiteralBlock.__init__cCs|r t‚n ||gfSdS)N)rL)r&rËrQr6rrrrBÞ szQuotedLiteralBlock.blankcCs†|rH|j |j¡\}}d |¡}t ||¡}||_||_|j|7_n*|j|j j d|j  ¡d7_|j  ¡|j|j 7_gS)Nr…z#Literal block expected; none found.)rP)rErGrrˆrr{r1rPrIr+r”r“rwrr)r&rQrkrlrr{rrrrÿä s     zQuotedLiteralBlock.eofcCs<|s tdƒ‚|j |jjd|j ¡d¡|j ¡t‚dS)Nz7QuotedLiteralBlock.indent: context should not be empty!zUnexpected indentation.)rP) r;rrr\r+r|rEr“rwrL)r&rËrQr6rrrr8ö s   zQuotedLiteralBlock.indentcCsZ| d¡|jd}t t |¡tj¡}| d||j|jj f¡|j   ¡|_ |jg|gfS)z7Match arbitrary quote character on the first line only.rrÚquoted) Zremove_transitionrÑrŠr›rðrœÚadd_transitionrrOrrEr“r)r&rËrQr6Úquoterrrrrÿ s   z!QuotedLiteralBlock.initial_quotedcCs| |j¡||gfS)z,Match consistent quotes on subsequent lines.)r\rÑ)r&rËrQr6rrrr s zQuotedLiteralBlock.quotedcCs4|r,|j |jjd|j ¡d¡|j ¡t‚dS)Nz#Inconsistent literal block quoting.)rP)rrr\r+r|rEr“rwrL)r&rËrQr6rrrr s  zQuotedLiteralBlock.textN)F)rrrr(rArïrÀrñr'rBrÿr8rrrrrrrrÍ s   r)T)Gr(Z __docformat__ÚsysrŠÚtypesrrrÐrrrrrZdocutils.statemachiner r Zdocutils.nodesr rr rÎr rrrZdocutils.parsers.rst.languagesrZ_fallback_language_moduleZdocutils.utilsrrrrrrrrrr r!Ú Exceptionr"r#r)r?r@r™r4rrrrrAròrørErúrJrdrorôrär~rêr¿rrrûrìrrBrrrrÚes†    'l LS.,  7K