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mZ ddl	Z	ddl	m
Z
mZmZmZ ddlmZ dZerVdd	lmZmZ dd
lmZ ddlmZ ddlmZ ddlmZ G dd de
ZG dd deZG dd dejZejdd dk rddlZG dd de e Zi dddddddddddd d!d"d#d$d%d$d&d$d'd(d)d(d*d(d+d(d,d(d-d.d/d.d0d1d2Z!d9d7d8Z"dS ):z0
This package contains Docutils Writer modules.
    )annotationsreStructuredTextN)Path)	Component	languagesnodesutils)	universalF)AnyFinal)Output)LanguageModule)StrPath)	Transformc                      s   e Zd ZU dZdZded< dZded< d fd	d
ZdZded< 	 dZ	ded< 	 dZ
ded< 	 dZded< 	 d ddZd!ddZd ddZd ddZ  ZS )"Writera  
    Abstract base class for docutils Writers.

    Each writer module or package must export a subclass also called 'Writer'.
    Each writer must support all standard node types listed in
    `docutils.nodes.node_class_names`.

    The `write()` method is the main entry point.
    writerr   component_typewritersconfig_sectionreturnlist[type[Transform]]c                   s   t   tjtjtjg S N)superget_transformsr	   MessagesFilterMessagesStripClassesAndElementsself	__class__ _/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/docutils/writers/__init__.pyr   /   s   zWriter.get_transformsNznodes.document | Nonedocumentstr | bytes | NoneoutputzLanguageModule | NonelanguagezOutput | NonedestinationNonec                 C  s
   i | _ d S r   )partsr   r!   r!   r"   __init__F   s   zWriter.__init__nodes.documentr   c                 C  s6   || _ t|jj|j| _|| _|   | j	| j
S )a/  
        Process a document into its final form.

        Translate `document` (a Docutils document tree) into the Writer's
        native format, and write it out to its `destination` (a
        `docutils.io.Output` subclass object).

        Normally not overridden or extended in subclasses.
        )r#   r   get_languagesettingslanguage_codereporterr&   r'   	translatewriter%   )r   r#   r'   r!   r!   r"   r1   O   s   zWriter.writec                 C  s   t d)a  
        Do final translation of `self.document` into `self.output`.  Called
        from `write`.  Override in subclasses.

        Usually done with a `docutils.nodes.NodeVisitor` subclass, in
        combination with a call to `docutils.nodes.Node.walk()` or
        `docutils.nodes.Node.walkabout()`.  The ``NodeVisitor`` subclass must
        support all standard elements (listed in
        `docutils.nodes.node_class_names`) and possibly non-standard elements
        used by the current Reader as well.
        z"subclass must override this method)NotImplementedErrorr   r!   r!   r"   r0   d   s   zWriter.translatec                 C  s<   | j | jd< | jjj| jd< | jjj| jd< tj| jd< dS )zAssemble the `self.parts` dictionary.  Extend in subclasses.

        See <https://docutils.sourceforge.io/docs/api/publisher.html>.
        wholeencodingerrorsversionN)r%   r)   r#   r-   output_encodingoutput_encoding_error_handlerdocutils__version__r   r!   r!   r"   assemble_partsr   s
   zWriter.assemble_partsr   r   r   r(   )r#   r+   r'   r   r   r$   )__name__
__module____qualname____doc__r   __annotations__r   r   r#   r%   r&   r'   r*   r1   r0   r;   __classcell__r!   r!   r   r"   r       s"   
 


	
r   c                   @  s   e Zd ZdZdddZdS )UnfilteredWriterz
    A writer that passes the document tree on unchanged (e.g. a
    serializer.)

    Documents written by UnfilteredWriters are typically reused at a
    later date using a subclass of `readers.ReReader`.
    r   r   c                 C  s
   t | S r   )r   r   r   r!   r!   r"   r      s   
zUnfilteredWriter.get_transformsNr<   )r>   r?   r@   rA   r   r!   r!   r!   r"   rD   ~   s    rD   c                      s.   e Zd ZdZd fddZddddZ  ZS )DoctreeTranslatorz
    Generic Docutils document tree translator base class.

    Adds auxiliary methods and attributes that are used by several
    Docutils writers to the `nodes.NodeVisitor` abstract superclass.
    r   r(   c                   s   t  | |j| _d S r   )r   r*   r-   )r   r#   r   r!   r"   r*      s   zDoctreeTranslator.__init__Nuristroutput_pathStrPath | Noner   c                 C  s   |du r| j j}|drt|S tj|}|jdkr%t	d| dtj
|j}| j jr@|dr@t| j j|d S t|}|r[| s[t|j }ttd|| }|S )a  Return filesystem path corresponding to a `URI reference`__.

        The `root_prefix`__ setting` is applied to URI references starting
        with "/" (but not to absolute Windows paths or "file" URIs).

        If `output_path` (defaults to the `output_path`__ setting) is
        not empty, relative paths are adjusted.
        (To work in the output document, URI references with relative path
        relate to the output directory.  For access by the writer, paths
        must be relative to the working directory.)

        Use case:
          The <image> element refers to the image via a "URI reference".
          The corresponding filesystem path is required to read the
          image size from the file or to embed the image in the output.

          A filesystem path is also expected by the "LaTeX" output format
          (with relative paths unchanged, relating to the output directory,
          set `output_path` to the empty string).

        Provisional: the function's location, interface and behaviour
        may change without advance warning.

        __ https://www.rfc-editor.org/rfc/rfc3986.html#section-4.1
        __ https://docutils.sourceforge.io/docs/user/config.html#root-prefix
        __ https://docutils.sourceforge.io/docs/user/config.html#output-path
        Nfile: z&Cannot get file path corresponding to ./)r-   rH   
startswithr   from_uriurllibparseurlsplitscheme
ValueErrorunquotepathroot_prefixremoveprefixis_absoluteparentresolver   relative_path)r   rF   rH   	uri_partsrV   dest_dirr!   r!   r"   uri2path   s   


zDoctreeTranslator.uri2pathr=   r   )rF   rG   rH   rI   r   r   )r>   r?   r@   rA   r*   r_   rC   r!   r!   r   r"   rE      s    rE      )      c                   @  s   e Zd ZdZedd ZdS )r   zK`pathlib.Path` with `from_uri()` classmethod backported from 3.13.
        c                 C  s   | dstd||dd }|dd dkr!|dd }n|dd d	kr/|d
d }|dd dksG|dd dkrM|dd dv rM|dd }|dd dkrc|dd d |dd  }| tj|}| svtd||S )z,Return a new path from the given 'file' URI.rJ   z!URI does not start with 'file:':    Nra   z///r`      z//localhost/      rM   z:||:zURI is not absolute: )rN   rT   rP   rQ   rU   rY   )clsrF   rV   r!   r!   r"   rO      s   
0zPath.from_uriN)r>   r?   r@   rA   classmethodrO   r!   r!   r!   r"   r      s    r   html	html4css1html4xhtml10html5html5_polyglotxhtmls5s5_htmllatexlatex2exelatexxetexluatexlualatexodfodf_odtodtooffice
openofficelibreofficepprint	pseudoxmlpformatrlpdfdocutils_xml)pdfxmlwriter_namerG   r   type[Writer]c                 C  s|   |   }t||}ztd| }W |jS  ty=   z
t|}W Y |jS  ty< } z
td|  d| d}~ww w )z6Return the Writer class from the `writer_name` module.zdocutils.writers.zWriter "z" not found. N)lowerWRITER_ALIASESget	importlibimport_moduleImportErrorr   )r   namemoduleerrr!   r!   r"   get_writer_class
  s   r   )r   rG   r   r   )#rA   
__future__r   __docformat__r   sysrP   pathlibr   r9   r   r   r   r   docutils.transformsr	   TYPE_CHECKINGtypingr
   r   docutils.ior   docutils.languagesr   docutils.nodesr   r   r   rD   NodeVisitorrE   version_infotyper   r   r!   r!   r!   r"   <module>   sx   ^@	
