o
    i                     @  s  d Z ddlm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mZ ddlmZ ddlmZ dZerNd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							d>ddZ							d?d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#					d@ddZ$ddddddddddddeedej%fdd Z&dAd#d$Z'd%d& Z(dBdAd(d)Z)dAd*d+Z*dAd,d-Z+dAd.d/Z,dAd0d1Z-dAd2d3Z.dAd4d5Z/dAd6d7Z0dAd8d9Z1dAd:d;Z2dAd<d=Z3dS )Ca  
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
    )annotationsreStructuredTextN)__version____version_details__SettingsSpecioutilsreadersparserswriters)OptionParser)doctreeF)TextIO)StrPathc                   @  s   e Zd ZdZddddejdejdfd1ddZd2d1ddZd1d	d
Z	d1ddZ
		d3ddZ		d3ddZd1ddZ		d4d1ddZd2d1ddZ		d2d5ddZ		d2d6d d!Zd1d"d#Z			$d7d%d&Zd1d'd(Zd1d)d*Zd1d+d,Zd1d-d.Zd1d/d0ZdS )8	PublisherzK
    A facade encapsulating the high-level logic of a Docutils system.
    NreturnNonec	           	      C  s   t |trt||}t |tr+t |tjr%|jdu r!|| |j}nt| }t |tr6t	
| }d| _	 || _	 || _	 || _	 || _	 || _	 || _	 || _	 || _	 t | _dS )z
        Initial setup.

        The components `reader`, `parser`, or `writer` should all be
        specified, either as instances or via their names.
        N)
isinstancestrr	   get_reader_classReaderparser
set_parserr
   get_parser_classr   get_writer_classdocumentreaderwritersourcesource_classdestinationdestination_classsettingsr   ErrorOutput_stderr)	selfr   r   r   r   r   r    r!   r"    r&   S/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/docutils/core.py__init__+   s:   




zPublisher.__init__c                 C  sL   t |}|||| _| jjdur| jj| _dS | jdur$| j| j_dS dS )zSet `self.reader` by name.

        The "paser_name" argument is deprecated,
        use "parser" with parser name or instance.
        N)r	   r   r   r   )r%   r   r   parser_namereader_classr&   r&   r'   
set_readera   s   

zPublisher.set_readerc                 C  s   t |}| | _dS )zSet `self.writer` by name.N)r   r   r   )r%   writer_namewriter_classr&   r&   r'   
set_writern   s   
zPublisher.set_writerc                 C  sr   t jdtdd | jd u r| || j| | jd u r+| jjd u r&| j| | jj| _| jd u r7| | d S d S )Nzh`Publisher.set_components()` will be removed in Docutils 2.0.  Specify component names at instantiation.   
stacklevel)	warningswarnPendingDeprecationWarningr   r+   r   r   r   r.   )r%   reader_namer)   r,   r&   r&   r'   set_componentss   s   



zPublisher.set_componentsc                 K  s   t  = t jdtd |r*|st }||_| }t|dkr*|d dkr*dg|_t	| j
| j| j|f|d||dW  d    S 1 sDw   Y  d S )	Nignore)category   applicationapplicationsT)
componentsdefaultsread_config_filesusagedescription)r2   catch_warningsfilterwarningsDeprecationWarningr   config_sectionsplitlenconfig_section_dependenciesr   r   r   r   )r%   r@   rA   settings_specrE   r>   partsr&   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.
        )rK   get_default_valuesr"   )r%   r@   rA   rI   rE   r>   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)rI   rE   r&   )r"   copy
setdefaultrN   )r%   rI   settings_overridesrE   r>   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`).
        Nr9   )rK   sysargv
parse_argsr"   )r%   rU   r@   rA   rI   rE   r>   rM   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%   rX   rY   r&   r&   r'   set_io   s
   

zPublisher.set_ior   
str | NonerX   StrPath | Nonec                 C  sD   |d u r	| j j}n	t|}|| j _| j||| j j| j jd| _d S )N)r   rX   encodingerror_handler)r"   _sourceosfspathr   input_encodinginput_encoding_error_handlerr   )r%   r   rX   r&   r&   r'   rZ      s   

zPublisher.set_sourcer    TextIO | NonerY   c                 C  s   |d urt || j_n;t| jdd r| jjs| jj| j_| jjr1| jjr1| jj| jjkr1td| jjd u r=| jj| j_| jjdkrGd | j_| jj | j_| j_| j|| jj| jj	| jj
d| _d S )NoutputznThe --output-path option obsoletes the second positional argument (DESTINATION). You cannot use them together.-)r    rY   r_   r`   )rb   rc   r"   output_pathgetattrrg   _destination
SystemExitr!   output_encodingoutput_encoding_error_handlerr    )r%   r    rY   r&   r&   r'   r[      s*   zPublisher.set_destinationc                 C  s4   | j j| j| j| jj| j| jf | j j  d S )N)	r   transformerpopulate_from_componentsr   r   r   r   r    apply_transformsr%   r&   r&   r'   rq      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.
        NTr9   
   )r"   rW   r\   promptr   readr   r   r   rq   r   writer    assemble_partsrl   code	ExceptionrO   debugging_dumpsreport_Exceptionreporter	max_levelexit_status_levelrT   exit)r%   rU   r@   rA   rI   rR   rE   enable_exit_statusexit_rg   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pendingkwargsr&   r&   r'   
<listcomp>5  s
    

z-Publisher.debugging_dumps.<locals>.<listcomp>z
::: Pseudo-XML:raw_unicode_escape)r   r"   dump_settingsprintr$   pprintpformat__dict__dump_internalsdump_transformsro   applieddump_pseudo_xmlencoderr   r&   r&   r'   rz   '  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):r   )r   isattyr$   AttributeErrorrb   namer   	supportedr   
IndexErrorr   r   )r%   eot_key	in_format
out_formatr&   r&   r'   rt   >  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%sr   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$   rv   error_stringOutputErrorr   r   r   rT   versionrF   r%   r   r&   r&   r'   r{   T  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.r   )r   levelr   Reporterlevelsr$   r   r&   r&   r'   r   j  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$   rv   r   r   r"   rm   r   rn   r   rT   r   rF   )r%   r   datar&   r&   r'   r   o  s   

zPublisher.report_UnicodeErrorr   r   )NN)NNNN)NNNNN)r   r]   rX   r^   r   r   )r    rf   rY   r^   r   r   )NNNNNNF)r   r   __qualname____doc__r   	FileInput
FileOutputr(   r+   r.   r6   rK   rN   rS   rW   r\   rZ   r[   rq   r   rz   rt   r{   r   r   r&   r&   r&   r'   r   %   sJ    6







*


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.Tc              	   C  s\   t ||| | p|pd} |p|pd}|p|pd}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).
    
standalonerestructuredtext	pseudoxml)r"   rE   r   )_name_arg_warningr   r   )r   r5   r   r)   r   r,   r"   rI   rR   rE   r   rU   r@   rA   	publisherrg   r&   r&   r'   publish_cmdline  s   
r   c                 C  s   t |||	 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   rX   r!   r    rY   r   r5   r   r)   r   r,   r"   rI   rR   rE   r   Nr&   )r   publish_programmaticallyr   r   r   )r   rX   r    rY   r   r5   r   r)   r   r,   r"   rI   rR   rE   r   rg   
_publisherr&   r&   r'   publish_file  sJ   	
r   c                 C  s   t ||| 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 )u  
    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()` or
    https://docutils.sourceforge.io/docs/api/publisher.html#publish-string

    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   rX   r!   r    NrY   r   r5   r   r)   r   r,   r"   rI   rR   rE   r   r&   )r   r   r   StringInputStringOutput)r   rX   rY   r   r5   r   r)   r   r,   r"   rI   rR   rE   r   rg   r   r&   r&   r'   publish_string  sJ   	
r   c                 C  s   t |||	 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   rX   r   r!   r    NrY   r   r5   r   r)   r   r,   r"   rI   rR   rE   r   r&   )r   r   r   r   r   rJ   )r   rX   r   rY   r   r5   r   r)   r   r,   r"   rI   rR   rE   r   _outputr   r&   r&   r'   publish_parts	  sJ   	
r   c                 C  s   t ||d 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()`.
    Nr   rX   r   r    rY   r!   r   r5   r   r)   r   nullr,   r"   rI   rR   rE   r   r&   )r   r   r   
NullOutputr   )r   rX   r   r   r5   r   r)   r"   rI   rR   rE   r   r   r   r&   r&   r'   publish_doctree2  sJ   		
r   c	           
      C  sX   t dd| tt |p|pdt| tj|d}	|	||| |	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.
    Nr   )r   r   r   r!   r"   r   )
r   r   r   r   r   DocTreeInputr   rS   r[   r   )
r   rY   r   r,   r"   rI   rR   rE   r   r   r&   r&   r'   publish_from_doctreeO  s   
r   r   r   r   c              	   C  sL   t jdtdd t| ||||d}|||| |j||||||	|
d}|S )u
  
    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).

    Deprecated. Use `publish_cmdline()` (works with `bytes` since
    Docutils 0.20). Will be removed in Docutils 0.24.
    zg"publish_cmdline_to_binary()" is obsoleted by "publish_cmdline()" and will be removed in Docutils 0.24.r/   r0   )r"   r!   r   )r2   r3   rD   r   r6   r   )r   r5   r   r)   r   r,   r"   rI   rR   rE   r   rU   r@   rA   r    r!   r   rg   r&   r&   r'   publish_cmdline_to_binaryt  s    

r   r   r   c               	   G  sD   t d| D ]\}}|d urtjd| d| d| dtdd qd S )N)r   r   r   z
Argument "z1_name" will be removed in Docutils 2.0.  Specify z name in the "z" argument.   r0   )zipr2   r3   r4   )	name_args	componentname_argr&   r&   r'   r     s   r   c                 C  sr   |p|pd}|p|	pd}|
p|pd}
t |||
|| |d}|||| ||| ||| |j|d}||fS )aH  
    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.

    Internal:
    Applications should not 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` instance, name, or alias.
      Default: "standalone".

    * `reader_name`: Deprecated. Use `reader`.

    * `parser`: A `docutils.parsers.Parser` instance, name, or alias.
      Default: "restructuredtext".

    * `parser_name`: Deprecated. Use `parser`.

    * `writer`: A `docutils.writers.Writer` instance, name, or alias.
      Default: "pseudoxml".

    * `writer_name`: Deprecated. Use `writer`.

    * `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!   r   )r   rS   rZ   r[   r   )r   r   rX   r!   r    rY   r   r5   r   r)   r   r,   r"   rI   rR   rE   r   r   rg   r&   r&   r'   r     s   f
r   r   c              
   C  st   d| d| dt  }z	ttjd W n tjy1 } ztjd| d W Y d }~nd }~ww t| |d d S )Nz	Generate zZ documents from standalone reStructuredText sources <https://docutils.sourceforge.io/docs/z>.  r   z(WARNING: Cannot set the default locale: z.
)r   rA   )	default_descriptionlocale	setlocaleLC_ALLErrorrT   stderrrv   r   )r   documenttypedoc_pathrA   er&   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'   rst2html2     r   c                   C  r   )Nhtml4z	XHTML 1.1zuser/html.html#html4css1r   r&   r&   r&   r'   	rst2html46  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'   rst2manB  r   r   c                   C  r   )NodtzOpenDocument text (ODT)zuser/odt.htmlr   r&   r&   r&   r'   rst2odtF  r   r   c                   C  r   )Nr   zpseudo-XML (test)ref/doctree.htmlr   r&   r&   r&   r'   rst2pseudoxmlJ  r   r   c                   C  r   )Ns5zS5 HTML slideshowzuser/slide-shows.htmlr   r&   r&   r&   r'   rst2s5N  r   r   c                   C  r   )NxetexzLaTeX (XeLaTeX/LuaLaTeX)r   r   r&   r&   r&   r'   	rst2xetexR  r   r   c                   C  r   )NxmlzDocutils-native XMLr   r   r&   r&   r&   r'   rst2xmlV  r   r   )NNNNNNNNNNNNNNF)NNNNNNNNNNNNF)NNNNNNNFr   )r   )4r   
__future__r   __docformat__r   r   rb   rT   r2   docutilsr   r   r   r   r   r	   r
   r   docutils.frontendr   docutils.readersr   TYPE_CHECKINGtypingr   docutils.nodesr   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&   r'   <module>   s   (  k
"

*
)

%

,	x








