U
    ZSh                     @   s  d Z dZddlZddlZddlZddlZddlZddlmZm	Z	m
Z
mZmZmZmZ ddlmZ ddlmZ G dd dZd	Zd
ZddddddddddddeefddZd7ddZd8ddZdejddddddddddddfddZdejdddddddddfddZd9ddZddddddddddddeedejfddZdd Zd:d!d"Z d#d$ Z!d%d& Z"d'd( Z#d)d* Z$d+d, Z%d-d. Z&d/d0 Z'd1d2 Z(d3d4 Z)d5d6 Z*dS );a  
Calling the ``publish_*`` convenience functions (or instantiating a
`Publisher` object) with component names will result in default
behavior.  For custom behavior (setting component options), create
custom component objects first, and pass *them* to
``publish_*``/`Publisher`.  See `The Docutils Publisher`_.

.. _The Docutils Publisher:
    https://docutils.sourceforge.io/docs/api/publisher.html
reStructuredText    N)__version____version_details__SettingsSpecioutilsreaderswriters)OptionParser)doctreec                   @   s   e Zd ZdZddddejdejdfddZdd Zdd Z	d	d
 Z
d*ddZdd Zd+ddZdd Zd,ddZd-ddZd.ddZd/ddZdd Zd0ddZd d! Zd"d# Zd$d% Zd&d' Zd(d) ZdS )1	PublisherzK
    A facade encapsulating the high-level logic of a Docutils system.
    Nc	           
      C   sv   d| _ || _|| _|| _dD ],}	tt| |	trtdt| |	|	|	f q|| _|| _	|| _
|| _|| _t | _dS )a  
        Initial setup.  If any of `reader`, `parser`, or `writer` are not
        specified, ``set_components()`` or the corresponding ``set_...()``
        method should be called with component names
        (`set_reader` sets the parser as well).
        N)readerparserwriterzpassed string "%s" as "%s" parameter; pass an instance, or use the "%s_name" parameter instead (in docutils.core.publish_* convenience functions).)documentr   r   r   
isinstancegetattrstrAssertionErrorsourcesource_classdestinationdestination_classsettingsr   ZErrorOutput_stderr)
selfr   r   r   r   r   r   r   r   	component r   @/root/rtd-docs/venv/lib/python3.8/site-packages/docutils/core.py__init__$   s     zPublisher.__init__c                 C   s$   t |}|||| _| jj| _dS )zSet `self.reader` by name.N)r   Zget_reader_classr   r   )r   reader_namer   parser_nameZreader_classr   r   r   
set_readerU   s    
zPublisher.set_readerc                 C   s   t |}| | _dS )zSet `self.writer` by name.N)r	   Zget_writer_classr   )r   writer_nameZwriter_classr   r   r   
set_writer[   s    
zPublisher.set_writerc                 C   s^   | j d kr| || j| | jd krF| j jd kr<| j | | j j| _| jd krZ| | d S N)r   r"   r   
set_parserr   r$   )r   r    r!   r#   r   r   r   set_components`   s    



zPublisher.set_componentsc                 K   sl   t jdtdd |rL|st }||_| }t|dkrL|d dkrLdg|_t| j	| j
| j|f|d||d	S )
NzRPublisher.setup_option_parser is deprecated, and will be removed in Docutils 0.21.   )
stacklevel   ZapplicationZapplicationsT)
componentsdefaultsZread_config_filesusagedescription)warningswarnDeprecationWarningr   config_sectionsplitlenZconfig_section_dependenciesr
   r   r   r   )r   r.   r/   settings_specr3   r-   partsr   r   r   setup_option_parserj   s$       zPublisher.setup_option_parserc              
   O   s:   t  ( t jdtd | j||W  5 Q R  S Q R X d S )Nignore)category)r0   catch_warningsfilterwarningsr2   r8   )r   argskwargsr   r   r   _setup_settings_parser}   s    
z Publisher._setup_settings_parserc                 K   s$   | j ||||f|}| | _| jS )a  
        Return settings from components and config files.

        Please set components first (`self.set_reader` & `self.set_writer`).
        Use keyword arguments to override component defaults
        (before updating from configuration files).

        Calling this function also sets `self.settings` which makes
        `self.publish()` skip parsing command line options.
        )r?   get_default_valuesr   )r   r.   r/   r6   r3   r-   option_parserr   r   r   get_settings   s       
zPublisher.get_settingsc                 C   s@   | j d kr<|r| ni }|dd | jf ||d| d S )N	tracebackT)r6   r3   )r   copy
setdefaultrB   )r   r6   settings_overridesr3   r-   r   r   r   process_programmatic_settings   s    
z'Publisher.process_programmatic_settingsc                 K   s:   | j ||||f|}|dkr*tjdd }||| _dS )z
        Parse command line arguments and set ``self.settings``.

        Pass an empty sequence to `argv` to avoid reading `sys.argv`
        (the default behaviour).

        Set components first (`self.set_reader` & `self.set_writer`).
        Nr*   )r?   sysargv
parse_argsr   )r   rI   r.   r/   r6   r3   r-   rA   r   r   r   process_command_line   s       zPublisher.process_command_linec                 C   s0   | j d kr| j|d | jd kr,| j|d d S )N)source_path)destination_path)r   
set_sourcer   set_destination)r   rL   rM   r   r   r   set_io   s    

zPublisher.set_ioc                 C   s:   |d kr| j j}n|| j _| j||| j j| j jd| _d S )N)r   rL   encodingerror_handler)r   _sourcer   Zinput_encodingZinput_encoding_error_handlerr   )r   r   rL   r   r   r   rN      s    
 zPublisher.set_sourcec                 C   s|   |d krT| j jr0| j jr0| j j| j jkr0td| j jdkrDd | j _| j jpR| j j}|| j _| j||| j j| j jd| _d S )NziThe positional argument <destination> is obsoleted by the --output option.  You cannot use them together.-)r   rM   rQ   rR   )r   outputZ_destination
SystemExitr   output_encodingoutput_encoding_error_handlerr   )r   r   rM   r   r   r   rO      s"    zPublisher.set_destinationc                 C   s4   | j j| j| j| jj| j| jf | j j  d S r%   )	r   transformerZpopulate_from_componentsr   r   r   r   r   apply_transformsr   r   r   r   rZ      s    zPublisher.apply_transformsFc              
   C   sF  d}zt| j dkr*| j|||||f|p&i  |   |   | j| j| j| j | _| 	  | j
| j| j}	| j
  W nx tk
r }
 zd}|
j}W 5 d}
~
X Y nN tk
r }
 z0| j s | j jr|    | |
 d}d}W 5 d}
~
X Y nX |   |r2| jr2| jjj| j jkr2t| jjjd  n|rBt| |	S )z
        Process command line options and arguments (if `self.settings` not
        already set), run `self.reader` and then `self.writer`.  Return
        `self.writer`'s output.
        NTr*   
   )r   rK   rP   promptr   readr   r   r   rZ   r   writer   Zassemble_partsrV   code	ExceptionrC   debugging_dumpsreport_ExceptionreporterZ	max_levelZexit_status_levelrH   exit)r   rI   r.   r/   r6   rF   r3   enable_exit_statusre   rU   errorexit_statusr   r   r   publish   sT    
    

zPublisher.publishc                 C   s   | j s
d S | jjr8td| jd tt| jj| jd | jjrftd| jd tt| j j| jd | jj	rtd| jd td| jd ttdd | j j
jD | jd | jjrtd| jd t| j  d	| jd d S )
Nz
::: Runtime settings:filez
::: Document internals:z
::: Transforms applied:z@ (priority, transform class, pending node details, keyword args)c                 S   s2   g | ]*\}}}}|d |j |jf |o(|j|fqS )z%s.%s)
__module____name__details).0priorityZxclasspendingr>   r   r   r   
<listcomp>  s
   
 z-Publisher.debugging_dumps.<locals>.<listcomp>z
::: Pseudo-XML:Zraw_unicode_escape)r   r   Zdump_settingsprintr   pprintpformat__dict__Zdump_internalsZdump_transformsrY   ZappliedZdump_pseudo_xmlencoder[   r   r   r   rb     s6    zPublisher.debugging_dumpsc              
   C   s   z| j  r| j sW dS W n tk
r4   Y dS X tjdkrDdnd}d}d}z| jjd }| jjd }W n tt	fk
r   Y nX t
dt d	| d
| d| d	| jd dS )z=Print info and prompt when waiting for input from a terminal.NntzCtrl+ZzCtrl+D zuseful formatsr   z	Docutils z/ <https://docutils.sourceforge.io>
converting "z" into "zT".
Call with option "--help" for more info.
.. Waiting for source text (finish with z on an empty line):rj   )r   isattyr   AttributeErrorosnamer   	supportedr   
IndexErrorrs   r   )r   Zeot_keyZ	in_formatZ
out_formatr   r   r   r]     s     
zPublisher.promptc                 C   s   t |tjr| | nt |tr.| | nt |tjrR| j	dt
|  nvt |tjrv| j	dt
|  nRtdt
| | jd tdt trdt dnd d	tj d
  d| jd d S )Nz-Unable to open source file for reading:
  %s
z2Unable to open destination file for writing:
  %s
z%srj   zExiting due to error.  Use "--traceback" to diagnose.
Please report errors to <docutils-users@lists.sourceforge.net>.
Include "--traceback" output, Docutils version (z []ry   z),
Python version (r   z5), your OS type & version, and the command line used.)r   r   ZSystemMessagereport_SystemMessageUnicodeEncodeErrorreport_UnicodeErrorr   Z
InputErrorr   r_   error_stringZOutputErrorrs   r   r   rH   versionr4   r   rg   r   r   r   rc   1  s0    
zPublisher.report_Exceptionc                 C   s&   t d|jtjj|j f | jd d S )Nz,Exiting due to level-%s (%s) system message.rj   )rs   levelr   ZReporterZlevelsr   r   r   r   r   r   G  s     zPublisher.report_SystemMessagec                 C   s\   |j |j|j }| jdt|| jj|	dd|	dd| jj
ttj d f  d S )Na  %s

The specified output encoding (%s) cannot
handle all of the output.
Try setting "--output-encoding-error-handler" to

* "xmlcharrefreplace" (for HTML & XML output);
  the output will contain "%s" and should be usable.
* "backslashreplace" (for other output formats);
  look for "%s" in the output.
* "replace"; look for "?" in the output.

"--output-encoding-error-handler" is currently set to "%s".

Exiting due to error.  Use "--traceback" to diagnose.
If the advice above doesn't eliminate the error,
please report it to <docutils-users@lists.sourceforge.net>.
Include "--traceback" output, Docutils version (%s),
Python version (%s), your OS type & version, and the
command line used.
asciixmlcharrefreplacebackslashreplacer   )objectstartendr   r_   r   r   r   rW   rw   rX   r   rH   r   r4   )r   rg   datar   r   r   r   L  s    

 zPublisher.report_UnicodeError)NNNN)NNNN)NNNNN)NN)NN)NN)NNNNNNF)rm   rl   __qualname____doc__r   	FileInput
FileOutputr   r"   r$   r'   r8   r?   rB   rG   rK   rP   rN   rO   rZ   ri   rb   r]   rc   r   r   r   r   r   r   r      sP     
1
    
    
    




       
*r   z*%prog [options] [<source> [<destination>]]zReads from <source> (default is stdin) and writes to <destination> (default is stdout).  See https://docutils.sourceforge.io/docs/user/config.html for a detailed settings reference.
standalonerestructuredtext	pseudoxmlTc              	   C   s:   t | |||d}|||| |j||||||	|
d}|S )aT  
    Set up & run a `Publisher` for command-line-based file I/O (input and
    output file paths taken automatically from the command line).
    Also return the output as `str` or `bytes` (for binary output document
    formats).

    Parameters: see `publish_programmatically()` for the remainder.

    - `argv`: Command-line argument list to use instead of ``sys.argv[1:]``.
    - `usage`: Usage string, output if there's a problem parsing the command
      line.
    - `description`: Program description, output for the "--help" option
      (along with command-line option descriptions).
    )r   r3   rf   r   r'   ri   )r   r    r   r!   r   r#   r   r6   rF   r3   rf   rI   r.   r/   	publisherrU   r   r   r   publish_cmdline{  s         r   Fc                 C   s6   t tj| |tj||||||||	|
||||d\}}|S )z
    Set up & run a `Publisher` for programmatic use with file-like I/O.
    Also return the output as `str` or `bytes` (for binary output document
    formats).

    Parameters: see `publish_programmatically()`.
    r   r   rL   r   r   rM   r   r    r   r!   r   r#   r   r6   rF   r3   rf   )publish_programmaticallyr   r   r   )r   rL   r   rM   r   r    r   r!   r   r#   r   r6   rF   r3   rf   rU   r   r   r   r   publish_file  s(           
r   c                 C   s6   t tj| |tjd||||||||	|
|||d\}}|S )uC  
    Set up & run a `Publisher` for programmatic use with string I/O.

    Accepts a `bytes` or `str` instance as `source`.

    The output is encoded according to the `output_encoding`_ setting;
    the return value is a `bytes` instance (unless `output_encoding`_ is
    "unicode", cf. `docutils.io.StringOutput.write()`).

    Parameters: see `publish_programmatically()`.

    This function is provisional because in Python 3 name and behaviour
    no longer match.

    .. _output_encoding:
        https://docutils.sourceforge.io/docs/user/config.html#output-encoding
    Nr   )r   r   StringInputStringOutput)r   rL   rM   r   r    r   r!   r   r#   r   r6   rF   r3   rf   rU   r   r   r   r   publish_string  s(           
r   c                 C   s8   t | ||tjd|||||||	|
||||d\}}|jjS )a  
    Set up & run a `Publisher`, and return a dictionary of document parts.

    Dictionary keys are the names of parts.
    Dictionary values are `str` instances; encoding is up to the client,
    e.g.::

       parts = publish_parts(...)
       body = parts['body'].encode(parts['encoding'], parts['errors'])

    See the `API documentation`__ for details on the provided parts.

    Parameters: see `publish_programmatically()`.

    __ https://docutils.sourceforge.io/docs/api/publisher.html#publish-parts
    N)r   rL   r   r   r   rM   r   r    r   r!   r   r#   r   r6   rF   r3   rf   )r   r   r   r   r7   )r   rL   r   rM   r   r    r   r!   r   r#   r   r6   rF   r3   rf   rU   r   r   r   r   publish_parts  s(           
r   c                 C   s6   t | ||ddtj||||dd|||	|
|d\}}|jS )z
    Set up & run a `Publisher` for programmatic use. Return a document tree.

    Parameters: see `publish_programmatically()`.
    Nnull)r   rL   r   r   rM   r   r   r    r   r!   r   r#   r   r6   rF   r3   rf   )r   r   Z
NullOutputr   )r   rL   r   r   r    r   r!   r   r6   rF   r3   rf   _outputr   r   r   r   publish_doctree   s(           
r   c	                 C   s`   t jdd}	t|	d|t| tj|d}
|s:|r:|
| |
||| |
d| |
j	|dS )u  
    Set up & run a `Publisher` to render from an existing document tree
    data structure. For programmatic use with string output
    (`bytes` or `str`, cf. `publish_string()`).

    Note that ``document.settings`` is overridden; if you want to use the
    settings of the original `document`, pass ``settings=document.settings``.

    Also, new `document.transformer` and `document.reporter` objects are
    generated.

    Parameters: `document` is a `docutils.nodes.document` object, an existing
    document tree.

    Other parameters: see `publish_programmatically()`.

    This function is provisional because in Python 3 name and behaviour
    of the `io.StringOutput` class no longer match.
    r   )r!   N)r   r   r   rf   )
r   Readerr   r   ZDocTreeInputr   r$   rG   rO   ri   )r   rM   r   r#   r   r6   rF   r3   rf   r   r   r   r   r   publish_from_doctree  s    
  r   c              	   C   s<   t | ||||d}|||| |j||||||	|
d}|S )a  
    Set up & run a `Publisher` for command-line-based file I/O (input and
    output file paths taken automatically from the command line).
    Also return the output as `bytes`.

    This is just like publish_cmdline, except that it uses
    io.BinaryFileOutput instead of io.FileOutput.

    Parameters: see `publish_programmatically()` for the remainder.

    - `argv`: Command-line argument list to use instead of ``sys.argv[1:]``.
    - `usage`: Usage string, output if there's a problem parsing the command
      line.
    - `description`: Program description, output for the "--help" option
      (along with command-line option descriptions).
    )r   r   r   r   )r   r    r   r!   r   r#   r   r6   rF   r3   rf   rI   r.   r/   r   r   r   rU   r   r   r   publish_cmdline_to_binary?  s    
     r   c                 C   s\   t |||
|| |d}|||	| |||| ||| ||| |j|d}||fS )a^  
    Set up & run a `Publisher` for custom programmatic use.

    Return the output (as `str` or `bytes`, depending on `destination_class`,
    writer, and the "output_encoding" setting) and the Publisher object.

    Applications should not need to call this function directly.  If it does
    seem to be necessary to call this function directly, please write to the
    Docutils-develop mailing list
    <https://docutils.sourceforge.io/docs/user/mailing-lists.html#docutils-develop>.

    Parameters:

    * `source_class` **required**: The class for dynamically created source
      objects.  Typically `io.FileInput` or `io.StringInput`.

    * `source`: Type depends on `source_class`:

      - If `source_class` is `io.FileInput`: Either a file-like object
        (must have 'read' and 'close' methods), or ``None``
        (`source_path` is opened).  If neither `source` nor
        `source_path` are supplied, `sys.stdin` is used.

      - If `source_class` is `io.StringInput` **required**:
        The input as either a `bytes` object (ensure the 'input_encoding'
        setting matches its encoding) or a `str` object.

    * `source_path`: Type depends on `source_class`:

      - `io.FileInput`: Path to the input file, opened if no `source`
        supplied.

      - `io.StringInput`: Optional.  Path to the file or name of the
        object that produced `source`.  Only used for diagnostic output.

    * `destination_class` **required**: The class for dynamically created
      destination objects.  Typically `io.FileOutput` or `io.StringOutput`.

    * `destination`: Type depends on `destination_class`:

      - `io.FileOutput`: Either a file-like object (must have 'write' and
        'close' methods), or ``None`` (`destination_path` is opened).  If
        neither `destination` nor `destination_path` are supplied,
        `sys.stdout` is used.

      - `io.StringOutput`: Not used; pass ``None``.

    * `destination_path`: Type depends on `destination_class`:

      - `io.FileOutput`: Path to the output file.  Opened if no `destination`
        supplied.

      - `io.StringOutput`: Path to the file or object which will receive the
        output; optional.  Used for determining relative paths (stylesheets,
        source links, etc.).

    * `reader`: A `docutils.readers.Reader` object.

    * `reader_name`: Name or alias of the Reader class to be instantiated if
      no `reader` supplied.

    * `parser`: A `docutils.parsers.Parser` object.

    * `parser_name`: Name or alias of the Parser class to be instantiated if
      no `parser` supplied.

    * `writer`: A `docutils.writers.Writer` object.

    * `writer_name`: Name or alias of the Writer class to be instantiated if
      no `writer` supplied.

    * `settings`: A runtime settings (`docutils.frontend.Values`) object, for
      dotted-attribute access to runtime settings.  It's the end result of the
      `SettingsSpec`, config file, and option processing.  If `settings` is
      passed, it's assumed to be complete and no further setting/config/option
      processing is done.

    * `settings_spec`: A `docutils.SettingsSpec` subclass or object.  Provides
      extra application-specific settings definitions independently of
      components.  In other words, the application becomes a component, and
      its settings data is processed along with that of the other components.
      Used only if no `settings` specified.

    * `settings_overrides`: A dictionary containing application-specific
      settings defaults that override the defaults of other components.
      Used only if no `settings` specified.

    * `config_section`: A string, the name of the configuration file section
      for this application.  Overrides the ``config_section`` attribute
      defined by `settings_spec`.  Used only if no `settings` specified.

    * `enable_exit_status`: Boolean; enable exit status at end of processing?
    )r   r   r   r   )r   r'   rG   rN   rO   ri   )r   r   rL   r   r   rM   r   r    r   r!   r   r#   r   r6   rF   r3   rf   r   rU   r   r   r   r   e  s    e
  r   ry   c                 C   s4   d| d| dt  }ttjd t| |d d S )Nz	Generate zZ documents from standalone reStructuredText sources <https://docutils.sourceforge.io/docs/z>.  ry   )r#   r/   )default_descriptionlocale	setlocaleLC_ALLr   )r   ZdocumenttypeZdoc_pathr/   r   r   r   rst2something  s    r   c                   C   s   t ddd d S )NhtmlHTMLzuser/html.html#htmlr   r   r   r   r   rst2html  s    r   c                   C   s   t ddd d S )NZhtml4z	XHTML 1.1zuser/html.html#html4css1r   r   r   r   r   	rst2html4  s    r   c                   C   s   t ddd d S )Nhtml5ZHTML5zuser/html.html#html5-polyglotr   r   r   r   r   	rst2html5  s    r   c                   C   s   t ddd d S )NlatexZLaTeXuser/latex.htmlr   r   r   r   r   	rst2latex  s    r   c                   C   s   t ddd d S )NZmanpagezUnix manual (troff)zuser/manpage.htmlr   r   r   r   r   rst2man  s    r   c                   C   s   t ddd d S )NZodtzOpenDocument text (ODT)zuser/odt.htmlr   r   r   r   r   rst2odt  s    r   c                   C   s   t ddd d S )Nr   zpseudo-XML (test)ref/doctree.htmlr   r   r   r   r   rst2pseudoxml  s    r   c                   C   s   t ddd d S )NZs5zS5 HTML slideshowzuser/slide-shows.htmlr   r   r   r   r   rst2s5  s    r   c                   C   s   t ddd d S )NZxetexzLaTeX (XeLaTeX/LuaLaTeX)r   r   r   r   r   r   	rst2xetex  s    r   c                   C   s   t ddd d S )NxmlzDocutils-native XMLr   r   r   r   r   r   rst2xml  s    r   )NNNNNr   Nr   Nr   NNNNF)NNNr   Nr   Nr   NNNNF)NNr   NNNNF)ry   )+r   __docformat__r   rt   r|   rH   r0   Zdocutilsr   r   r   r   r   r   r	   Zdocutils.frontendr
   Zdocutils.readersr   r   Zdefault_usager   r   r   r   r   r   r   r   ZBinaryFileOutputr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s   $  O      
                     
                 
&     
&    
           
%  
&t
