
Sc           @   s  d  Z  d Z d d l Z d d l Z d d l m Z m Z d d l m Z m	 Z	 m
 Z
 d d l m Z m Z d d l m Z m Z d d l m Z d d	 l m Z d d l Z d d
 l m Z m Z m Z m Z d d l m Z d d l m Z m Z m Z d d l m  Z  m! Z! d d l" Z" d e f d     YZ# d e f d     YZ$ d e f d     YZ% d e f d     YZ& d e' f d     YZ( d f  d     YZ) d e f d     YZ* d e f d     YZ+ d e f d     YZ, e- d   Z. d! f  d"     YZ/ e0 d#  d$ d%  Z1 e0 d&  d$ d'  Z2 d(   Z3 d) e, f d*     YZ4 d+ e4 f d,     YZ5 d- e4 f d.     YZ6 d/ e6 f d0     YZ7 d1 e6 f d2     YZ8 d3 e6 f d4     YZ9 d5 e6 f d6     YZ: d7 e6 f d8     YZ; d9 e6 e5 f d:     YZ< d; e: f d<     YZ= d= e6 f d>     YZ> d? e6 f d@     YZ? dA e4 f dB     YZ@ dC e, f dD     YZA dE eA f dF     YZB dG eB f dH     YZC dI eB f dJ     YZD dK e, f dL     YZE e4 e7 e8 e9 e: e; e> e= e? eA eC eD e@ e5 e< f ZF d S(M   s  
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.
t   reStructuredTextiN(   t   FunctionTypet
   MethodType(   t   nodest   statemachinet   utils(   t   ApplicationErrort	   DataError(   t   StateMachineWSt   StateWS(   t   fully_normalize_name(   t   whitespace_normalize_name(   t
   directivest	   languagest   tableparsert   roles(   t   en(   t   escape2nullt   unescapet   column_width(   t   punctuation_charst
   urischemest   MarkupErrorc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR   z   s    t   UnknownInterpretedRoleErrorc           B   s   e  Z RS(    (   R   R   (    (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR   {   s    t"   InterpretedRoleNotImplementedErrorc           B   s   e  Z RS(    (   R   R   (    (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR   |   s    t   ParserErrorc           B   s   e  Z RS(    (   R   R   (    (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR   }   s    t   MarkupMismatchc           B   s   e  Z RS(    (   R   R   (    (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR   ~   s    t   Structc           B   s   e  Z d  Z d   Z RS(   s3   Stores data attributes for dotted-attribute access.c         K   s   |  j  j |  d  S(   N(   t   __dict__t   update(   t   selft   keywordargs(    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyt   __init__   s    (   R   R   t   __doc__R"   (    (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR      s   t   RSTStateMachinec           B   s    e  Z d  Z d e d d  Z RS(   sy   
    reStructuredText's master StateMachine.

    The entry point to reStructuredText parsing is the `run()` method.
    i    c         C   s  t  j | j j  |  _ | |  _ | d k r9 t   } n  | j | j  t	 d | d | j
 d |  j d g  d d d t d |  |  _ | |  _ |  j | j  |  j j
 |  _
 | |  _ t j |  | | d	 | d
 } | g  k s t d   d |  _ |  _ d S(   s   
        Parse `input_lines` and modify the `document` node in place.

        Extend `StateMachineWS.run()`: set up parse-global data and
        run the StateMachine.
        t   documentt   reportert   languaget   title_stylest   section_leveli    t   section_bubble_up_kludget   inlinert   input_sourcet   sources.   RSTStateMachine.run() results should be empty!N(   R   t   get_languaget   settingst   language_codeR'   t   match_titlest   Nonet   Inlinert   init_customizationsR   R&   t   Falset   memoR%   t   attach_observert   note_sourcet   nodeR   t   runt   AssertionError(   R    t   input_linesR%   t   input_offsetR1   R+   t   results(    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR:      s*    					N(   R   R   R#   t   TrueR2   R:   (    (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR$      s   t   NestedStateMachinec           B   s   e  Z d  Z e d  Z RS(   sh   
    StateMachine run from within other StateMachine runs, to parse nested
    document structures.
    c         C   s   | |  _  | |  _ | j |  _ |  j |  j j  | j |  _ | j |  _ | |  _ t j	 |  | |  } | g  k s t
 d   | S(   s   
        Parse `input_lines` and populate a `docutils.nodes.document` instance.

        Extend `StateMachineWS.run()`: set up document-wide data.
        s1   NestedStateMachine.run() results should be empty!(   R1   R6   R%   R7   R8   R&   R'   R9   R   R:   R;   (   R    R<   R=   R6   R9   R1   R>   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR:      s    			(   R   R   R#   R?   R:   (    (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR@      s   t   RSTStatec           B   s   e  Z d  Z e Z g  Z e d  Z d   Z d   Z	 d   Z
 d   Z e d d d  Z d i  e d d d  Z d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z RS(   s`   
    reStructuredText State superclass.

    Contains methods used by all State subclasses.
    c         C   s.   i t  d 6d d 6|  _ t j |  | |  d  S(   Nt   state_classest   Bodyt   initial_state(   RB   t   nested_sm_kwargsR	   R"   (   R    t   state_machinet   debug(    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR"      s    
c         C   s   t  j |   |  j j } | |  _ | j |  _ | j |  _ | j |  _ |  j j |  _ t	 |  j d  s| |  j j
 |  j _
 n  d  S(   Nt   get_source_and_line(   R	   t   runtime_initRF   R6   R&   R+   R%   R9   t   parentt   hasattrRH   (   R    R6   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRI      s    	c         C   s,   y |  j  j |  Wn t k
 r' n Xd S(   sT   
        Jump to input line `abs_line_offset`, ignoring jumps past the end.
        N(   RF   t	   goto_linet   EOFError(   R    t   abs_line_offset(    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRL      s    c         C   s9   |  j  j d |  j j | | |  j j f  | d g  f S(   ss   
        Override `StateWS.no_match` to generate a system message.

        This code should never be run.
        sj   Internal error: no transition pattern match.  State: "%s"; transitions: %s; context: %s; current line: %r.N(   R&   t   severet	   __class__R   RF   t   lineR2   (   R    t   contextt   transitions(    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyt   no_match   s
    	c         C   s
   g  g  f S(   s   Called at beginning of file.(    (   R    RR   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyt   bof   s    c      	   C   sJ  d } | d k r( |  j } | d 7} n  | d k rJ |  j } | d 7} n  t |  } d }	 | d k r y |  j j   }	 Wq t k
 r q Xn  |	 s | d |  j |  }	 n  |	 j | | d |  j	 d | d | | d k r |  j j
 |	  n
 |	 j   |	 j   }
 | j rFt |  | d k rF|  j j t |  |  n  |
 S(	   sg   
        Create a new StateMachine rooted at `node` and run it over the input
        `block`.
        i    i   i   RG   R6   R9   R1   N(   R2   t	   nested_smRE   t   lent   nested_sm_cachet   popt
   IndexErrorRG   R:   R6   t   appendt   unlinkRN   RJ   RF   t	   next_line(   R    t   blockR=   R9   R1   t   state_machine_classt   state_machine_kwargst   use_defaultt   block_lengthRF   t
   new_offset(    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyt   nested_parse  s4    		
c      	   C   s   |	 d k r |  j }	 n  |
 d k r6 |  j j   }
 n  | |
 d <|	 d |  j |
  } | d k rj | } n  | | j | _ x1 | j   D]# \ } } t | j | | |  q W| j	 | | d |  j
 d | d | | j | j } | j   | j   | f S(   s   
        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.
        RD   RG   R6   R9   R1   N(   R2   RV   RE   t   copyRG   t   statest   blank_finisht   itemst   setattrR:   R6   R\   RN   (   R    R^   R=   R9   RD   Rg   t   blank_finish_statet   extra_settingsR1   R_   R`   RF   t   keyt   value(    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyt   nested_list_parse'  s"    
		
c         C   s/   |  j  | | |  r+ |  j | | |  n  d S(   s=   Check for a valid subsection and create one if it checks out.N(   t   check_subsectiont   new_subsection(   R    t   titleR-   t   stylet   linenot   messages(    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyt   sectionE  s    c         C   s  |  j  } | j } | j } y | j |  d } WnV t k
 r t |  | j k rh | j |  d S|  j |  j | |  7_ d Sn X| | k r | | _ t |  d k r t
 | _ n  |  j j t |  d  t  n  | | d k r d S|  j |  j | |  7_ d Sd S(   s  
        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.
        i   i   N(   R6   R(   R)   t   indext
   ValueErrorRW   R[   RJ   t   title_inconsistentR2   R?   R*   RF   t   previous_lineRM   (   R    R-   Rr   Rs   R6   R(   t   mylevelt   level(    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRo   J  s*    					c         C   s+   |  j  j d t j d |  d | } | S(   Ns   Title level inconsistent:t    RQ   (   R&   RO   R   t   literal_block(   R    t
   sourcetextRs   t   error(    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRx   s  s    		c         C   s=  |  j  } | j } | j d 7_ t j   } |  j | 7_ |  j | |  \ } } t j | d |  }	 t |	 j    }
 | d j	 |
  | |	 7} | | 7} | | 7} |  j
 j | |  |  j j d } |  j j   d } |  j |  j j | d | d | d t } |  j |  | j | k r0t  n  | | _ d S(   s?   Append new subsection to document tree. On return, check level.i   R|   t   namesR=   R9   R1   N(   R6   R)   R   Ru   RJ   t   inline_textRq   t   normalize_namet   astextR[   R%   t   note_implicit_targetRF   t   line_offsetRN   Rd   R<   R?   RL   RM   (   R    Rq   Rs   Rt   R6   Rz   t   section_nodet	   textnodest   title_messagest	   titlenodet   namet   offsett	   absoffsett   newabsoffset(    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRp   y  s,    		


	c   	      C   s   d j  |  j   } t j d |  ry t |  d k rC g  d f S| d d k rf | d  j   } n
 | d  } d } n | } d } |  j | |  \ } } t j | d	 |  } |  j j	 |  \ | _
 | _ | g | | f S(
   sW   
        Return a list (paragraph & messages) & a boolean: literal_block next?
        s   
s   (?<!\\)(\\\\)*::$i   i   is    
ii    R|   (   t   joint   rstript   ret   searchRW   R   R   t	   paragraphRF   RH   R-   RQ   (	   R    t   linesRs   t   datat   textt   literalnextR   Rt   t   p(    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR     s    

	c         C   s   |  j  j | | |  j |  j  S(   sX   
        Return 2 lists: nodes (text and inline elements), and system_messages.
        (   R+   t   parseR6   RJ   (   R    R   Rs   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR     s    c         C   s-   |  j  j   d } |  j j d | d | S(   Ni   s2   %s ends without a blank line; unexpected unindent.RQ   (   RF   t   abs_line_numberR&   t   warning(   R    t	   node_nameRs   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyt   unindent_warning  s    N(   R   R   R#   R@   RV   RX   R5   R"   RI   RL   RT   RU   R2   Rd   Rn   Ru   Ro   Rx   Rp   R   R   R   (    (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRA      s,   					&		)				c   
      C   s   |  \ } } } } g  } xF | D]> } t  |  t k rP | j t | d   q | j |  q Wd j |  } d t   }	 | r t j |	 t j	  S|	 Sd S(   s!  
    Build, compile and return a regular expression based on `definition`.

    :Parameter: `definition`: a 4-tuple (group name, prefix, suffix, parts),
        where "parts" is a list of regular expressions and/or regular
        expression definitions to be joined into an or-group.
    t   |s.   %(prefix)s(?P<%(name)s>%(or_group)s)%(suffix)sN(
   t   typet   tupleR[   t   build_regexpR2   R   t   localsR   t   compilet   UNICODE(
   t
   definitionR   R   t   prefixt   suffixt   partst   part_stringst   partt   or_groupt   regexp(    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR     s    R3   c           B   s  e  Z d  Z d   Z d   Z d   Z d e j e j f Z	 d e j
 e j e j f Z d Z d Z d Z d	 Z d
 Z d Z d Z d Z d e   Z d Z d Z d e	 d d d e d d d d d g f d d e d e d d d d d e d  d! e g f g f d" d# e e d$ g f g f Z e d% e e  d& e j e d' e e j  d( e j e d) e e j  d* e j d+ e   e j e j B d, e j d- e   e j e j B d. e j e d/ e  d0 e j e d1 e  d2 e j e d3 e  d4 e j e e   d5 e j e j B d6 e j d7 e d8 e   e j e j B d9 e j d: e   e j e j B d; e j d< e   e j e j B  Z  d=   Z! e" d>  Z# d?   Z$ d@   Z% dA   Z& dB   Z' dC   Z( dD   Z) dE   Z* dF   Z+ dG   Z, dH   Z- dI   Z. e" dJ  Z/ dK   Z0 dL   Z1 dM   Z2 dN Z3 dO   Z4 dP   Z5 i	 e% dQ 6e& dR 6e' dS 6e+ d 6e, d 6e. dT 6e- dU 6e/ dV 6e0 dW 6Z6 RS(X   s9   
    Parse inline markup; call the `parse()` method.
    c         C   s   |  j  j |  j f g |  _ d  S(   N(   t   patternst   urit   standalone_urit   implicit_dispatch(   R    (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR"     s    c         C   sZ   | j  r+ |  j j |  j j |  j f  n  | j rV |  j j |  j j |  j f  n  d S(   s6   Setting-based customizations; run when parsing begins.N(	   t   pep_referencesR   R[   R   t   pept   pep_referencet   rfc_referencest   rfct   rfc_reference(   R    R/   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR4     s    		c         C   sg  | j  |  _  | j |  _ | j |  _ | |  _ |  j j j } |  j } t |  } g  } g  }	 g  }
 x | r*| |  } | r&| j	   } | | d p | d p | d p | d } | |  | |  \ } } } } |	 j
 |  |
 | 7}
 | r'| |  j d j |	  |  7} | | 7} g  }	 q'qf Pqf Wd j |	  | } | r]| |  j | |  7} n  | |
 f S(   s  
        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.
        t   startt	   backquotet   refendt   fnendR|   (   R&   R%   R'   RJ   R   t   initialR   t   dispatchR   t	   groupdictR[   t   implicit_inlineR   (   R    R   Rs   R6   RJ   t   pattern_searchR   t	   remainingt	   processedt   unprocessedRt   t   matcht   groupst   methodt   beforet   inlinest   sysmessages(    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR     s<    				


u   (^|(?<=\s|[%s%s]))u   ($|(?=\s|[ %s%s%s]))s
   (?<![ \n])s   (?<![ \n\x00])s   (?<!(?<!\x00)[ \n\x00])s	   (?![ \n])s$   (?:(?!_)\w)+(?:[-._+:](?:(?!_)\w)+)*s%   [-_.!~*'()[\];/:@&=+$,%a-zA-Z0-9\x00]s   [>]s   [_~*/=+a-zA-Z0-9]s-   (?:%(urilast)s|%(uric)s(?=%(uri_end_delim)s))s"   [-_!~*'{|}/#?^`&=+$%a-zA-Z0-9\x00]s   
          %(emailc)s+(?:\.%(emailc)s+)*   # name
          (?<!\x00)@                      # at
          %(emailc)s+(?:\.%(emailc)s*)*   # host
          %(uri_end)s                     # final URI char
          t   initial_inlineR|   R   s   \*\*s   \*(?!\*)s   ``s   _`s   \|(?!\|)t   wholes   (?P<refname>%s)(?P<refend>__?)t   footnotelabels   \[s   (?P<fnend>\]_)s   [0-9]+s   \#(%s)?s   \*s   (?P<citationlabel>%s)R   s   (?P<role>(:%s:)?)s   `(?!`)R   t   emphasiss   (\*)t   strongs   (\*\*)t   interpreted_or_phrase_refs  
              %(non_unescaped_whitespace_escape_before)s
              (
                `
                (?P<suffix>
                  (?P<role>:%(simplename)s:)?
                  (?P<refend>__?)?
                )
              )
              %(end_string_suffix)s
              t   embedded_links%  
              (
                (?:[ \n]+|^)            # spaces or beginning of line/string
                <                       # open bracket
                %(non_whitespace_after)s
                ([^<>\x00]+(\x00_)?)    # anything but angle brackets & nulls
                                        # except escaped trailing low line
                %(non_whitespace_before)s
                >                       # close bracket w/o whitespace before
              )
              $                         # end of string
              t   literals   (``)t   targets   (`)t   substitution_refs
   (\|_{0,2})t   emailt   $R   s5  
                %(start_string_prefix)s
                (?P<whole>
                  (?P<absolute>           # absolute URI
                    (?P<scheme>             # 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>              # email address
                    s]   
                  )
                )
                %(end_string_suffix)s
                R   s  
                %(start_string_prefix)s
                (
                  (pep-(?P<pepnum1>\d+)(.txt)?) # reference to source file
                |
                  (PEP\s+(?P<pepnum2>\d+))      # reference by name
                )
                %(end_string_suffix)sR   s{   
                %(start_string_prefix)s
                (RFC(-|\s+)?(?P<rfcnum>\d+))
                %(end_string_suffix)sc         C   sl   | j  } | j   } | d k r% t S| | d } y | | j   } Wn t k
 r[ t SXt j | |  S(   s   Test if inline markup start-string is 'quoted'.

        'Quoted' in this context means the start-string is enclosed in a pair
        of matching opening/closing delimiters (not necessarily quotes)
        or at the end of the match.
        i    i   (   t   stringR   R5   t   endRZ   R?   R   t   match_chars(   R    R   R   R   t   prestartt	   poststart(    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyt   quoted_start  s    	c         C   sr  | j  } | j d  } | j d  } |  j |  rQ | |  g  | | g  d f S| j | |  }	 |	 r |	 j d  r t |	 j  |	 j d   |  }
 | |	 j d  } t | | | !d  } | |  | | |
  g | | g  |	 j d  f S|  j j d | j	 d | } t | | | !d  }
 t | | | !d  } |  j
 |
 | |  } | |  | g | | | g d f S(   NR   R|   i   s*   Inline %s start-string without end-string.RQ   (   R   R   R   R   R   R   t   groupR&   R   R   t   problematic(   R    R   Rs   t   end_patternt	   nodeclasst   restore_backslashesR   t
   matchstartt   matchendt   endmatchR   t   textendt	   rawsourcet   msgt   prb(    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyt
   inline_obj  s(    			c         C   sS   |  j  j | |  j  } t j | | d | } |  j  j |  } | j |  | S(   Nt   refid(   R%   t   set_idRJ   R   R   t   add_backref(   R    R   R   t   messaget   msgidR   t   prbid(    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR     s
    c         C   s@   |  j  | | |  j j t j  \ } } } } } | | | | f S(   N(   R   R   R   R   (   R    R   Rs   R   R   R   R   t	   endstring(    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR     s    *c         C   s@   |  j  | | |  j j t j  \ } } } } } | | | | f S(   N(   R   R   R   R   (   R    R   Rs   R   R   R   R   R   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR     s    *c         C   s  |  j  j } | j } | j d  } | j d  } | j d  } | j d  } d }	 | rs | d d !} d }	 n' |  j |  r | |  g  | | g  f S| j | |  }
 |
 r|
 j d  r| |
 j   } |
 j d  rg| rH|  j j	 d d | } t
 | | | !d  } |  j | | |  } | |  | g | | | g f S|
 j d	  d d !} d	 }	 n  |
 j |
 j d   } t
 | | | !d  } | d d
 k r5| r|  j j	 d |	 d | } t
 | | | !d  } |  j | | |  } | |  | g | | | g f S|  j | |  | | | | t
 |   St
 | | | !d  } |  j | | | |  \ } } | |  | | | | f Sn  |  j j	 d d | } t
 | | | !d  } |  j | | |  } | |  | g | | | g f S(   NR   t   roleR|   i   iR   sV   Multiple roles in interpreted text (both prefix and suffix present; only one allowed).RQ   R   t   _s=   Mismatch: both interpreted text role %s and reference suffix.sL   Inline interpreted text or phrase reference start-string without end-string.(   R   R   R   R   R   R   R   R   R&   R   R   R   t
   phrase_reft   interpreted(   R    R   Rs   R   R   R   R   t	   rolestartR   t   positionR   R   R   R   R   t   escapedR   t   nodelistRt   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR     s`    						
		c         C   s  |  j  j j |  } | rct | | j d    } t | j d  d t } | j d  r | j d  p |  j  j j	 |  r d } t
 | d   }	 t j | j d  d	 |	 }
 | d  |
 _ nq d
 } d j | j    }	 |  j |	  }	 |	 j d  r|	 d  d }	 n  t j | j d  d |	 }
 d |
 _ | sQt d |   n  | si|	 } qin d  }
 t
 |  } t j | | d t |  } | g } | d d k r|
 r| d k r|	 | d	 <|  j j |  q|
 r| d
 k r|	 | d <qd | d <n |
 r|
 d j |  | d k rW|	 | d	 <|  j j |
  |  j j |  n  |	 | d <|  j j |
 |  j  | j |
  n | | d	 <|  j j |  | | | g  f S(   Ni    i   R   R   s   \_R   ii   t   refnameR   R|   it   refuris   problem with embedded link: %rt   __t	   anonymousR   (   R   R   R   R   R   R   R?   t   endswithR   R   R   R   R   t   indirect_reference_nameR   t   splitt
   adjust_urit
   referencedR   R2   t	   referenceR   R%   t   note_refnameR[   t   note_indirect_targett   note_explicit_targetRJ   (   R    R   t   afterR   R   R   R   t	   aliastextt	   aliastypet   aliasR   R   R   t	   node_list(    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR     s\    		



c         C   s+   |  j  j j |  } | r# d | S| Sd  S(   Ns   mailto:(   R   R   R   (   R    R   R   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR   N  s    c   
      C   s   t  j | |  j | |  j  \ } } | rV | | | | | |   \ } } | | | f S|  j j d | d | }	 |  j | | |	  g | |	 g f Sd  S(   Ns#   Unknown interpreted text role "%s".RQ   (   R   R   R'   R&   R   R   (
   R    R   R   R   Rs   t   role_fnRt   R   t	   messages2R   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR   U  s    	
	c         C   sF   |  j  | | |  j j t j d t \ } } } } } | | | | f S(   NR   (   R   R   R   R   R?   (   R    R   Rs   R   R   R   R   R   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR   b  s    c   
      C   s   |  j  | | |  j j t j  \ } } } } } | r t | d t j  r t |  d k sd t  | d } t | j    }	 | d j	 |	  |  j
 j | |  j  n  | | | | f S(   Ni    i   R   (   R   R   R   R   t
   isinstanceRW   R;   R   R   R[   R%   R  RJ   (
   R    R   Rs   R   R   R   R   R   R   R   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyt   inline_internal_targeth  s    *
c         C   s  |  j  | | |  j j t j  \ } } } } } t |  d k r| d } t | t j  r| j   }	 |  j j	 | |	  | d d k r t j
 d |	 | f d  }
 | d d k r d |
 d	 <n  t |	  |
 d
 <|  j j |
  |
 | 7}
 |
 g } q qn  | | | | f S(   Ni   i    iR   s   |%s%sR|   iR   R   R   (   R   R   R   R   t   substitution_referenceRW   R
  R   R%   t   note_substitution_refR   R   R   (   R    R   Rs   R   R   R   R   R   t   subref_nodet   subref_textt   reference_node(    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  s  s$    

c   	      C   s~  | j  d  } t |  } | j } | | j d   } | | j d  } | j  d  r t j d | d | } | t j |  7} |  j j	 |  n t j
 d |  } | d d k r | d } d | d	 <|  j j |  nB | d
 k rd } d
 | d	 <|  j j |  n | t j |  7} | rG| | d <|  j j |  n  t j |  j j  rk| j   } n  | | g | g  f S(   se   
        Handles `nodes.footnote_reference` and `nodes.citation_reference`
        elements.
        R   R   t   citationlabels   [%s]_R   i    t   #i   t   autot   *R|   (   R   R   R   R   R   R   t   citation_referencet   TextR%   t   note_citation_reft   footnote_referencet   note_autofootnote_reft   note_symbol_footnote_reft   note_footnote_refR   t   get_trim_footnote_ref_spaceR/   R   (	   R    R   Rs   t   labelR   R   R   R   t   refnode(    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR    s6    		


	

c   
      C   s   | j  d  } t |  } t j | | j  d  | d t |  } | rY d | d <n | | d <|  j j |  | j } | j d  } | j	 d  }	 | |  | g | |	 g  f S(   NR   R   R   i   R   R   (
   R   R   R   R   R   R%   R   R   R   R   (
   R    R   Rs   R   t   referencenameR   t   referencenodeR   R   R   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR     s    
	c         C   s   |  j  | | d d S(   NR   i   (   R   (   R    R   Rs   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyt   anonymous_reference  s    c         C   s   | j  d  s. | j  d  j   t j k r | j  d  rF d } n d } | j  d  } t | d  } t j t | d  | d | | g St  d  S(	   Nt   schemeR   s   mailto:R|   R   i    i   R   (   R   t   lowerR   t   schemesR   R   R   R   (   R    R   Rs   t	   addschemeR   t	   unescaped(    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR     s    	c         C   s   | j  d  } | j d  r6 t | j  d   } n- | j d  r] t | j  d   } n t  |  j j j |  j j j | } t | d  } t	 j
 t | d  | d | g S(   Ni    s   pep-t   pepnum1t   PEPt   pepnum2i   R   (   R   t
   startswitht   intR   R%   R/   t   pep_base_urlt   pep_file_url_templateR   R   R   (   R    R   Rs   R   t   pepnumt   refR&  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR     s    s
   rfc%d.htmlc         C   s   | j  d  } | j d  rP t | j  d   } |  j j j |  j | } n t  t | d  } t	 j
 t | d  | d | g S(   Ni    t   RFCt   rfcnumi   R   (   R   R*  R+  R%   R/   t   rfc_base_urlt   rfc_urlR   R   R   R   (   R    R   Rs   R   R1  R/  R&  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR     s    c         C   s   | s
 g  Sx |  j  D]} \ } } | j |  } | r yE |  j | | j    |  | | |  |  j | | j   |  SWq t k
 r q Xq q Wt j t |  d t | d  g S(   s  
        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.
        R   i   (	   R   R   R   R   R   R   R   R  R   (   R    R   Rs   t   patternR   R   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR     s    &R  s   **t   `s   ]_R   R   R   (7   R   R   R#   R"   R4   R   R   t   openerst
   delimiterst   start_string_prefixt   closing_delimiterst   closerst   end_string_suffixt   non_whitespace_beforet   non_whitespace_escape_beforet&   non_unescaped_whitespace_escape_beforet   non_whitespace_aftert
   simplenamet   urict   uri_end_delimt   urilastR   t   uri_endt   emailct   email_patternR   R   R   R   R   R   t   VERBOSER   R   R5   R   R   R   R   R   R   R   R   R   R  R  R  R   R!  R   R   R3  R   R   R   (    (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR3     s   				3					 					4	;						#				
	
t   ai   c         C   s   t  |   | S(   N(   t   ord(   t   st   _zero(    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyt   _loweralpha_to_int  s    t   Ac         C   s   t  |   | S(   N(   RI  (   RJ  RK  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyt   _upperalpha_to_int	  s    c         C   s   t  j |  j    S(   N(   t   romant	   fromRomant   upper(   RJ  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyt   _lowerroman_to_int  s    RC   c           B   s*  e  Z d  Z e j j Z e   Z i e d d d d d d d d  d	 6e d d
 d d d d d d  d 6e d d
 d d d d d d  d 6e _ e j j	   e _
 d d d d d g e _ i d d 6d d 6d d 6d d 6d d 6e _ i e d 6e d 6e d 6e d 6e j d 6e _ i  e _ x8 e j D]- Z e j e j e d e j  e j e <q(We j d  Z e j d  Z e j d  Z i  Z d e d <d e d  <d! e d" <d# e d$ <d% e j e d& <d' e e d( <d) e e d* <d+ e e d, <d- e e d. <d/ e e d0 <xU e j
 D]J Z d1 e e j e j e j  e d& e j e j e j   f e e <qWi d2 d3 6d4 e d5 6d6 d7 6d8 e d9 6d: d; 6d< d= 6e d> 6e d? 6d@ dA 6dB dC 6dD e dE 6d
 dF 6Z! d Z" dG   Z# dH   Z$ e j dI e j  Z% dJ   Z& dK   Z' dL   Z( dM   Z) dN   Z* dO   Z+ d dP  Z- dQ   Z. dR   Z/ dS   Z0 dT   Z1 dU   Z2 dV   Z3 dW   Z4 dX   Z5 dY   Z6 dZ   Z7 d[   Z8 d\   Z9 d]   Z: d^   Z; d_   Z< d`   Z= da   Z> db   Z? dc   Z@ dd   ZA d
 d de  ZB d df  ZC dg   ZD e   ZE e dh e j di eF eG  e jH e j B dj e j dk eF eG  e jH e j B dl e j dm eF eG  e jH e j B  eE _! dn   ZI do   ZJ dp   ZK dq   ZL dr   ZM ds   ZN dt   ZO du   ZP dv   ZQ dw   ZR dx   ZS dy   ZT dz   ZU d{   ZV d|   ZW d}   ZX d~   ZY eI e j d eG jZ e jH e j B f eJ e j d eG jZ e jH e j B f eK e j d e jH e j B f eP e j d e jH e j B f eR e j d eG jZ e jH e j B f g eE _[ d   Z\ d   Z] d   Z^ d   Z_ d   Z` d   Za d   Zb RS(   s:   
    Generic classifier of the first line of a block.
    R   t   (R   t   )R   i   R   it   parensR|   i    t   rparent   .t   periodt   arabict
   loweralphat
   upperalphat
   lowerromant
   upperromans   [0-9]+s   [a-z]s   [A-Z]s
   [ivxlcdm]+s
   [IVXLCDM]+R   s   \+-[-+]+-\+ *$s   =+( +=+)+ *$s   =+[ =]*$s   [!-/:-@[-`{-~]t   nonalphanum7bits   [a-zA-Z]t   alphas   [a-zA-Z0-9]t   alphanums   [a-zA-Z0-9_-]t   alphanumplussJ   (%(arabic)s|%(loweralpha)s|%(upperalpha)s|%(lowerroman)s|%(upperroman)s|#)t   enums   %(alphanum)s%(alphanumplus)s*t   optnames%   (%(alpha)s%(alphanumplus)s*|<[^<>]+>)t   optargs!   (-|\+)%(alphanum)s( ?%(optarg)s)?t   shortopts"   (--|/)%(optname)s([ =]%(optarg)s)?t   longopts   (%(shortopt)s|%(longopt)s)t   options   (?P<%s>%s%s%s)u   [-+*•‣⁃]( +|$)t   bullets(   (%(parens)s|%(rparen)s|%(period)s)( +|$)t
   enumerators#   :(?![: ])([^:\\]|\\.)*(?<! ):( +|$)t   field_markers"   %(option)s(, %(option)s)*(  +| ?$)t   option_markers	   >>>( +|$)t   doctests   \|( +|$)t
   line_blockt   grid_table_topt   simple_table_tops
   \.\.( +|$)t   explicit_markups   __( +|$)R   s   (%(nonalphanum7bit)s)\1* *$RQ   R   c   	      C   sj   |  j  j   \ } } } } |  j | |  } |  j | 7_ | s] |  j |  j d  7_ n  | | g  f S(   s   Block quote.s   Block quote(   RF   t   get_indentedt   block_quoteRJ   R   (	   R    R   RR   t
   next_statet   indentedt   indentR   Rg   t   elements(    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRu  l  s    c         C   s   g  } x | r |  j  | |  \ } } } } } t j   } |  j | | |  | j |  | r |  j | |  \ }	 }
 | |	 7} | |
 7} n  | } x) | r | d r | d } | d 7} q Wq	 W| S(   Ni    i   (   t   split_attributionR   Rr  Rd   R[   t   parse_attribution(   R    Rt  R   Rv  t   blockquote_linest   attribution_linest   attribution_offsett   new_line_offsett
   blockquotet   attributionRt   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRr  v  s     	!

u   (---?(?!-)|—) *(?=[^ \n])c         C   s  d } t } x t t |   D] } | | j   } | r | r | | d k r |  j j |  } | r |  j | |  \ } }	 | r | | | !}
 |
 j | j	   d d |
 j |	 d d | |  |
 | | | | | f Sq n  t
 } q | } q W| d d d d f Sd S(   s  
        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).
        i   R   R   N(   R2   R5   t   rangeRW   R   t   attribution_patternR   t   check_attributiont	   trim_leftR   R?   (   R    Rt  R   t   blankt   nonblank_seent   iRQ   R   t   attribution_endRu  t   a_lines(    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRw    s(    

	
c         C   s   d } | d } x t | d t |   D]q } | | j   } | sJ Pn  | d k ru t |  t | j    } q* t |  t | j    | k r* d Sq* W| d 7} | | p d f S(   st   
        Check attribution shape.
        Return the index past the end of the attribution, and the indent.
        i   i    N(   NN(   R2   R  RW   R   t   lstrip(   R    Rt  t   attribution_startRu  R  RQ   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR    s    
 "
c         C   s}   d j  |  j   } |  j j   | } |  j | |  \ } } t j | d |  } |  j j |  \ | _ | _	 | | f S(   Ns   
R|   (
   R   R   RF   R   R   R   R~  RH   R-   RQ   (   R    Rt  R   R   Rs   R   Rt   R9   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRx    s    c   	   
   C   s   t  j   } |  j | 7_ | j d | d <|  j | j    \ } } | | 7} |  j j d } |  j |  j j	 | d |  j j
   d d | d d d | \ } } |  j |  | s |  j |  j d	  7_ n  g  | g  f S(
   s   Bullet list item.i    Rh  i   R=   R9   RD   t
   BulletListRg   s   Bullet list(   R   t   bullet_listRJ   R   t	   list_itemR   RF   R   Rn   R<   RN   RL   R   (	   R    R   RR   Rs  t
   bulletlistR  Rg   R   R|  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRh    s    
c         C   s   |  j  j | r. |  j  j |  \ } } } n |  j  j |  \ } } } } t j d j |   } | r |  j | d | d | n  | | f S(   Ns   
R=   R9   (   RF   RQ   t   get_known_indentedt   get_first_known_indentedR   R  R   Rd   (   R    Ru  Rt  R   Rg   t   listitem(    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR    s    
c         C   s  |  j  |  \ } } } } |  j | | |  sB t j d   n  t j   } |  j | 7_ | d k rv d | d <n
 | | d <|  j j | j	 | d <|  j j | j
 | d <| d k r | | d <|  j j d	 | | f  }	 |  j |	 7_ n  |  j | j    \ }
 } | |
 7} |  j j d } |  j |  j j | d
 |  j j   d d | d d d | d i | d 6| d 6| d k d 6\ } } |  j |  | s|  j |  j d  7_ n  g  | g  f S(   s   Enumerated List ItemR   R  RY  t   enumtypeR   R   i   R   s<   Enumerated list start value not ordinal-1: "%s" (ordinal %s)R=   R9   RD   t   EnumeratedListRg   Rk   t   lastordinalt   formatR  s   Enumerated list(   t   parse_enumeratort   is_enumerated_list_itemR   t   TransitionCorrectionR   t   enumerated_listRJ   Rb  t
   formatinfoR   R   R&   t   infoR  R   RF   R   Rn   R<   RN   RL   R   (   R    R   RR   Rs  R  t   sequenceR   t   ordinalt   enumlistR   R  Rg   R   t   newline_offset(    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRi    s>    

	

c         C   s  | j    } d } x. |  j j D] } | | r Pq q Wt d   | | |  j j | j |  j j | j !} | d k r d } n} | r y& |  j j | j |  r | } n  Wq t	 k
 r t d |   q Xn* | d k r d } n | d k r d } n  | sIx@ |  j j
 D]# } |  j j | j |  rPqqWt d	   n  | d k r^d
 } n7 y |  j j | |  } Wn t j k
 rd } n X| | | | f S(   sA  
        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.
        R|   s   enumerator format not matchedR  s   unknown enumerator sequence: %sR  R\  t   IR]  s   enumerator sequence not matchedi   N(   R   Rb  t   formatsR   R  R   R   t   sequenceregexpsR   t   KeyErrort	   sequencest
   convertersRO  t   InvalidRomanNumeralErrorR2   (   R    R   t   expected_sequenceR   R  R  R   R  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR    sB    
				
c         C   s   | d k r d Sy |  j j   } Wn t k
 rD |  j j   d SX|  j j   | d  j   sf d S|  j | d | |  } | r | \ } } y& | j |  s | j |  r d SWq t k
 r q Xn  d S(   s   
        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.
        i   N(	   R2   RF   R]   RM   Ry   t   stript   make_enumeratorR*  t	   TypeError(   R    R  R  R  R]   t   resultt   next_enumeratort   auto_enumerator(    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  H  s(    c         C   sO  | d k r d } n | d k r0 t  |  } n | j d  rl | d k rO d St | t d  d  } nM | j d  r y t j |  } Wq t j k
 r d SXn t d |   | j	 d	  r | j
   } n. | j	 d
  r | j   } n t d |   |  j j | } | j | | j d } | j d | j d } | | f S(   s   
        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.
        R  RY  R_  i   RH  i   RO  s!   unknown enumerator sequence: "%s"R#  RQ  t    N(   t   strR   R2   t   chrRI  RO  t   toRomant
   RomanErrorR   R*  R#  RQ  Rb  R  R   R   (   R    R  R  R  Ri  R  R  R  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  e  s2    	

c   	   
   C   s   t  j   } |  j | 7_ |  j |  \ } } | | 7} |  j j d } |  j |  j j | d |  j j   d d | d d d | \ } } |  j	 |  | s |  j |  j
 d  7_ n  g  | g  f S(   s   Field list item.i   R=   R9   RD   t	   FieldListRg   s
   Field list(   R   t
   field_listRJ   t   fieldRF   R   Rn   R<   RN   RL   R   (	   R    R   RR   Rs  R  R  Rg   R   R  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRj    s    
c         C   s   |  j  |  } |  j j   \ } } |  j j   } |  j j | j    \ } } } }	 t j   }
 | |
 _ | |
 _	 |  j
 | |  \ } } |
 t j | d |  7}
 t j d j |  |  } |
 | 7}
 | r |  j | | |  n  |
 |	 f S(   NR|   s   
(   t   parse_field_markerRF   RH   R   R  R   R   R  R-   RQ   R   t
   field_namet
   field_bodyR   t   parse_field_body(   R    R   R   t   srct   srclineRs   Rt  Ru  R   Rg   t
   field_nodet
   name_nodest   name_messagesR  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR    s    $		
c         C   s'   | j    d } | | j d   } | S(   s6   Extract & return field name from a field marker match.i   t   :(   R   t   rfind(   R    R   R  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR    s    c         C   s   |  j  | d | d | d  S(   NR=   R9   (   Rd   (   R    Rt  R   R9   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR    s    c      
   C   sx  t  j   } y |  j |  \ } } Wn t k
 r } |  j j d |  } |  j | 7_ |  j j | j	    \ }	 }
 } } |  j
 |	 |  } |  j | 7_ | s |  j |  j d  7_ n  g  | g  f SX|  j | 7_ | | 7} |  j j d } |  j |  j j | d |  j j   d d | d d d | \ } } |  j |  | sk|  j |  j d  7_ n  g  | g  f S(	   s   Option list item.u   Invalid option list marker: %ss   Option listi   R=   R9   RD   t
   OptionListRg   (   R   t   option_listt   option_list_itemR   R&   R   RJ   RF   R  R   Rr  R   R   Rn   R<   RN   RL   (   R    R   RR   Rs  t
   optionlistR  Rg   R   R   Rt  Ru  R   Rv  R   R  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRk    s2    
$
c         C   s   |  j  j   } |  j |  } |  j  j | j    \ } } } } | sg |  j |  t j d   n  t j	 d |  } t j
 d j |   }	 t j d | |	  }
 | r |  j | d | d |	 n  |
 | f S(   NR   R|   s   
R=   R9   (   RF   RN   t   parse_option_markerR  R   RL   R   R  R   t   option_groupt   descriptionR   R  Rd   (   R    R   R   t   optionsRt  Ru  R   Rg   R  R  R  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR    s    $	
c   	      C   s  g  } | j    j   j d  } x| D]} | j   } d } | d j d d  } t |  d k r{ | | d *d } ny t | d  d k r | d j d  r | d j d  s | d j d	  r | d d  | d d g | d *d
 } n  t |  d k rI| d j d  rI| d j d  rId j | d  g | d )n  d t |  k  ofd k n rt j |  } | t j	 | d | d  7} t |  d k r| t j
 | d | d d | 7} n  | j |  q( t d t |  | f   q( W| S(   s   
        Return a list of `node.option` and `node.option_argument` objects,
        parsed from an option marker match.

        :Exception: `MarkupError` for invalid option markers.
        s   , R  i    t   =i   i   t   -s   --t   +R|   t   <it   >t	   delimiters;   wrong number of option tokens (=%s), should be 1 or 2: "%s"(   R   R   R   RW   R*  R   R   R   Rg  t   option_stringt   option_argumentR[   R   (	   R    R   t   optlistt   optionstringst   optionstringt   tokensR  t   firstoptRg  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR    s:    
	 	%"c         C   s@   d j  |  j j    } |  j t j | |  7_ g  | g  f S(   Ns   
(   R   RF   t   get_text_blockRJ   R   t   doctest_block(   R    R   RR   Rs  R   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRl    s    c      
   C   sB  t  j   } |  j | 7_ |  j j   } |  j | |  \ } } } | | 7} |  j | 7_ | s |  j j d }	 |  j |  j j |	 d |  j j	   d d | d d d d \ }
 } |  j
 |
  n  | s |  j |  j j d d	 | d 7_ n  t |  r5| d j d
 k r%d | d _ n  |  j |  n  g  | g  f S(   s   First line of a line block.i   R=   R9   RD   t	   LineBlockRg   i    s%   Line block ends without a blank line.RQ   N(   R   Rm  RJ   RF   R   t   line_block_lineR   Rn   R<   RN   RL   R&   R   RW   Ru  R2   t   nest_line_block_lines(   R    R   RR   Rs  R^   Rs   RQ   Rt   Rg   R   R|  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRm    s.    
c         C   s   |  j  j | j   d t \ } } } } d j |  } |  j | |  \ } }	 t j | d |  }
 | j j	   d k r t
 | j d   d |
 _ n  |
 |	 | f S(   s(   Return one line element of a line_block.t   until_blanku   
R|   R   i   (   RF   R  R   R?   R   R   R   RQ   R   R   RW   R   Ru  (   R    R   Rs   Rt  Ru  R   Rg   R   t
   text_nodesRt   RQ   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  ,  s    c         C   sh   xT t  d t |   D]= } t | | d d   d  k r | | d j | | _ q q W|  j |  d  S(   Ni   Ru  (   R  RW   t   getattrR2   Ru  t   nest_line_block_segment(   R    R^   Rv   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  8  s    c         C   s   g  | D] } | j  ^ q } t |  } g  } t j   } xo | D]g } | j  | k rf | j |  qA t |  r |  j |  | j |  t j   } n  | j |  qA Wt |  r |  j |  | j |  n  | | (d  S(   N(   Ru  t   minR   Rm  R[   RW   R  (   R    R^   t   itemt   indentst   leastt	   new_itemst	   new_block(    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  >  s     c         C   s   |  j  | | | |  j t j  S(   s   Top border of a full table.(   t	   table_topt   isolate_grid_tableR   t   GridTableParser(   R    R   RR   Rs  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRn  Q  s    c         C   s   |  j  | | | |  j t j  S(   s   Top border of a simple table.(   R  t   isolate_simple_tableR   t   SimpleTableParser(   R    R   RR   Rs  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRo  W  s    c   	      C   sq   |  j  | |  \ } } |  j | 7_ | sd |  j j d d |  j j   d } |  j | 7_ n  g  | g  f S(   s   Top border of a generic table.s    Blank line required after table.RQ   i   (   t   tableRJ   R&   R   RF   R   (	   R    R   RR   Rs  t   isolate_functiont   parser_classR   Rg   R   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  ]  s    	c         C   s   |   \ } } } | r yX |   } | j  |  } |  j j   t |  d } |  j | |  }	 |	 g | }
 Wq t j k
 r } |  j | d j | j	  d | j
 | }
 q Xn | }
 |
 | f S(   s   Parse a table.i   R  R   (   R   RF   R   RW   t   build_tableR   t   TableMarkupErrort   malformed_tableR   t   argsR   (   R    R  R  R^   Rt   Rg   t   parsert	   tabledatat	   tablelineR  R   t   err(    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  i  s    	c   	      C   s>  g  } d } y |  j  j d t  } WnS t j k
 rz } | j \ } } } | j |  j j d d | d |  d } n X| j	   | j
 |  j  t | d j    } xm t t |   D]Y } | | j   | | <| | d d k r d } |  j  j t |  |  | | 3Pq q W|  j j | d  sd } x t t |  d	 d d  D]I } |  j j | |  rT|  j  j t |  | d  | | d 3PqTqTW| j |  j |   g  | | f Sn  xg t t |   D]S } t | |  | k s
| | d d k r| j |  j |   g  | | f SqW| | | f S(
   Ni   t
   flush_lefts   Unexpected indentation.R-   RQ   i    s   +|ii   (   RF   R  R?   R   t   UnexpectedIndentationErrorR  R[   R&   R   t
   disconnectt   pad_double_widtht   double_width_pad_charRW   R  R  Ry   t   grid_table_top_patR   t   extendR  (	   R    Rt   Rg   R^   R  R  R  t   widthR  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  {  sB    

#*c         C   s1  |  j  j } |  j  j } t |  d } t | | j    } |  j j } d } d  } | d } xq| | k rS| | }	 | |	  }
 |
 rFt |	 j    | k r |  j  j | |  |  j	 | | | d !d  } g  | | | k p | | d j   f S| d 7} | } | d k s9| | k s9| | d j   rF| } PqFn  | d 7} qc W| rd } |  j  j | |  | | | d !} n( d } |  j  j | | d  | | } |  j	 | d |  } g  | | f S|  j  j | |  | | | d !} | j
 |  j  | g  | | k p-| | d j   f S(   Ni   i    s5   Bottom/header table border does not match top border.i   s$    or no blank line after table bottomR|   s   No bottom table border found%s.(   RF   R   R<   RW   R  t   simple_table_border_patR   R2   R]   R  R  R  (   R    R   R   t   limitt   toplent   pattern_matcht   foundt   found_atR  RQ   R   Rt   R   t   extraR^   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR    sJ    

(
-
c         C   s   | j  |  j d  d j |  } d } |  j j   t |  d } | r\ | d | 7} n  |  j j | t j	 | |  d | | } | g S(   NR|   s   
s   Malformed table.i   RQ   (
   t   replaceR  R   RF   R   RW   R&   R   R   R}   (   R    R^   t   detailR   R   R   t	   startlineR   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR    s    c         C   s  | \ } } } t  j   } t  j d t |   } | | 7} xJ | D]B }	 t  j d |	  }
 | r| d |
 j d <| d 8} n  | |
 7} qD W| r t  j   } | | 7} x' | D] } | |  j | |  7} q Wn  t  j   } | | 7} x$ | D] } | |  j | |  7} q W| S(   Nt   colst   colwidthi   t   stub(	   R   R  t   tgroupRW   t   colspect
   attributest   theadt   build_table_rowt   tbody(   R    R  R  t   stub_columnst	   colwidthst   headrowst   bodyrowsR  R	  R  R
  R  t   rowR  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR    s(    


c         C   s   t  j   } x | D] } | d  k r+ q n  | \ } } } } i  }	 | rV | |	 d <n  | ri | |	 d <n  t  j |	   }
 | |
 7} d j |  r |  j | d | | d |
 q q W| S(   Nt   morerowst   morecolsR|   R=   R9   (   R   R  R2   t   entryR   Rd   (   R    t   rowdataR  R  t   cellR  R  R   t	   cellblockR  R  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR    s     
R   s?  
                            (
                              _               # anonymous target
                            |               # *OR*
                              (?!_)           # no underscore at the beginning
                              (?P<quote>`?)   # optional open quote
                              (?![ `])        # first char. not space or
                                              # backquote
                              (?P<name>       # reference name
                                .+?
                              )
                              %(non_whitespace_escape_before)s
                              (?P=quote)      # close quote if open quote used
                            )
                            (?<!(?<!\x00):) # no unescaped colon at end
                            %(non_whitespace_escape_before)s
                            [ ]?            # optional space
                            :               # end of reference name
                            ([ ]+|$)        # followed by whitespace
                            R   s  
                               (
                                 (?P<simple>%(simplename)s)_
                               |                  # *OR*
                                 `                  # open backquote
                                 (?![ ])            # not space
                                 (?P<phrase>.+?)    # hyperlink phrase
                                 %(non_whitespace_escape_before)s
                                 `_                 # close backquote,
                                                    # reference mark
                               )
                               $                  # end of string
                               t   substitutions  
                                  (
                                    (?![ ])          # first char. not space
                                    (?P<name>.+?)    # substitution text
                                    %(non_whitespace_escape_before)s
                                    \|               # close delimiter
                                  )
                                  ([ ]+|$)           # followed by whitespace
                                  c         C   s  |  j  j   \ } } |  j  j | j    \ } } } } | j d  } t |  }	 t j d j |   }
 | |
 _	 | |
 _
 |	 d d k r |	 d }	 d |
 d <|	 r |
 d j |	  n  |  j j |
  nf |	 d k r d }	 d |
 d <|  j j |
  n7 |
 t j d |  7}
 |
 d j |	  |  j j |
  |	 rQ|  j j |
 |
  n |  j j |
 |
  | r|  j | d	 | d
 |
 n  |
 g | f S(   Ni   s   
i    R  R  R   R  R|   R=   R9   (   RF   RH   R  R   R   R   R   t   footnoteR   R-   RQ   R[   R%   t   note_autofootnotet   note_symbol_footnoteR  t   note_footnoteR  R   Rd   (   R    R   R  R  Rt  Ru  R   Rg   R  R   R  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  0  s4    $		


c         C   s   |  j  j   \ } } |  j  j | j    \ } } } } | j d  } t |  }	 t j d j |   }
 | |
 _	 | |
 _
 |
 t j d |  7}
 |
 d j |	  |  j j |
  |  j j |
 |
  | r |  j | d | d |
 n  |
 g | f S(   Ni   s   
R|   R   R=   R9   (   RF   RH   R  R   R   R   R   t   citationR   R-   RQ   R  R[   R%   t   note_citationR  Rd   (   R    R   R  R  Rt  Ru  R   Rg   R  R   R  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  O  s    $		c         C   sd  |  j  j j } |  j j   } |  j j | j   d t d t \ } } } } | j	 | j    d j
 |  } g  | D] }	 t |	  ^ qu } | d }
 d } x_ t r | j |
  } | r Pn  | d 7} y |
 | | 7}
 Wq t k
 r t d   q Xq W| | 4| d d | j   t |
  d j   | d <|  j | | | | j d   } | g | f S(	   NR  t   strip_indents   
i    i   s   malformed hyperlink target.R  R   (   t   explicitR   R   RF   R   R  R   R?   R5   R   R   R   R   RZ   R   RW   R  t   make_targetR   (   R    R   R4  Rs   R^   Ru  R   Rg   t	   blocktextRQ   R   t
   blockindext   targetmatchR   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyt   hyperlink_target`  s,    	' 
	
0c         C   s   |  j  | | |  \ } } | d k rx t j | d d t |  } | | _ |  j | d | |  |  j j |  | S| d k r t j | d  } |  j | | | |  | S| Sd  S(   NR   R|   R   (   t   parse_targetR   R   R   R   t
   add_targetR%   R  (   R    R^   t
   block_textRs   t   target_namet   target_typeR   R   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR#  y  s    	c         C   s   | rj | d j    d d k rj d j g  | D] } | j    ^ q-  } |  j |  } | rj d | f Sn  d j g  | D] } d j | j    ^ qw  } d t |  f S(   s   
        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
        iR   R  R   R|   R   (   R  R   t   is_referenceR   R   (   R    R^   R*  Rs   RQ   R   R   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR(    s    
 (1c         C   sJ   |  j  j j j t |   } | s( d  St | j d  pF | j d   S(   Nt   simplet   phrase(   R"  R   R   R   R   R2   R   R   (   R    R   R   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR-    s
    c         C   s   | | _  | r t t |   } | d j |  | rp |  j j |  } | r] | | d <qp t d |   n  |  j j | |  j	  n- | r | | d <n  d | d <|  j j
 |  d  S(   NR   R   s   problem with URI: %ri   R   (   RQ   R   R   R[   R+   R   R   R%   R  RJ   t   note_anonymous_target(   R    t
   targetnameR   R   Rs   R   R   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR)    s    	
c      
   C   s  |  j  j j } |  j j   \ } } |  j j | j   d t \ } } } } | j | j    d j	 |  }	 | j
   t | d j    }
 d } xo t r| j |
  } | r Pn  | d 7} y" |
 d t | | j    }
 Wq t k
 rt d   q Xq W| | 4| d j   d | j   t |
  d d !| d <| d s^| d =| d 7} n  x% | r| d j   r| j   qaW| j d  } t j |	  } | | _ | | _ | s|  j j d	 | t j |	 |	  d
 | d | } | g | f S| d j   | d <| d j t j |   |  j | d | d | d d d | \ } } d } xZ | D]Q } t | t j   pt | t j!  s|  j" | | 7_" | | =qc| d 7} qcWx | j# t j$  D]p } |  j% |  rt j d | j&   j    } |  j j' d | t j |	 |	  d
 | d | } | g | f SqWt |  d k r|  j j d | t j |	 |	  d
 | d | } | g | f S|  j( j) | | |  j"  | g | f S(   NR!  s   
i    i   R  s"   malformed substitution definition.iR   s.   Substitution definition "%s" missing contents.R-   RQ   R   R=   R9   RD   t   SubstitutionDefRg   R|   s1   Substitution definition contains illegal element:s.   Substitution definition "%s" empty or invalid.(*   R"  R   R  RF   RH   R  R   R5   R   R   R  R   R   R?   R   R  RZ   R   RW   RY   R   R   t   substitution_definitionR-   RQ   R&   R   R}   R[   R   Rn   R
  t   InlineR  RJ   t   traverset   Elementt*   disallowed_inside_substitution_definitionst   pformatR   R%   t   note_substitution_def(   R    R   R4  R  R  R^   Ru  R   Rg   R$  R   R%  t   subdefmatcht   subnamet   substitution_nodeR   t   new_abs_offsetR  R9   R8  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyt   substitution_def  s     
	
"3
			

			c         C   sX   | d sL t  | t j  r+ | j d  sL t  | t j  rP | j d  rP d Sd Sd  S(   Nt   idsR   R  i   i    (   R
  R   R   t   getR  (   R    R9   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR7    s
    
!!c         K   so   | j  d  } t j | |  j j |  j  \ } } |  j | 7_ | r^ |  j | | | |  S|  j |  Sd S(   s?   Returns a 2-tuple: list of nodes, and a "blank finish" boolean.i   N(	   R   R   t	   directiveR6   R'   R%   RJ   t   run_directivet   unknown_directive(   R    R   t   option_presetst	   type_namet   directive_classRt   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRA    s    c      
   C   sB  t  | t t f  r4 d d l m } | |  } n  |  j j   } |  j j } |  j j | j	   d d \ } }	 }
 } d j
 |  j j | |  j j d ! } y( |  j | |
 | |  \ } } } } WnZ t k
 r#} |  j j d | d j
 | j  f t j | |  d	 | } | g | f SX| | | | | | | | |  |  j 	 } y | j   } Wn\ t j j j k
 r} |  j j | j | j d	 | } | t j | |  7} | g } n Xt  | t  st d
 |   xM t t |   D]9 } t  | | t j  st d | | | | f   qW| | p>|  j j    f S(   s  
        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.
        i(   t   convert_directive_functiont	   strip_topi    s   
i   s   Error in "%s" directive:
%s.R  RQ   s+   Directive "%s" must return a list of nodes.s6   Directive "%s" returned non-Node object (index %s): %r(!   R
  R   R   t   docutils.parsers.rstRG  RF   R   R   R  R   R   R<   t   parse_directive_blockR   R&   R   R  R   R}   R:   t   docutilst   parserst   rstt   DirectiveErrort   system_messageR{   R   t   listR;   R  RW   t   Nodet   is_next_line_blank(   R    RA  R   RE  RD  RG  Rs   t   initial_line_offsetRt  Ru  R   Rg   R*  t	   argumentsR  t   contentt   content_offsetR  R   t   directive_instanceR  t   msg_nodeR  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRB    sH    		c         C   s  | j  } | j } | r@ | d j   r@ | j   | d 7} n  x% | rg | d j   rg | j   qC W| r | j s | j s | r x4 t |  D] \ } } | j   s Pq q W| d 7} | |  }	 | | d }
 | | d } n | }
 | } g  }	 | r|  j | | |	  \ } }	 n i  } |	 rX| j p7| j rX|	 | | }
 | } g  }	 n  x/ |
 r|
 d j   r|
 j   | d 7} q[W| j s| j r|  j	 | |	  } n g  } |
 r| rt
 d   n  | | |
 | f S(   Ni    i   is   no content permitted(   t   option_spect   has_contentR  t
   trim_startt   trim_endt   required_argumentst   optional_argumentst	   enumeratet   parse_directive_optionst   parse_directive_argumentsR   (   R    Rt  R   RA  RD  RY  RZ  R  RQ   t	   arg_blockRU  RV  R  RT  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRJ  G  sN    		
	


	
c   
      C   s   | j    } xQ t |  D]= \ } } t j t j d |  r | | } | |  } Pq q Wg  } | r |  j | |  \ } }	 | r | j |	  q t |	   n  | | f S(   NRj  (	   Re   R_  R   R   RC   R   t   parse_extension_optionsR   R   (
   R    RD  RY  Rb  R  R  RQ   t	   opt_blockt   successR   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR`  u  s    

	c         C   s   | j  } | j } d j |  } | j   } t |  | k  r^ t d | t |  f   n_ t |  | | k r | j r | j d  | | d  } q t d | | t |  f   n  | S(   Ns   
s$   %s argument(s) required, %s suppliedi   s+   maximum %s argument(s) allowed, %s supplied(   R]  R^  R   R   RW   R   t   final_argument_whitespaceR2   (   R    RA  Rb  t   requiredt   optionalt   arg_textRT  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRa    s    			c         C   s   t  j   } |  j | d | d d d t \ } } | t |  k rI d Sy t j | |  } Wn t k
 r } d d | j d f St	 t
 f k
 r } d d d j | j  f St j k
 r } d d	 d j | j  f SX| r d
 | f Sd Sd S(   s  
        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.
        i    RD   t   ExtensionOptionsRg   s   invalid option blocks   unknown option: "%s"s   invalid option value: %sR  s   invalid option data: %si   s   option data incompletely parsedN(   i    s   invalid option block(   i    s   option data incompletely parsed(   R   R  Rn   R?   RW   R   t   extract_extension_optionsR  R  Rw   R  R   t   ExtensionOptionError(   R    RY  t	   datalinesR9   R  Rg   R  R  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRc    s"    
c   	      C   sz   |  j  j   } |  j  j d d t \ } } } } d j |  } |  j j d | t j | |  d | } | g | f S(   Ni    R!  s   
s   Unknown directive type "%s".RQ   (	   RF   R   R  R5   R   R&   R   R   R}   (	   R    RE  Rs   Rt  Ru  R   Rg   R   R   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRC    s    $	c         C   s   | j  | j   j   r< |  j j   r< t j   g d f S|  j j | j    \ } } } } x% | r | d j   r | j   qc Wd j	 |  } t j | |  g | f S(   Ni   is   
(
   R   R   R  RF   RR  R   t   commentR  R\  R   (   R    R   Rt  Ru  R   Rg   R   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRn    s    $s  
                      \.\.[ ]+          # 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
                      s   
                      \.\.[ ]+          # explicit markup start
                      \[(%s)\]          # citation label
                      ([ ]+|$)          # whitespace or end of line
                      s   
                      \.\.[ ]+          # explicit markup start
                      _                 # target indicator
                      (?![ ]|$)         # first char. not space or EOL
                      s   
                      \.\.[ ]+          # explicit markup start
                      \|                # substitution indicator
                      (?![ ]|$)         # first char. not space or EOL
                      sK  
                      \.\.[ ]+          # explicit markup start
                      (%s)              # directive name
                      [ ]?              # optional space
                      ::                # directive delimiter
                      ([ ]+|$)          # whitespace or end of line
                      c         C   s>   |  j  |  \ } } |  j | 7_ |  j |  g  | g  f S(   s3   Footnotes, hyperlink targets, directives, comments.(   t   explicit_constructRJ   t   explicit_list(   R    R   RR   Rs  R   Rg   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRp    s    c         C   s   g  } x |  j  j D] \ } } | j | j  } | r y | |  |  SWq t k
 r } |  j j   } d j | j  } | j	 |  j
 j | d |  Pq Xq q W|  j |  \ }	 }
 |	 | |
 f S(   s>   Determine which explicit construct this is, parse & return it.R  RQ   (   R"  t
   constructsR   R   R   RF   R   R   R  R[   R&   R   Rn  (   R    R   t   errorsR   R4  t   expmatchR   Rs   R   R   Rg   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRo  	  s    c         C   s   |  j  j d } |  j |  j  j | d |  j  j   d d |  j d d d | d |  j  j \ } } |  j |  | s |  j |  j d  7_ n  d	 S(
   s   
        Create a nested state machine for a series of explicit markup
        constructs (including anonymous hyperlink targets).
        i   R=   R9   RD   t   ExplicitRg   R1   s   Explicit markupN(	   RF   R   Rn   R<   RN   RJ   R1   RL   R   (   R    Rg   R   R  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRp  	  s    c         C   s>   |  j  |  \ } } |  j | 7_ |  j |  g  | g  f S(   s   Anonymous hyperlink targets.(   t   anonymous_targetRJ   Rp  (   R    R   RR   Rs  R   Rg   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR   !	  s    c   
      C   s   |  j  j   } |  j  j | j   d t \ } } } } | j | j    d j |  } g  | D] } t |  ^ q` } |  j | | | d  }	 |	 g | f S(   NR  s   
R|   (	   RF   R   R  R   R?   R   R   R   R#  (
   R    R   Rs   R^   Ru  R   Rg   R$  RQ   R   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRu  (	  s     c         C   s   |  j  j r | j g d g  f S| j j   d k rF t j d   n t | j j    d k  r |  j j d d |  j  j	   } |  j
 | 7_
 t j d   nX |  j  j } |  j j d t j | |  d |  j  j	   } |  j
 | 7_
 g  | g  f Sd S(	   s,   Section title overline or transition marker.t   Lines   ::R   i   se   Unexpected possible title overline or transition.
Treating it as ordinary text because it's so short.RQ   s'   Unexpected section title or transition.N(   RF   R1   R   R  R   R  RW   R&   R  R   RJ   RQ   RO   R   R}   (   R    R   RR   Rs  R   R$  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRQ   2	  s"    		c         C   s   | j  g d g  f S(   s%   Titles, definition lists, paragraphs.R  (   R   (   R    R   RR   Rs  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR   H	  s    (   s   bullets
   enumerators   field_markers   option_markers   doctests
   line_blocks   grid_table_tops   simple_table_tops   explicit_markups	   anonymouss   lines   textN(c   R   R   R#   R   t   TableParserR  R   Rb  R  t   keysR  R  t   sequencepatsR+  RL  RN  RR  RO  RP  R  R  R  R   R   R   R  t   simple_table_top_patR  t   patsR  t   escapeR   R   R   t   initial_transitionsRu  Rr  R  Rw  R  Rx  Rh  R  Ri  R2   R  R  R  Rj  R  R  R  Rk  R  R  Rl  Rm  R  R  R  Rn  Ro  R  R  R  R  R  R  R  R"  t   varsR3   RG  R  R  R'  R#  R(  R-  R)  R>  R7  RA  RB  RJ  R`  Ra  Rc  RC  Rn  R@  Rq  Rp  Ro  Rp  R   Ru  RQ   R   (    (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRC     s,  	""(	

	%



,
           	
			#					#7		%							)										&	+		  								D			<	.			!	
	&					
	t   RFC2822Bodyc           B   sk   e  Z d  Z e j j   Z d e d <g  e j D] Z e d f ^ q/ Z e j d d  d   Z	 d   Z
 RS(   s   
    RFC2822 headers are only valid as the first constructs in documents.  As
    soon as anything else appears, the `Body` state should take over.
    s   [!-9;-~]+:( +|$)t   rfc2822RC   ic   	   
   C   s   t  j d d g  } |  j | 7_ |  j |  \ } } | | 7} |  j j d } |  j |  j j | d |  j j   d d | d d d | \ } } |  j	 |  | s |  j |  j
 d	  7_ n  g  | g  f S(
   s   RFC2822-style field list item.t   classesR  i   R=   R9   RD   t   RFC2822ListRg   s   RFC2822-style field list(   R   R  RJ   t   rfc2822_fieldRF   R   Rn   R<   RN   RL   R   (	   R    R   RR   Rs  t	   fieldlistR  Rg   R   R  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  Z	  s    
c   	      C   s   | j  | j  j d   } |  j j | j   d t \ } } } } t j   } | t j | |  7} t j	 d j
 |   } | | 7} | r |  j | d | d | n  | | f S(   NR  R  s   
R=   R9   (   R   t   findRF   R  R   R?   R   R  R  R  R   Rd   (	   R    R   R   Rt  Ru  R   Rg   t	   fieldnodet	   fieldbody(    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  l	  s    

(   s   rfc2822s   Body(   R   R   R#   RC   R   Re   R}  R   t   insertR  R  (    (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  M	  s   
	t   SpecializedBodyc           B   sn   e  Z d  Z d d d d  Z e Z e Z e Z e Z e Z	 e Z
 e Z e Z e Z e Z e Z e Z e Z RS(   s  
    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`.
    c         C   s   |  j  j   t  d S(   s8   Not a compound element member. Abort this state machine.N(   RF   Ry   RM   (   R    R   RR   Rs  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyt   invalid_input	  s    N(   R   R   R#   R2   R  Ru  Rh  Ri  Rj  Rk  Rl  Rm  Rn  Ro  Rp  R   RQ   R   (    (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  {	  s   R  c           B   s   e  Z d  Z d   Z RS(   s-   Second and subsequent bullet_list list_items.c         C   sg   | j  d |  j d k r' |  j   n  |  j | j    \ } } |  j | 7_ | |  _ g  | g  f S(   s   Bullet list item.i    Rh  (   R   RJ   R  R  R   Rg   (   R    R   RR   Rs  R  Rg   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRh  	  s    	(   R   R   R#   Rh  (    (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  	  s   t   DefinitionListc           B   s   e  Z d  Z d   Z RS(   s,   Second and subsequent definition_list_items.c         C   s   | j  g d g  f S(   s   Definition lists.t
   Definition(   R   (   R    R   RR   Rs  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR   	  s    (   R   R   R#   R   (    (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  	  s   R  c           B   s   e  Z d  Z d   Z RS(   s1   Second and subsequent enumerated_list list_items.c   
      C   s   |  j  | |  j d  \ } } } } | |  j k s | d k ro | |  j d k s |  j s | |  j d k s |  j | | |  r |  j   n  | d k r d |  _ n  |  j | j    \ } }	 |  j | 7_ |	 |  _	 | |  _ g  | g  f S(   s   Enumerated list item.R  R  i   (
   R  RJ   R  R  R  R  R  R  R   Rg   (
   R    R   RR   Rs  R  R  R   R  R  Rg   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRi  	  s    			(   R   R   R#   Ri  (    (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  	  s   R  c           B   s   e  Z d  Z d   Z RS(   s(   Second and subsequent field_list fields.c         C   s:   |  j  |  \ } } |  j | 7_ | |  _ g  | g  f S(   s   Field list field.(   R  RJ   Rg   (   R    R   RR   Rs  R  Rg   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRj  	  s    	(   R   R   R#   Rj  (    (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  	  s   R  c           B   s   e  Z d  Z d   Z RS(   s4   Second and subsequent option_list option_list_items.c         C   s\   y |  j  |  \ } } Wn t k
 r6 |  j   n X|  j | 7_ | |  _ g  | g  f S(   s   Option list item.(   R  R   R  RJ   Rg   (   R    R   RR   Rs  R  Rg   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRk  	  s    	(   R   R   R#   Rk  (    (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  	  s   R  c           B   s2   e  Z d  Z e j Z e j Z d   Z e j Z	 RS(   s6   Second and subsequent RFC2822-style field_list fields.c         C   s:   |  j  |  \ } } |  j | 7_ | |  _ g  d g  f S(   s   RFC2822-style field list item.R  (   R  RJ   Rg   (   R    R   RR   Rs  R  Rg   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  	  s    	(
   R   R   R#   R  R   R}  R  R  R  R  (    (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  	  s
   			Rj  c           B   s   e  Z d  Z d   Z RS(   sz   
    Parse field_list fields for extension options.

    No nested parsing is done (including inline markup parsing).
    c         C   sx   g  } xk t  |  d g D]V } | j   r< | j |  q | r d j |  } | t j | |  7} g  } q q Wd S(   s5   Override `Body.parse_field_body` for simpler parsing.R|   s   
N(   RP  R  R[   R   R   R   (   R    Rt  R   R9   R   RQ   R   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  
  s    (   R   R   R#   R  (    (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRj  
  s   R  c           B   s    e  Z d  Z e j Z d   Z RS(   s,   Second and subsequent lines of a line_block.c         C   sa   |  j  j   } |  j | |  \ } } } |  j | 7_ |  j j | 7_ | |  _ g  | g  f S(   s   New line of line block.(   RF   R   R  RJ   Rg   (   R    R   RR   Rs  Rs   RQ   Rt   Rg   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRm  
  s    	(   R   R   R#   R  R  R  Rm  (    (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  
  s   	Rt  c           B   s)   e  Z d  Z d   Z d   Z e j Z RS(   s0   Second and subsequent explicit markup construct.c         C   s:   |  j  |  \ } } |  j | 7_ | |  _ g  | g  f S(   s3   Footnotes, hyperlink targets, directives, comments.(   Ro  RJ   Rg   (   R    R   RR   Rs  R   Rg   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRp  +
  s    	c         C   s:   |  j  |  \ } } |  j | 7_ | |  _ g  | g  f S(   s   Anonymous hyperlink targets.(   Ru  RJ   Rg   (   R    R   RR   Rs  R   Rg   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR   2
  s    	(   R   R   R#   Rp  R   R  R  R  (    (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRt  '
  s   		R2  c           B   sV   e  Z d  Z i e j d e j e j  d 6d d 6Z d d g Z	 d   Z
 d   Z RS(   sG   
    Parser for the contents of a substitution_definition element.
    s   (%s)::( +|$)t   embedded_directiveR|   R   c         C   sZ   |  j  | d |  j d d \ } } |  j | 7_ |  j j   sP | |  _ n  t  d  S(   Nt   altR   i    (   RA  RJ   RF   t   at_eofRg   RM   (   R    R   RR   Rs  R   Rg   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  H
  s    c         C   s.   |  j  j   s$ |  j  j   |  _ n  t  d  S(   N(   RF   R  RR  Rg   RM   (   R    R   RR   Rs  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR   P
  s    (   R   R   R#   R   R   R3   R@  R   R   R}  R  R   (    (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR2  <
  s   	
	R  c           B   s   e  Z d  Z i e j d d 6d d 6Z d d g Z d   Z d   Z d   Z d	   Z	 d
   Z
 d   Z d   Z d   Z e j d  Z d   Z RS(   ss   
    Classifier of second line of a text block.

    Could be a paragraph, a definition list item, or a title.
    RQ   t	   underlineR|   R   RC   c         C   s_   |  j  | |  j j   d  \ } } |  j | 7_ | rR |  j |  j   7_ n  g  d g  f S(   s   End of paragraph.i   RC   (   R   RF   R   RJ   R}   (   R    R   RR   Rs  R   R   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  b
  s    c         C   s    | r |  j  d  | d   n  g  S(   N(   R  R2   (   R    RR   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyt   eofl
  s    c   	      C   s   t  j   } |  j |  \ } } | | 7} |  j | 7_ |  j j d } |  j |  j j | d |  j j   d d | d d d | d d \ } } |  j	 |  | s |  j |  j
 d	  7_ n  g  d
 g  f S(   s   Definition list item.i   R=   R9   RD   R  Rg   Rj   R  s   Definition listRC   (   R   t   definition_listt   definition_list_itemRJ   RF   R   Rn   R<   RN   RL   R   (	   R    R   RR   Rs  t   definitionlistt   definitionlistitemRg   R   R  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRu  q
  s    
c         C   s  |  j  j   } | d j   } | j j   } | d | } g  } t |  t |  k rt |  d k  r |  j  j r |  j j d d | }	 |  j	 |	 7_	 n  t
 j d   q| d d |  j  j }
 |  j j d t j |
 |
  d | }	 | j |	  n  |  j  j s| d d |  j  j }
 |  j  j   \ } } |  j j d t j |
 |
  d	 | d | }	 |  j	 | 7_	 |  j	 |	 7_	 g  | g  f S| d } g  | (|  j | | | | d
 |  g  | g  f S(   s   Section title.i    s   
i   sf   Possible title underline, too short for the title.
Treating it as ordinary text because it's so short.RQ   R   s   Title underline too short.s   Unexpected section title.R-   i   (   RF   R   R   R   R   RW   R1   R&   R  RJ   R   R  RQ   R   R   R}   R[   RH   RO   Ru   (   R    R   RR   Rs  Rs   Rq   R  R-   Rt   R   R$  R  R  Rr   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  
  s<    		
c         C   s  |  j  j   d } d } y |  j  j d t  } WnF t j k
 rz } | j \ } } }	 |  j j	 d d | d |	 } n X| t
 |  }
 |  j |
 |  \ } } |  j | 7_ |  j | 7_ | ry |  j  j   Wn t k
 r n X|  j |  j   7_ n  g  | g  f S(   s
   Paragraph.i   R  s   Unexpected indentation.R-   RQ   N(   RF   R   R2   R  R?   R   R  R  R&   R   RP  R   RJ   R]   RM   R}   (   R    R   RR   Rs  R  R   R^   R  R  R  R   R   R   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR   
  s&    c         C   s   |  j  j   \ } } } } x% | rB | d j   rB | j   q W| sS |  j   Sd j |  } t j | |  } | d | _ | g } | s | j	 |  j
 d   n  | S(   s   Return a list of nodes.is   
i   s   Literal block(   RF   Rq  R  R\  t   quoted_literal_blockR   R   R}   RQ   R[   R   (   R    Rt  Ru  R   Rg   R   R}   R   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR}   
  s    
	c         C   s}   |  j  j   } |  j  j } t j   } |  j |  j  j | d | d | d t d i t f d 6d d 6} |  j	 |  | j
 S(   NR=   R9   R1   R`   RB   t   QuotedLiteralBlockRD   (   RF   RN   R   R   R6  Rd   R<   R5   R  RL   t   children(   R    RN   R   t   parent_nodeR=  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  
  s    c         C   s  |  j  j   \ } } } } t j d j | t |    } |  j  j   d } |  j  j |  \ | _ | _	 |  j
 | |  \ } }	 | | 7} t j d |	  }
 | |
 7} | d d d k r |
 |  j j d d | d 7}
 n  |  j | d	 | d
 |
 | | f S(   Ns   
i   R|   i    is   ::s`   Blank line missing before literal block (after the "::")? Interpreted as a definition list item.RQ   R=   R9   (   RF   Rq  R   R  R   RP  R   RH   R-   RQ   t   termR   R&   R  Rd   (   R    t   termlineRt  Ru  R   Rg   t   itemnodeRs   t   termlistRt   R   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  
  s    

s    +: +c         C   sa  t  |  d k s t  |  j | d |  \ } } t j   } |  j j |  \ | _ | _ t	 | d  | _
 | g } x t t  |   D] } | | } t | t j  rC|  j j | j
  }	 t  |	  d k r | d c | 7<qS| d c t j |	 d j    7<xD |	 d D]% }
 t j d |
  } | j |  qWq | d c | 7<q W| | f S(   s9   Return a definition_list's term and optional classifiers.i   i    iR|   (   RW   R;   R   R   R  RF   RH   R-   RQ   R   R   R  R
  R  t   classifier_delimiterR   R   t
   classifierR[   (   R    R   Rs   R  Rt   t	   term_nodeR  R  R9   R   R   t   classifier_node(    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  
  s$    	
#(   s	   underlines   Body(   s   texts   Body(   R   R   R#   RC   R   R}  R  R  Ru  R  R   R}   R  R  R   R   R  R  (    (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  V
  s   
	
			(				t   SpecializedTextc           B   sA   e  Z d  Z d   Z d d d d  Z e Z e Z e Z e Z	 RS(   s   
    Superclass for second and subsequent lines of Text-variants.

    All transition methods are disabled. Override individual methods in
    subclasses to re-enable.
    c         C   s   g  S(   s   Incomplete construct.(    (   R    RR   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR    s    c         C   s
   t   d S(   s8   Not a compound element member. Abort this state machine.N(   RM   (   R    R   RR   Rs  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR    s    N(
   R   R   R#   R  R2   R  R  Ru  R  R   (    (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR    s   	R  c           B   s    e  Z d  Z d   Z d   Z RS(   s.   Second line of potential definition_list_item.c         C   s   |  j  j d  g  S(   s   Not a definition.i   (   RF   Ry   (   R    RR   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  '  s    c         C   s:   |  j  |  \ } } |  j | 7_ | |  _ g  d g  f S(   s   Definition list item.R  (   R  RJ   Rg   (   R    R   RR   Rs  R  Rg   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRu  ,  s    	(   R   R   R#   R  Ru  (    (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  #  s   	Rv  c           B   sV   e  Z d  Z d Z d   Z d   Z d   Z e Z d   Z d d  Z	 d d  Z
 RS(   sO   
    Second line of over- & underlined section title or transition marker.
    i   c         C   s   | d j    } |  j j r+ t |  j _ n" t |  d k  rM |  j |  n  |  j r |  j j   d } t	 j
 d | d  } | | _ |  j | 7_ n  d |  _ g  S(   s0   Transition marker at end of section or document.i    i   i   R   (   R  R6   R*   R5   RW   t   state_correctiont   eofcheckRF   R   R   t
   transitionRQ   RJ   (   R    RR   t   markerRs   R  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  =  s    			c         C   s   |  j  j   \ } } | d j   } t |  d k  rG |  j |  n  t j d |  } | | _ | d | _ |  j	 | 7_	 g  d g  f S(   s   Transition marker.i    i   R   i   RC   (
   RF   RH   R  RW   R  R   R  R-   RQ   RJ   (   R    R   RR   Rs  R  R  R  R  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR  L  s    	c         C   s>  |  j  j   d } | d } | j } d } y |  j  j   } Wn t k
 r | d | } t | j    d k  r |  j | | | d  q |  j j	 d t
 j | |  d | }	 |  j |	 7_ g  d	 g  f Sn Xd
 | | | f }
 | j   } | j   } |  j d d j |  s| d | d | } t | j    d k  ra|  j | | | d  q@|  j j	 d t
 j |
 |
  d | }	 |  j |	 7_ g  d	 g  f Sn | | k r@| d | d | } t | j    d k  r|  j | | | d  q@|  j j	 d t
 j |
 |
  d | }	 |  j |	 7_ g  d	 g  f Sn  | j   } g  } t |  t |  k r| d | d | } t | j    d k  r|  j | | | d  q|  j j d t
 j |
 |
  d | }	 | j |	  n  | d | d f } d |  _ |  j | j   |
 | | d |  d |  _ g  d	 g  f S(   s#   Potential over- & underlined title.i   i    R|   s   
i   i   s   Incomplete section title.RQ   RC   s   %s
%s
%sR  s6   Missing matching underline for section title overline.s$   Title overline & underline mismatch.s   Title overline too short.(   RF   R   R   R]   RM   RW   R   t   short_overlineR&   RO   R   R}   RJ   RS   R   R   R   R[   R  Ru   R  (   R    R   RR   Rs  Rs   t   overlineRq   R  R$  R   R-   Rt   Rr   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR   X  sn    
										#	c         C   s   | d } | d |  j  j } |  j  j   d } t | j    d k  rb |  j | | | d  n  |  j j d t j	 | |  d | } |  j
 | 7_
 g  d g  f S(   Ni    s   
i   i   s+   Invalid section title or transition marker.RQ   RC   (   RF   RQ   R   RW   R   R  R&   R   R   R}   RJ   (   R    R   RR   Rs  R  R$  Rs   R   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR    s    
		c         C   s;   |  j  j d d | } |  j | 7_ |  j | |  d  S(   Ns`   Possible incomplete section title.
Treating the overline as ordinary text because it's so short.RQ   (   R&   R  RJ   R  (   R    RR   R$  Rs   R   R   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR    s
    		c         C   s-   |  j  j |  g  | (t j d d   d  S(   NRC   R   (   RF   Ry   R   t   StateCorrection(   R    RR   R   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR    s    (   R   R   R#   R  R  R  R   Ru  R  R  R  (    (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRv  4  s   			>	R  c           B   sq   e  Z d  Z i d e j d 6d d 6Z d Z e d  Z d   Z	 d   Z
 d   Z d	   Z d
   Z d   Z RS(   s   
    Nested parse handler for quoted (unindented) literal blocks.

    Special-purpose.  Not for inclusion in `state_classes`.
    s   (%(nonalphanum7bit)s)t   initial_quotedR|   R   c         C   s)   t  j |  | |  g  |  _ d  |  _ d  S(   N(   RA   R"   Rt   R2   t   initial_lineno(   R    RF   RG   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR"     s    	c         C   s    | r t   n | | g  f Sd  S(   N(   RM   (   R    R   RR   Rs  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR    s    	c         C   s   | rf |  j  j |  j  \ } } d j |  } t j | |  } | | _ | | _ |  j | 7_ n7 |  j |  j	 j
 d d |  j  j   7_ |  j  j   |  j |  j 7_ g  S(   Ns   
s#   Literal block expected; none found.RQ   (   RF   RH   R  R   R   R}   R-   RQ   RJ   R&   R   R   Ry   Rt   (   R    RR   R  R  R   R}   (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR    s    			c         C   sT   | s t  d   |  j j |  j j d d |  j j    |  j j   t  d  S(   Ns7   QuotedLiteralBlock.indent: context should not be empty!s   Unexpected indentation.RQ   (	   R;   Rt   R[   R&   R   RF   R   Ry   RM   (   R    R   RR   Rs  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyRu    s    	c         C   s   |  j  d  | j d } t j t j |  t j  } |  j d | |  j |  j j	 f  |  j
 j   |  _ | j g | g  f S(   s7   Match arbitrary quote character on the first line only.R  i    t   quoted(   t   remove_transitionR   R   R   R|  R   t   add_transitionR  RP   R   RF   R   R  (   R    R   RR   Rs  t   quoteR4  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR    s    	c         C   s   | j  | j  | | g  f S(   s,   Match consistent quotes on subsequent lines.(   R[   R   (   R    R   RR   Rs  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR    s    c         C   sK   | rA |  j  j |  j j d d |  j j    |  j j   n  t  d  S(   Ns#   Inconsistent literal block quoting.RQ   (   Rt   R[   R&   R   RF   R   Ry   RM   (   R    R   RR   Rs  (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR     s    	(   s   initial_quoteds   text(   R   R   R#   RC   R{  R   R}  R5   R"   R  R  Ru  R  R  R   (    (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyR    s   
						(G   R#   t   __docformat__t   sysR   t   typesR   R   RK  R   R   R   R   R   t   docutils.statemachineR   R	   t   docutils.nodesR
   R   R   RI  R   R   R   R   t   docutils.parsers.rst.languagesR   t   _fallback_language_modulet   docutils.utilsR   R   R   R   R   RO  R   R   R   R   t	   ExceptionR   R   R$   R@   RA   R?   R   R3   RI  RL  RN  RR  RC   R  R  R  R  R  R  R  R  Rj  R  Rt  R2  R  R  R  Rv  R  RB   (    (    (    s?   /usr/lib/python2.7/dist-packages/docutils/parsers/rst/states.pyt   <module>e   st   "'  ;	     B.,	K