
    -PhR>                         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	 ddl
mZ  G d dej        j                  Z G d	 d
e          Z G d d          Zd ZdS )a	  
This is ``docutils.parsers.rst`` package. It exports a single class, `Parser`,
the reStructuredText parser.


Usage
=====

1. Create a parser::

       parser = docutils.parsers.rst.Parser()

   Several optional arguments may be passed to modify the parser's behavior.
   Please see `Customizing the Parser`_ below for details.

2. Gather input (a multi-line string), by reading a file or the standard
   input::

       input = sys.stdin.read()

3. Create a new empty `docutils.nodes.document` tree::

       document = docutils.utils.new_document(source, settings)

   See `docutils.utils.new_document()` for parameter details.

4. Run the parser, populating the document tree::

       parser.parse(input, document)


Parser Overview
===============

The reStructuredText parser is implemented as a 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, then see the
`states` module.


Customizing the Parser
----------------------

Anything that isn't already customizable is that way simply because that type
of customizability hasn't been implemented yet.  Patches welcome!

When instantiating an object of the `Parser` class, two parameters may be
passed: ``rfc2822`` and ``inliner``.  Pass ``rfc2822=True`` to enable an
initial RFC-2822 style header block, parsed as a "field_list" element (with
"class" attribute set to "rfc2822").  Currently this is the only body-level
element which is customizable without subclassing.  (Tip: subclass `Parser`
and change its "state_classes" and "initial_state" attributes to refer to new
classes. Contact the author if you need more details.)

The ``inliner`` parameter takes an instance of `states.Inliner` or a subclass.
It handles inline markup recognition.  A common extension is the addition of
further implicit hyperlinks, like "RFC 2822".  This can be done by subclassing
`states.Inliner`, adding a new method for the implicit markup, and adding a
``(pattern, method)`` pair to the "implicit_dispatch" attribute of the
subclass.  See `states.Inliner.implicit_inline()` for details.  Explicit
inline markup can be customized in a `states.Inliner` subclass via the
``patterns.initial`` and ``dispatch`` attributes (and new methods as
appropriate).
reStructuredText    N)rolesstates)frontendnodes)	universalc                       e Zd ZdZdZ	 ej        j        j        ddddgde	j
        dfd	d
gdde	j        dfddgdddfddgde	j
        dfddgdde	j        dfddgddde	j        dfddgde	j
        dfdd gd!d"d#fd$d%gg d&d'd(d)fd*d+gd,d-e	j        d.fd/d0gd1d2e	j        d3fd4d5gd!d6d#fd7d8gdd,d6d9fffz   Zd:Zd;Zd?d<Z fd=Zd> Z xZS )@ParserzThe reStructuredText parser.)rstrestructuredtextrestrestxrtxtrstxzreStructuredText Parser OptionsNzARecognize and link to standalone PEP references (like "PEP 258").z--pep-references
store_true)action	validatorzABase URL for PEP references (default "https://peps.python.org/").z--pep-base-urlz<URL>zhttps://peps.python.org/)metavardefaultr   z7Template for PEP file part of URL. (default "pep-%04d")z--pep-file-url-templatezpep-%04d)r   r   zARecognize and link to standalone RFC references (like "RFC 822").z--rfc-referenceszEBase URL for RFC references (default "https://tools.ietf.org/html/").z--rfc-base-urlzhttps://tools.ietf.org/html/z3Set number of spaces for tab expansion (default 8).z--tab-widthz<width>int   )r   typer   r   z)Remove spaces before footnote references.z--trim-footnote-reference-spacez(Leave spaces before footnote references.z --leave-footnote-reference-spacestore_falsetrim_footnote_reference_space)r   destzqToken name set for parsing code with Pygments: one of "long", "short", or "none" (no parsing). Default is "long".z--syntax-highlight)longshortnoner   z<format>)choicesr   r   zhChange straight quotation marks to typographic form: one of "yes", "no", "alt[ernative]" (default "no").z--smart-quotesFz<yes/no/alt>)r   r   r   z4Characters to use as "smart quotes" for <language>. z--smartquotes-localesz'<language:quotes[,language:quotes,...]>append)r   r   r   zInline markup recognized at word boundaries only (adjacent to punctuation or whitespace). Force character-level inline markup recognition with "\ " (backslash + space). Default.z--word-level-inline-markupcharacter_level_inline_markupzInline markup recognized anywhere, regardless of surrounding characters. Backslash-escapes must be used to avoid unwanted markup recognition. Useful for East Asian languages. Experimental.z--character-level-inline-markup)r   r   r   zrestructuredtext parser)parsersc                 X    |rd| _         nd| _         t          j        | _        || _        d S )NRFC2822BodyBody)initial_stater   state_classesinliner)selfrfc2822r(   s      ]/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/docutils/parsers/rst/__init__.py__init__zParser.__init__   s3     	(!.D!'D#1    c                 `    t                                                      t          j        gz   S N)superget_transformsr   SmartQuotes)r)   	__class__s    r+   r1   zParser.get_transforms   s$    ww%%''9+@*AAAr-   c                    |                      ||           | j        j                            dd           | j        j                            dd           t	          j        | j        | j        |j        j	                  | _
        t          j
                            ||j        j        d          }t          |          D ]h\  }}t          |          | j        j        j        k    rA| j        j                            d|d	z   z            }| j                            |            n#i| j
                            ||| j        
           dt*          j        v rt*          j        d= |                                  dS )z=Parse `inputstring` and populate `document`, a document tree.	tab_widthr   syntax_highlightr   )r'   r&   debugT)r5   convert_whitespacez&Line %d exceeds the line-length-limit.   )r(    N)setup_parsedocumentsettings
setdefaultr   RSTStateMachiner'   r&   reporter
debug_flagstatemachinedocutilsstring2linesr5   	enumeratelenline_length_limiterrorr    runr(   r   _rolesfinish_parse)r)   inputstringr<   
inputlinesilinerH   s          r+   parsezParser.parse   s}   h///))+q999))*<fEEE"2 . .%02 2 2 *77X%6%@!% 8 ' '
 !,, 	N 	NGAt4yy4=1CCC.44DacJL L$$U+++	 D !!*h!MMMR r-   )FN)__name__
__module____qualname____doc__	supportedrC   r"   r
   settings_specr   validate_booleanvalidate_url_trailing_slashvalidate_nonnegative_intvalidate_ternaryvalidate_smartquotes_localesconfig_sectionconfig_section_dependenciesr,   r1   rP   __classcell__)r3   s   @r+   r
   r
   P   sb       &&LI'$+9)
M
!0I
J
J
L2
*D <> >
?
 D$
%*
5
5
7 N
!0I
J
J
L6
*H <> >
?
 @/1 9; ;
< 6,
-!0I
J
J
L 5-
.",K
L
L
NH
 ///5 5
6
@
 13 3
4
 A"
#? =? ?
@
0 (
(",K
L
L
N -
-!e24 4
5e9	==
 =
M~ /N".   B B B B B      r-   r
   c                       e Zd ZdZd ZdS )DirectiveErrorz
    Store a message and a system message level.

    To be thrown from inside directive code.

    Do not instantiate directly -- use `Directive.directive_error()`
    instead!
    c                 V    t                               |            || _        || _        dS )zSet error `message` and `level`N)	Exceptionr,   levelmsgr)   rc   messages      r+   r,   zDirectiveError.__init__   s(    4   
r-   N)rQ   rR   rS   rT   r,    r-   r+   r`   r`      s-             r-   r`   c                   l    e Zd ZdZdZ	 dZ	 dZ	 dZ	 dZ	 d Z	d Z
d Zd Zd	 Zd
 Zd Zd Zd Zd ZdS )	Directivea<  
    Base class for reStructuredText directives.

    The following attributes may be set by subclasses.  They are
    interpreted by the directive parser (which runs the directive
    class):

    - `required_arguments`: The number of required arguments (default:
      0).

    - `optional_arguments`: The number of optional arguments (default:
      0).

    - `final_argument_whitespace`: A boolean, indicating if the final
      argument may contain whitespace (default: False).

    - `option_spec`: A dictionary, mapping known option names to
      conversion functions such as `int` or `float` (default: {}, no
      options).  Several conversion functions are defined in the
      directives/__init__.py module.

      Option conversion functions take a single parameter, the option
      argument (a string or ``None``), validate it and/or convert it
      to the appropriate form.  Conversion functions may raise
      `ValueError` and `TypeError` exceptions.

    - `has_content`: A boolean; True if content is allowed.  Client
      code must handle the case where content is required but not
      supplied (an empty content list will be supplied).

    Arguments are normally single whitespace-separated words.  The
    final argument may contain whitespace and/or newlines if
    `final_argument_whitespace` is True.

    If the form of the arguments is more complex, specify only one
    argument (either required or optional) and set
    `final_argument_whitespace` to True; the client code must do any
    context-sensitive parsing.

    When a directive implementation is being run, the directive class
    is instantiated, and the `run()` method is executed.  During
    instantiation, the following instance variables are set:

    - ``name`` is the directive type or name (string).

    - ``arguments`` is the list of positional arguments (strings).

    - ``options`` is a dictionary mapping option names (strings) to
      values (type depends on option conversion functions; see
      `option_spec` above).

    - ``content`` is a list of strings, the directive content line by line.

    - ``lineno`` is the absolute line number of the first line
      of the directive.

    - ``content_offset`` is the line offset of the first line
      of the content from the beginning of the current input.
      Used when initiating a nested parse.

    - ``block_text`` is a string containing the entire directive.

    - ``state`` is the state which called the directive function.

    - ``state_machine`` is the state machine which controls the state
      which called the directive function.

    - ``reporter`` is the state machine's `reporter` instance.

    Directive functions return a list of nodes which will be inserted
    into the document tree at the point where the directive was
    encountered.  This can be an empty list if there is nothing to
    insert.

    For ordinary directives, the list must contain body elements or
    structural elements.  Some directives are intended specifically
    for substitution definitions, and must return a list of `Text`
    nodes and/or inline elements (suitable for inline insertion, in
    place of the substitution reference).  Such directives must verify
    substitution definition context, typically using code like this::

        if not isinstance(state, states.SubstitutionDef):
            error = self.reporter.error(
                'Invalid context: the "%s" directive can only be used '
                'within a substitution definition.' % (name),
                nodes.literal_block(block_text, block_text), line=lineno)
            return [error]
    r   FNc
                     || _         || _        || _        || _        || _        || _        || _        || _        |	| _        |	j	        | _	        d S r/   )
name	argumentsoptionscontentlinenocontent_offset
block_textstatestate_machiner@   )
r)   rk   rl   rm   rn   ro   rp   rq   rr   rs   s
             r+   r,   zDirective.__init__?  sQ    	",$
*%.r-   c                      t          d          )Nz Must override run() in subclass.)NotImplementedErrorr)   s    r+   rI   zDirective.runL  s    !"DEEEr-   c                 "    t          ||          S )a  
        Return a DirectiveError suitable for being thrown as an exception.

        Call "raise self.directive_error(level, message)" from within
        a directive implementation to return one single system message
        at level `level`, which automatically gets the directive block
        and the line number added.

        Preferably use the `debug`, `info`, `warning`, `error`, or `severe`
        wrapper methods, e.g. ``self.error(message)`` to generate an
        ERROR-level directive error.
        )r`   re   s      r+   directive_errorzDirective.directive_errorQ  s     eW---r-   c                 .    |                      d|          S )Nr   rx   r)   rf   s     r+   r7   zDirective.debug`      ##Aw///r-   c                 .    |                      d|          S )Nr9   rz   r{   s     r+   infozDirective.infoc  r|   r-   c                 .    |                      d|          S )N   rz   r{   s     r+   warningzDirective.warningf  r|   r-   c                 .    |                      d|          S )N   rz   r{   s     r+   rH   zDirective.errori  r|   r-   c                 .    |                      d|          S )N   rz   r{   s     r+   severezDirective.severel  r|   r-   c                 N    | j         s|                     d| j        z            dS )ze
        Throw an ERROR-level DirectiveError if the directive doesn't
        have contents.
        z:Content block expected for the "%s" directive; none found.N)rn   rH   rk   rv   s    r+   assert_has_contentzDirective.assert_has_contentq  s=    
 | 	8** +-1Y7 8 8 8	8 	8r-   c                     d| j         v rpt          j        | j                             d                    }d|v r|d= |d                             |           | j        j                            ||           dS dS )zAppend self.options['name'] to node['names'] if it exists.

        Also normalize the name string and register it as explicit target.
        rk   namesN)rm   r   fully_normalize_namepopr    rr   r<   note_explicit_target)r)   noderk   s      r+   add_namezDirective.add_namez  s    
 T\!!-dl.>.>v.F.FGGD~~LM  &&&J44T4@@@@@ "!r-   )rQ   rR   rS   rT   required_argumentsoptional_argumentsfinal_argument_whitespaceoption_spechas_contentr,   rI   rx   r7   r~   r   rH   r   r   r   rg   r-   r+   ri   ri      s        W Wz 1D %4K9K)/ / /F F F
. . .0 0 00 0 00 0 00 0 00 0 0
8 8 8
A 
A 
A 
A 
Ar-   ri   c                 2      G  fddt                     }|S )z
    Define & return a directive class generated from `directive_fn`.

    `directive_fn` uses the old-style, functional interface.
    c                   t    e Zd Z e dd          Z e dd          Z e dd          Ze\  ZZZ	 fdZ
dS )7convert_directive_function.<locals>.FunctionalDirectiverm   Nrn   Frl   )r   r   Fc                      | j         | j        | j        | j        | j        | j        | j        | j        | j        	  	        S r/   )	rk   rl   rm   rn   ro   rp   rq   rr   rs   )r)   directive_fns    r+   rI   z;convert_directive_function.<locals>.FunctionalDirective.run  s@    <	4>4<T0$/
D.0 0 0r-   )rQ   rR   rS   getattrr   r   _argument_specr   r   r   rI   )r   s   r+   FunctionalDirectiver     sy        glIt<<glIu== {MJJ 	J.0I	0 	0 	0 	0 	0 	0 	0r-   r   )ri   )r   r   s   ` r+   convert_directive_functionr     s?    0 0 0 0 0 0 0i 0 0 0 r-   )rT   __docformat__docutils.parsersrC   docutils.statemachinedocutils.parsers.rstr   r   r   r   docutils.transformsr   r"   r
   rb   r`   ri   r   rg   r-   r+   <module>r      s(  
? ?B #         . . . . . . . . $ $ $ $ $ $ $ $ ) ) ) ) ) )l l l l lX$ l l l^    Y   $sA sA sA sA sA sA sA sAl    r-   