
    vg                     (   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
 d dlmZmZmZmZmZmZmZmZ dZdZ edd          Z ed	d          Z ed
d          Z edd          Z edd          Z edd          Z edd          xZZ edd          Z edd          Z edd          Z  edd          Z! edd          Z" edd          Z# edd          Z$ edd          Z% edd          Z& edd          Z' edd          Z( edd          Z) edd          Z* edd          Z+ edd          Z, edd          Z-erd Z.nd Z.d]d!Z/ G d" d#          Z0 e0            Z1d$Z2d%e2z  Z3d&Z4e3e4Z5d'e4z  Z6d(Z7d%e7z  Z8 e9e8          Z:g Z; G d) d*          Z< G d+ d,          Z= G d- d.e          Z> G d/ d0e          Z?d1 Z@d2 ZAd^d3ZBd4 ZCd^d5ZD ejE        d6          jF        ZG ejE        d7          jF        ZHd8 ZId9d9d9d9d9d9d9d9d9d9d9d9d9d:ZJ eIeJ           d9d9d;ZK eIeK           d9d9d9d9d9d9d9d9d9d9d9d9d<ZL eIeL           d_d>ZMd]d?ZNd@ ZO ejE         edAd                    ZPd^dBZQdC ZRdD ZSdE ZT ejE        dF          ZU ejE        dG          ZVe<jW        fdHZXdI ZYe<jW        fdJZZdK Z[dL Z\dM Z]de5fdNZ^ edOdP          Z_ edQdP          Z`dddRddSZadTdUdVdWdXZbdY ZcdZ Zddaed[ Zfd\ ZgdS )`    N)CommentElementPathProcessingInstructionQNameTreeBuilder	XMLParserparse)PY2htmlentitydefs
HTMLParserStringIOStringTypesunichras_bytes	as_string)plitrthtdheadbody)imghrmetalinkbr latin1encoding ="<z</>z />z [...]
<!--  -->z<?z?>z&amp;z&lt;z&quot;z<?xml version="1.0"r!   z?>
	<!DOCTYPEPUBLICz>
c                 ,    |                      |          S N)encodetextr!   s     R/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/supervisor/templating.pyr-   r-   :   s    {{8$$$    c                 Z    t          | t                    s|                     |          } | S r,   )
isinstancebytesr-   r.   s     r0   r-   r-   =   s*    $&& 	);;x((Dr1   Fc                 L    t          t          i           }| |_        ||_        |S r,   )_MeldElementInterfaceReplacer/   	structure)r/   r8   elements      r0   r7   r7   C   s%    #GR00GGL!GNr1   c                   <    e Zd Zd	dZd	dZd Zd	dZd	dZd
dZdS )PyHelperNc                     |                      |          }|D ]+}|j                            t                    }||k    r|c S ,|S r,   )getiteratorattribget_MELD_ID)selfnodenamedefaultiteratorr9   vals          r0   findmeldzPyHelper.findmeldJ   sU    ##D)) 	 	G.$$X..Cd{{ r1   c                 ,   t          |j        |j                                                  }|j        |_        |j        |_        |j        |_        |!|j                            |           ||_	        |j        D ]}| 
                    ||           |S r,   )r6   tagr>   copyr/   tailr8   	_childrenappendparentclone)rA   rB   rN   r9   childs        r0   rO   zPyHelper.cloneR   s    '$+2B2B2D2DEEyy N##G,,,#GN^ 	' 	'EJJug&&&&r1   c                 >   g }|D ]}t          |j        |j                                                  }||_        |j        |_        |j        |_        |j        |_        |j        r| 	                    |j        |           |
                    |           ||_        d S r,   )r6   rI   r>   rJ   rN   r/   rK   r8   rL   _bfclonerM   )rA   nodesrN   LrB   r9   s         r0   rR   zPyHelper._bfclone_   s     	 	D+DHdk6F6F6H6HIIG#GN9GL9GL $G~ 7dng666HHWr1   c                 0   t          |j        |j                                                  }|j        |_        |j        |_        |j        |_        ||_        ||j        	                    |           |j        r| 
                    |j        |           |S r,   )r6   rI   r>   rJ   r/   rK   r8   rN   rL   rM   rR   )rA   rB   rN   r9   s       r0   bfclonezPyHelper.bfclonel   s    '$+2B2B2D2DEEyy N##G,,,> 	3MM$.'222r1   c                     g }|dk    rd }||j         |k    r|                    |           |j        D ]+}|                    |                     ||                     ,|S )N*)rI   rM   rL   extendr=   )rA   rB   rI   rS   r9   s        r0   r=   zPyHelper.getiteratorx   sq    #::C;$(c//LL~ 	9 	9GLL))'3778888r1   Fc                 n    d |_         t          ||          }||_        ||_         ||_        |g|_        d S r,   )r/   r7   rN   r8   rL   )rA   rB   r/   r8   replacenodes        r0   contentzPyHelper.content   s=    	dI..! )%r1   r,   F)	__name__
__module____qualname__rG   rO   rR   rV   r=   r\    r1   r0   r;   r;   I   s                
 
 
 
   ' ' ' ' ' 'r1   r;   z(https://github.com/Supervisor/supervisorz{%s}idzmeld:%shttp://www.w3.org/1999/xhtmlc                       e Zd ZdZdZdZdZdS )doctype)HTMLz-//W3C//DTD HTML 4.01//ENz%http://www.w3.org/TR/html4/strict.dtd)rf   z&-//W3C//DTD HTML 4.01 Transitional//ENz$http://www.w3.org/TR/html4/loose.dtd)htmlz -//W3C//DTD XHTML 1.0 Strict//ENz1http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd)rg   z&-//W3C//DTD XHTML 1.0 Transitional//ENz7http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtdN)r^   r_   r`   html_strictrg   xhtml_strictxhtmlra   r1   r0   re   re      s,        =K;DILOEEEr1   re   c                      e Zd ZdZdZdZdZdZd Zd Z	d Z
d Zd Zd Zd Zd2d	Zd
 Zd Zd2dZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d2dZ"d Z#d2dZ$d2dZ%d3d!Z&d3d"Z'd# Z(	 	 d4d%Z)	 	 d4d&Z*de+j,        d fd'Z-de+j,        d fd(Z.de+j/        d d d fd)Z0de+j/        d d d fd*Z1d2d+Z2d, Z3d- Z4d2d.Z5d/ Z6d0 Z7d1 Z8dS )5r6   Nc                 0    || _         || _        g | _        d S r,   )rI   r>   rL   rA   rI   r>   s      r0   __init__z_MeldElementInterface.__init__   s    r1   c                 4    d| j         t          |           fz  S )Nz<MeldElement %s at %x>)rI   rb   rA   s    r0   __repr__z_MeldElementInterface.__repr__   s    '48RXX*>>>r1   c                 *    t          | j                  S r,   )lenrL   rp   s    r0   __len__z_MeldElementInterface.__len__   s    4>"""r1   c                     | j         |         S r,   rL   )rA   indexs     r0   __getitem__z!_MeldElementInterface.__getitem__   s    ~e$$r1   c                      | j         ||         S r,   rv   )rA   startstops      r0   __getslice__z"_MeldElementInterface.__getslice__   s    ~eDj))r1   c                     | j         S r,   rv   rp   s    r0   getchildrenz!_MeldElementInterface.getchildren   s
    ~r1   c                 ,    t          j        | |          S r,   )r   findrA   paths     r0   r   z_MeldElementInterface.find   s    d+++r1   c                 .    t          j        | ||          S r,   )r   findtext)rA   r   rD   s      r0   r   z_MeldElementInterface.findtext   s    #D$888r1   c                 ,    t          j        | |          S r,   )r   findallr   s     r0   r   z_MeldElementInterface.findall   s    "4...r1   c                 b    | j                                          g | _        d x| _        | _        d S r,   )r>   clearrL   r/   rK   rp   s    r0   r   z_MeldElementInterface.clear   s/     $$	DIIIr1   c                 8    | j                             ||          S r,   )r>   r?   )rA   keyrD   s      r0   r?   z_MeldElementInterface.get   s    {sG,,,r1   c                     || j         |<   d S r,   )r>   )rA   r   values      r0   setz_MeldElementInterface.set   s     Cr1   c                 N    t          | j                                                  S r,   )listr>   keysrp   s    r0   r   z_MeldElementInterface.keys   s    DK$$&&'''r1   c                 N    t          | j                                                  S r,   )r   r>   itemsrp   s    r0   r   z_MeldElementInterface.items   s    DK%%''(((r1   c                 6    t                               |           S r,   )helperr=   )rA   ignored_args
ignored_kws      r0   r=   z!_MeldElementInterface.getiterator   s     !!$'''r1   c                 l    t          |t                    r|D ]	}| |_        
n| |_        || j        |<   d S r,   )r3   slicerN   rL   )rA   rw   r9   es       r0   __setitem__z!_MeldElementInterface.__setitem__   sL    eU## 	"      "GN 'ur1   c                 P    |D ]	}| |_         
t          |          | j        ||<   d S r,   )rN   r   rL   )rA   rz   r{   elementsr9   s        r0   __setslice__z"_MeldElementInterface.__setslice__   s6     	" 	"G!GNN%)(^^uTz"""r1   c                 H    | j                             |           | |_        d S r,   )rL   rM   rN   rA   r9   s     r0   rM   z_MeldElementInterface.append   #    g&&&r1   c                 J    | j                             ||           | |_        d S r,   )rL   insertrN   )rA   rw   r9   s      r0   r   z_MeldElementInterface.insert   s%    eW---r1   c                     t          |t                    r| j        |         D ]	}d |_        
nd | j        |         _        | j        |         }| j        |= d S r,   )r3   r   rL   rN   )rA   rw   obs      r0   __delitem__z!_MeldElementInterface.__delitem__   se    eU## 	0nU+ ! ! 		! ,0DN5!(^E"N5!!!r1   c                 P    | j         ||         }|D ]	}d |_        
| j         ||= d S r,   )rL   rN   )rA   rz   r{   obsr   s        r0   __delslice__z"_MeldElementInterface.__delslice__  s>    nU4Z( 	 	BBIIN5:&&&r1   c                 H    | j                             |           d |_        d S r,   )rL   removerN   r   s     r0   r   z_MeldElementInterface.remove  r   r1   c                 .    |                      ||          S r,   )	__class__rm   s      r0   makeelementz!_MeldElementInterface.makeelement  s    ~~c6***r1   c                      | j         di |S )z Fill in the text values of meld nodes in tree; only
        support dictionarylike operand (sequence operand doesn't seem
        to make sense here)ra   )	fillmelds)rA   others     r0   __mod__z_MeldElementInterface.__mod__  s     t~&&&&&r1   c                     g }|D ]<}|                      |          }||                    |           /||         |_        =|S )aq   Fill in the text values of meld nodes in tree using the
        keyword arguments passed in; use the keyword keys as meld ids
        and the keyword values as text that should fill in the node
        text on which that meld id is found.  Return a list of keys
        from **kw that were not able to be found anywhere in the tree.
        Never raises an exception. )rG   rM   r/   )rA   kwunfilledkrB   s        r0   r   z_MeldElementInterface.fillmelds  sU      	" 	"A==##D|""""qE		r1   c                 2   g }|D ]}|                      |          }||                    |           0||         }|                    d          rg }g }|                    d          D ]}|j                            dd                                          }	|	dvr4|j                            dd          }
||
k    r|                    |           k|                    |           |s|                    |           |D ]}d|j        d<   |D ]}	 |j        d= # t          $ r Y w xY w.|j                                        }|dk    r|j                            dd	                                          }	|	d
v r||j        d<   |	dv r*|rd|j        d<   	 |j        d= # t          $ r Y w xY w|                    |           |dk    rg }g }|                    d          D ]L}|j                            dd          |k    r|                    |           7|                    |           M|s|                    |           T|D ]}d|j        d<   |D ]}	 |j        d= # t          $ r Y w xY w||         |_	        |S )aF	   Perform magic to 'fill in' HTML form element values from a
        dictionary.  Unlike 'fillmelds', the type of element being
        'filled' is taken into consideration.

        Perform a 'findmeld' on each key in the dictionary and use the
        value that corresponds to the key to perform mutation of the
        tree, changing data in what is presumed to be one or more HTML
        form elements according to the following rules::

          If the found element is an 'input group' (its meld id ends
          with the string ':inputgroup'), set the 'checked' attribute
          on the appropriate subelement which has a 'value' attribute
          which matches the dictionary value.  Also remove the
          'checked' attribute from every other 'input' subelement of
          the input group.  If no input subelement's value matches the
          dictionary value, this key is treated as 'unfilled'.

          If the found element is an 'input type=text', 'input
          type=hidden', 'input type=submit', 'input type=password',
          'input type=reset' or 'input type=file' element, replace its
          'value' attribute with the value.

          If the found element is an 'input type=checkbox' or 'input
          type='radio' element, set its 'checked' attribute to true if
          the dict value is true, or remove its 'checked' attribute if
          the dict value is false.

          If the found element is a 'select' element and the value
          exists in the 'value=' attribute of one of its 'option'
          subelements, change that option's 'selected' attribute to
          true and mark all other option elements as unselected.  If
          the select element does not contain an option with a value
          that matches the dictionary value, do nothing and return
          this key as unfilled.

          If the found element is a 'textarea' or any other kind of
          element, replace its text with the value.

          If the element corresponding to the key is not found,
          do nothing and treat the key as 'unfilled'.

        Return a list of 'unfilled' keys, representing meld ids
        present in the dictionary but not present in the element tree
        or meld ids which could not be filled due to the lack of any
        matching subelements for 'select' nodes or 'inputgroup' nodes.
        Nz:inputgroupinputtyper   )checkboxradior   checkedr/   )hiddensubmitr/   passwordresetfileselectoptionselected)
rG   rM   endswithr   r>   r?   lowerKeyErrorrI   r/   )rA   r   r   r   rB   rF   foundunfoundrP   
input_type	input_valr   rI   s                r0   fillmeldhtmlformz&_MeldElementInterface.fillmeldhtmlform'  sk   `  Z	& Z	&A==##D|"""Q%Czz-(( Q&
 !\\'22 
. 
.E!&!1!1&"!=!=!C!C!E!EJ!)>>>  % 0 0" = =Ii''U++++u---- 
!OOA&&&& #( = =3<i00") ! !! &i 8 8' ! ! ! D!! hnn&&'>>!%!@!@!F!F!H!HJ " &C C C/2G,, $'<<< %5>DK	22%$(K	$:$:#+ % % % $% !****H__ E G"&,,x"8"8 3 3!=,,Wb99S@@!LL0000#NN62222  	% ****&+ C CF8BFM*55&- % %F%$*M*$=$=#+ % % % $%% !#1DIIs6   D!!
D.-D."F,,
F:9F:-I66
JJc                 D    t                               | |          }||S |S )z Find a node in the tree that has a 'meld id' corresponding
        to 'name'. Iterate over all subnodes recursively looking for a
        node which matches.  If we can't find the node, return None.)r   rG   )rA   rC   rD   results       r0   rG   z_MeldElementInterface.findmeld  s&     t,,>Nr1   c                 6    |                      t                    S )zZ Find all nodes that have a meld id attribute and return
        the found nodes in a list)findwithattribr@   rp   s    r0   	findmeldsz_MeldElementInterface.findmelds  s     ""8,,,r1   c                     t                               |           }g }|D ]Q}|j                            |          }|3||                    |           6||k    r|                    |           R|S )z Find all nodes that have an attribute named 'attrib'.  If
        'value' is not None, omit nodes on which the attribute value
        does not compare equally to 'value'. Return the found nodes in
        a list.)r   r=   r>   r?   rM   )rA   r>   r   rE   r   r9   	attribvals          r0   r   z$_MeldElementInterface.findwithattrib  s    
 %%d++ 	1 	1G**622I$=OOG,,,,	)) 000r1   c                     |r|                      |          }n| }|j        }g }d}|D ]=}|du r|}nt                              ||          }|                    ||f           d}>|S )aI  repeats an element with values from an iterable.  If
        'childname' is not None, repeat the element on which the
        repeat is called, otherwise find the child element with a
        'meld:id' matching 'childname' and repeat that.  The element
        is repeated within its parent element (nodes that are created
        as a result of a repeat share the same parent).  This method
        returns an iterable; the value of each iteration is a
        two-sequence in the form (newelement, data).  'newelement' is
        a clone of the template element (including clones of its
        children) which has already been seated in its parent element
        in the template. 'data' is a value from the passed in
        iterable.  Changing 'newelement' (typically based on values
        from 'data') mutates the element 'in place'.TF)rG   rN   r   rV   rM   )	rA   iterable	childnamer9   rN   rT   firstthingrO   s	            r0   repeatz_MeldElementInterface.repeat  s      	mmI..GGG 	 	E}}w77HHeU^$$$EEr1   Fc                     | j         }|                                 }|4t          ||          }|j                            ||           ||_         |S dS )a0   Replace this element with a Replace node in our parent with
        the text 'text' and return the index of our position in
        our parent.  If we have no parent, do nothing, and return None.
        Pass the 'structure' flag to the replace node so it can do the right
        thing at render time. N)rN   deparentr7   rL   r   )rA   r/   r8   rN   irB   s         r0   replacez_MeldElementInterface.replace  sX     MMOO=4++D##At,,, DKH =r1   c                 >    t                               | ||           dS )z Delete this node's children and append a Replace node that
        contains text.  Always return None.  Pass the 'structure' flag
        to the replace node so it can do the right thing at render
        time.N)r   r\   )rA   r/   r8   s      r0   r\   z_MeldElementInterface.content  s     
 	tT9-----r1   c                     |                                 D ]c\  }}t          |t                    st          d|z            t          |t                    st          d|z            ||         | j        |<   ddS )z Set attributes on this node. z$do not set non-stringtype as key: %sz$do not set non-stringtype as val: %sN)r   r3   r   
ValueErrorr>   )rA   r   r   vs       r0   
attributesz _MeldElementInterface.attributes  s    HHJJ 	# 	#DAqa-- M !G!!KLLLa-- M !G!!KLLLUDKNN	# 	#r1   Tc                     g }|j         }|s$|rt          ||           |rt          ||           t          || |i |           t                              |          S r,   rM   _write_declaration_write_doctype
_write_xml_BLANKjoinrA   r!   re   fragmentdeclarationpipelinedatawrites           r0   write_xmlstringz%_MeldElementInterface.write_xmlstring  sn     	/ 4"5(333 /ug...5$"h777{{4   r1   c                     t          |d          st          |d          }|                     |||||          }|                    |           dS )a   Write XML to 'file' (which can be a filename or filelike object)

        encoding    - encoding string (if None, 'utf-8' encoding is assumed)
                      Must be a recognizable Python encoding type.
        doctype     - 3-tuple indicating name, pubid, system of doctype.
                      The default is to prevent a doctype from being emitted.
        fragment    - True if a 'fragment' should be emitted for this node (no
                      declaration, no doctype).  This causes both the
                      'declaration' and 'doctype' parameters to become ignored
                      if provided.
        declaration - emit an xml declaration header (including an encoding
                      if it's not None).  The default is to emit the
                      doctype.
        pipeline    - preserve 'meld' namespace identifiers in output
                      for use in pipelining
        r   wbN)hasattropenr   r   )rA   r   r!   re   r   r   r   r   s           r0   	write_xmlz_MeldElementInterface.write_xml&  s]    $ tW%% 	$d##D##Hgx$,. .

4r1   c                     g }|j         }|d}|s|rt          ||           t          || |i            t                              |          }|S )Nutf8)rM   r   _write_htmlr   r   )rA   r!   re   r   r   r   joineds          r0   write_htmlstringz&_MeldElementInterface.write_htmlstring>  sc    H 	/ /ug...E42...T""r1   c                     t          |d          st          |d          }|                     |||          }|                    |           dS )a   Write HTML to 'file' (which can be a filename or filelike object)

        encoding    - encoding string (if None, 'utf-8' encoding is assumed).
                      Unlike XML output, this is not used in a declaration,
                      but it is used to do actual character encoding during
                      output.  Must be a recognizable Python encoding type.
        doctype     - 3-tuple indicating name, pubid, system of doctype.
                      The default is the value of doctype.html (HTML 4.0
                      'loose')
        fragment    - True if a "fragment" should be omitted (no doctype).
                      This overrides any provided "doctype" parameter if
                      provided.

        Namespace'd elements and attributes have their namespaces removed
        during output when writing HTML, so pipelining cannot be performed.

        HTML is not valid XML, so an XML declaration header is never emitted.
        r   r   N)r   r   r   r   )rA   r   r!   re   r   pages         r0   
write_htmlz _MeldElementInterface.write_htmlK  sT    ( tW%% 	$d##D$$XwAA

4r1   c                     g }|j         }|s$|rt          ||           |rt          ||           t          || |i |d           t                              |          S )NT)rj   r   r   s           r0   write_xhtmlstringz'_MeldElementInterface.write_xhtmlstringd  ss     	/ 4"5(333 /ug...5$"hdCCCC{{4   r1   c                     t          |d          st          |d          }|                     |||||          }|                    |           dS )ad   Write XHTML to 'file' (which can be a filename or filelike object)

        encoding    - encoding string (if None, 'utf-8' encoding is assumed)
                      Must be a recognizable Python encoding type.
        doctype     - 3-tuple indicating name, pubid, system of doctype.
                      The default is the value of doctype.xhtml (XHTML
                      'loose').
        fragment    - True if a 'fragment' should be emitted for this node (no
                      declaration, no doctype).  This causes both the
                      'declaration' and 'doctype' parameters to be ignored.
        declaration - emit an xml declaration header (including an encoding
                      string if 'encoding' is not None)
        pipeline    - preserve 'meld' namespace identifiers in output
                      for use in pipelining
        r   r   N)r   r   r   r   )rA   r   r!   re   r   r   r   r   s           r0   write_xhtmlz!_MeldElementInterface.write_xhtmlp  s]    " tW%% 	$d##D%%h;&.0 0

4r1   c                 8    t                               | |          S )z Create a clone of an element.  If parent is not None,
        append the element to the parent.  Recurse as necessary to create
        a deep clone of the element. )r   rV   rA   rN   s     r0   rO   z_MeldElementInterface.clone  s     ~~dF+++r1   c                 F    |                                  }|
| j        |= |S dS )zq Remove ourselves from our parent node (de-parent) and return
        the index of the parent which was deleted. N)parentindexrN   )rA   r   s     r0   r   z_MeldElementInterface.deparent  s/     =AH =r1   c                 L    | j         }||j                            |           S dS )z/ Return the parent node index in which we live N)rN   rL   rw   r  s     r0   r  z!_MeldElementInterface.parentindex  s.    #))$/// r1   c                 l    g }t          |j        | |i d           t                              |          S )N   )maxdepth)r   rM   r   r   )rA   r!   r   s      r0   	shortreprz_MeldElementInterface.shortrepr  s4    DKxa@@@@{{4   r1   c                    |                                  }|                                 }d |D             }d |D             }g }|D ]-}|                                |vr|                    |           .g }|D ]-}	|	                                |vr|                    |	           .g }
|D ]\}|                                }||v rB|                    |          }||         }	t	          ||	          s|
                    |	           ]|||
d}t          |
          }t          |          }t          |          }|||d}||dS )a^   Compute the meld element differences from this node (the
        source) to 'other' (the target).  Return a dictionary of
        sequences in the form {'unreduced:
               {'added':[], 'removed':[], 'moved':[]},
                               'reduced':
               {'added':[], 'removed':[], 'moved':[]},}
                               c                 6    g | ]}|                                 S ra   meldid.0xs     r0   
<listcomp>z2_MeldElementInterface.diffmeld.<locals>.<listcomp>       444!188::444r1   c                 6    g | ]}|                                 S ra   r  r  s     r0   r  z2_MeldElementInterface.diffmeld.<locals>.<listcomp>  r  r1   )addedremovedmoved)r  r  r  )	unreducedreduced)r   r  rM   rw   sharedlineage
diffreduce)rA   r   srcelementstgtelementssrcidstgtidsr  
srcelementr  
tgtelementr  srcidr   r  moved_reducedadded_reducedremoved_reducedr  s                     r0   diffmeldz_MeldElementInterface.diffmeld  s    nn&&oo''44{44444{444% 	+ 	+J  ""&00z***% 	) 	)J  ""&00Z(((% 	- 	-J%%''ELL''(^
$Z<< -LL,,,"guEE	"5))"5))$W--(-,. . &!# # 	#r1   c                 @    | j                             t                    S r,   )r>   r?   r@   rp   s    r0   r  z_MeldElementInterface.meldid  s    {x(((r1   c                 N    g }| }||                     |           |j        }||S r,   )rM   rN   )rA   rT   rN   s      r0   lineagez_MeldElementInterface.lineage  s:     HHV]F   r1   r,   r]   )NNFTF)9r^   r_   r`   rN   r>   r/   rK   r8   rn   rq   rt   rx   r|   r~   r   r   r   r   r?   r   r   r   r=   r   r   rM   r   r   r   r   r   r   r   r   rG   r   r   r   r   r\   r   r   r   re   rg   r   r   rj   r   r   rO   r   r  r	  r%  r  r(  ra   r1   r0   r6   r6      sz       FFDDI  
? ? ?# # #% % %* * *  , , ,9 9 9 9/ / /% % %
- - - -! ! !( ( () ) )( ( (( ( (4 4 4
    " " "' ' '  + + +
' ' '   N N N`	 	 	 	- - -
   $   @   . . . .# # # EJ38
! 
! 
! 
! 6:=B   0 )-gl"'    )-gl!   2 *.w}#(ee
! 
! 
! 
! *.w}"   ., , , ,  0 0 0! ! ! !
*# *# *#X) ) )    r1   r6   c                   &    e Zd Zd Zd Zd Zd ZdS )MeldTreeBuilderc                 J    t          j        | t                     i | _        d S )N)element_factory)r   rn   r6   meldidsrp   s    r0   rn   zMeldTreeBuilder.__init__  s$    T3HIIIIr1   c                     t          j        | ||          }|                                D ]7\  }}|t          k    r'|| j        v rt          d|z            d| j        |<    n8|S )NRepeated meld id "%s" in source   )r   rz   r   r@   r-  r   )rA   rI   attrselemr   r   s         r0   rz   zMeldTreeBuilder.start  s     sE22++-- 	 	JChDL(($%F%*&+ , , ,&'U#  r1   c                     |                      t          i            |                     |           |                     t                     d S r,   )rz   r   r   endrA   r   s     r0   commentzMeldTreeBuilder.comment  s=    

7B		$r1   c                     d S r,   ra   )rA   rC   pubidsystems       r0   re   zMeldTreeBuilder.doctype      r1   N)r^   r_   r`   rn   rz   r6  re   ra   r1   r0   r*  r*    sP          	 	 	  
    r1   r*  c                   J    e Zd ZdZddZd Zd Zd Zd Zd Z	d	 Z
d
 Zd ZdS )HTMLXMLParserz A mostly-cut-and-paste of ElementTree's HTMLTreeBuilder that
    does special meld3 things (like preserve comments and munge meld
    ids).  Subclassing is not possible due to private attributes. :-(Nc                     g | _         |t                      }|| _        |pd| _        	 t	          j        | d           n$# t          $ r t	          j        |            Y nw xY wi | _        d S )Nz
iso-8859-1F)convert_charrefs)_HTMLXMLParser__stackr*  builderr!   r   rn   	TypeErrorr-  )rA   r@  r!   s      r0   rn   zHTMLXMLParser.__init__  s    ?%''G 0L	& u===== 	& 	& 	&%%%%%	&s   A   A! A!c                 j    t          j        |            i | _        | j                                        S r,   )r   closer-  r@  rp   s    r0   rC  zHTMLXMLParser.close  s.    |!!###r1   c                    |dk    rod x}}|D ](\  }}|dk    r|                                 } |dk    r|})|dk    r:|r8t          j        |d|d          }|                    d          }|r|| _        |t
          v r-| j        r&| j        d         |k    r|                     |           | j                            |           i }	|rj|D ]g\  }}|t          k    r>t          }| j                            |          rt          d	|z            d
| j        |<   n|                                 }||	|<   h| j                            ||	           |t           v r5| j                                         | j                            |           d S d S )Nr   z
http-equivr\   zcontent-typez: z

charsetr/  r0  )r   emailmessage_from_string	get_paramr!   	AUTOCLOSEr?  handle_endtagrM   _MELD_SHORT_IDr@   r-  r?   r   r@  rz   	IGNOREENDpopr4  )
rA   rI   r1  
http_equivr\   r   r   msgr!   r>   s
             r0   handle_starttagzHTMLXMLParser.handle_starttag  s   &==#''J    1$$!"JJ)^^G^+++/$.JJ8  ==33 -$,DM)| (R 0C 7 7""3'''C    
	 	 	1&& A|''** ,()J)**+ , , ,&'DLOO		Aq		3''')LLS!!!!! r1   c                     |t           v rd S | j                                        }||k    r|t          v r|                     |           | j                            |           d S r,   )rM  r?  rN  rJ  rK  r@  r4  )rA   rI   lasttags      r0   rK  zHTMLXMLParser.handle_endtag.  sh    )F,""$$'>>g22w'''r1   c                     |d d         dk    rt          |dd          d          }nt          |          }| j                            t          |                     d S )Nr0  r     )intr@  r   r   )rA   chars     r0   handle_charrefzHTMLXMLParser.handle_charref6  sY    8s??tABBx$$DDt99D&,,'''''r1   c                 8   t           j                            |          }|rct          |          dk    rt	          |          }nt          |dd                   }| j                            t          |                     d S | 	                    |           d S )Nr0  r  rF  )
r   
entitydefsr?   rs   ordrV  r@  r   r   unknown_entityref)rA   rC   entitys      r0   handle_entityrefzHTMLXMLParser.handle_entityref=  s    *..t44 	)6{{aVVAbD\**LfVnn-----""4(((((r1   c                     t          |t                    rt          || j                  }| j                            |           d S r,   )r3   r4   r   r!   r@  r   r5  s     r0   handle_datazHTMLXMLParser.handle_dataH  sA    dE"" 	2T4=11D$r1   c                     d S r,   ra   )rA   rC   s     r0   r\  zHTMLXMLParser.unknown_entityrefM  r:  r1   c                     | j                             t          i            | j                             |           | j                             t                     d S r,   )r@  rz   r   r   r4  r5  s     r0   handle_commentzHTMLXMLParser.handle_commentP  sL    7B'''$!!!!!r1   )NN)r^   r_   r`   __doc__rn   rC  rQ  rK  rX  r^  r`  r\  rc  ra   r1   r0   r<  r<    s        I I   $ $ $
$" $" $"L  ( ( (	) 	) 	)     
  " " " " "r1   r<  c                     t          | |                                          }|                                }|D ]}|D ]	}||_        
|S )N)parser)et_parsegetrootr=   rN   )sourcerf  rootrE   r   cs         r0   do_parserl  U  sb    F6***2244D!!H   	 	AAHH	Kr1   c                 ^    t                      }t          |          }t          | |          S )z Parse source (a filelike object) into an element tree.  If
    html is true, use a parser that can resolve somewhat ambiguous
    HTML into XHTML.  Otherwise use a 'normal' parser only.)target)r*  r   rl  )ri  r@  rf  s      r0   	parse_xmlro  ]  s/     Gg&&&FFF###r1   c                 ^    t                      }t          ||          }t          | |          S r,   )r*  r<  rl  )ri  r!   r@  rf  s       r0   
parse_htmlrq  e  s,    G7H--FFF###r1   c                 >    t          |           }t          |          S r,   )r   ro  )r/   ri  s     r0   parse_xmlstringrs  j  s    d^^FVr1   c                 @    t          |           }t          ||          S r,   )r   rq  )r/   r!   ri  s      r0   parse_htmlstringru  n  s    d^^Ffh'''r1   z[&"<]z[&<]c                     t          |                                           }|D ]}| |         | |                                <    d S r,   )r   r   upper)mappinglc_keysr   s      r0   
_both_caserz  u  sI    7<<>>""G ( ($QZ		( (r1   r0  )areabasebasefontr   colframer   r   r   isindexr   r   param)scriptstyle)r   r   compactdeclaredeferdisabledismapmultiplenohrefnoresizenoshadenowraprF  c           	         |d}|j         }|j        }|j        }|j        }t          }	|t          u r@|j        st          |          rt          |          } | t          ||                     n|t          u r?t          |          rt          |          } | t          d|z   dz   |                     n|t          u r?t          |          rt          |          } | t          d|z   dz   |                     ng }
	 |dd         dk    rR|dt                   t          k    r|t          d         }n*t          ||          \  }}|r|
                    |           n# t          $ r t!          |           Y nw xY w|	t"          t          ||          z   z  }	|j        }|t'          |          dk    r6t)          |                                          }|                                 n|}|D ]s}	 |dd         dk    rn# t          $ r t!          |           Y nw xY w|t.          v r|	t0          t          ||          z   z  }	W||         }|	t3          |||          z  }	t|
D ]\  }}|	t3          |||          z  }	|	t4          z  }	|T|rR|t6          v r|	t          ||          z  }	n5t          |          r|	t          |          z  }	n|	t          ||          z  }	 | |	           |j        D ]Q}|9|dz   }||k     rt;          | |||||           $||k    r|r | t<                     =t;          | |||||           R|s|j        s	|t>          vr) | t@          t          ||          z   tB          z              |rDt          |          r | t          |                     dS  | t          ||                     dS dS )z1 Walk 'node', calling 'write' with bytes(?).
    Nutf-8r'   r(   r0  {)"rI   rK   r/   r   r7   r8   cdata_needs_escaping_escape_cdatar-   r   r   _XHTML_PREFIX_LEN_XHTML_PREFIXfixtagrM   rA  _raise_serialization_error_OPEN_TAG_STARTr>   rs   r   r   sort_HTMLATTRS_BOOLEAN_SPACE_encode_attrib_OPEN_TAG_END_HTMLTAGS_NOESCAPErL   r   _OMITTED_TEXT_HTMLTAGS_UNBALANCED_CLOSE_TAG_START_CLOSE_TAG_END)r   rB   r!   
namespacesdepthr  rI   rK   r/   to_writexmlns_itemsxmlnsr>   attrib_keysr   r   rP   s                    r0   r   r     s    8C9D9D9DH
g~~~ 	+#D)) +$T**fT8$$%%%%	%% 	' &&DfWt^f,h778888	%	%	%%% 	' &&DfWt^f,h778888 		,2A2w#~~)))*m;;/001CC!'Z!8!8JC 2#**5111 	, 	, 	,&s+++++	, 	OfS(&;&;;;6{{Q"6;;==11  """"$  
? 
?2!u||  $  2 2 2.q111112***8)<)< <<HHq	Aq!X > >>HH 	7 	7DAqq!X666HHM!(((F4222%d++ 2M$///F4111h^ 
	Q 
	QE#	8##uh
E (* * * *h&&4&E-((( E5(JxPPPP 	M4> 	MS0D%D%DE"VC%:%::^KLLL )%% 	)E-%%&&&&&E&h''(((((	) )s%   A E% %F F8HH$#H$c           	      |   |d}|j         }|t          u r0 | t          t          |j        |          z   t
          z              n|t          u r0 | t          t          |j        |          z   t          z              n|t          u rG|j
        r  | t          |j        |                     ng | t          |j        |                     nG|r'|dt                   t          k    r|t          d         }|j        r't          |j                                                  }ng }g }	 |dd         dk    r*t#          ||          \  }}	|	r|                    |	           n# t&          $ r t)          |           Y nw xY w | t*          t          ||          z              |s|r|                                 |D ]\  }
}	 |
dd         dk    r8|s|
t.          k    r"t#          |
|          \  }
}	|	r|                    |	           |s|
dk    rUn# t&          $ r t)          |
           Y nw xY w | t1          |
||                     |D ]\  }
} | t1          |
||                      |j        s|j        r} | t4                     |j        r | t          |j        |                     |j        D ]}t7          | |||||            | t8          t          ||          z   t:          z              n | t<                     |D ]\  }
}||= 	|j        r  | t          |j        |                     dS dS )z Write XML to a file Nr  r0  r  
xmlns:meld) rI   r   _COMMENT_STARTr  r/   _COMMENT_ENDr   	_PI_START_PI_ENDr7   r8   r-   r  r  r>   r   r   r  rM   rA  r  r  r  r@   r  rL   r  r   r  r  _SELF_CLOSErK   )r   rB   r!   r  r   rj   rI   r   r  r  r   r   ns                r0   r   r     s   
(C
g~~nDIx001 	 	 	 	 
%	%	%iDIx001 	 	 	 	 
> 	6E&H--....E-	8445555 	.%%%&-77+,,-; 	**,,--EEE	,2A2w#~~#C44
U .&&u--- 	, 	, 	,&s+++++	,osH 5 55666 	6K 	6JJLLL 6 612!u||' ) H}} (#)!Z#8#85 ;+"4"4U";";";# %,,$  2 2 2.q111112nQ8445555# 6 61nQ84455559 	 	E-   y :mDIx88999^ L L5!Xz8UKKKKE"VC%:%::^KLLLLE+ 	 	DAq1y 2mDIx00111112 2s*   *8E# #E?>E?H2HH/.H/c           
          t                               t          t          | |          t          t
          t          ||          t
          f          S r,   )r   r   r  r-   _EQUAL_QUOTE_escape_attrib)r   r   r!   s      r0   r  r  2  sB    ;;q(++&q(33   r1   z&(?!([#\w]*;))c                 ^   	 |r1	 t          | |          }n0# t          $ r t          |           cY S w xY wt          | d          }t                              t          |          }|                    t          t                    }|S # t          t          f$ r t          |            Y d S w xY wNr   r    )r-   UnicodeError_encode_entityr   _NONENTITY_REsub_AMPER_ESCAPEDr   _LT_LT_ESCAPEDrA  AttributeErrorr  r/   r!   encodeds      r0   r  r  @  s    ) 	8, x00 , , ,%d+++++, th777G##NG<<//#{33~& ) ) )"4(((((()s-   B  B 2B 2AB  B,+B,c                    	 |r1	 t          | |          }n0# t          $ r t          |           cY S w xY wt          | d          }t                              t          |          }|                    t          t                    }|                    t          t                    }|S # t          t          f$ r t          |            Y d S w xY wr  )r-   r  r  r   r  r  r  r   r  r  r  _QUOTE_ESCAPEDrA  r  r  r  s      r0   r  r  P  s    ) 	8, x00 , , ,%d+++++, th777G##NG<<//#{33//&.99~& ) ) )"4(((((()s-   B(  B( 2B( 2A5B( ( CCc                     |s | t           t          z              d S  | t           t          z   t          z   t          z   t
          z   t          |d          z   t
          z   t          z              d S r  )_XML_PROLOG_BEGIN_XML_PROLOG_ENDr  	_ENCODINGr  r  r   )r   r!   s     r0   r   r   d  s     
/122222  	
 x(3334   	 	 	 	 	r1   c                    	 |\  }}}n,# t           t          f$ r t          d|j        z            w xY w | t          t          z   t          |d          z   t          z   t          z   t          z   t          z   t          |d          z   t          z   t          z   t          z   t          |d          z   t          z   t          z              d S )NzQdoctype must be supplied as a 3-tuple in the form (name, pubid, system) e.g. '%s'r   r    )	r   rA  rj   _DOCTYPE_BEGINr  r   _PUBLICr  _DOCTYPE_END)r   re   rC   r8  r9  s        r0   r   r   r  s   L%eVV	" L L L ;=D]K L L 	LL 
E.6
!HTH$E$E$E
E
#$
EH55568>?AGH  FX6667 :@@ 	     s   	 )2z<\?xml .*?\?>z<[^/?!]?\w+c                     t                               |           }d|z  }|A|                    d          \  }}| d |         }| ||         }| |d          }||z   |z   |z   S || z   S )Nz<!DOCTYPE %s PUBLIC "%s" "%s">r   )_XML_DECL_REsearchspan)	r   re   match	dt_stringrz   r4  beforerI   afters	            r0   insert_doctyper    s     %%E07:IZZ]]
sfuf59oSTT
|i'%//4r1   c                     t                               |           }|I|                    d          \  }}| d |         }| ||         dt          z  z   }| |d          }||z   |z   } | S )Nr   z xmlns:meld="%s")_BEGIN_TAG_REr  r  _MELD_NS_URL)r   r  rz   r4  r  rI   r  s          r0   insert_meld_ns_declr    ss      &&EZZ]]
sfuf59o 2\ AASTT
u$Kr1   c                     |                      d          dk    rt          | |          } |                      d          dk    rt          |           } | S )Nr)   rF  r  )r   r  r  )r   re   s     r0   prefeedr    sQ    yy##dG,,yy"$$"4((Kr1   c                     | j         }|j         }t          |dd           }t          |dd           }||k    rdS ||dS |r|rt          ||          S dS )NrI   FT)rN   getattrr  )r  r   	srcparent	tgtparentsrcparenttagtgtparenttags         r0   r  r    sx    !I!I9eT22L9eT22L|##u		,"6t	 3y 3Y	2225r1   c                     g }| D ];}|j         }||                    |           !||v r&|                    |           <|S r,   )rN   rM   )r   r  r9   rN   s       r0   r  r    sa     G    >NN7###WwNr1   c                 F    g }| D ]}||v r|                     |           |S r,   )rM   )S1S2rT   r9   s       r0   intersectionr    s7    
A  b==HHWHr1   c              #      K   | j                             |          }||||k    r| V  | j        D ]=}t          ||          D ]*}|j                             |          }||||k    r|V  +>d S r,   )r>   r?   rL   melditerator)r9   r  r@   nodeidrP   el2s         r0   r  r    s      ^))F>Vv--MMM"  v.. 	 	CZ^^H--F!>Vv%5%5III		 r1   u   Âr  u   ï¿¿z&gt;)&r%   r&   r$   xmlrg   rdfwsdl)z$http://www.w3.org/XML/1998/namespacerc   z+http://www.w3.org/1999/02/22-rdf-syntax-ns#z http://schemas.xmlsoap.org/wsdl/c                 R    	 |                      |          S # t          $ r | cY S w xY wr,   )r-   r  )sr!   s     r0   _encoder    s=    xx!!!   s    &&c                 R    t          d| dt          |           j        d          )Nzcannot serialize z (type ))rA  r   r^   )r/   s    r0   r  r    s1    
)+/44d1D1D1DE
 
 
r1   c                    t           ,dt          z   dz   t          z   dz   }t          j        |          a d }	 t          t                               ||           d          S # t          $ r t          |            Y d S w xY w)Nz[&<>\"-z]+c                     g }|j         }|                                 D ];}t                              |          }|dt	          |          z  } ||           <d                    |          S )Nz&#%d;r   )rM   group_escape_mapr?   r[  r   )moutrM   rW  r/   s        r0   _escape_entitiesz(_encode_entity.<locals>._escape_entities  sj    GGII 	 	D??4((D|T*F4LLLLwws||r1   ascii)	_pattern_NON_ASCII_MIN_NON_ASCII_MAXrecompiler  r  rA  r  )r/   _ptxtr  s      r0   r  r    s     N*S0>ADH:e$$  )x||$4d;;WEEE ) ) )"4(((((()s   (A! !A>=A>c                 H   t          | t                    r| j        } | dd                              dd          \  }} |                    |          }|Dt
                              |          }|dt          |          z  }|||<   |dk    rd }n
d|z  |f}nd }|d| |fS )Nr0  }zns%dr  zxmlns:%s:)r3   r   r/   splitr?   _namespace_maprs   )rI   r  namespace_uriprefixr  s        r0   r  r    s     #u hQRRsA..M3^^M**F~##M22>c*oo-F$*
=!U??EE&(-8EEffcc"E))r1   r]   r,   )rF  N)hrG  r  xml.etree.ElementTreer   r   r   r   r   r   r	   rg  supervisor.compatr
   r   r   r   r   r   r   r   rJ  rM  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r-   r7   r;   r   r  _MELD_PREFIX_MELD_LOCALr@   rL  _XHTML_NS_URLr  rs   r  _markerre   r6   r*  r<  rl  ro  rq  rs  ru  r  r  attrib_needs_escapingr  rz  r  r  r  r   r   r  r  r  r  r   r   r  r  rj   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  ra   r1   r0   <module>r     sa    				                 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 8	-		"x	(	(	(	#	)	)	)	#	)	)	)	#	)	)	)(32228D8444 !)#!A!A!A Ahux000h777'H555x222HTH---	
(4(
+
+
+'H555hsX&&&hv111(X666H2XFFF HZ(333	(6H555+999
(8h
/
/
/x111 % % % %     ?' ?' ?' ?' ?' ?' ?' ?'B 
:%&,4[(.&C&&  	O 	O 	O 	O 	O 	O 	O 	Or r r r r r r rh    k   0d" d" d" d" d"J d" d" d"L  $ $ $$ $ $ $
  ( ( ( ( #
8,,3 !rz'**1 ( ( ( #$A!!1#$1AqA"#Aq: :  
      $%q11  

   &'1Q#$A!$%!q1N N  
   b) b) b) b)HC2 C2 C2 C2J   
88$5IIIJJ) ) ) ) ) ) )(     rz*++
>**!(           "-           "& 
 
 
 
( :w//>733 
				  -2$*38(.   
 
 

 ) ) ),* * * * *r1   