o
    î?À]Þ  ã                   @   s¶   d Z dZddlZddlZddlZddlmZmZmZ ej	dkr&ddl
mZ nddlmZ ej	dkr3eZG dd„ dejƒZG d	d
„ d
ejƒZG dd„ dejƒZG dd„ dejjjƒZdS )zv
Simple document tree Writer, writes Docutils XML according to
http://docutils.sourceforge.net/docs/ref/docutils.dtd.
ÚreStructuredTexté    N)ÚfrontendÚwritersÚnodes©é   r   )ÚStringIOc                   @   s   e Zd ZdS )ÚRawXmlErrorN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú?/usr/lib/python3/dist-packages/docutils/writers/docutils_xml.pyr	      s    r	   c                   @   s’   e Zd ZdZ	 ddddgdejdœfdd	gdejdœfd
dgdddejdœfddgdddejdœfffZddiZdZdZ	dZ
	 dd„ Zdd„ ZdS )ÚWriter)Úxmlz"Docutils XML" Writer OptionsNz1Generate XML with newlines before and after tags.z
--newlinesÚ
store_true)ÚactionÚ	validatorz'Generate XML with indents and newlines.z	--indentsz,Omit the XML declaration.  Use with caution.z--no-xml-declarationÚxml_declarationé   Ústore_false)ÚdestÚdefaultr   r   zOmit the DOCTYPE declaration.z--no-doctypeÚdoctype_declarationÚoutput_encoding_error_handlerÚxmlcharrefreplacezdocutils_xml writer)r   c                 C   s   t j | ¡ t| _d S ©N)r   r   Ú__init__ÚXMLTranslatorÚtranslator_class)Úselfr   r   r   r   ?   s   
zWriter.__init__c                 C   s0   |   | j¡ | _}| j |¡ d |j¡| _d S )NÚ )r   ÚdocumentÚvisitorÚ	walkaboutÚjoinÚoutput)r    r#   r   r   r   Ú	translateC   s   zWriter.translate)r
   r   r   Ú	supportedr   Úvalidate_booleanÚsettings_specÚsettings_defaultsÚconfig_sectionÚconfig_section_dependenciesr&   r   r'   r   r   r   r   r       sD    
þ
þÿþÿþöýr   c                   @   st   e Zd ZdZdZdZej ¡ Z		 e	 
dd¡ dd„ ZejejejejfZdd	„ Zd
d„ Zdd„ Zdd„ Zdd„ ZdS )r   z$<?xml version="1.0" encoding="%s"?>
z”<!DOCTYPE document PUBLIC "+//IDN docutils.sourceforge.net//DTD Docutils Generic//EN//XML" "http://docutils.sourceforge.net/docs/ref/docutils.dtd">
z"<!-- Generated by Docutils %s -->
z5http://xml.org/sax/features/external-general-entitiesTc                 C   sÐ   t j | |¡ | jjj| _| jjj| _|j | _}d | _	| _
|jr%d| _
|jr.d| _
d| _	d| _d| _d| _g | _|jrG| j | j|j ¡ |jrQ| j | j¡ | j | jtj ¡ tƒ | _| j | j¡ d S )Nr!   Ú
z    r   )r   ÚNodeVisitorr   r"   ÚreporterÚwarningÚwarnÚerrorÚsettingsÚindentÚnewlineÚnewlinesÚindentsÚlevelÚ	in_simpleÚ
fixed_textr&   r   ÚappendÚoutput_encodingr   ÚdoctypeÚ	generatorÚdocutilsÚ__version__ÚTestXmlÚ
the_handleÚ	xmlparserÚsetContentHandler)r    r"   r4   r   r   r   r   Y   s.   
ÿzXMLTranslator.__init__c                 C   s–   | j s| j | j| j ¡ | j | tjjj	¡¡ |  jd7  _t
|tjtjfƒr0|  jd7  _t
|| jƒr=|  j d7  _ | j sI| j | j¡ dS dS )zDefault node visit method.r   N)r:   r&   r<   r5   r9   Ústarttagr   ÚsaxÚsaxutilsÚ	quoteattrÚ
isinstancer   ÚFixedTextElementÚliteralr;   Úsimple_nodesr6   ©r    Únoder   r   r   Údefault_visit   s   ÿzXMLTranslator.default_visitc                 C   sŽ   |  j d8  _ | js| j | j| j  ¡ | j | ¡ ¡ t|tjtj	fƒr,|  j
d8  _
t|| jƒr9|  jd8  _| jsE| j | j¡ dS dS )zDefault node depart method.r   N)r9   r:   r&   r<   r5   ÚendtagrJ   r   rK   rL   r;   rM   r6   rN   r   r   r   Údefault_departure�   s   ÿzXMLTranslator.default_departurec                 C   s@   t jj | ¡ ¡}| js| dd| j| j  ¡}| j	 
|¡ d S )Nr.   )r   rG   rH   ÚescapeÚastextr;   Úreplacer5   r9   r&   r<   )r    rO   Útextr   r   r   Ú
visit_Textž   s   zXMLTranslator.visit_Textc                 C   s   d S r   r   rN   r   r   r   Údepart_Text¥   s   zXMLTranslator.depart_Textc              
   C   s  d|  dd¡ ¡ vr|  |¡ d S |  |¡ | ¡ }| j |¡ |  |¡ t|tƒr4t	j
dk r4| d¡}z| j t|ƒ¡ W tj‚ tjjjy‡ } z8| jj ¡ }| jj ¡ }|j}t|jtjƒse|d7 }d||| ¡ f }| j||j|| d d	� W Y d }~tj‚d }~ww )
Nr   Úformatr!   r   Úutf8é   z0Invalid raw XML in column %d, line offset %d:
%sr   )ÚsourceÚline)ÚgetÚsplitrP   rT   r&   r<   rR   rJ   ÚunicodeÚsysÚversion_infoÚencoderD   Úparser   r   rG   Ú_exceptionsÚSAXParseExceptionrC   ÚlocatorÚgetColumnNumberÚgetLineNumberr]   Úparentr   ÚTextElementr2   r\   ÚSkipNode)r    rO   Ú
xml_stringr3   Úcol_numÚline_numÚsrclineÚmsgr   r   r   Ú	visit_raw¨   s2   




÷
ÿ$€÷zXMLTranslator.visit_rawN)r
   r   r   r   r>   r?   r   rG   Úmake_parserrD   Ú
setFeaturer   r   rk   ÚimageÚcolspecÚ
transitionrM   rP   rR   rW   rX   rr   r   r   r   r   r   I   s&    ÿ
ÿ#ÿr   c                   @   s   e Zd Zdd„ ZdS )rB   c                 C   s
   || _ d S r   )rg   )r    rg   r   r   r   ÚsetDocumentLocatorÆ   s   
zTestXml.setDocumentLocatorN)r
   r   r   rx   r   r   r   r   rB   Ä   s    rB   )Ú__doc__Ú__docformat__ra   Úxml.sax.saxutilsr   r@   r   r   r   rb   Úior   Ústrr`   ÚApplicationErrorr	   r   ÚGenericNodeVisitorr   rG   ÚhandlerÚContentHandlerrB   r   r   r   r   Ú<module>   s   

){