B
    u9aA ã               @   s¢   d dl Z d dlZd dlmZ d dlZd dlZd dlmZmZm	Z	m
Z
 d dlmZ ejdddZdZdd	d
„Zdd„ Zdd„ ZG dd„ dejƒZedkrže ¡  dS )é    N)Úsupport)ÚparseÚNodeÚDocumentÚparseString)ÚgetDOMImplementationztest.xmlZxmltestdata)Zsubdira  <?xml version='1.0' encoding='us-ascii'?>
<!DOCTYPE doc PUBLIC 'http://xml.python.org/public' 'http://xml.python.org/system' [
  <!ELEMENT e EMPTY>
  <!ENTITY ent SYSTEM 'http://xml.python.org/entity'>
]><doc attr='value'> text
<?pi sample?> <!-- comment --> <e/> </doc>c             C   s   t ƒ  d d| ¡S )NÚdoc)r   ÚcreateDocument)Údoctype© r   ú"/usr/lib/python3.7/test_minidom.pyÚcreate_doc_without_doctype   s    r   c              C   sx   t ƒ  dd d ¡} g | j_g | j_tjj dd d¡}| jj 	|¡ tjj 
dd dd¡}d|_d|_d|_| jj 	|¡ | S )	Nr   zmy-notationz"http://xml.python.org/notations/myz	my-entityz!http://xml.python.org/entities/myz1.0zutf-8zus-ascii)r   ZcreateDocumentTypeÚentitiesZ_seqÚ	notationsÚxmlÚdomÚminidomZNotationÚappendZEntityÚversionÚencodingÚactualEncoding)r
   ZnotationÚentityr   r   r   Úcreate_nonempty_doctype   s    r   c              C   s.   t ƒ } t| ƒ}|| j d¡_|| j d¡_|S )Nr   )r   r   r   ÚitemÚownerDocumentr   )r
   r   r   r   r   Úcreate_doc_with_doctype-   s
    r   c               @   sd  e 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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.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Zd:d;„ Zd<d=„ Z d>d?„ Z!d@dA„ Z"dBdC„ Z#dDdE„ Z$dFdG„ Z%dHdI„ Z&dJdK„ Z'dLdM„ Z(dNdO„ Z)dPdQ„ Z*dRdS„ Z+dTdU„ Z,dVdW„ Z-dXdY„ Z.dZd[„ Z/d\d]„ Z0d^d_„ Z1d`da„ Z2dbdc„ Z3ddde„ Z4dfdg„ Z5dhdi„ Z6djdk„ Z7dldm„ Z8dndo„ Z9dpdq„ Z:drds„ Z;dtdu„ Z<dvdw„ Z=dxdy„ Z>dzd{„ Z?d|d}„ Z@d~d„ ZAd€d„ ZBd‚dƒ„ ZCd„d…„ ZDd†d‡„ ZEdˆd‰„ ZFdŠd‹„ ZGdŒd„ ZHdŽd„ ZIdd‘„ ZJd’d“„ ZKd”d•„ ZLd–d—„ ZMd˜d™„ ZNdšd›„ ZOdœd„ ZPdždŸ„ ZQd d¡„ ZRd¢d£„ ZSd¤d¥„ ZTd¦d§„ ZUd¨d©„ ZVdªd«„ ZWd¬d­„ ZXd®d¯„ ZYd°d±„ ZZd²d³„ Z[d´dµ„ Z\d¶d·„ Z]d¸d¹„ Z^dºd»„ Z_d¼d½„ Z`d¾d¿„ ZadÀdÁ„ ZbdÂdÃ„ ZcdÄdÅ„ ZddÆdÇ„ ZedÈdÉ„ ZfdÊdË„ ZgdÌdÍ„ ZhdÎdÏ„ ZidÐdÑ„ ZjdÒdÓ„ ZkdÔdÕ„ ZldÖd×„ ZmdØdÙ„ ZndÚdÛ„ ZodÜdÝ„ ZpdÞdß„ Zqdàdá„ Zrdâdã„ ZsG dädå„ dåƒZtdædç„ Zudèdé„ Zvdêdë„ Zwdìdí„ Zxdîdï„ Zydðdñ„ Zzdò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d	„ Z†d
d„ Z‡dd„ ZˆdS (  ÚMinidomTestÚTestc             C   s   |   ||¡ d S )N)Ú
assertTrue)ÚselfÚtestZtestnamer   r   r   Úconfirm5   s    zMinidomTest.confirmc             C   s"   |j }|  ||kd||f ¡ d S )Nzlooking for %r, found %r)Ú	wholeTextr!   )r   ÚnodeÚsÚtr   r   r   ÚcheckWholeText8   s    zMinidomTest.checkWholeTextc             C   s"   t ƒ }|  |j¡ |  t j¡ d S )N)r   ÚassertFalseZasync_)r   r   r   r   r   ÚtestDocumentAsyncAttr<   s    z!MinidomTest.testDocumentAsyncAttrc          	   C   s:   t tdƒ&}t|ƒ}| ¡  |  t|tƒ¡ W d Q R X d S )NÚrb)ÚopenÚtstfiler   Úunlinkr!   Ú
isinstancer   )r   Úfiler   r   r   r   ÚtestParseFromBinaryFileA   s    z#MinidomTest.testParseFromBinaryFilec          	   C   s>   t tddd&}t|ƒ}| ¡  |  t|tƒ¡ W d Q R X d S )NÚrz
iso-8859-1)r   )r*   r+   r   r,   r!   r-   r   )r   r.   r   r   r   r   ÚtestParseFromTextFileG   s    z!MinidomTest.testParseFromTextFilec             C   s0   t tƒ}|  | d¡|j d¡k¡ | ¡  d S )NZLI)r   r+   r!   ÚgetElementsByTagNameÚdocumentElementr,   )r   r   r   r   r   ÚtestGetElementsByTagNameM   s    z$MinidomTest.testGetElementsByTagNamec             C   s   t dƒ}|j}|jd }| d¡}| ||¡ |  t|jƒdko¦|jjdko¦|jd |ko¦|j d¡|ko¦|jd |ko¦|j d¡|ko¦|j	|ko¦|j
|ko¦| ¡ dkd¡ | d¡}| |d ¡ |  t|jƒdkoJ|jjdkoJ|jd |koJ|j d¡|koJ|jd |koJ|j d¡|koJ|j
|koJ|j|koJ| ¡ d	kd¡ | d
¡}| ||¡ |  t|jƒdkoî|jjdkoî|jd |koî|j d¡|koî|jd |koî|j d¡|koî|j|koî|j|koî| ¡ dkd¡ | ¡  d S )Nz<doc><foo/></doc>r   Úelementé   é   z<doc><element/><foo/></doc>z0testInsertBefore -- node properly placed in treeé   z%<doc><element/><foo/><element/></doc>Úbaré   z+<doc><element/><foo/><bar/><element/></doc>)r   r3   Ú
childNodesÚcreateElementÚinsertBeforer!   ÚlenÚlengthr   Ú
firstChildÚ	lastChildÚtoxmlÚpreviousSiblingÚnextSiblingr,   )r   r   ÚrootÚelemZnelemZnelem2r   r   r   ÚtestInsertBeforeS   sR    







zMinidomTest.testInsertBeforec             C   sr   t dƒ}| d¡}| d¡}| d¡}| d¡}|j |¡ | ¡ }| |¡ | |¡ | |¡ ||||||fS )Nz<doc/>ZoriginalÚfoor9   Zbat)r   ÚcreateTextNoder3   ÚappendChildZcreateDocumentFragment)r   r   ÚorigÚc1Úc2Úc3Úfragr   r   r   Ú_create_fragment_test_nodes~   s    






z'MinidomTest._create_fragment_test_nodesc             C   s¨   |   ¡ \}}}}}}|j |d ¡ |  t|jjƒ||||fkd¡ | ¡  | ¡  |   ¡ \}}}}}}|j ||¡ |  t|jjƒ||||fkd¡ | ¡  | ¡  d S )NzinsertBefore(<fragment>, None)zinsertBefore(<fragment>, orig))rP   r3   r=   r!   Útupler;   r,   )r   r   rK   rL   rM   rN   rO   r   r   r   ÚtestInsertBeforeFragment‹   s    z$MinidomTest.testInsertBeforeFragmentc             C   sV   t tƒ}|j | d¡¡ |  |jjd jdk¡ |  |jjd jdk¡ | 	¡  d S )NZHelloéÿÿÿÿz#comment)
r   r+   r3   rJ   ÚcreateCommentr!   r;   ÚnodeNameÚdatar,   )r   r   r   r   r   ÚtestAppendChildœ   s
    zMinidomTest.testAppendChildc             C   sT   |   ¡ \}}}}}}|j |¡ |  t|jjƒ||||fkd¡ | ¡  | ¡  d S )NzappendChild(<fragment>))rP   r3   rJ   r!   rQ   r;   r,   )r   r   rK   rL   rM   rN   rO   r   r   r   ÚtestAppendChildFragment£   s    z#MinidomTest.testAppendChildFragmentc             C   s\   |   ¡ \}}}}}}|j ||¡ | ¡  |  t|jjƒ|||fkd¡ | ¡  | ¡  d S )NzreplaceChild(<fragment>))rP   r3   ÚreplaceChildr,   r!   rQ   r;   )r   r   rK   rL   rM   rN   rO   r   r   r   ÚtestReplaceChildFragment¬   s    z$MinidomTest.testReplaceChildFragmentc             C   s¨   t ƒ }| d¡}| d¡}|  tjj|j|¡ | |¡ |  tjj|j||¡ |  tjj|j	||¡ |j
}|  tjj|j|¡ |  tjj|j|¡ | |¡ | ¡  d S )Nr5   Útext)r   r<   rI   ÚassertRaisesr   r   ÚHierarchyRequestErrrJ   r=   rY   Ú
attributesZsetNamedItemZsetNamedItemNSr,   )r   r   rF   r[   Znodemapr   r   r   ÚtestLegalChildrenµ   s     



zMinidomTest.testLegalChildrenc             C   s„   t ƒ }| d¡}|j}d|d< | d¡}|  |j|kd¡ |  |j|kd¡ |  |jdkd¡ |  |jdkd¡ | 	¡  | 	¡  d S )	Nr5   r9   rH   r   z-NamedNodeMap.__setitem__() sets ownerDocumentz,NamedNodeMap.__setitem__() sets ownerElementz%NamedNodeMap.__setitem__() sets valuez)NamedNodeMap.__setitem__() sets nodeValue)
r   r<   r^   r   r!   r   ÚownerElementÚvalueÚ	nodeValuer,   )r   r   rF   ÚattrsÚar   r   r   ÚtestNamedNodeMapSetItemÊ   s    

z#MinidomTest.testNamedNodeMapSetItemc             C   sB   t tƒ}|  |¡ | | d¡¡ |  |jd j ¡ | ¡  d S )NrH   rS   )r   r+   r!   rJ   rT   r;   r,   )r   r   r   r   r   ÚtestNonZeroÛ   s
    
zMinidomTest.testNonZeroc             C   s,   t tƒ}|  |j¡ | ¡  |  |j¡ d S )N)r   r+   r   r;   r,   r'   )r   r   r   r   r   Ú
testUnlinkâ   s    zMinidomTest.testUnlinkc          	   C   s0   t tƒ}|  |j¡ W d Q R X |  |j¡ d S )N)r   r+   r   r;   r'   )r   r   r   r   r   ÚtestContextè   s    
zMinidomTest.testContextc             C   s.   t ƒ }| | d¡¡ |  |j¡ | ¡  d S )NÚabc)r   rJ   r<   r!   r3   r,   )r   r   r   r   r   ÚtestElementí   s    zMinidomTest.testElementc             C   sj   t dƒ}|j}| dd¡ |  | ¡ dkd¡ | d¡}|  |j|kd¡ |  |j|jkd¡ | ¡  d S )Nz<abc/>ÚspamÚjam2z<abc spam="jam2"/>ÚtestAAAz!setAttribute() sets ownerDocumentz setAttribute() sets ownerElement)	r   r3   ÚsetAttributer!   rB   ÚgetAttributeNoder   r`   r,   )r   r   Úelrd   r   r   r   rm   ó   s    
zMinidomTest.testAAAc             C   sF   t dƒ}|j}| dd¡ | dd¡ |  | ¡ dkd¡ | ¡  d S )Nz<abc/>rk   Újamrl   z<abc spam="jam2"/>ÚtestAAB)r   r3   rn   r!   rB   r,   )r   r   rp   r   r   r   rr   ÿ   s    zMinidomTest.testAABc             C   sì   t ƒ }| | d¡¡}| dd¡ |  | d¡dk¡ |  |jd jdk¡ | dd¡ |  | d¡dk¡ |  |jd jdk¡ |  t|jƒdk¡ | dd¡ |  | d¡dk¡ |  |jd jdk¡ |  t|jƒdk¡ | 	¡  d S )Nri   ÚdefÚghiZjklZmnor6   Znewval)
r   rJ   r<   rn   r!   ÚgetAttributer^   ra   r>   r,   )r   r   Úchildr   r   r   ÚtestAddAttr  s    zMinidomTest.testAddAttrc             C   sr   t ƒ }| | d¡¡}|  t|jƒdk¡ | dd¡ |  t|jƒdk¡ |jd= |  t|jƒdk¡ | ¡  d S )Nri   r   rs   rt   r7   )r   rJ   r<   r!   r>   r^   rn   r,   )r   r   rv   r   r   r   ÚtestDeleteAttr  s    zMinidomTest.testDeleteAttrc             C   st   t ƒ }| | d¡¡}| dd¡ |  t|jƒdk¡ |  tj	j
|jd¡ | d¡ |  t|jƒdk¡ | ¡  d S )Nri   rs   rt   r7   rH   r   )r   rJ   r<   rn   r!   r>   r^   r\   r   r   ÚNotFoundErrZremoveAttributer,   )r   r   rv   r   r   r   ÚtestRemoveAttr'  s    
zMinidomTest.testRemoveAttrc             C   sŠ   t ƒ }| | dd¡¡}| ddd¡ | ddd¡ |  tjj|jdd¡ |  	t
|jƒdk¡ | dd¡ |  	t
|jƒd	k¡ | ¡  d S )
Nzhttp://www.python.orgz
python:abczhttp://www.w3.orgzxmlns:pythonzpython:abcattrrH   r6   Zabcattrr7   )r   rJ   ÚcreateElementNSÚsetAttributeNSr\   r   r   ry   ZremoveAttributeNSr!   r>   r^   r,   )r   r   rv   r   r   r   ÚtestRemoveAttrNS2  s    zMinidomTest.testRemoveAttrNSc             C   sÀ   t ƒ }| | d¡¡}| dd¡ |  t|jƒdk¡ | d¡}|  t	j
j|jd ¡ | |¡ |  t|jƒdko|| d¡d k¡ t ƒ }| | d¡¡}| d¡}|  t	j
j|j|¡ | ¡  d S )NrH   rk   rq   r7   r   )r   rJ   r<   rn   r!   r>   r^   ro   r\   r   r   ry   ZremoveAttributeNoder,   )r   r   rv   r#   Údom2Úchild2Znode2r   r   r   ÚtestRemoveAttributeNode@  s     


z#MinidomTest.testRemoveAttributeNodec             C   s6   t ƒ }| | d¡¡}| dd¡ |  | d¡¡ d S )NrH   rk   rq   )r   rJ   r<   rn   r!   ZhasAttribute)r   r   rv   r   r   r   ÚtestHasAttributeR  s    zMinidomTest.testHasAttributec             C   s  t dƒ}|j}| dd¡ |  t|jƒdk¡ | dd¡ | d¡ |  t|jƒdkoŽ|jd jdkoŽ|jd jdkoŽ| 	d¡dkoŽ| 
d¡j¡ d|jd< |  t|jƒdkoæ|jd jdkoæ|jd jdkoæ| 	d¡dkoæ|jd j¡ | dd¡ |  t|jƒdkon|jd jdkon|jd jdkon| 	d¡dkon|jd jdkon|jd jdkon| 	d¡dk¡ d	|jd< |  t|jƒdkoô|jd jdkoô|jd jdkoô| 	d¡dkoô|jd jd	koô|jd jd	koô| 	d¡d	k¡ | ¡  d S )
Nz<abc/>rk   rq   r7   ZbamZhamZspam2r6   Zbam2)r   r3   rn   r!   r>   r^   ÚsetIdAttributera   rb   ru   ro   ÚisIdr,   )r   r   rp   r   r   r   ÚtestChangeAttrX  sD    


zMinidomTest.testChangeAttrc             C   s   d S )Nr   )r   r   r   r   ÚtestGetAttrList~  s    zMinidomTest.testGetAttrListc             C   s   d S )Nr   )r   r   r   r   ÚtestGetAttrValues  s    zMinidomTest.testGetAttrValuesc             C   s   d S )Nr   )r   r   r   r   ÚtestGetAttrLength„  s    zMinidomTest.testGetAttrLengthc             C   s.   t ƒ }| | dd¡¡}|  | d¡d¡ d S )Nzhttp://www.python.orgz
python:abcÚmissingÚ )r   rJ   r{   ÚassertEqualru   )r   r   rv   r   r   r   ÚtestGetAttribute‡  s    zMinidomTest.testGetAttributec             C   sv   t ƒ }| | dd¡¡}| ddd¡ |  | dd¡d¡ |  | dd¡d¡ | | d¡¡}|  | dd	¡d¡ d S )
Nzhttp://www.python.orgz
python:abczhttp://www.w3.orgzxmlns:pythonZpythonÚotherr‰   ri   rˆ   )r   rJ   r{   r|   rŠ   ZgetAttributeNSr<   )r   r   rv   r   r   r   r   ÚtestGetAttributeNS  s    zMinidomTest.testGetAttributeNSc             C   s   d S )Nr   )r   r   r   r   ÚtestGetAttributeNode›  ó    z MinidomTest.testGetAttributeNodec             C   s|   d}t |ƒ}| dd¡}|  t|ƒdkol|d jdkol|d jdkol|d jdkol|d jdkol|d jdk¡ | 	¡  d S )NzZ<foo xmlns:minidom='http://pyxml.sf.net/minidom'>
        <minidom:myelem/>
        </foo>zhttp://pyxml.sf.net/minidomZmyelemr7   r   r   zminidom:myelem)
r   ÚgetElementsByTagNameNSr!   r>   ÚnamespaceURIÚ	localNameÚprefixÚtagNamerU   r,   )r   Údr   Zelemsr   r   r   ÚtestGetElementsByTagNameNS  s    z&MinidomTest.testGetElementsByTagNameNSc             C   s"   |  ||¡}|  t|ƒdk¡ d S )Nr   )r   r!   r>   )r   r   ZnsuriZlnameZnodelistr   r   r   Ú5get_empty_nodelist_from_elements_by_tagName_ns_helper¬  s    zAMinidomTest.get_empty_nodelist_from_elements_by_tagName_ns_helperc             C   sh   t dƒ}|  |dd¡ |  |dd¡ |  |dd¡ t dƒ}|  |dd¡ |  |dd¡ |  |d	d
¡ d S )Nz<doc/>z"http://xml.python.org/namespaces/aZ	localnameÚ*Zsplatz3<doc xmlns="http://xml.python.org/splat"><e/></doc>zhttp://xml.python.org/splatz	not-therez#http://somewhere.else.net/not-thereÚe)r   r—   )r   r   r   r   r   Ú+testGetEmptyNodeListFromElementsByTagNameNS±  s    




z7MinidomTest.testGetEmptyNodeListFromElementsByTagNameNSc             C   s@   t ƒ }| | d¡¡}t|ƒ}t|ƒ}|  ||k¡ | ¡  d S )Nri   )r   rJ   r<   ÚreprÚstrr!   r,   )r   r   rp   Ústring1Ústring2r   r   r   ÚtestElementReprAndStrÂ  s    z!MinidomTest.testElementReprAndStrc             C   s@   t ƒ }| | d¡¡}t|ƒ}t|ƒ}|  ||k¡ | ¡  d S )Nri   )r   rJ   r<   r›   rœ   r!   r,   )r   r   rp   r   rž   r   r   r   ÚtestElementReprAndStrUnicodeÊ  s    z(MinidomTest.testElementReprAndStrUnicodec             C   sP   t ƒ }| | dd¡¡}t|ƒ}t|ƒ}|  ||k¡ |  d|k¡ | ¡  d S )Nzhttp://www.slashdot.orgz	slash:abc)r   rJ   r{   r›   rœ   r!   r,   )r   r   rp   r   rž   r   r   r   ÚtestElementReprAndStrUnicodeNSÒ  s    z*MinidomTest.testElementReprAndStrUnicodeNSc             C   sD   t ƒ }| | d¡¡}| dd¡}|  t|ƒt|ƒk¡ | ¡  d S )Nri   rs   )r   rJ   r<   rn   r!   rœ   r›   r,   )r   r   rp   r#   r   r   r   ÚtestAttributeReprÜ  s
    zMinidomTest.testAttributeReprc             C   s   d S )Nr   )r   r   r   r   ÚtestTextNodeReprã  r   zMinidomTest.testTextNodeReprc             C   s.   d}t |ƒ}| ¡ }| ¡  |  ||k¡ d S )Nz <?xml version="1.0" ?><a b="c"/>)r   rB   r,   r!   )r   rœ   r   Údomstrr   r   r   ÚtestWriteXMLå  s
    zMinidomTest.testWriteXMLc             C   s:   d}t |ƒ}|jdd}| ¡  |  || dd¡k¡ d S )Nz"<?xml version="1.0" ?>
<a b="c"/>
z
)ZnewlÚ
)r   Útoprettyxmlr,   r!   Úreplace)r   rœ   r   r¤   r   r   r   ÚtestAltNewlineì  s
    zMinidomTest.testAltNewlinec             C   s€   d}|   tdƒ ¡ |d ¡ |   tdƒ ¡ |d ¡ |   tdƒ ¡ |d ¡ |   tdƒ ¡ |d	 ¡ |   td
ƒ ¡ |d ¡ d S )Nz<?xml version="1.0" ?>
z<B>A</B>z	<B>A</B>
z<C>A<B>A</B></C>z<C>
	A
	<B>A</B>
</C>
z<C><B>A</B>A</C>z<C>
	<B>A</B>
	A
</C>
z<C><B>A</B><B>A</B></C>z<C>
	<B>A</B>
	<B>A</B>
</C>
z<C><B>A</B>A<B>A</B></C>z <C>
	<B>A</B>
	A
	<B>A</B>
</C>
)rŠ   r   r§   )r   Údeclr   r   r   Ú test_toprettyxml_with_text_nodesó  s    



z,MinidomTest.test_toprettyxml_with_text_nodesc             C   sV   t ƒ }| d¡}| | d¡¡ | | d¡¡ | |¡ d}|  | ¡ |d ¡ d S )NrF   ZTEXTz<?xml version="1.0" ?>
z<elem>
	TEXT
	TEXT
</elem>
)r   r<   rJ   rI   rŠ   r§   )r   r   rF   rª   r   r   r   Ú)test_toprettyxml_with_adjacent_text_nodes  s    


z5MinidomTest.test_toprettyxml_with_adjacent_text_nodesc             C   sZ   xTdD ]L}t |ƒ}t | ¡ ƒ}|  | d¡d jd  ¡ | d¡d jd  ¡ ¡ qW d S )N)z<B>A</B>z<A><B>C</B></A>ÚBr   )r   r§   rŠ   r2   r;   rB   )r   rœ   r   r~   r   r   r   Ú/test_toprettyxml_preserves_content_of_text_node  s    
z;MinidomTest.test_toprettyxml_preserves_content_of_text_nodec             C   s’   t dƒ}|jj}|  |jdkoŠ|jdkoŠ|jdkoŠ|jtj	koŠ|j
d koŠ| ¡  oŠt|jƒdkoŠ|jd koŠ|jd koŠ|jd koŠ|jtjjk¡ d S )Nz<e><?mypi 	
 data 	
 ?></e>Zmypizdata 	
 r   )r   r3   r@   r!   ÚtargetrV   rU   ÚnodeTyper   ÚPROCESSING_INSTRUCTION_NODEr^   ÚhasChildNodesr>   r;   rA   r’   r‘   r   r   ÚEMPTY_NAMESPACE)r   r   Úpir   r   r   ÚtestProcessingInstruction  s    






z%MinidomTest.testProcessingInstructionc             C   s   d S )Nr   )r   r   r   r   ÚtestProcessingInstructionRepr$  r   z)MinidomTest.testProcessingInstructionReprc             C   s   d S )Nr   )r   r   r   r   ÚtestTextRepr&  r   zMinidomTest.testTextReprc             C   s   d S )Nr   )r   r   r   r   ÚtestWriteText(  r   zMinidomTest.testWriteTextc             C   s   d S )Nr   )r   r   r   r   ÚtestDocumentElement*  r   zMinidomTest.testDocumentElementc             C   s:   t dƒ}| d¡}|  tjj|j|¡ | ¡  | ¡  d S )Nz<doc/>Zextra)r   r<   r\   r   r   r]   rJ   r,   )r   r   rF   r   r   r   ÚtestTooManyDocumentElements,  s
    
z'MinidomTest.testTooManyDocumentElementsc             C   s   d S )Nr   )r   r   r   r   ÚtestCreateElementNS4  r   zMinidomTest.testCreateElementNSc             C   s   d S )Nr   )r   r   r   r   ÚtestCreateAttributeNS6  r   z!MinidomTest.testCreateAttributeNSc             C   s   d S )Nr   )r   r   r   r   Ú	testParse8  r   zMinidomTest.testParsec             C   s   d S )Nr   )r   r   r   r   ÚtestParseString:  r   zMinidomTest.testParseStringc             C   s   d S )Nr   )r   r   r   r   ÚtestComment<  r   zMinidomTest.testCommentc             C   s   d S )Nr   )r   r   r   r   ÚtestAttrListItem>  r   zMinidomTest.testAttrListItemc             C   s   d S )Nr   )r   r   r   r   ÚtestAttrListItems@  r   zMinidomTest.testAttrListItemsc             C   s   d S )Nr   )r   r   r   r   ÚtestAttrListItemNSB  r   zMinidomTest.testAttrListItemNSc             C   s   d S )Nr   )r   r   r   r   ÚtestAttrListKeysD  r   zMinidomTest.testAttrListKeysc             C   s   d S )Nr   )r   r   r   r   ÚtestAttrListKeysNSF  r   zMinidomTest.testAttrListKeysNSc             C   sP   t dƒ}|j}|j}| d¡}| d¡}|  | |¡¡ |  tj	j
|jd¡ d S )Nz<doc a=''/>rd   )r   r3   r^   ro   ZremoveNamedItemr!   Ú
isSameNoder\   r   r   ry   )r   r   r™   rc   Úa1Úa2r   r   r   ÚtestRemoveNamedItemH  s    

zMinidomTest.testRemoveNamedItemc             C   sV   t dƒ}|j}|j}| dd¡}| dd¡}|  | |¡¡ |  tj	j
|jdd¡ d S )Nz.<doc xmlns:a='http://xml.python.org/' a:b=''/>zhttp://xml.python.org/Úb)r   r3   r^   ÚgetAttributeNodeNSZremoveNamedItemNSr!   rÅ   r\   r   r   ry   )r   r   r™   rc   rÆ   rÇ   r   r   r   ÚtestRemoveNamedItemNSQ  s    z!MinidomTest.testRemoveNamedItemNSc             C   s   d S )Nr   )r   r   r   r   ÚtestAttrListValues[  r   zMinidomTest.testAttrListValuesc             C   s   d S )Nr   )r   r   r   r   ÚtestAttrListLength]  r   zMinidomTest.testAttrListLengthc             C   s   d S )Nr   )r   r   r   r   ÚtestAttrList__getitem___  r   z#MinidomTest.testAttrList__getitem__c             C   s   d S )Nr   )r   r   r   r   ÚtestAttrList__setitem__a  r   z#MinidomTest.testAttrList__setitem__c             C   s   d S )Nr   )r   r   r   r   ÚtestSetAttrValueandNodeValuec  r   z(MinidomTest.testSetAttrValueandNodeValuec             C   s   d S )Nr   )r   r   r   r   ÚtestParseElemente  r   zMinidomTest.testParseElementc             C   s   d S )Nr   )r   r   r   r   ÚtestParseAttributesg  r   zMinidomTest.testParseAttributesc             C   s   d S )Nr   )r   r   r   r   ÚtestParseElementNamespacesi  r   z&MinidomTest.testParseElementNamespacesc             C   s   d S )Nr   )r   r   r   r   ÚtestParseAttributeNamespacesk  r   z(MinidomTest.testParseAttributeNamespacesc             C   s   d S )Nr   )r   r   r   r   ÚtestParseProcessingInstructionsm  r   z+MinidomTest.testParseProcessingInstructionsc             C   s   d S )Nr   )r   r   r   r   ÚtestChildNodeso  r   zMinidomTest.testChildNodesc             C   s   d S )Nr   )r   r   r   r   ÚtestFirstChildq  r   zMinidomTest.testFirstChildc             C   s<   t dƒ}|j}|  | ¡ ¡ t dƒ}|j}|  | ¡ ¡ d S )Nz<doc><foo/></doc>z<doc/>)r   r3   r   r²   r'   )r   r   r   r~   Údoc2r   r   r   ÚtestHasChildNodess  s    zMinidomTest.testHasChildNodesc             C   sÄ   |j }|j }t| ¡ ƒ}t| ¡ ƒ}| ¡  | ¡  |  ||kd¡ xztt|ƒƒD ]j}| |¡}	| |¡}
|  |	|
k	o¤|	j|
jko¤|	j	|
j	ko¤|	j
|
j
ko¤|	j|
jkd¡ |  |
j|kd¡ qRW d S )Nz(clone of element has same attribute keysz3clone of attribute node has proper attribute valuesz'clone of attribute node correctly owned)r^   ÚlistÚkeysÚsortr!   Úranger>   r   ra   rb   r‘   r’   r`   )r   Úe1Úe2r    Zattrs1Zattrs2Zkeys1Zkeys2ÚirÆ   rÇ   r   r   r   Ú!_testCloneElementCopiesAttributes{  s$    


z-MinidomTest._testCloneElementCopiesAttributesc             C   s^   t dƒ}|j}| |¡}|  ||d|r*dp,d ¡ d |_|_| dd¡ | dd	¡ ||fS )
Nz<doc attr='value'><foo/></doc>ZtestCloneElementZDeepZShallowZMODIFIEDÚattrz	NEW VALUEZaddedZVALUE)r   r3   Ú	cloneNoderá   r”   rU   rn   )r   Údeepr   rE   Úcloner   r   r   Ú_setupCloneElement  s    
zMinidomTest._setupCloneElementc             C   sR   |   d¡\}}|  t|jƒdko@|jjdko@|jd ko@| ¡ dkd¡ | ¡  d S )Nr   z<doc attr="value"/>ÚtestCloneElementShallow)ræ   r!   r>   r;   r?   Ú
parentNoderB   r,   )r   r   rå   r   r   r   rç   ›  s    

z#MinidomTest.testCloneElementShallowc             C   sR   |   d¡\}}|  t|jƒdko@|jjdko@|jd ko@| ¡ dkd¡ | ¡  d S )Nr7   z<doc attr="value"><foo/></doc>ÚtestCloneElementDeep)ræ   r!   r>   r;   r?   rè   rB   r,   )r   r   rå   r   r   r   ré   ¤  s    

z MinidomTest.testCloneElementDeepc             C   s&   t dƒ}| d¡}|  |d kd¡ d S )Nz<?xml version='1.0'?>
<!-- comment --><!DOCTYPE doc [
<!NOTATION notation SYSTEM 'http://xml.python.org/'>
]>
<doc attr='value'/>r   zFtestCloneDocumentShallow: shallow cloning of documents makes no sense!)r   rã   r!   )r   r   rØ   r   r   r   ÚtestCloneDocumentShallow­  s    

z$MinidomTest.testCloneDocumentShallowc             C   sÞ   t dƒ}| d¡}|  | |¡p(| |¡ d¡ |  t|jƒt|jƒkd¡ |  |jjtj	kd¡ |  |jj
 |¡d¡ |  |j |j¡ d¡ |jd k	rÚ|  |jjtjkd¡ |  |jj
 |¡¡ |  |j |j¡ ¡ d S )	Nz<?xml version='1.0'?>
<!-- comment --><!DOCTYPE doc [
<!NOTATION notation SYSTEM 'http://xml.python.org/'>
]>
<doc attr='value'/>r7   z4testCloneDocumentDeep: document objects not distinctz8testCloneDocumentDeep: wrong number of Document childrenz:testCloneDocumentDeep: documentElement not an ELEMENT_NODEz@testCloneDocumentDeep: documentElement owner is not new documentz;testCloneDocumentDeep: documentElement should not be sharedz7testCloneDocumentDeep: doctype not a DOCUMENT_TYPE_NODE)r   rã   r!   rÅ   r>   r;   r3   r°   r   ZELEMENT_NODEr   r
   ÚDOCUMENT_TYPE_NODE)r   r   rØ   r   r   r   ÚtestCloneDocumentDeep¹  s"    

z!MinidomTest.testCloneDocumentDeepc             C   sâ  t ƒ }| d¡}|  |d k	o¬|j|jko¬|j|jko¬|j|jko¬|j|jko¬t|jƒt|jƒko¬|j 	t|jƒ¡d ko¬t|j
ƒt|j
ƒko¬|j
 	t|j
ƒ¡d ko¬t|jƒdk¡ x°tt|jƒƒD ]ž}|j 	|¡}|j 	|¡}|  | |¡ oZ| |¡ oZ|j|jkoZ|j|jkoZ|j|jkoZ|j|jkoZ|j|jkoZ|j|jkoZ|j|jk¡ qÀW xztt|j
ƒƒD ]h}|j
 	|¡}|j
 	|¡}|  | |¡ oÔ| |¡ oÔ|j|jkoÔ|j|jkoÔ|j|jk¡ qrW d S )Nr7   r   )r   rã   r!   rU   ÚnameÚpublicIdÚsystemIdr>   r   r   r   r;   rÝ   rÅ   ÚnotationNamer   r   r   )r   r
   rå   rà   ZseZceZsnZcnr   r   r   ÚtestCloneDocumentTypeDeepOkÒ  s@    
z'MinidomTest.testCloneDocumentTypeDeepOkc             C   s&   t ƒ }|j d¡}|  |d kd¡ d S )Nr7   ÚtestCloneDocumentTypeDeepNotOk)r   r
   rã   r!   )r   r   rå   r   r   r   rò   ô  s    z*MinidomTest.testCloneDocumentTypeDeepNotOkc             C   sœ   t ƒ }| d¡}|  |d k	o”|j|jko”|j|jko”|j|jko”|j|jko”t|jƒdko”|j 	d¡d ko”t|j
ƒdko”|j
 	d¡d ko”t|jƒdk¡ d S )Nr   )r   rã   r!   rU   rí   rî   rï   r>   r   r   r   r;   )r   r
   rå   r   r   r   ÚtestCloneDocumentTypeShallowOkù  s    
z*MinidomTest.testCloneDocumentTypeShallowOkc             C   s&   t ƒ }|j d¡}|  |d kd¡ d S )Nr   Ú!testCloneDocumentTypeShallowNotOk)r   r
   rã   r!   )r   r   rå   r   r   r   rô     s    z-MinidomTest.testCloneDocumentTypeShallowNotOkc             C   s*   t dƒ}t dƒ}|  tjj|j||¡ d S )Nz<doc/>)r   r\   r   r   ÚNotSupportedErrÚ
importNode)r   rä   ÚtestNameZdoc1rØ   r   r   r   Úcheck_import_document  s    z!MinidomTest.check_import_documentc             C   s   |   dd¡ d S )Nr   ÚtestImportDocumentShallow)rø   )r   r   r   r   rù     s    z%MinidomTest.testImportDocumentShallowc             C   s   |   dd¡ d S )Nr7   ÚtestImportDocumentDeep)rø   )r   r   r   r   rú     s    z"MinidomTest.testImportDocumentDeepc             C   s(   t ƒ }tƒ }|  tjj|j|jd¡ d S )Nr   )r   r   r\   r   r   rõ   rö   r
   )r   Úsrcr¯   r   r   r   ÚtestImportDocumentTypeShallow  s    z)MinidomTest.testImportDocumentTypeShallowc             C   s(   t ƒ }tƒ }|  tjj|j|jd¡ d S )Nr7   )r   r   r\   r   r   rõ   rö   r
   )r   rû   r¯   r   r   r   ÚtestImportDocumentTypeDeep  s    z&MinidomTest.testImportDocumentTypeDeepc             C   s”   t dƒ}|j d¡}|  |d ¡ | |¡}|  | |¡ ¡ |  | |¡ ¡ |  |jd k|d ¡ |  |j |j¡|d ¡ |  |j	|d ¡ d S )Nz<doc attr='value'/>râ   z: ownerElement should be Nonez: ownerDocument does not matchz.: cloned attribute must have specified == True)
r   r3   ro   ZassertNotEqualrã   r!   rÅ   r`   r   Z	specified)r   rä   r÷   r   râ   rå   r   r   r   Úcheck_clone_attribute%  s    


z!MinidomTest.check_clone_attributec             C   s   |   dd¡ d S )Nr   ÚtestCloneAttributeShallow)rþ   )r   r   r   r   rÿ   3  s    z%MinidomTest.testCloneAttributeShallowc             C   s   |   dd¡ d S )Nr7   ÚtestCloneAttributeDeep)rþ   )r   r   r   r   r   6  s    z"MinidomTest.testCloneAttributeDeepc             C   sJ   t dƒ}|j}|  |jtj¡ | |¡}|  |j|jkoB|j	|j	k¡ d S )Nz<?target data?><doc/>)
r   r@   rŠ   r°   r   r±   rã   r!   r¯   rV   )r   rä   r÷   r   r´   rå   r   r   r   Úcheck_clone_pi9  s    
zMinidomTest.check_clone_pic             C   s   |   dd¡ d S )Nr   ÚtestClonePIShallow)r  )r   r   r   r   r  A  s    zMinidomTest.testClonePIShallowc             C   s   |   dd¡ d S )Nr7   ÚtestClonePIDeep)r  )r   r   r   r   r  D  s    zMinidomTest.testClonePIDeepc       
   	   C   s  t jj d ¡ ¡}G dd„ dƒ}|ƒ }|j}|jd }| dd|¡ |r~|jdd}|  	|j
jjd	¡ t jjj}|jjd }	n:t |d
d ¡ |jdd}W d Q R X t jjj}|jd }	|  	|j|¡ |  	|jd¡ |  	|jd¡ |  |j|¡ |  |j|	¡ d S )Nu  
            <?xml version="1.0" ?>
            <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
                "http://www.w3.org/TR/html4/strict.dtd"
                [ <!ENTITY smile "â˜º"> ]
            >
            <doc>Don't let entities make you frown &smile;</doc>
        c               @   s   e Zd Zdd„ ZdS )z4MinidomTest.check_clone_node_entity.<locals>.Handlerc             S   s"   || _ || _|| _|| _|| _d S )N)Ú	operationÚkeyrV   rû   Údst)r   r  r  rV   rû   r  r   r   r   ÚhandleT  s
    z;MinidomTest.check_clone_node_entity.<locals>.Handler.handleN)Ú__name__Ú
__module__Ú__qualname__r  r   r   r   r   ÚHandlerS  s   r  Zsmiler  rV   T)rä   u%   Don't let entities make you frown â˜ºr   )r   r   r   r   Ústripr
   r   ÚsetUserDatarã   rŠ   r3   r@   r"   ÚUserDataHandlerZNODE_IMPORTEDr   Z	swap_attrZNODE_CLONEDr  r  rV   ZassertIsrû   r  )
r   Zclone_documentZdocumentr  Úhandlerr
   r   rå   r  r  r   r   r   Úcheck_clone_node_entityG  s,    




z#MinidomTest.check_clone_node_entityc             C   s   |   d¡ |   d¡ d S )NFT)r  )r   r   r   r   ÚtestCloneNodeEntityv  s    
zMinidomTest.testCloneNodeEntityc             C   sî   t dƒ}|j}| | d¡¡ | | d¡¡ |  t|jƒdkoJ|jjdkd¡ | ¡  |  t|jƒdkoŒ|jjdkoŒ|j	|j
koŒ|j	jdkd¡ | ¡  t dƒ}|j}| | d	¡¡ | ¡  |  t|jƒd
koÜ|jjd
kd¡ | ¡  d S )Nz<doc/>ÚfirstÚsecondr6   ztestNormalize -- preparationr7   ÚfirstsecondztestNormalize -- resultr‰   r   z*testNormalize -- single empty node removed)r   r3   rJ   rI   r!   r>   r;   r?   Ú	normalizer@   rA   rV   r,   )r   r   rE   r   r   r   ÚtestNormalizez  s,    


zMinidomTest.testNormalizec             C   sâ   t dƒ}|j}| | d¡¡ | | d¡¡ | | d¡¡ |  t|jƒdkoZ|jjdkd¡ | 	¡  |  t|jƒdkoÐ|jjdkoÐ|j
jdkoÐ|j
|jk	oÐ|j
j|jkoÐ|j
jd koÐ|jj|j
koÐ|jjd kd	¡ | ¡  d S )
Nz<doc/>r  r  rà   r8   z1testNormalizeCombineAndNextSibling -- preparationr6   r  z-testNormalizeCombinedAndNextSibling -- result)r   r3   rJ   rI   r<   r!   r>   r;   r?   r  r@   rV   rA   rD   rC   r,   )r   r   rE   r   r   r   Ú"testNormalizeCombineAndNextSibling“  s&    

z.MinidomTest.testNormalizeCombineAndNextSiblingc             C   s¶   t dƒ}|j}| | d¡¡ | | d¡¡ |  t|jƒdkoJ|jjdkd¡ | ¡  |  t|jƒdko¤|jjdko¤|j	j
dko¤|j	|jko¤|j	jd ko¤|j	jd kd¡ | ¡  d S )Nz<doc/>r  r‰   r6   z1testNormalizeDeleteWithPrevSibling -- preparationr7   z,testNormalizeDeleteWithPrevSibling -- result)r   r3   rJ   rI   r!   r>   r;   r?   r  r@   rV   rA   rD   rC   r,   )r   r   rE   r   r   r   Ú"testNormalizeDeleteWithPrevSibling¨  s     

z.MinidomTest.testNormalizeDeleteWithPrevSiblingc             C   s¶   t dƒ}|j}| | d¡¡ | | d¡¡ |  t|jƒdkoJ|jjdkd¡ | ¡  |  t|jƒdko¤|jjdko¤|j	j
dko¤|j	|jko¤|j	jd ko¤|j	jd kd¡ | ¡  d S )Nz<doc/>r‰   r  r6   z1testNormalizeDeleteWithNextSibling -- preparationr7   z,testNormalizeDeleteWithNextSibling -- result)r   r3   rJ   rI   r!   r>   r;   r?   r  r@   rV   rA   rD   rC   r,   )r   r   rE   r   r   r   Ú"testNormalizeDeleteWithNextSiblingº  s     

z.MinidomTest.testNormalizeDeleteWithNextSiblingc             C   sÖ   t dƒ}|j}| | d¡¡ | | d¡¡ | | d¡¡ |  t|jƒdkoZ|jjdkd¡ | 	¡  |  t|jƒdkoÄ|jjdkoÄ|j
|jk	oÄ|j
j|jkoÄ|j
jd koÄ|jj|j
koÄ|jjd kd¡ | ¡  d S )Nz<doc/>rà   r‰   r8   z1testNormalizeDeleteWithTwoSiblings -- preparationr6   z,testNormalizeDeleteWithTwoSiblings -- result)r   r3   rJ   r<   rI   r!   r>   r;   r?   r  r@   rA   rD   rC   r,   )r   r   rE   r   r   r   Ú)testNormalizeDeleteWithTwoNonTextSiblingsÌ  s$    

z5MinidomTest.testNormalizeDeleteWithTwoNonTextSiblingsc             C   sæ   t dƒ}|j}| | d¡¡ | | d¡¡ | | d¡¡ | | d¡¡ | | d¡¡ |  t|jƒdkoz|jjdkd¡ | ¡  |  t|jƒdkoÔ|jjdkoÔ|j	|j
koÔ|j	jdkoÔ|j	jd koÔ|j	jd kd	¡ | ¡  d S )
Nz<doc/>r‰   r  Zfourthé   z,testNormalizeDeleteAndCombine -- preparationr7   Zsecondfourthz'testNormalizeDeleteAndCombine -- result)r   r3   rJ   rI   r!   r>   r;   r?   r  r@   rA   rV   rC   rD   r,   )r   r   rE   r   r   r   ÚtestNormalizeDeleteAndCombineà  s&    

z)MinidomTest.testNormalizeDeleteAndCombinec             C   s6  t dƒ}|j}|jd  | d¡¡ |jd  | d¡¡ |jd jd  | d¡¡ |jd  | d¡¡ | | d¡¡ |  t|jƒdko$|jjdko$t|jd jƒd	ko$|jd jjd	ko$t|jd jƒdko$|jd jjdko$t|jd jd jƒd
ko$|jd jd jjd
kd¡ | ¡  |  t|jƒd
koÚ|jjd
koÚt|jd jƒd
koÚ|jd jjd
koÚt|jd jƒd
koÚ|jd jjd
koÚt|jd jd jƒdkoÚ|jd jd jjdkd¡ |  |jd jd j	dko.|jd jd jd j	dko.|jd jd j	dkd¡ |  |jd jd j
d ko$|jd jd j|jd jd ko$|jd jd jd ko$|jd jd j
|jd jd ko$|jd jd j
d ko$|jd jd j|jd jd ko$|jd jd jd ko$|jd jd j
|jd jd kd¡ | ¡  d S )Nz)<doc><o><i/>t</o><o><o>t2</o>t3</o></doc>r   r‰   Úxr7   Zx2Zx3r8   r:   r6   ztestNormalize2 -- preparationz$testNormalize2 -- childNodes lengthsZtxZt2x2Zt3x3z$testNormalize2 -- joined text fieldsz"testNormalize2 -- sibling pointers)r   r3   r;   rJ   rI   r!   r>   r?   r  rV   rD   rC   r,   )r   r   rE   r   r   r   ÚtestNormalizeRecursionõ  sX    z"MinidomTest.testNormalizeRecursionc             C   s8   t dƒ}|jjd }|  |jtj¡ | ¡  | ¡  d S )Nz<o>text</o>r   )	r   r3   r;   rŠ   r°   r   Ú	TEXT_NODEr  r,   )r   r   r[   r   r   r   ÚtestBug07778844  s
    zMinidomTest.testBug0777884c             C   s>   t dƒ}|j}d|jd _| ¡  |  |jd jd kd¡ d S )Nz<o><i/>t</o>r‰   r7   rS   z)Final child's .nextSibling should be None)r   r3   r;   rb   r  r!   rD   )r   r   r#   r   r   r   ÚtestBug1433694<  s    zMinidomTest.testBug1433694c             C   sj   t dƒ}|j}|j\}}}|  |j|koX|jd koX|j|koX|j|koX|jd koX|j|kd¡ | ¡  d S )Nz<doc><?pi?>text?<elm/></doc>ÚtestSiblings)r   r3   r;   r!   rD   rC   r,   )r   r   rE   r´   r[   Zelmr   r   r   r"  D  s    



zMinidomTest.testSiblingsc             C   sr   t dƒ}|j}|jd }|j\}}|jd }|  |j|ko`|j|ko`|j|ko`|j|ko`|j|kd¡ | ¡  d S )Nz3<doc><elm1><elm2/><elm2><elm3/></elm2></elm1></doc>r   ÚtestParents)r   r3   r;   r!   rè   r,   )r   r   rE   Zelm1Zelm2aZelm2bZelm3r   r   r   r#  R  s    





zMinidomTest.testParentsc             C   sŽ   t dƒ}|j}|d }|  |d | d¡ko|| d¡d ko||j d¡|jd ko||j d¡|jd ko||j d¡j d¡d kd¡ | ¡  d S )Nz<doc><e/><e/></doc>r   r7   ztest NodeList.item())r   r;   r!   r   r,   )r   r   ZchildrenZdocelemr   r   r   ÚtestNodeListItema  s    zMinidomTest.testNodeListItemc             C   s€   t dƒ}|  | ¡ d¡ |  | d¡d¡ |  | d¡d¡ |  | d¡d¡ |  | d	¡d
 d	¡¡ |  tt d¡ | ¡  d S )Nz<foo>&#x20ac;</foo>u$   <?xml version="1.0" ?><foo>â‚¬</foo>zutf-8s4   <?xml version="1.0" encoding="utf-8"?><foo>â‚¬</foo>ziso-8859-15s8   <?xml version="1.0" encoding="iso-8859-15"?><foo>¤</foo>zus-asciis;   <?xml version="1.0" encoding="us-ascii"?><foo>&#8364;</foo>zutf-16u5   <?xml version="1.0" encoding="utf-16"?><foo>â‚¬</foo>s0   <français>Comment ça va ? Très bien ?</français>)r   rŠ   rB   Úencoder\   ÚUnicodeDecodeErrorr,   )r   r   r   r   r   ÚtestEncodingsm  s    
zMinidomTest.testEncodingsc               @   s   e Zd ZdZdd„ ZdS )zMinidomTest.UserDataHandlerr   c             C   s*   |  ||d | ¡ |  |d d ¡ d| _d S )Nr7   )r  Úcalled)r   r  r  rV   rû   r  r   r   r   r  „  s    z"MinidomTest.UserDataHandler.handleN)r  r	  r
  r(  r  r   r   r   r   r  ‚  s   r  c             C   s(  t ƒ }| d¡}|  | d¡d k¡ | dd d ¡ |  | d¡d k¡ | ddd¡ | ddd¡ |  | d¡dk¡ |  | d¡dk¡ | dd d ¡ |  | d¡d k¡ |  | d¡dk¡ |  ¡ }| dd|¡ | d¡}|  |jo| d¡d ko| d¡dk¡ | ¡  | ¡  | ¡  d S )Nr™   rH   é   r9   é   r7   )	r   r<   r!   ZgetUserDatar  r  rã   r(  r,   )r   r   Únr  Úcr   r   r   ÚtestUserData‰  s*    

zMinidomTest.testUserDatac             C   s@   |   tjj|j|dd¡ tdƒ}|   tjj|j|tjjd¡ d S )Nzhttp://xml.python.org/nsz	xmlns:fooz<doc/>rH   )r\   r   r   ÚNamespaceErrÚ
renameNoder   ZWrongDocumentErrr³   )r   r   r#   rØ   r   r   r   Ú checkRenameNodeSharedConstraints¡  s
    z,MinidomTest.checkRenameNodeSharedConstraintsc             C   sb  t dƒ}|j}|j}|jd }| |tjjd¡}|  |jdko¶|j	dko¶|j
d ko¶|jtjjko¶|jd ko¶|jdko¶| d¡d ko¶| d¡ |¡o¶|d  |¡o¶|j |¡o¶|j |¡¡ | |dd¡}|  |jdkov|j	dkov|j
dkov|jdkov|jd kov|jdkov| d¡d kov| d¡d kov| d¡ |¡ov| dd¡ |¡ov|d  |¡ov|d  |¡¡ | |dd	¡}|  |jd	koX|j	d	koX|j
d
koX|jdkoX|jdkoX|jdkoX| d¡d koX| d¡d koX| d¡d koX| dd¡d koX| d	¡ |¡oX| dd
¡ |¡oX|d	  |¡oX|d  |¡¡ | |tjjd¡}|  |jdko.|j	dko.|j
d ko.|jtjjko.|jd ko.|jdko.| d¡d ko.| d¡d ko.| d¡d ko.| d	¡d ko.| dd¡d ko.| d¡ |¡o.|d  |¡¡ |  tjj|j|dd¡ |  ||¡ | ¡  d S )Nz<doc a='v'/>rd   rÉ   Úvzhttp://xml.python.org/nsr,  )zhttp://xml.python.org/nsr,  zhttp://xml.python.org/ns2zp:dr•   Úp)zhttp://xml.python.org/ns2r•   r™   Zxmlns)r   r3   r^   r/  r   r   r³   r!   rí   rU   r’   r‘   r“   ra   ro   rÅ   r   r`   rÊ   r\   r.  r0  r,   )r   r   rF   Zattrmaprâ   r   r   r   ÚtestRenameAttribute©  s„    




zMinidomTest.testRenameAttributec             C   s’  t dƒ}|j}| |tjjd¡}|  |jdkod|jdkod|j	d kod|j
tjjkod|jd kod|j |¡¡ | |dd¡}|  |jdko¶|jdko¶|j	dko¶|j
dko¶|jd ko¶|j |¡¡ | |dd¡}|  |jdko|jdko|j	dko|j
dko|jdko|j |¡¡ | |tjjd	¡}|  |jd	kov|jd	kov|j	d kov|j
tjjkov|jd kov|j |¡¡ |  ||¡ | ¡  d S )
Nz<doc/>rd   zhttp://xml.python.org/nsrÉ   zhttp://xml.python.org/ns2zp:cr,  r2  r•   )r   r3   r/  r   r   r³   r!   r”   rU   r’   r‘   r“   r   rÅ   r0  r,   )r   r   rF   r   r   r   ÚtestRenameElementö  s@    






zMinidomTest.testRenameElementc             C   sL   t jj ¡  t jjdd ¡}| d¡}|  t jj|j	|t jjd¡ | 
¡  d S )Nr™   ÚcommentrH   )r   r   r   r   r	   r³   rT   r\   rõ   r/  r,   )r   r   r#   r   r   r   ÚtestRenameOther!  s    
zMinidomTest.testRenameOtherc             C   s:  t dƒ}|j}|jd }|  |jtj¡ |  |d¡ | | 	d¡¡ |  |d¡ | 
| d¡|¡ |  |d¡ | d¡}| |¡ | 	d	¡}| |¡ |  |d¡ |  |d	¡ | d
¡}| ||¡ |}|  |d¡ |  |d	¡ | dd¡}| ||¡ |}|  |d¡ |  |d	¡ | |¡ |  |d¡ |  |d¡ d S )Nz<doc>a</doc>r   rd   rÉ   Zabr,  Úcabr5  r•   r  ÚyÚzZcabd)r   r3   r;   rŠ   r°   r   r  r&   rJ   rI   r=   ÚcreateCDATASectionrT   r<   rY   ÚcreateProcessingInstructionÚremoveChild)r   r   rF   r[   ÚsplitterÚtext2r  r   r   r   ÚtestWholeText+  s8    






zMinidomTest.testWholeTextc             C   sH   t dƒ}|j}|j}|  |j|kd¡ | ||¡ |  |j|kd¡ d S )Nz<doc><e/></doc>zBefore replaceChild()zAfter replaceChild())r   r3   r@   r!   rè   rY   )r   r   rF   r™   r   r   r   ÚtestPatch1094164O  s    zMinidomTest.testPatch1094164c             C   sÚ   dd„ }|ƒ \}}}}}|  d¡}|  |d¡ |  |d¡ |  t|jƒdk¡ |ƒ \}}}}}|  d¡}|  |d¡ |  |d¡ |  t|jƒdk¡ |ƒ \}}}}}|  d¡}|  |d¡ |  |d koÒt|jƒd	k¡ d S )
Nc              S   sR   t dƒ} | j}|j}|j}|j}| |  d¡|¡ | |  d¡|¡ | ||||fS )Nz<doc>a<e/>d</doc>rÉ   r,  )r   r3   r@   rA   rD   r=   rI   r:  )r   rF   Útext1r>  r=  r   r   r   ÚsetupY  s    z/MinidomTest.testReplaceWholeText.<locals>.setupznew contentr•   r8   r7  r  r‰   r6   )ZreplaceWholeTextr&   r!   r>   r;   )r   rB  r   rF   rA  r=  r>  r[   r   r   r   ÚtestReplaceWholeTextX  s     



z MinidomTest.testReplaceWholeTextc             C   sz   t dƒ}|j}|j}|  |jd ko.|jtjjk¡ d 	¡ }x:|D ]2}| 
|¡}|j}|  t|dƒon|jtjjk¡ q@W d S )Nal  <!DOCTYPE doc [
  <!ENTITY e1 SYSTEM 'http://xml.python.org/e1'>
  <!ENTITY e2 SYSTEM 'http://xml.python.org/e2'>
  <!ATTLIST doc id   ID       #IMPLIED 
                ref  IDREF    #IMPLIED 
                refs IDREFS   #IMPLIED 
                enum (a|b)    #IMPLIED 
                ent  ENTITY   #IMPLIED 
                ents ENTITIES #IMPLIED 
                nm   NMTOKEN  #IMPLIED 
                nms  NMTOKENS #IMPLIED 
                text CDATA    #IMPLIED 
    >
]><doc id='name' notid='name' text='splat!' enum='b'       ref='name' refs='name name' ent='e1' ents='e1 e2'       nm='123' nms='123 abc' />z+id notid text enum ref refs ent ents nm nmsrí   )r   r3   Z
schemaTyper!   rí   Ú	namespacer   r   r³   Úsplitro   Úhasattr)r   r   rF   r%   Únamesrí   rd   r   r   r   ÚtestSchemaTypeu  s    

zMinidomTest.testSchemaTypec             C   s@  t dƒ}|j}| d¡}| d¡}|  | d¡d koB|j oB|j ¡ | d¡ |  | | d¡¡op|jop|j ¡ | d¡ |  | | d¡¡o¬| | d¡¡o¬|jo¬|j¡ | d¡}d|_	| 
|¡ |  | d¡d ko| | d¡¡o|j o|jo|j ¡ | |tjjd¡ |  | | d¡¡o8|j¡ d S )Nz<doc a1='v' a2='w'/>rÆ   rÇ   r1  ÚwÚan)r   r3   ro   r!   ÚgetElementByIdrƒ   r‚   rÅ   ZcreateAttributera   ÚsetAttributeNoder/  r   r   r³   )r   r   r™   rÆ   rÇ   Úa3r   r   r   ÚtestSetIdAttribute–  s6    









zMinidomTest.testSetIdAttributec             C   sr  d}d}t d| d | d ƒ}|j}| |d¡}| |d¡}|  | d¡d ko^|j o^|j ¡ | |d¡ |  | | d¡¡oŽ|joŽ|j ¡ | |d¡ |  | | d¡¡oÌ| | d	¡¡oÌ|joÌ|j¡ | |d¡}d|_	| 
|¡ |  | | d	¡¡¡ |  |j ¡ |  |j¡ |  |j ¡ |  | d¡d k¡ | |tjjd
¡ |  | | d	¡¡oj|j¡ d S )Nzhttp://xml.python.org/ns1zhttp://xml.python.org/ns2z<doc xmlns:ns1='z' xmlns:ns2='z' ns1:a1='v' ns2:a2='w'/>rÆ   rÇ   r1  rI  rJ  )r   r3   rÊ   r!   rK  rƒ   ZsetIdAttributeNSrÅ   ÚcreateAttributeNSra   rL  r/  r   r   r³   )r   ÚNS1ÚNS2r   r™   rÆ   rÇ   rM  r   r   r   ÚtestSetIdAttributeNSµ  s<    


z MinidomTest.testSetIdAttributeNSc             C   sn  d}d}t d| d | d ƒ}|j}| |d¡}| |d¡}|  | d¡d ko^|j o^|j ¡ | |¡ |  | | d¡¡oŒ|joŒ|j ¡ | |¡ |  | | d¡¡oÈ| | d	¡¡oÈ|joÈ|j¡ | |d¡}d|_	| 
|¡ |  | | d	¡¡¡ |  |j ¡ |  |j¡ |  |j ¡ |  | d¡d k¡ | |tjjd
¡ |  | | d	¡¡of|j¡ d S )Nzhttp://xml.python.org/ns1zhttp://xml.python.org/ns2z<doc xmlns:ns1='z' xmlns:ns2='z' ns1:a1='v' ns2:a2='w'/>rÆ   rÇ   r1  rI  rJ  )r   r3   rÊ   r!   rK  rƒ   ZsetIdAttributeNoderÅ   rO  ra   rL  r/  r   r   r³   )r   rP  rQ  r   r™   rÆ   rÇ   rM  r   r   r   ÚtestSetIdAttributeNodeÙ  s<    




z"MinidomTest.testSetIdAttributeNodec             C   s*  ||fg}x|r$|  ¡ \}}|  |j|j¡ |  t|jƒt|jƒ¡ |  |j|j¡ |  | |¡¡ |  | |¡¡ |jtj	kr¼t|j
ƒ t|j
ƒ t|jƒ t|jƒ |  t|j
ƒt|j
ƒ¡ |  t|jƒt|jƒ¡ xltt|jƒƒD ]Z}|j |¡}|j |¡}|  |j|j¡ |  |j|j¡ |  |j|j¡ | ||f¡ qîW xntt|j
ƒƒD ]\}|j
 |¡}	|j
 |¡}
|  |	j|
j¡ |  |	j|
j¡ |  |	j|
j¡ | |	|
f¡ q\W |jtjkrî|  |j |¡¡ |  |j |¡¡ x2tt|jƒƒD ] }| |j| |j| f¡ qþW qW d S )N)ÚpoprŠ   r°   r>   r;   rU   r'   rÅ   r   rë   r   r   rÝ   r   rí   rî   rï   r   rð   ZDOCUMENT_NODEr   r   )r   r   rØ   ÚstackZn1Zn2rà   Zno1Zno2rÞ   rß   r   r   r   Úassert_recursive_equalý  sD    





z"MinidomTest.assert_recursive_equalc             C   sH   t tƒ}x:tdtjd ƒD ]&}t ||¡}t |¡}|  ||¡ qW d S )Nr6   r7   )r   ÚsamplerÝ   ÚpickleZHIGHEST_PROTOCOLÚdumpsÚloadsrV  )r   r   Úprotor$   rØ   r   r   r   ÚtestPickledDocument"  s
    
zMinidomTest.testPickledDocumentc             C   s"   t tƒ}t |¡}|  ||¡ d S )N)r   rW  ÚcopyZdeepcopyrV  )r   r   rØ   r   r   r   ÚtestDeepcopiedDocument)  s    
z"MinidomTest.testDeepcopiedDocumentc             C   s(   t ƒ }| | d¡¡ |  t|j¡ d S )Nzfoo--bar)r   rJ   rT   r\   Ú
ValueErrorrB   )r   r   r   r   r   Ú(testSerializeCommentNodeWithDoubleHyphen.  s    z4MinidomTest.testSerializeCommentNodeWithDoubleHyphenc             C   s,   t dƒ}t | ¡ ƒ}|  |jtjjk¡ d S )Nz$<element xmlns=''>
<foo/>
</element>)r   rB   r!   r‘   r   r   r³   )r   r   rØ   r   r   r   ÚtestEmptyXMLNSValue4  s    zMinidomTest.testEmptyXMLNSValuec          	   C   s$   |   td¡ tdƒ W d Q R X d S )NzUnsupported syntaxzE<element xmlns:abc="http:abc.com/de f g/hi/j k"><abc:foo /></element>)ZassertRaisesRegexr_  r   )r   r   r   r   Ú!testExceptionOnSpacesInXMLNSValue:  s    z-MinidomTest.testExceptionOnSpacesInXMLNSValuec             C   sf   t tƒ}|j d¡d }|  tjj|j|¡ t	|j
ƒ}| |j
d ¡ t	|j
ƒ}|  ||d k¡ d S )NZTITLEr   r7   )r   r+   r3   r2   r\   r   r   ry   r<  r>   r;   r   )r   r   Z	title_tagZnum_children_beforeZnum_children_afterr   r   r   ÚtestDocRemoveChild>  s    

zMinidomTest.testDocRemoveChildc             C   s   t tƒ}| dd¡}d|_d S )Nr8  r9  Zcrash)r   r+   r;  rb   )r   r   r´   r   r   r   Ú"testProcessingInstructionNameErrorG  s    z.MinidomTest.testProcessingInstructionNameErrorN)r   )‰r  r	  r
  r!   r&   r(   r/   r1   r4   rG   rP   rR   rW   rX   rZ   r_   re   rf   rg   rh   rj   rm   rr   rw   rx   rz   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¶   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Ô   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  r  r  r  r  r  r  r  r  r  r   r!  r"  r#  r$  r'  r  r-  r0  r3  r4  r6  r?  r@  rC  rH  rN  rR  rS  rV  r\  r^  r`  ra  rb  rc  rd  r   r   r   r   r   4   s  +		&
		
		"/?M+
$	!$$%	r   Ú__main__)N)r]  rX  r    r   ZunittestZxml.dom.minidomr   r   r   r   r   r   Zfindfiler+   rW  r   r   r   ZTestCaser   r  Úmainr   r   r   r   Ú<module>   s4   
            &