a
    /§»a¬   ã                   @   sÜ   d Z ddlZddlZejdkr2dd„ Zddd„Zndd„ ZeZG d	d
„ d
eƒZG dd„ deƒZ	ede
fde	ddœƒZG dd„ de	ƒZG dd„ deƒZG dd„ de
ƒZG dd„ de
ƒZG dd„ deƒZG dd„ dƒZeƒ ZdS )z�
module for generating and serializing xml and html structures
by using simple python objects.

(c) holger krekel, holger at merlinux eu. 2009
é    N)é   r   c                 C   s   | S ©N© ©Úsr   r   úD/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/py/_xmlgen.pyÚu
   s    r   c                 C   s   t | dƒr|  ¡ S t| ƒS )NÚ__unicode__)Úhasattrr	   Ústr)ÚxÚerrorsr   r   r   Úunicode   s    
r   c                 C   s   t | ƒS r   ©r   r   r   r   r   r      s    c                   @   s   e Zd Zdd„ ZdS )ÚNamespaceMetaclassc                 C   sx   |d d… dkrt |ƒ‚| tkr(tdƒ‚| j}|d urF||vrFt |ƒ‚i }| jrX||d< t|| jf|ƒ}t| ||ƒ |S )Né   Ú_zNamespace class is abstractÚxmlname)ÚAttributeErrorÚ	NamespaceÚ
ValueErrorÚ__tagspec__Ú__stickyname__ÚtypeÚ__tagclass__Úsetattr)ÚselfÚnameZtagspecÚ	classattrÚclsr   r   r   Ú__getattr__   s    zNamespaceMetaclass.__getattr__N)Ú__name__Ú
__module__Ú__qualname__r    r   r   r   r   r      s   r   c                       sJ   e Zd ZG dd„ deƒZ‡ fdd„Zdd„ ZeZddd	„Zd
d„ Z	‡  Z
S )ÚTagc                   @   s   e Zd Zdd„ ZdS )zTag.Attrc                 K   s   | j  |¡ d S r   )Ú__dict__Úupdate)r   Úkwargsr   r   r   Ú__init__(   s    zTag.Attr.__init__N©r!   r"   r#   r(   r   r   r   r   ÚAttr'   s   r*   c                    s&   t t| ƒ |¡ | jf i |¤Ž| _d S r   )Úsuperr$   r(   r*   Úattr)r   Úargsr'   ©Ú	__class__r   r   r(   +   s    zTag.__init__c                 C   s   | j dd�S )Nr   )Úindentr   ©r   r   r   r   r	   /   s    zTag.__unicode__é   c                 C   s$   g }t |j|ƒ | ¡ tdƒ |¡S ©NÚ )ÚSimpleUnicodeVisitorÚappendÚvisitr   Újoin©r   r0   Úlr   r   r   r   3   s    zTag.unicodec                 C   s   | j j}d|t| ƒf S )Nz<%r tag object %d>)r/   r!   Úid)r   r   r   r   r   Ú__repr__8   s    zTag.__repr__)r2   )r!   r"   r#   Úobjectr*   r(   r	   Ú__str__r   r<   Ú__classcell__r   r   r.   r   r$   &   s   
r$   r   F)r   r   r   c                   @   s   e Zd Zddd„ZdS )ÚHtmlTagr2   c                 C   s(   g }t |j|dd� | ¡ tdƒ |¡S )NF©Ú
shortemptyr4   )ÚHtmlVisitorr6   r7   r   r8   r9   r   r   r   r   C   s    zHtmlTag.unicodeN)r2   )r!   r"   r#   r   r   r   r   r   r@   B   s   r@   c                   @   s<   e Zd ZeZdZedd„ d d¡D ƒƒZG dd„ de	ƒZ
dS )	ÚhtmlTc                 C   s   g | ]}|r|d f‘qS ©r   r   ©Ú.0r   r   r   r   Ú
<listcomp>L   s   ózhtml.<listcomp>aÉ  a,abbr,acronym,address,applet,area,article,aside,audio,b,base,basefont,bdi,bdo,big,blink,blockquote,body,br,button,canvas,caption,center,cite,code,col,colgroup,command,comment,datalist,dd,del,details,dfn,dir,div,dl,dt,em,embed,fieldset,figcaption,figure,footer,font,form,frame,frameset,h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,i,iframe,img,input,ins,isindex,kbd,keygen,label,legend,li,link,listing,map,mark,marquee,menu,meta,meter,multicol,nav,nobr,noembed,noframes,noscript,object,ol,optgroup,option,output,p,param,pre,progress,q,rp,rt,ruby,s,samp,script,section,select,small,source,span,strike,strong,style,sub,summary,sup,table,tbody,td,textarea,tfoot,th,thead,time,title,tr,track,tt,u,ul,xmp,var,video,wbrú,c                   @   s   e Zd Zdd„ ZdS )z
html.Stylec                 K   s.   |  ¡ D ] \}}| dd¡}t| ||ƒ qd S )Nr   ú-)ÚitemsÚreplacer   )r   Úkwr   Úyr   r   r   r(   \   s    zhtml.Style.__init__Nr)   r   r   r   r   ÚStyle[   s   rO   N)r!   r"   r#   r@   r   r   ÚdictÚsplitr   r=   rO   r   r   r   r   rD   I   s   ÿó
rD   c                   @   s   e Zd ZdZdd„ ZdS )Úrawz]just a box that can contain a unicode string that will be
    included directly in the outputc                 C   s
   || _ d S r   )Úuniobj)r   rS   r   r   r   r(   e   s    zraw.__init__N)r!   r"   r#   Ú__doc__r(   r   r   r   r   rR   b   s   rR   c                   @   sj   e Zd ZdZddd„Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ ZdS )r5   z% recursive visitor to write unicode. r   Tc                 C   s.   || _ i | _i | _|| _|| _g | _|| _d S r   )ÚwriteÚcacheÚvisitedr0   Ú	curindentÚparentsrB   )r   rU   r0   rX   rB   r   r   r   r(   j   s    zSimpleUnicodeVisitor.__init__c                 C   sj   |j }z| j| }W nH ty\   |jD ]}t| |jdƒ}|dur( qNq(| j}|| j|< Y n0 ||ƒ dS )z( dispatcher on node's class/bases name. N)r/   rV   ÚKeyErrorÚ__mro__Úgetattrr!   Ú_SimpleUnicodeVisitor__object)r   Únoder   ZvisitmethodÚsubclassr   r   r   r7   s   s    
zSimpleUnicodeVisitor.visitc                 C   s   |   tt|ƒƒ¡ d S r   )rU   Úescaper   ©r   Úobjr   r   r   Z__object„   s    zSimpleUnicodeVisitor.__objectc                 C   s   |   |j¡ d S r   )rU   rS   ra   r   r   r   rR   ˆ   s    zSimpleUnicodeVisitor.rawc                 C   s8   t |ƒ| jvsJ ‚d| jt |ƒ< |D ]}|  |¡ q$d S )Nr   )r;   rW   r7   )r   rb   Úelemr   r   r   Úlist‹   s    zSimpleUnicodeVisitor.listc                 C   sL  t |ƒ| jvsJ ‚z| jd |_W n ty:   d |_Y n0 d| jt |ƒ< t|d|jjƒ}| jr‚|  	|¡s‚|  
dtdƒ| j  ¡ |�r|  j| j7  _|  
tdƒ||  |¡f ¡ | j |¡ |D ]}|  |¡ qÄ| j ¡  |  
tdƒ| ¡ |  j| j8  _nF||  |¡ }|  |¡�r2|  
tdƒ|f ¡ n|  
td	ƒ||f ¡ d S )
Néÿÿÿÿr   r   Ú
ú z<%s%s>z</%s>z<%s/>z	<%s></%s>)r;   rW   rY   ÚparentÚ
IndexErrorr\   r/   r!   rX   Ú	_isinlinerU   r   r0   Ú
attributesr6   r7   ÚpopÚ_issingleton)r   ÚtagÚtagnamer   Znameattrr   r   r   r$   ‘   s,    
zSimpleUnicodeVisitor.Tagc                 C   s^   t |jƒ}| ¡  g }|D ]$}|  |j|¡}|d ur| |¡ q| |  |¡¡ tdƒ |¡S r3   )	Údirr,   ÚsortÚrepr_attributer6   ÚextendÚgetstyler   r8   )r   rn   Zattrlistr:   r   Úresr   r   r   rk   «   s    
zSimpleUnicodeVisitor.attributesc                 C   s^   |d d… dkrZt ||ƒ}| d¡r0|d d… }t|tƒrB|j}ntt|ƒƒ}d||f S d S )Nr2   Ú__r   re   z %s="%s")r\   ÚendswithÚ
isinstancerR   rS   r`   r   )r   Úattrsr   ÚvalueÚinsertr   r   r   rr   ·   s    


z#SimpleUnicodeVisitor.repr_attributec                 C   sR   z|j j}W n ty"   g  Y S 0 dd„ | ¡ D ƒ}tdƒtdƒ |¡ gS dS )z- return attribute list suitable for styling. c                 S   s   g | ]\}}|d  | ‘qS )z: r   )rG   r   rN   r   r   r   rH   É   ó    z1SimpleUnicodeVisitor.getstyle.<locals>.<listcomp>z style="%s"z; N)Ústyler%   r   rK   r   r8   )r   rn   Z	styledictZ	stylelistr   r   r   rt   Â   s    
zSimpleUnicodeVisitor.getstylec                 C   s   | j S )ú*can (and will) be overridden in subclassesrA   ©r   ro   r   r   r   rm   Ì   s    z!SimpleUnicodeVisitor._issingletonc                 C   s   dS )r~   Fr   r   r   r   r   rj   Ð   s    zSimpleUnicodeVisitor._isinlineN)r   r   T)r!   r"   r#   rT   r(   r7   r]   rR   rd   r$   rk   rr   rt   rm   rj   r   r   r   r   r5   h   s   
	
r5   c                       s\   e Zd Zedd„ d d¡D ƒƒZedd„ d d¡D ƒƒZ‡ fdd	„Zd
d„ Zdd„ Z	‡  Z
S )rC   c                 C   s   g | ]}|d f‘qS rE   r   rF   r   r   r   rH   Ö   r|   zHtmlVisitor.<listcomp>z3br,img,area,param,col,hr,meta,link,base,input,framerI   c                 C   s   g | ]}|d f‘qS rE   r   rF   r   r   r   rH   Ù   r|   z“a abbr acronym b basefont bdo big br cite code dfn em font i img input kbd label q s samp select small span strike strong sub sup textarea tt u varrg   c                    s0   |dkrt ||ƒ}|d u rd S tt| ƒ ||¡S )NÚclass_)r\   r+   rC   rr   )r   ry   r   rz   r.   r   r   rr   Þ   s
    
zHtmlVisitor.repr_attributec                 C   s
   || j v S r   )Úsingler   r   r   r   rm   å   s    zHtmlVisitor._issingletonc                 C   s
   || j v S r   )Úinliner   r   r   r   rj   è   s    zHtmlVisitor._isinline)r!   r"   r#   rP   rQ   r�   r‚   rr   rm   rj   r?   r   r   r.   r   rC   Ô   s   ÿÿþÿrC   c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )Ú_escapec                 C   sb   t dƒt dƒt dƒt dƒt dƒt dƒt dƒt dƒt d	ƒt d
ƒi| _t t dƒ | j ¡ ¡¡| _d S )Nú"z&quot;ú<z&lt;ú>z&gt;ú&z&amp;ú'z&apos;ú|)r   r`   ÚreÚcompiler8   ÚkeysÚ
charef_rexr1   r   r   r   r(   í   s    $þz_escape.__init__c                 C   s   | j | d¡ S )Nr   )r`   Úgroup)r   Úmatchr   r   r   Ú	_replacerô   s    z_escape._replacerc                 C   s>   zt |ƒ}W n  ty,   t |ddd�}Y n0 | j | j|¡S )z& xml-escape the given unicode string. zutf-8rL   )r   )r   ÚUnicodeDecodeErrorr�   Úsubr�   )r   Zustringr   r   r   Ú__call__÷   s
    z_escape.__call__N)r!   r"   r#   r(   r�   r“   r   r   r   r   rƒ   ì   s   rƒ   )N)rT   ÚsysrŠ   Úversion_infor   r   r   r   rd   r$   r=   r   r@   rD   rR   r5   rC   rƒ   r`   r   r   r   r   Ú<module>   s(   
ýl