o
    Ni                     @   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			d-ddZd d! Zd"d# Zd$d% Zd&d' Zd(d) ZdS ).	PublisherzK
    A facade encapsulating the high-level logic of a Docutils system.
    Nc	           
      C   s   d| _ 	 || _	 || _	 || _	 dD ]}	tt| |	tr(J 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sourcesource_classdestinationdestination_classsettingsr   ErrorOutput_stderr)
selfr   r   r   r   r   r   r   r   	component r   A/home/ubuntu/.local/lib/python3.10/site-packages/docutils/core.py__init__$   s2   zPublisher.__init__c                 C   s$   t |}|||| _| jj| _dS )zSet `self.reader` by name.N)r   get_reader_classr   r   )r   reader_namer   parser_namereader_classr   r   r   
set_readerU   s   
zPublisher.set_readerc                 C   s   t |}| | _dS )zSet `self.writer` by name.N)r	   get_writer_classr   )r   writer_namewriter_classr   r   r   
set_writer[   s   
zPublisher.set_writerc                 C   sb   | j d u r| || j| | jd u r#| j jd u r| j | | j j| _| jd u r/| | d S 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 |r&|st }||_| }t|dkr&|d dkr&dg|_t| j	| j
| j|f|d||d	S )
NzRPublisher.setup_option_parser is deprecated, and will be removed in Docutils 0.21.   )
stacklevel   applicationapplicationsT)
componentsdefaultsread_config_filesusagedescription)warningswarnDeprecationWarningr   config_sectionsplitlenconfig_section_dependenciesr
   r   r   r   )r   r5   r6   settings_specr:   r3   partsr   r   r   setup_option_parserj   s   zPublisher.setup_option_parserc                 O   sJ   t   t jdtd | j|i |W  d    S 1 sw   Y  d S )Nignore)category)r7   catch_warningsfilterwarningsr9   r@   )r   argskwargsr   r   r   _setup_settings_parser}   s   
$z Publisher._setup_settings_parserc                 K   s(   | j ||||fi |}| | _| 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.
        )rG   get_default_valuesr   )r   r5   r6   r>   r:   r3   option_parserr   r   r   get_settings   s   
zPublisher.get_settingsc                 C   sD   | j d u r |r| ni }|dd | jd||d| d S d S )N	tracebackT)r>   r:   r   )r   copy
setdefaultrJ   )r   r>   settings_overridesr:   r3   r   r   r   process_programmatic_settings   s   

z'Publisher.process_programmatic_settingsc                 K   s>   | j ||||fi |}|du 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.   )rG   sysargv
parse_argsr   )r   rQ   r5   r6   r>   r:   r3   rI   r   r   r   process_command_line   s   zPublisher.process_command_linec                 C   s4   | j d u r| j|d | jd u r| j|d d S d S )N)source_path)destination_path)r   
set_sourcer   set_destination)r   rT   rU   r   r   r   set_io   s
   

zPublisher.set_ioc                 C   s:   |d u r	| j j}n|| j _| j||| j j| j jd| _d S )N)r   rT   encodingerror_handler)r   _sourcer   input_encodinginput_encoding_error_handlerr   )r   r   rT   r   r   r   rV      s   
zPublisher.set_sourcec                 C   s|   |d u r*| j jr| j jr| j j| j jkrtd| j jdkr"d | j _| j jp)| 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   rU   rY   rZ   )r   output_destination
SystemExitr   output_encodingoutput_encoding_error_handlerr   )r   r   rU   r   r   r   rW      s    zPublisher.set_destinationc                 C   s4   | j j| j| j| jj| j| jf | j j  d S r)   )	r   transformerpopulate_from_componentsr   r   r   r   r   apply_transformsr   r   r   r   rf      s   zPublisher.apply_transformsFc              
   C   sH  d}z<| j du r| j|||||fi |pi  |   |   | j| j| j| j | _| 	  | j
| j| j}	| j
  W n> tyU }
 zd}|
j}W Y d}
~
n,d}
~
w ty| }
 z| j s` | j jri|    | |
 d}d}W Y d}
~
nd}
~
ww |   |r| jr| jjj| j jkrt| jjjd  |	S |rt| |	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   rS   rX   promptr   readr   r   r   rf   r   writer   assemble_partsra   code	ExceptionrK   debugging_dumpsreport_Exceptionreporter	max_levelexit_status_levelrP   exit)r   rQ   r5   r6   r>   rN   r:   enable_exit_statusrt   r_   errorexit_statusr   r   r   publish   sR   


	

zPublisher.publishc                 C   s   | j sd S | jjrtd| jd tt| jj| jd | jjr3td| jd tt| j j| jd | jj	rWtd| jd td| jd ttdd | j j
jD | jd | jjrqtd| jd t| j  d	| jd d S 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priorityxclasspendingrF   r   r   r   
<listcomp>  s
    

z-Publisher.debugging_dumps.<locals>.<listcomp>z
::: Pseudo-XML:raw_unicode_escape)r   r   dump_settingsprintr   pprintpformat__dict__dump_internalsdump_transformsrd   applieddump_pseudo_xmlencoderg   r   r   r   ro     s8   
zPublisher.debugging_dumpsc              
   C   s   z| j  r| j sW dS W n
 ty   Y dS w tjdkr!dnd}d}d}z| jjd }| jjd }W n tt	fy@   Y nw 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):ry   )r   isattyr   AttributeErrorosnamer   	supportedr   
IndexErrorr   r   )r   eot_key	in_format
out_formatr   r   r   ri     s2   

zPublisher.promptc                 C   s   t |tjr| | d S t |tr| | d S t |tjr,| j	dt
|  d S t |tjr?| j	dt
|  d S tdt
| | jd tdt trWd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%sry   zExiting due to error.  Use "--traceback" to diagnose.
Please report errors to <docutils-users@lists.sourceforge.net>.
Include "--traceback" output, Docutils version (z []r   z),
Python version (r   z5), your OS type & version, and the command line used.)r   r   SystemMessagereport_SystemMessageUnicodeEncodeErrorreport_UnicodeErrorr   
InputErrorr   rk   error_stringOutputErrorr   r   r   rP   versionr;   r   rv   r   r   r   rp   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.ry   )r   levelr   Reporter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   rk   r   r   r   rb   r   rc   r   rP   r   r;   )r   rv   datar   r   r   r   L  s   

zPublisher.report_UnicodeError)NNNN)NNNNN)NN)NNNNNNF)r|   r{   __qualname____doc__r   	FileInput
FileOutputr   r$   r(   r+   r@   rG   rJ   rO   rS   rX   rV   rW   rf   rx   ro   ri   rp   r   r   r   r   r   r   r      sD    
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   r:   ru   r   r+   rx   )r   r!   r   r"   r   r&   r   r>   rN   r:   ru   rQ   r5   r6   	publisherr_   r   r   r   publish_cmdline{  s   
r   Fc                 C   s|   t di dtjd| d|dtjd|d|d|d|d	|d
|d|d|	d|
d|d|d|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   rT   r   r   rU   r   r!   r   r"   r   r&   r   r>   rN   r:   ru   Nr   )publish_programmaticallyr   r   r   )r   rT   r   rU   r   r!   r   r"   r   r&   r   r>   rN   r:   ru   r_   r   r   r   r   publish_file  sH   	
r   c                 C   s|   t di dtjd| d|dtjddd|d|d	|d
|d|d|d|d|	d|
d|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
    r   r   rT   r   r   NrU   r   r!   r   r"   r   r&   r   r>   rN   r:   ru   r   )r   r   StringInputStringOutput)r   rT   rU   r   r!   r   r"   r   r&   r   r>   rN   r:   ru   r_   r   r   r   r   publish_string  sH   	
r   c                 C   s~   t di d| d|d|dtjddd|d|d	|d
|d|d|d|	d|
d|d|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
    r   rT   r   r   r   NrU   r   r!   r   r"   r   r&   r   r>   rN   r:   ru   r   )r   r   r   r   r?   )r   rT   r   rU   r   r!   r   r"   r   r&   r   r>   rN   r:   ru   r_   r   r   r   r   publish_parts  sH   	
r   c                 C   s|   t di d| d|d|dddddtjd|d	|d
|d|ddddd|d|d|	d|
d|\}}|jS )z
    Set up & run a `Publisher` for programmatic use. Return a document tree.

    Parameters: see `publish_programmatically()`.
    r   rT   r   r   NrU   r   r   r!   r   r"   r   r&   nullr   r>   rN   r:   ru   r   )r   r   
NullOutputr   )r   rT   r   r   r!   r   r"   r   r>   rN   r:   ru   _outputr   r   r   r   publish_doctree   sH   		
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   ru   )
r   Readerr   r   DocTreeInputr   r(   rO   rW   rx   )r   rU   r   r&   r   r>   rN   r:   ru   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   r>   rN   r:   ru   rQ   r5   r6   r   r   r   r_   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+   rO   rV   rW   rx   )r   r   rT   r   r   rU   r   r!   r   r"   r   r&   r   r>   rN   r:   ru   r   r_   r   r   r   r   e  s   
er   r   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>.  r   )r&   r6   )default_descriptionlocale	setlocaleLC_ALLr   )r   documenttypedoc_pathr6   r   r   r   rst2something  s   r   c                   C      t ddd d S )NhtmlHTMLzuser/html.html#htmlr   r   r   r   r   rst2html     r   c                   C   r   )Nhtml4z	XHTML 1.1zuser/html.html#html4css1r   r   r   r   r   	rst2html4  r   r   c                   C   r   )Nhtml5HTML5zuser/html.html#html5-polyglotr   r   r   r   r   	rst2html5  r   r   c                   C   r   )NlatexLaTeXuser/latex.htmlr   r   r   r   r   	rst2latex  r   r   c                   C   r   )NmanpagezUnix manual (troff)zuser/manpage.htmlr   r   r   r   r   rst2man  r   r   c                   C   r   )NodtzOpenDocument text (ODT)zuser/odt.htmlr   r   r   r   r   rst2odt  r   r   c                   C   r   )Nr   zpseudo-XML (test)ref/doctree.htmlr   r   r   r   r   rst2pseudoxml  r   r   c                   C   r   )Ns5zS5 HTML slideshowzuser/slide-shows.htmlr   r   r   r   r   rst2s5  r   r   c                   C   r   )NxetexzLaTeX (XeLaTeX/LuaLaTeX)r   r   r   r   r   r   	rst2xetex  r   r   c                   C   r   )NxmlzDocutils-native XMLr   r   r   r   r   r   rst2xml  r   r   )NNNNNr   Nr   Nr   NNNNF)NNNr   Nr   Nr   NNNNF)NNr   NNNNF)r   )+r   __docformat__r   r   r   rP   r7   docutilsr   r   r   r   r   r   r	   docutils.frontendr
   docutils.readersr   r   default_usager   r   r   r   r   r   r   r   BinaryFileOutputr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s   $  O


&
&

%
&
t