U å€C^I?ã@s„dZdZddlZddlZddlmZddlmZmZm Z ddl m Z Gdd„dej j ƒZ Gd d „d eƒZGd d „d eƒZd d„ZdS)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). ZreStructuredTextéN)Ústates)ÚfrontendÚnodesÚ Component)Ú universalc@s~eZdZdZdZddddgdejdœfd d gd d ejd œfddgd ddœfddgdejdœfddgd dejd œfddgdddejdœfddgdejdœfdd gd!d"d#œfd$d%gd!d&d'ejd(œfd)d*gd+difd,d-gd!d&d.ejd(œfd/d0gd+difd1d2gd3d4d5gd3d6d7œfd8d9gd:d;ej d<œfd=d>gd?d@ej dAœfdBdCgd!dDd#œfdEdFgdd:dDdGœfffZ dHZ dIZ dPdJdK„ZdLdM„ZdNdO„ZdS)QÚParserzThe reStructuredText parser.)ZrestructuredtextZrstÚrestZrestxZrtxtZrstxzreStructuredText Parser OptionsNzARecognize and link to standalone PEP references (like "PEP 258").z--pep-referencesÚ store_true)ÚactionÚ validatorzHBase URL for PEP references (default "http://www.python.org/dev/peps/").z--pep-base-urlzzhttp://www.python.org/dev/peps/)ÚmetavarÚdefaultr z7Template for PEP file part of URL. (default "pep-%04d")z--pep-file-url-templatezpep-%04d)r r zARecognize and link to standalone RFC references (like "RFC 822").z--rfc-referenceszDBase URL for RFC references (default "http://tools.ietf.org/html/").z--rfc-base-urlzhttp://tools.ietf.org/html/z3Set number of spaces for tab expansion (default 8).z --tab-widthzÚ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_falseZtrim_footnote_reference_space)r Údestz{Disable directives that insert the contents of external file ("include" & "raw"); replaced with a "warning" system message.z--no-file-insertionéZfile_insertion_enabled)r r rr zeEnable directives that insert the contents of external file ("include" & "raw"). Enabled by default.z--file-insertion-enabledr zGDisable the "raw" directives; replaced with a "warning" system message.z--no-rawZ raw_enabledz0Enable the "raw" directive. Enabled by default.z --raw-enabledzqToken name set for parsing code with Pygments: one of "long", "short", or "none (no parsing)". Default is "long".z--syntax-highlightÚlongÚshortÚnonez)Úchoicesr r zhChange straight quotation marks to typographic form: one of "yes", "no", "alt[ernative]" (default "no").z--smart-quotesFz )r r r z4Characters to use as "smart quotes" for . z--smartquotes-localesz'Úappend)r r r z±Inline 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-markupZcharacter_level_inline_markupz¼Inline 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 rzrestructuredtext parser)ÚparserscCs$|r d|_nd|_tj|_||_dS)NZ RFC2822BodyZBody)Ú initial_staterÚ state_classesÚinliner)ÚselfZrfc2822r©rúC/tmp/pip-install-6_kvzl1k/docutils/docutils/parsers/rst/__init__.pyÚ__init__©s zParser.__init__cCst |¡tjgS©N)rÚget_transformsrZ SmartQuotes©rrrrr"±sÿzParser.get_transformscCsn| ||¡tj|j|j|jjd�|_tjj ||j j dd�}|jj |||j d�dtjkrbtjd=| ¡dS)z=Parse `inputstring` and populate `document`, a document tree.)rrÚdebugT)Ú tab_widthZconvert_whitespace)rÚN)Z setup_parserZRSTStateMachinerrZreporterZ debug_flagZ statemachineÚdocutilsZ string2linesÚsettingsr%ÚrunrZrolesZ_rolesZ finish_parse)rZ inputstringÚdocumentZ inputlinesrrrÚparseµs ýþ z Parser.parse)FN)Ú__name__Ú __module__Ú __qualname__Ú__doc__Ú supportedrZvalidate_booleanZvalidate_url_trailing_slashZvalidate_nonnegative_intZvalidate_ternaryZvalidate_smartquotes_localesZ settings_specZconfig_sectionZconfig_section_dependenciesr r"r+rrrrrPsÈ þÿýþ þÿþÿþ þþþýýÿýþÿýÿýþþûÿû½ýO rc@seZdZdZdd„ZdS)Ú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! cCst |¡||_||_dS)zSet error `message` and `level`N)Ú Exceptionr ÚlevelÚmsg©rr3Úmessagerrrr Ñs zDirectiveError.__init__N)r,r-r.r/r rrrrr1Æs r1c@steZdZdZdZdZdZdZdZdd„Z dd„Z d d „Z d d „Z d d„Z dd„Zdd„Zdd„Zdd„Zdd„ZdS)Ú 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. 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 = state_machine.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] rFNc Cs:||_||_||_||_||_||_||_||_| |_dSr!© ÚnameÚ argumentsÚoptionsÚcontentÚlinenoÚcontent_offsetÚ block_textÚstateÚ state_machine) rr9r:r;r<r=r>r?r@rArrrr CszDirective.__init__cCs tdƒ‚dS)Nz Must override run() is subclass.)ÚNotImplementedErrorr#rrrr)Osz Directive.runcCs 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. )r1r5rrrÚdirective_errorTs zDirective.directive_errorcCs | d|¡S)Nr©rC©rr6rrrr$cszDirective.debugcCs | d|¡S)NrrDrErrrÚinfofszDirective.infocCs | d|¡S)NérDrErrrÚwarningiszDirective.warningcCs | d|¡S)NérDrErrrÚerrorlszDirective.errorcCs | d|¡S)NérDrErrrÚsevereoszDirective.severecCs|js| d|j¡‚dS)ze Throw an ERROR-level DirectiveError if the directive doesn't have contents. z:Content block expected for the "%s" directive; none found.N)r<rJr9r#rrrÚassert_has_contenttsÿzDirective.assert_has_contentcCsLd|jkrHt |j d¡¡}d|kr*|d=|d |¡|jj ||¡dS)z�Append self.options['name'] to node['names'] if it exists. Also normalize the name string and register it as explicit target. r9ÚnamesN)r;rZfully_normalize_nameÚpoprr@r*Znote_explicit_target)rÚnoder9rrrÚadd_name}s  zDirective.add_name)r,r-r.r/Úrequired_argumentsÚoptional_argumentsÚfinal_argument_whitespaceÚ option_specÚ has_contentr r)rCr$rFrHrJrLrMrQrrrrr7Øs Z  r7csG‡fdd„dtƒ}|S)zˆ Define & return a directive class generated from `directive_fn`. `directive_fn` uses the old-style, functional interface. csFeZdZe”ddƒZe”ddƒZe”ddƒZe\ZZZ ‡fdd„Z dS) z7convert_directive_function..FunctionalDirectiver;Nr<Fr:)rrFc s*ˆ|j|j|j|j|j|j|j|j|jƒ Sr!r8r#©Ú directive_fnrrr)™sýz;convert_directive_function..FunctionalDirective.run) r,r-r.ÚgetattrrUrVZ_argument_specrRrSrTr)rrWrrÚFunctionalDirective‘s    ÿrZ)r7)rXrZrrWrÚconvert_directive_functionŠsr[)r/Z __docformat__Zdocutils.parsersr'Zdocutils.statemachineZdocutils.parsers.rstrrrrZdocutils.transformsrrrr2r1Úobjectr7r[rrrrÚsA  v3