
    qi&                        S r SSKrSSKJr  Sr\R
                  " S5      rSr SSKJ	r	  Sr\	R                  rS rS rSS.S jrS rS rSS.S jrS rg! \ a*    SS	KJrJrJr  SS
KJr	  \=\	l        r\\	l        \\	l         NMf = f)z-
Small wrapper for different etree packages.
    N)StringIOreStructuredTextwsgidavF)etreeT)Element
SubElementtostring)ElementTreec                 "    [        U [        5      $ )N)
isinstance_ElementType)objs    F/home/kali/flask_env/lib/python3.13/site-packages/wsgidav/xml_tools.pyis_etree_elementr   '   s    c<((    c                      [         R                  " U 5      $ ! [         a/    [        R	                  S5        [        R	                  SU  35        e f = f)z&Convert XML string into etree.Element.zyError parsing XML string. If lxml is not available, and unicode is involved, then installing lxml _may_ solve this issue.zXML source: )r   XML	Exception_loggererror)texts    r   string_to_xmlr   +   sO    yy  	6	

 	TF+,!s	    9Aprettyc                    [         (       a  [        R                  " U SSUS9nO0[        R                  " U SS9nUR                  S5      (       d  SU-   nUR                  S5      (       d   eU$ )zoWrapper for etree.tostring, that takes care of unsupported pretty_print
option and prepends an encoding header.zUTF-8T)encodingxml_declarationpretty_print)r   s   <?xml s(   <?xml version="1.0" encoding="utf-8" ?>
)use_lxmlr   r	   
startswith)elementr   xmls      r   xml_to_bytesr#   B   sh     xnn 	
 nnWw7~~i((>DC>>)$$$$Jr   c                  r    [         (       a  [        R                  " SSS0S9$ [        R                  " S5      $ )GWrapper for etree.Element, that takes care of unsupported nsmap option.z{DAV:}multistatusDDAV:nsmapr   r   r    r   r   make_multistatus_elr,   U   s-    x}}0fFF==,--r   c                  r    [         (       a  [        R                  " SSS0S9$ [        R                  " S5      $ )r%   z
{DAV:}propr&   r'   r(   r*   r+   r   r   make_prop_elemr.   \   s+    x}}\#v??==&&r   r(   c                n    [         (       a  [        R                  " XUS9$ [        R                  " X5      $ )zJWrapper for etree.SubElement, that takes care of unsupported nsmap option.r(   )r   r   r   )parenttagr)   s      r   make_sub_elementr2   c   s+    x599F((r   c                     [        U 5      S:X  a  U R                  =(       d    S$ [        5       nU  H  nUR                  [	        USS9S-   5        M!     UR                  5       nUR                  5         U$ )zSerialize etree.Element.

Note: element may contain more than one child or only text (i.e. no child
      at all). Therefore the resulting string may raise an exception, when
      passed back to etree.XML().
r    Fr   
)lenr   r   writer#   getvalueclose)r!   stream	childnodess       r   element_content_as_stringr=   j   sd     7|q||!r!ZF	\)E:TAB  	A
LLNHr   )__doc__loggingior   __docformat__	getLoggerr   r   lxmlr   _Elementr   ImportErrorxml.etree.ElementTreer   r   r	   
defusedxmlr
   r   r   r#   r,   r.   r2   r=   r+   r   r   <module>rH      s   
  " 

I
& H>>L"). %* &.' ,0 )g  CC/#**EML!EENs   A -BB