U O`@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)Gddde*Z+GdddeZ,GdddeZ-Gdd d eZ.dSd"d#Z/Gd$d%d%e*Z0e1d&d'fd(d)Z2e1d*d'fd+d,Z3d-d.Z4Gd/d0d0e.Z5Gd1d2d2e5Z6Gd3d4d4e5Z7Gd5d6d6e7Z8Gd7d8d8e7Z9Gd9d:d:e7Z:Gd;d<dd>e7ZGdCdDdDe7Z?GdEdFdFe7Z@GdGdHdHe5ZAGdIdJdJe.ZBGdKdLdLeBZCGdMdNdNeCZDGdOdPdPeCZEGdQdRdRe.ZFe5e8e9e:e;ee@eBeDeEeAe6e=fZGdS)Ta This is the ``docutils.parsers.rst.states`` module, the core of the reStructuredText parser. It defines the following: :Classes: - `RSTStateMachine`: reStructuredText parser's entry point. - `NestedStateMachine`: recursive StateMachine. - `RSTState`: reStructuredText State superclass. - `Inliner`: For parsing inline markup. - `Body`: Generic classifier of the first line of a block. - `SpecializedBody`: Superclass for compound element members. - `BulletList`: Second and subsequent bullet_list list_items - `DefinitionList`: Second+ definition_list_items. - `EnumeratedList`: Second+ enumerated_list list_items. - `FieldList`: Second+ fields. - `OptionList`: Second+ option_list_items. - `RFC2822List`: Second+ RFC2822-style fields. - `ExtensionOptions`: Parses directive option fields. - `Explicit`: Second+ explicit markup constructs. - `SubstitutionDef`: For embedded directives in substitution definitions. - `Text`: Classifier of second line of a text block. - `SpecializedText`: Superclass for continuation lines of Text-variants. - `Definition`: Second line of potential definition_list_item. - `Line`: Second line of overlined section title or transition marker. - `Struct`: An auxiliary collection class. :Exception classes: - `MarkupError` - `ParserError` - `MarkupMismatch` :Functions: - `escape2null()`: Return a string, escape-backslashes converted to nulls. - `unescape()`: Return a string, nulls removed or restored to backslashes. :Attributes: - `state_classes`: set of State classes used with `RSTStateMachine`. Parser Overview =============== The reStructuredText parser is implemented as a recursive state machine, examining its input one line at a time. To understand how the parser works, please first become familiar with the `docutils.statemachine` module. In the description below, references are made to classes defined in this module; please see the individual classes for details. Parsing proceeds as follows: 1. The state machine examines each line of input, checking each of the transition patterns of the state `Body`, in order, looking for a match. The implicit transitions (blank lines and indentation) are checked before any others. The 'text' transition is a catch-all (matches anything). 2. The method associated with the matched transition pattern is called. A. Some transition methods are self-contained, appending elements to the document tree (`Body.doctest` parses a doctest block). The parser's current line index is advanced to the end of the element, and parsing continues with step 1. B. Other transition methods trigger the creation of a nested state machine, whose job is to parse a compound construct ('indent' does a block quote, 'bullet' does a bullet list, 'overline' does a section [first checking for a valid section header], etc.). - In the case of lists and explicit markup, a one-off state machine is created and run to parse contents of the first item. - A new state machine is created and its initial state is set to the appropriate specialized state (`BulletList` in the case of the 'bullet' transition; see `SpecializedBody` for more detail). This state machine is run to parse the compound element (or series of explicit markup elements), and returns as soon as a non-member element is encountered. For example, the `BulletList` state machine ends as soon as it encounters an element which is not a list item of that bullet list. The optional omission of inter-element blank lines is enabled by this nested state machine. - The current line index is advanced to the end of the elements parsed, and parsing continues with step 1. C. The result of the 'text' transition depends on the next line of text. The current state is changed to `Text`, under which the second line is examined. If the second line is: - Indented: The element is a definition list item, and parsing proceeds similarly to step 2.B, using the `DefinitionList` state. - A line of uniform punctuation characters: The element is a section header; again, parsing proceeds as in step 2.B, and `Body` is still used. - Anything else: The element is a paragraph, which is examined for inline markup and appended to the parent element. Processing continues with step 1. ZreStructuredTextN) FunctionType MethodType)nodes statemachineutils)ApplicationError DataError)StateMachineWSStateWS)fully_normalize_name)whitespace_normalize_name) directives languages tableparserroles)en) escape2nullunescape column_width)punctuation_charsroman urischemes)split_escaped_whitespacec@s eZdZdS) MarkupErrorN__name__ __module__ __qualname__rrB/tmp/pip-target-hkkqj8fq/lib/python/docutils/parsers/rst/states.pyrzsrc@s eZdZdS)UnknownInterpretedRoleErrorNrrrrrr {sr c@s eZdZdS)"InterpretedRoleNotImplementedErrorNrrrrrr!|sr!c@s eZdZdS) ParserErrorNrrrrrr"}sr"c@s eZdZdS)MarkupMismatchNrrrrrr#~sr#c@seZdZdZddZdS)Structz3Stores data attributes for dotted-attribute access.cKs|j|dSN)__dict__update)selfZ keywordargsrrr__init__szStruct.__init__N)rrr__doc__r)rrrrr$sr$c@seZdZdZdddZdS)RSTStateMachinezy reStructuredText's master StateMachine. The entry point to reStructuredText parsing is the `run()` method. rTNc Cst|jj|_||_|dkr$t}||jt||j |jgdd|d|_ ||_ | |j |j j |_ ||_tj||||dd}|gkstdd|_|_ dS)z Parse `input_lines` and modify the `document` node in place. Extend `StateMachineWS.run()`: set up parse-global data and run the StateMachine. NrF)documentreporterlanguage title_styles section_levelsection_bubble_up_kludgeinlinersource)Z input_sourcez.RSTStateMachine.run() results should be empty!)rZ get_languagesettingsZ language_coder. match_titlesInlinerinit_customizationsr$r-memor,attach_observer note_sourcenoder runAssertionError)r( input_linesr, input_offsetr5r2resultsrrrr<s0    zRSTStateMachine.run)rTNrrrr*r<rrrrr+sr+c@seZdZdZdddZdS)NestedStateMachinezh StateMachine run from within other StateMachine runs, to parse nested document structures. TcCsZ||_||_|j|_||jj|j|_|j|_||_t |||}|gksVt d|S)z Parse `input_lines` and populate a `docutils.nodes.document` instance. Extend `StateMachineWS.run()`: set up document-wide data. z1NestedStateMachine.run() results should be empty!) r5r8r,r9r:r-r.r;r r<r=)r(r>r?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|_|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_finishitemssetattrr<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(r3rvrwr8r/mylevellevelrrrrsIs*    zRSTState.check_subsectioncCs|jjdtd||d}|S)NzTitle level inconsistent:rU)r-rSr literal_block)r(Z sourcetextrwerrorrrrr|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)r8r0rryrN inline_textrunormalize_nameastextrcr,Znote_implicit_targetrJ line_offsetrRrir>rPrQ)r(rurwrxr8r~Z section_node textnodesZtitle_messagesZ titlenodenameoffsetZ absoffsetZ newabsoffsetrrrrtxs2    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) isinstancetuplerc build_regexprlocalsrcompileUNICODE) definitionrrprefixsuffixparts part_stringspartZor_groupregexprrrrs     rc @seZdZdZddZddZddZdZd Zd Z d Z d Z d Z dZ dZdeZdZdZddZd=ddZddZddZddZddZd>d!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd?d/d0Z d1d2Z!d3d4Z"d5d6Z#d7Z$d8d9Z%d:d;Z&eeeeeeee e!d< Z'd S)@r6z9 Parse inline markup; call the `parse()` method. cCs g|_dSr%)implicit_dispatch)r(rrrr)szInliner.__init__cCs4t|ddrd}d}n$dtjtjf}dtjtjtjf}t}|t |j d|ddd|j d d d d d gfdd|d|j ddddd|j dd|j gfgfdd|j |j dgfgf}||_ ||_||_tt|t|jd|tjt|jd|tjtd|tjtjBtd|tjtjBt|jd|tjt|jd|tjt|jd |tjt|j|d!tjtjBtd"|jd#|tjtjBtd$|tjtjBtd%|tjtjBd& |_|j|jj|jf|jr|j|jj|j f|j!r0|j|jj"|j#fdS)'NZcharacter_level_inline_markupFz (^|(?%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(rrwr8rNZpattern_searchr remaining processedZ unprocessedrxmatchgroupsmethodbeforeinlines 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 (?5sz%Inliner.phrase_ref..refurizproblem with embedded link: %rr__rr anonymousr)rrrrrrendswithrrrrrr indirect_reference_namerr adjust_uriZ referencedr referencerr, note_refnamercnote_indirect_targetnote_explicit_targetrN)r(rafterrrrrZ unescapedZrawtextZ aliastextZ rawaliastextZunderscore_escapedZ aliastypealiasrZ alias_partsrr node_listrrrr s               zInliner.phrase_refcCs"|jj|}|rd|S|SdS)Nmailto:)rrr)r(rrrrrrkszInliner.adjust_uric Csnt||j||j\}}|r<||||||\}}|||fS|jjd||d} |||| g|| gfSdS)Nz#Unknown interpreted text role "%s".r)rrr.r-rr) r(rrrrwZrole_fnrxrZ messages2rrrrrrs  zInliner.interpretedcCs0|j|||jjtjdd\}}}}}||||fS)NT)r)rrrrrrrrrszInliner.literalc Cs||||jjtj\}}}}}|rvt|dtjrvt|dksDt|d}t|} |d | |j ||j ||||fS)Nrr[r) rrrrrr_r=rrrcr,r rN) r(rrwrrrrrrrrrrinline_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_refrrr ) r(rrwrrrrrZ 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(rrwlabelrrrrZrefnoderrrrs:      zInliner.footnote_referencec Cs|d}t|}tj||d|t|d}||d_|rHd|d<n||d<|j||j}| d}| d} |d||g|| dgfS)Nrrrrr[rr) rrrrr rr,r rrr) r(rrwrZ referencenamerZ referencenoderrrrrrrs        zInliner.referencecCs|j||ddS)Nr[)r)r)r(rrwrrranonymous_referenceszInliner.anonymous_referencecCsl|dr|dtjkrd|dr.d}nd}|d}|t|}tjt|d||d}|gStdS)NschemerrrrTr)rlowerrschemesrrrr#)r(rrwZ addschemerrrrrrrs    zInliner.standalone_uricCsz|d}|dr(tt|d}n"|drFtt|d}nt|jjj|jjj|}t j t|d||dgS)Nrzpep-Zpepnum1ZPEPZpepnum2Tr) r startswithintrr#r,r4Z pep_base_urlZpep_file_url_templaterr)r(rrwrZpepnumrefrrrrs    zInliner.pep_referencez rfc%d.htmlcCsX|d}|drd?Z'd@dAZ(dBdCZ)dDdEZ*dFdGZ+dHdIZ,ddKdLZ-dMdNZ.dOdPZ/dQdRZ0dSdTZ1dUdVZ2dWdXZ3dYdZZ4d[d\Z5d]d^Z6d_d`Z7dadbZ8dcddZ9dedfZ:dgdhZ;didjZdodpZ?dqdrZ@dsdtZAddudvZBddwdxZCdydzZDeZEeed{eFeGejHejBed|eFeGejHejBed}eFeGejHejBd~eE_"ddZIddZJddZKddZLddZMddZNddZOddZPddZQddZRddZSddZTddZUddZVddZWddZXddZYeIedeGjZejHejBfeJedeGjZejHejBfeKedejHejBfePedejHejBfeRedeGjZejHejBfgeE_[ddZ\ddZ]ddZ^ddZ_ddZ`ddZaddZbdJS)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]+)r2r3r4r5r6rz\+-[-+]+-\+ *$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_stateindentedindentrrkelementsrrrrIs  z Body.indentc Csg}|r|||\}}}}}t}|||||||rb|||\} } || 7}|| 7}|}|r|ds|dd}|d7}qfq|S)Nrr[)split_attributionrrFrircparse_attribution) r(rHrrJZblockquote_linesZattribution_linesZattribution_offsetnew_line_offset blockquote attributionrxrrrrFs.     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(rHrblankZ nonblank_seenirUrZattribution_endrIZa_linesrrrrKs0      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)rPr_rlstrip)r(rHZattribution_startrIrTrUrrrrRs zBody.check_attributioncCsZd|}|j|}|||\}}tj|df|}|j|\|_|_ ||fS)Nrr) rrrJrrrrOrLr3rU)r(rHrrrwrrxr;rrrrLs 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_itemrrrrr>rRrPr) r(rrVrGZ bulletlistrTrkrrMrrrr<s(    z Body.bulletcCsd|jj|dr$|j|\}}}n|j|\}}}}td|}|r\|j|||d||fS)Nrr?r;)rJrUZget_known_indentedget_first_known_indentedrrYrri)r(rIrHrrklistitemrrrrYs  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 Itemrrr2enumtyperrr[rzrRrPr)r(rrVrGr`sequencerordinalZenumlistrr\rkrnewline_offsetrrrr= sH      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: %srTr5Ir6zenumerator sequence not matchedr[N)rr8formatsr"rdrrsequenceregexpsrKeyError sequences convertersrZInvalidRomanNumeralError)r(rZexpected_sequencerrfr`rrgrrrra0sF    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(rgrfr`reresultnext_enumeratorauto_enumeratorrrrrbgs*    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. rr2r7Nr#r[rz!unknown enumerator sequence: "%s"rr,r)strrchrr%rZtoRomanZ RomanErrorr"rrr,r8rdrr)r(rgrfr`r=rdrsrtrrrrps:         zBody.make_enumeratorc Cst}|j|7_||\}}||7}|jjd}|j|jj|d|jd|d|d\}}| ||s|j| d7_g|gfS)zField list item.r[N FieldListrXz Field list) r field_listrNfieldrJrrrr>rRrPr) r(rrVrGryrzrkrrhrrrr>s     zBody.field_markercCs||}|j\}}|j}|j|\}}}} t} || _|| _ | ||\} } | tj |df| 7} tj d |f| } | | 7} |r|||| | | fS)Nrr)parse_field_markerrJrLrr[rrrzr3rUr field_name field_bodyrparse_field_body)r(rrsrcsrclinerwrHrIrrkZ field_nodeZ name_nodesZ name_messagesr}rrrrzs   z Body.fieldcCs&|dd}|d|d}|S)z6Extract & return field name from a field marker match.r[N:)rrfind)r(rrzrrrr{szBody.parse_field_markercCs|j|||ddS)NrZ)ri)r(rHrr;rrrr~szBody.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[ OptionListrX)r option_listrJrLr3rUoption_list_itemrr-rrNr[rrFrrrrr>rRrP)r(rrVrGZ optionlistr\rkrrrHrIrrJrrhrrrr?s<       zBody.option_markerc Cs|j}||}|j|\}}}}|sD||tdtj d|}t d |} t d|| } |r|j ||| d| |fS)NrrrrZ)r)rJrRparse_option_markerr[rrPrrcr option_group descriptionrrri) r(rroptionsrHrIrrkrrrrrrrs"     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; option_stringZoption_argumentrcr) r(rZoptlistZ optionstringsZ optionstringtokensrZfirstoptr;rrrrsH      (     zBody.parse_option_markercCs0d|j}|jt||7_g|gfS)Nr)rrJget_text_blockrNrZ doctest_block)r(rrVrGrrrrr@-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 LineBlockrrXz%Line block ends without a blank line.r)rrArNrJrline_block_linerrrr>rRrPr-rr_rInest_line_block_lines) r(rrVrGrfrwrUrxrkrrMrrrrA5s4         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_rrI) r(rrwrHrIrrkr text_nodesrxrUrrrrOs   zBody.line_block_linecCsJtdt|D],}t||dddkr||dj||_q||dS)Nr[rI)rPr_rrInest_line_block_segment)r(rfrzrrrr[szBody.nest_line_block_linescCsdd|D}t|}g}t}|D]H}|j|kr@||q&t|rd||||t}||q&t|r||||||dd<dS)NcSsg|] }|jqSr)rI)ritemrrr bsz0Body.nest_line_block_segment..)minrrArIrcr_r)r(rfindentsZleastZ new_itemsZ new_blockrrrrras        zBody.nest_line_block_segmentcCs|||||jtjS)zTop border of a full table.) table_topisolate_grid_tablerZGridTableParserr(rrVrGrrrrBts zBody.grid_table_topcCs|||||jtjS)zTop border of a simple table.)risolate_simple_tablerZSimpleTableParserrrrrrCzs 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(rrVrGisolate_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(rrrfrxrkparser 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_rorPr}grid_table_top_patrextendr) r(rxrkrfrrrwidthrTrrrrsF      $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_rosimple_table_border_patrrerrr)r(rrlimitZtoplenZ pattern_matchfoundZfound_atrTrUrrxrextrarfrrrrsR       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)NmorerowsmorecolsrrZ)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[rrrrrrrrZ)rJrLr[rrrrfootnoterr3rUrcr,Znote_autofootnoteZnote_symbol_footnoterZ note_footnoter rri) r(rrrrHrIrrkrrrrrrrWs6     z Body.footnotec Cs|j\}}|j|\}}}}|d}t|} td|} || _ || _ | t d|7} | d | |j | |j | | |r|j||| d| g|fS)Nr[rrrrZ)rJrLr[rrrrcitationrr3rUrrcr,Z note_citationr ri) r(rrrrHrIrrkrrrrrrrvs   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_ro make_targetr) r(rr!rwrfrIrrk 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_textrwZ 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)rorrrrrsz%Body.parse_target..rcss |]}dt|VqdSr)rrrrrrrrsz$Body.parse_target..r)ror is_referencer)r(rfrrwrrZ ref_partsrrrrs   zBody.parse_targetcCs4|jjjt|}|sdSt|dp0|dS)Nsimplephrase)rrrrr rr)r(rrrrrrs  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 targetnamerrrwrrrrrrs    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.rrSubstitutionDefrXrz6Substitution definition contains illegal element <%s>:z.Substitution definition "%s" empty or invalid.))rrrrJrLr[rrrrrrrrorbrr_rarrZsubstitution_definitionr3rUr-rrrcr rrrZInlinerrNZtraverseElement*disallowed_inside_substitution_definitionspformatrtagnamer,Znote_substitution_def)r(rr!rrrfrIrrkrrrZ subdefmatchsubnameZsubstitution_nodernew_abs_offsetrTr;rrrrsubstitution_defs     ,             zBody.substitution_defcCs@|ds4t|tjr|ds4t|tjr8|dr8dSdSdS)NidsrrTF)rrrgetr)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_classrxrrrr)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_messagerrlistr=rPr_Nodeis_next_line_blank)r(rrrrrrwZinitial_line_offsetrHrIrrkr argumentsrcontentcontent_offsetrrZdirective_instancerrZmsg_noderTrrrr5sv           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_contentroZ trim_starttrim_endrequired_argumentsoptional_arguments enumerateparse_directive_optionsparse_directive_argumentsr)r(rHrrrrrrTrU arg_blockrrrrrrrrqs^       zBody.parse_directive_blockc Cs|}t|D]6\}}ttjd|r||d}|d|}qLqg}|rx|||\}} |rp|| nt| ||fS)Nr>) rjrrrrDrparse_extension_optionsr'r) r(rrrrrTrUZ 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) rryrrr_rZextract_extension_optionsrlrr{rqrZExtensionOptionError)r(rZ datalinesr;rhrkrrrrrrs*  &(*zBody.parse_extension_optionsc CsT|j}|jjddd\}}}}d|}|jjd|t|||d}|g|fS)NrFrrzUnknown directive type "%s".r)rJrr[rr-rrr) r(rrwrHrIrrkrrrrrrs    zBody.unknown_directivecCs||j|ds.|jr.tgdfS|j|\}}}}|r`|ds`|qFd |}t||g|fS)Nr[rr) rrrorJrrcommentr[rr)r(rrHrIrrkrrrrrs   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(rrVrGrrkrrrrD$ 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!Zexpmatchrrwrrrkrrrr+ 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) rJrrrr>rRrNr5rPr)r(rkrrhrrrr; s    zBody.explicit_listcCs0||\}}|j|7_||g|gfSzAnonymous hyperlink targets.)anonymous_targetrNrr rrrrK s zBody.anonymousc Csj|j}|jj|dd\}}}}|jd|d|}dd|D}||||d}|g|fS)NTrrcSsg|] }t|qSrrrrrrrX sz)Body.anonymous_target..r)rJrr[rrrr) r(rrwrfrIrrkrrrrrrR 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)rJr5rrorrcr_r-rerrNrUrSrr)r(rrVrGrrrrrrU\ s&   z Body.linecCs|jgdgfS)z%Titles, definition lists, paragraphs.rrrrrrrr sz Body.text)N)rr)rN)crrrr*rZ TableParserrr$r8rdkeysrjrmZ sequencepatsrr(r*r-rr+rnrkrfrrrrZsimple_table_top_patrpatsr`escaperrrinitial_transitionsrIrFrQrKrRrLr<rYr=rarbrpr>rzr{r~r?rrr@rArrrrBrCrrrrrrrrrr6rrrrrrrrrrrrrrrrrrrr rDrrrrrUrrrrrrD-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 RFC2822ListrXzRFC2822-style field list) rryrN rfc2822_fieldrJrrrr>rRrPr) r(rrVrGZ fieldlistrzrkrrhrrrr s$     zRFC2822Body.rfc2822c Cs~|jd|jd}|jj|dd\}}}}t}|t||7}td |}||7}|rv|j |||d||fS)NrTrrrZ) rfindrJr[rrrzr|r}rri) r(rrrHrIrrkZ fieldnodeZ fieldbodyrrrr s  zRFC2822Body.rfc2822_fieldN) rrrr*rDrrjrinsertrrrrrrrw 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 rIr<r=r>r?r@rArBrCrDrrUrrrrrr s rc@seZdZdZddZdS)rWz-Second and subsequent bullet_list list_items.cCsL|jd|jdkr|||\}}|j|7_||_g|gfS)rVrr<)rrNr rYrrk)r(rrVrGr\rkrrrr< s zBulletList.bulletN)rrrr*r<rrrrrW srWc@seZdZdZddZdS)DefinitionListz,Second and subsequent definition_list_items.cCs|jgdgfS)zDefinition lists. Definitionrrrrrr szDefinitionList.textN)rrrr*rrrrrr! sr!c@seZdZdZddZdS)r^z1Second and subsequent enumerated_list list_items.c Cs|||jd\}}}}||jks\|dkrN||jdks\|js\||jdks\||||sd||dkrrd|_||\}} |j|7_| |_ ||_g|gfS)zEnumerated list item.r]rr[) rarNr`rr_rbr rYrrk) r(rrVrGr`rfrrgr\rkrrrr= s.     zEnumeratedList.enumeratorN)rrrr*r=rrrrr^ sr^c@seZdZdZddZdS)rxz(Second and subsequent field_list fields.cCs,||\}}|j|7_||_g|gfS)zField list field.)rzrNrkr(rrVrGrzrkrrrr> szFieldList.field_markerN)rrrr*r>rrrrrx srxc@seZdZdZddZdS)rz4Second and subsequent option_list option_list_items.cCsNz||\}}Wntk r.|YnX|j|7_||_g|gfS)r)rrr rNrk)r(rrVrGrrkrrrr? szOptionList.option_markerN)rrrr*r?rrrrr src@s*eZdZdZejZejZddZej Z dS)rz6Second and subsequent RFC2822-style field_list fields.cCs,||\}}|j|7_||_gdgfS)rr)rrNrkr#rrrr# szRFC2822List.rfc2822N) rrrr*rrrrrr rSrrrrr 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)rrorcrrr)r(rHrr;rrUrrrrr~5 s  z!ExtensionOptions.parse_field_bodyN)rrrr*r~rrrrr- 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(rrVrGrwrUrxrkrrrrAG s  zLineBlock.line_blockN)rrrr*rr rSrArrrrrA src@s&eZdZdZddZddZejZdS)r z0Second and subsequent explicit markup construct.cCs,||\}}|j|7_||_g|gfSr)rrNrkr rrrrDU szExplicit.explicit_markupcCs,||\}}|j|7_||_g|gfSr )rrNrkr rrrr\ szExplicit.anonymousN) rrrr*rDrrr rSrrrrr Q sr c@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$r s  z"SubstitutionDef.embedded_directivecCs|js|j|_tdSr%)rJr%rrkrQrrrrrz s  zSubstitutionDef.textN) rrrr*rrr6rrrrr$rrrrrrf 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(rrVrGrrrrrrS s z Text.blankcCs|r|d|dgSr%)rSrYrrreof 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;rGrkrnzDefinition listrD) rZdefinition_listdefinition_list_itemrNrJrrrr>rRrPr) r(rrVrGZdefinitionlistZdefinitionlistitemrkrrhrrrrI 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-rerNrrcrUrrrrcrLrSry)r(rrVrGrwrur&r3rxrrrrrvrrrr& 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-rrrrNrerQr) r(rrVrGrrrfrrrrrrrrrr 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) rJrErorquoted_literal_blockrrrrLr3rUrcr)r(rHrIrrkrrrrrrr 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.rrZ)r)rJrErr)rrrrLr3rUtermrr-reri) r(ZtermlinerHrIrrkitemnoderwZtermlistrxrrrrr) s(  zText.definition_list_itemz +: +c Cst|dkst||d|\}}t|d}|j|\|_|_|g}t t|D]}||}t |tj r|j |} t| dkr|d|7<q| d} t | } |d| 7<| ddD]} |tt| d| qqX|d|7<qX||fS)z9Return a definition_list's term and optional classifiers.r[rrNT)r_r=rrr-rJrLr3rUrPrrclassifier_delimiterrrrc classifierr) r(rrwrrxZ term_noderrTr;rrZtextnoderrrrr- s,      z Text.termN)rrrr*rDrrrSr'rIr&rrr*r)rrr/r-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'@ szSpecializedText.eofNcCstdSrrQrrrrr D szSpecializedText.invalid_input)NNN) rrrr*r'r rSrIr&rrrrrr17 s r1c@s eZdZdZddZddZdS)r"z.Second line of potential definition_list_item.cCs|jdgS)zNot a definition.r\)rJr}rYrrrr'R s zDefinition.eofcCs,||\}}|j|7_||_gdgfS)r(r!)r)rNrk)r(rrVrGr.rkrrrrIW szDefinition.indentN)rrrr*r'rIrrrrr"N 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) ror8r1r_state_correctioneofcheckrJrr transitionrUrN)r(rVmarkerrwr6rrrr'h s    zLine.eofcCsd|j\}}|d}t|dkr0||tj|d}||_|d|_|j |7_ gdgfS)zTransition marker.rrr3r[rD) rJrLror_r4rr6r3rUrN)r(rrVrGrrr7r6rrrrSw 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-rSrrrNrWrrrrcr5ryrU) r(rrVrGrwoverlinerur&rrr3rxrvrrrr 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_rr8r-rrrrN)r(rrVrGr9rrwrrrrr& 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-rerNr4)r(rVrrwrrrrrr8 s zLine.short_overlinecCs(|j|g|dd<tdddS)NrDr)rJr}rZStateCorrection)r(rVrrrrr4 s  zLine.state_correctionN)r[)r[) rrrr*r5r'rSrrIr&r8r4rrrrr_ 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)rxinitial_linenorIrrrr) szQuotedLiteralBlock.__init__cCs|r tn ||gfSdSr%r2rrrrrS 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}rx)r(rVrrrrrrrr' s      zQuotedLiteralBlock.eofcCs<|s td|j|jjd|jd|jtdS)Nz7QuotedLiteralBlock.indent: context should not be empty!rr) r=rxrcr-rrJrr}rQrrrrrI 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(rrVrGquoter!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)rxrcr-rrJrr}rQrrrrr s zQuotedLiteralBlock.textN)F)rrrr*rDrrrr)rSr'rIr:r<rrrrrr+ s   r+)T)Hr*Z __docformat__sysrtypesrrrrrrrrZdocutils.statemachiner r Zdocutils.nodesr rr rr rrrZdocutils.parsers.rst.languagesrZ_fallback_language_moduleZdocutils.utilsrrrrrrrrr r!r" Exceptionr#objectr$r+rBrCrr6r%r(r*r-rDrrrWr!r^rxrrrrr rrr1r"rr+rFrrrrsb    'n YT.,  8K