o
    i                     @  s   d Z ddlmZ dZddlZddlm  mZ ddl	m
Z
mZmZmZ G dd dejZG dd	 d	ejejejZdd
dZdddZdddZdS )zA Docutils-XML parser.

   Provisional:
     The API is not fixed yet.
     Defined objects may be renamed or changed
     in any Docutils release without prior notice.
    )annotationsreStructuredTextN)frontendnodesparsersutilsc                   @  s2   e Zd ZdZdZ	 dZdZdddZdd
dZdS )ParserzA Docutils-XML parser.)xmlzdocutils-xmlz
xml parser)r   FT)doctitle_xformvalidatereturnNonec                 C  s8   |  || t||}t|tjs|| |   dS )zg
        Parse `inputstring` and populate `document`, a "document tree".

        Provisional.
        N)setup_parseparse_element
isinstancer   documentappendfinish_parse)selfinputstringr   node r   c/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/docutils/parsers/docutils_xml.pyparse.   s
   

zParser.parseNr   r   )	__name__
__module____qualname____doc__	supportedconfig_sectionconfig_section_dependenciessettings_default_overridesr   r   r   r   r   r   !   s    r   c                   @  s"   e Zd ZdZejejfdffZdS )Unknownz+An unknown element found by the XML parser.*N)r   r   r   r   r   ElementTextcontent_modelr   r   r   r   r#   =   s    r#   c           	      C  s   d}t jdd}t| jddD ]N\}}z|| | D ]\}}|du r(|}t|d |jd< qW q t jy^ } z|du rA |j	j
d| d	|jj|jd
 d W Y d}~ nd}~ww t||S )aU  
    Parse `inputstring` as "Docutils XML", return `nodes.Element` instance.

    :inputstring: XML source.
    :document: `nodes.document` instance (default: a new dummy instance).
               Provides settings and reporter.
               Populated and returned, if the inputstring's root element
               is <document>.

    Caution:
      The function does not detect invalid XML.

      To check the validity of the returned node,
      you may use its `validate()` method::

        node = parse_element('<tip><hint>text</hint></tip>')
        node.validate()

    Provisional.
    N)start)eventsT)keepends   source linezXML parse error: .r   )sourceline)ETXMLPullParser	enumerate
splitlinesfeedread_eventsstrattrib
ParseErrorreportererrorsettings_sourcepositionelement2node)	r   r   rootparserir/   eventelementer   r   r   r   B   s*   

r   Tc           	   
   C  s  |du rt dtt}|jdk | du r#tdd}tdd|S zt	t| j
}t|tjs2t}W n ty>   t}Y nw |tjkrO|}|jpL|jj|_n| }t| d|_t|trp| j
|_|jjd| j
 d|d |  D ]3\}}|d	s|dkrqtztj| ||j|< W qt ttfy   ||jv r|  }||j|< Y qtw t|tj!r||_!nt|tj"r|#|d
$|d | |d r|%| |ot|tj&tj'tf }t(|| j)| | D ]}|*t+||| t(||j,| q|S )a  
    Convert an `etree` element and its children to Docutils doctree nodes.

    :element:  `xml.etree` element
    :document: see `parse_element()`
    :unindent: Remove formatting indentation of follow-up text lines?
               Cf. `append_text()`.
               TODO: do we need an "unindent" configuration setting?

    Return a `docutils.nodes.Element` instance.

    Internal.
    Nz	xml input zNo XML element found.r,   zUnknown element type <z>.)	base_node{ namesids)-r   new_documentr   get_default_settingsr   r.   r   problematic	paragraphgetattrtag
issubclassr%   r#   AttributeErrorr   r;   r<   intgetr/   r   tagnamer9   warningitems
startswithATTRIBUTE_VALIDATORS
attributes
ValueErrorKeyErrorlist_attributessplit
decorationsubstitution_definitionnote_substitution_defjoinset_idFixedTextElementliteralappend_texttextr   r>   tail)	rC   r   unindentproblem	nodeclassr   keyvaluechildr   r   r   r>   j   sf   




r>   r   r   c                 C  s^   |sd S |rt dd|}t| tjr| t| d S | r-| t|  d S d S )Nz
 +
)resubr   r   TextElementr   r&   strip)r   rg   ri   r   r   r   rf      s   rf   )N)NTr   )r   
__future__r   __docformat__rp   xml.etree.ElementTreeetreeElementTreer0   docutilsr   r   r   r   r   SpecialInliner%   r#   r   r>   rf   r   r   r   r   <module>   s   

(L