HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.10/test/__pycache__/test_xml_etree.cpython-310.pyc
o

�ii��@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlmZddlmZmZddlmZddlmZddlmZddlmZmZmZmZddlmZdd	lmZdada ed
dd�Z!ze!�"d
�Wne#y�e�$d��weddd�Z%eddd�Z&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dd�dd�Z.dd�Z/Gdd�dej0�Z1dud"d#�Z2d$d%�Z3Gd&d'�d'�Z4Gd(d)�d)ej0�Z5Gd*d+�d+ej0�Z6iZ7d,e7d-<d.e7d/<d0e7d1<d2e7d3<d4e7d5<d6e7d7<d8e7d9<d:e7d;<d<�8e�9e!d ��e7d=<d>e7d?<iZ:d@e:dA<dBe:dC<dDe7dE<dFe7dG<dHe7dI<GdJdK�dKej0�Z;GdLdM�dMej0�Z<GdNdO�dOe4ej0�Z=GdPdQ�dQe4ej0�Z>GdRdS�dSe?�Z@e?jAe@_AGdTdU�dUe?�ZBe?jAeB_AGdVdW�dWe4ej0�ZCGdXdY�dYej0�ZDGdZd[�d[ej0�ZEGd\d]�d]ej0�ZFGd^d_�d_ej0�ZGGd`da�daej0�ZHGdbdc�dcej0�ZIGddde�deej0�ZJGdfdg�dgej0�ZKGdhdi�diej0�ZLGdjdk�dkej0�ZMGdldm�dmej0�ZNdndo�ZOGdpdq�dqej0�ZPdvdrds�ZQeRdtk�r�eQ�dSdS)w�N)�partial)�product�islice)�support)�	os_helper)�warnings_helper)�findfile�
gc_collect�	swap_attr�	swap_item)�import_fresh_module)�TESTFNz
simple.xml�xmltestdata�Zsubdir�utf-8z!filename is not encodable to utf8z
simple-ns.xmlzexpat224_utf8_bug.xmlz�<body>
  <tag class='a'>text</tag>
  <tag class='b' />
  <section>
    <tag class='b' id='inner'>subtext</tag>
  </section>
</body>
zz<section>
  <tag class='b' id='inner'>subtext</tag>
  <nexttag />
  <nextsection>
    <tag />
  </nextsection>
</section>
zy
<body xmlns="http://effbot.org/ns">
  <tag>text</tag>
  <tag />
  <section>
    <tag>subtext</tag>
  </section>
</body>
z�
<root>
<h:table xmlns:h="hello">
  <h:tr>
    <h:td>Apples</h:td>
    <h:td>Bananas</h:td>
  </h:tr>
</h:table>

<f:table xmlns:f="foo">
  <f:name>African Coffee Table</f:name>
  <f:width>80</f:width>
  <f:length>120</f:length>
</f:table>
</root>
zy<!DOCTYPE points [
<!ENTITY % user-entities SYSTEM 'user-entities.xml'>
%user-entities;
]>
<document>&entity;</document>
zl<!DOCTYPE points [
<!ENTITY entity SYSTEM "file:///non-existing-file.xml">
]>
<document>&entity;</document>
z�<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Foo [
<!ELEMENT foo (bar*)>
<!ELEMENT bar (#PCDATA)*>
<!ATTLIST bar xml:lang CDATA "eng">
<!ENTITY qux "quux">
]>
<foo>
<bar>&qux;</bar>
</foo>
F)�quietcs��fdd�}|S)Ncs ���fdd�}t�|��|S)NcsDtj�d�i���|i|��Wd�dS1swYdS)Nr)rZcheck_warnings)�args�kwargs)�filtersr�test��0/usr/local/lib/python3.10/test/test_xml_etree.py�newtest~s"�z1checkwarnings.<locals>.decorator.<locals>.newtest)�	functools�update_wrapper)rr�rr)rr�	decorator}sz checkwarnings.<locals>.decoratorr)rrrrrr�
checkwarnings|srcCs|�dtj���S)N�
)�replace�os�linesep�encode)�datarrr�convlinesep��r$c@�eZdZdd�Zdd�ZdS)�
ModuleTestcCs(ddlm}ddlm}ddlm}dS)Nr)�ElementTree��ElementInclude��ElementPath)�	xml.etreer(r*r,)�selfr(r*r,rrr�test_sanity�szModuleTest.test_sanitycCsd}tj|t|dd�dS)N)�xml.etree.ElementTree�_elementtree)Z
HTML_EMPTY)Znot_exported)rZcheck__all__�ET)r.�namesrrr�test_all�szModuleTest.test_allN)�__name__�
__module__�__qualname__r/r4rrrrr'�sr'T�unicodecKsT|dkr	t��}nt��}t�|�}|j|fd|i|��|r#|��S|�d�|S)Nr8�encodingr)�io�BytesIO�StringIOr2r(�write�getvalue�seek)�elem�	to_stringr9�options�file�treerrr�	serialize�s


rEcCsdd�|D�S)NcS�g|]}|j�qSr��tag��.0r@rrr�
<listcomp>��z"summarize_list.<locals>.<listcomp>r)�seqrrr�summarize_list��rNc@s(eZdZedd��Zdd�Zdd�ZdS)�ElementTestCasecCstth|_dS�N)�pyETr2�modules)�clsrrr�
setUpClass��zElementTestCase.setUpClassc
Cs�z>ttj||��t�||�}Wd�n1swYttj||��t�|�}Wd�W|S1s7wYW|Stjyh}zttdft	dfg�}	t
�d||	�||�|	�||�f�|�d}~ww)NZcETrRz%Failed to round-trip %r from %r to %r)
r�sysrS�pickle�dumps�loads�
PicklingError�dictr2rRrZ
TestFailed�get)
r.�obj�name�dumper�loader�protoZtemp�result�peZhumanrrr�pickleRoundTrip�s,��	�	�

�����zElementTestCase.pickleRoundTripcCs�|�|tjtjf�|�|tjtjf�|�tt|��tt|���t||�D]
\}}|�||�q't	�
dddd�}|�||�||��dS)NrH�tail�text�attrib)�assertIsInstancer2�ElementrR�assertEqual�len�list�zip�assertEqualElements�operator�
attrgetter)r.Zalice�bob�x�yZ
propertiesrrrro�sz#ElementTestCase.assertEqualElementsN)r5r6r7�classmethodrUrerorrrrrP�s

rPc@steZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Z d=d>�Z!d?d@�Z"dAdB�Z#dCdD�Z$dEdF�Z%dGdH�Z&dIdJ�Z'dKdL�Z(dMdN�Z)dOdP�Z*dQdR�Z+dSdT�Z,dUdV�Z-dWdX�Z.dYdZ�Z/d[S)\�ElementTreeTestcCs|�t|�|�dSrQ)rkrE)r.r@�expectedrrr�serialize_check��zElementTreeTest.serialize_checkcsv��fdd��t�d�}�|�t�|�}�|���tjddd�}t�|�}��t|�d�tjddd�}�fdd	���|j��|j��|j��|j	��|j
��|j��|j��|j
��|j��|j��|j��|j��|j��|j��|j��fd
d�}||�d��||�d��||�d��||�d����tjtj���tjtj�dS)
Ncs��jt�|�dd�t|�}dD]}�jt||�d|d��j||d|d�q��|jt���|j	t
�|jdurC��|jt�|jdurO��|jt�|D]}�|�qQdS)Nznot an element��msg)rHrhrgrfzno %s memberzno %s visible by dir)
�
assertTruer2Z	iselement�dir�hasattr�assertInrirH�strrhr\rgrf)�elementZdirelem�attrr@)�
check_elementr.rrr��s$��


�z5ElementTreeTest.test_interface.<locals>.check_elementrH�täg�value��keyz^<Element 't\xe4g' at 0x.*>$cs�jt|d�d|d�dS)N�__call__z%s not callablerz)r|r~��method�r.rr�check_method�s
�z4ElementTreeTest.test_interface.<locals>.check_methodcs�|j�dSrQ)�__next__)�it)r�rr�
check_iterrOz2ElementTreeTest.test_interface.<locals>.check_iter�*)r2rjr(�getroot�assertRegex�repr�append�extend�insert�remove�find�iterfind�findall�findtext�clearr]�set�keys�items�iter�itertextrk�XML�
fromstring�PI�ProcessingInstruction)r.r�rDr�r)r�r�r.r�test_interface�s@

















zElementTreeTest.test_interfacecCs�t�d�}|�|jd�d|_|�|jd�d|_|�|jd�|�|j�d|_|�|jd�d|_|�|jd�|�|j�d|_|�|jd�d|_|�|jd�|�|ji�dd	d
�|_|�|jdd	d
��ddd
�|_|�|jddd
��dS)NrH�TagZTAG�TextZTEXTZTailZTAIL�b�d)�a�c�B�D)�A�C)r2rjrkrH�assertIsNonergrfrh)r.r�rrr�test_set_attributes*
z"ElementTreeTest.test_set_attributecCst�d�}|�|d�t�d�}|�|�|�|d�|�|�|�|d�|�d|�|�|d�|�|�|�|g�|�|d�|�|�|�t|g��|�|d�|�|�tjddd	�}|�|d
�t�d�}|�|�|�|d�|�d|�|�|d
�|�|�|�|d�|�|�|�|d
�|�	t
��
}|�|�Wd�n1s�wY|�t|j
�d�|�|d
�|||g|dd�<|�|dd�|�|dd�|d|dg�|�|ddd�|d|dg�|dd�=|�|d
�dS)N�<body><tag/></body>�<body><tag /></body>�tag2z<body><tag /><tag2 /></body>rz<body><tag2 /><tag /></body>rHr�r�z<tag key="value" />�subtagz!<tag key="value"><subtag /></tag>z+<tag key="value"><subtag /><subtag /></tag>zlist.remove(x): x not in list�z
<subtag />�	�)r2r�rxrjr�r�r�r�r��assertRaises�
ValueErrorrkr��	exception)r.r@�er�Z
subelement�cmrrr�test_simpleops*sT








�

� "
�zElementTreeTest.test_simpleopscCs:|�t�d�d�|�t�d�d�|�t�d�d�dS)Nz<tag>hello</tag>z)<tag>&#104;&#101;&#108;&#108;&#111;</tag>z<tag><![CDATA[hello]]></tag>)rxr2r�r�rrr�
test_cdataVs���zElementTreeTest.test_cdatacCs|t�t�d��}tj|d�}|�|�d�jd�|�|�d�jd�tjt	d�}|�|�d�jd�|�|�d�jd�dS)Nr)rCrH�section/tagr�zelement/../empty-element�
empty-element)
r:r;�
SAMPLE_XMLr"r2r(rkr�rH�SIMPLE_XMLFILE)r.Z
stringfilerDrrr�test_file_init`s�zElementTreeTest.test_file_initcCs�ddlm}t�t�}td�D]}t�|��dt|��qt	|j
�}td�D]}t�|��dt|��q'|�t	|j
�|�td�D]}t�|��dt|��qC|�t	|j
�|�td�D]}t�|��dt|��q_|�
t	|j
�d�dS)Nrr+�
z./�iXi�)r-r,r2r�r��ranger(r�r�rl�_cacherkZ
assertGreaterZ
assertLess)r.r,r@�iZcache_len_10rrr�test_path_cacheks
&
&&&zElementTreeTest.test_path_cachecCsZddl}t�d�}|�|�}|�|�}d|�d�_|�|d�|�|d�|�|d�dS)Nrz<tag>hello<foo/></tag>�bar�fooz<tag>hello<bar /></tag>z<tag>hello<foo /></tag>)�copyr2r��deepcopyr�rHrx)r.r��e1�e2�e3rrr�	test_copyzs


zElementTreeTest.test_copycCs&t�d�}|�d�|�|�dd�d�|�dd�|�|�d�d�tjddd�}|�|�d�d�|�|jddi�ddi}t�d|�}|��|�|�d�d�|�|jddi�ddi}tjdi|��}|��|�|�d�d�|�|jddi�tjdddidd�}|�|�d�d�|�|jddi�t�d�}d|_|�d	d
�|�dd�|�t�|�d
�|�t	|�
��d	dg�|�t	|���ddg�|�|jdd�d|jd<d|jd<|�t�|�d�t�d�}|�dd�|�dd�|�dd�|�dd�|�t�|�d�dS)NrHr��defaultr�r��otherrZaa�testa�testval�testb�test2s-<test testa="testval" testb="test2">aa</test>)r�r�)r�r�Ztest1Ztestcs;<test testa="testval" testb="test1" testc="test2">aa</test>r��
r��
r�z	

 r�z



		  s[<test a="&#13;" b="&#13;&#10;" c="&#09;&#10;&#13; " d="&#10;&#10;&#13;&#13;&#09;&#09;  " />rG)r2rjr]rkr�rhr�rg�tostring�sortedr�r�)r.r@rhrrr�test_attrib�s\


��

�
�zElementTreeTest.test_attribcCs�t�d�}ddi}|�d|�}|j|j|dd�|�|�|�|d�|��|�|d�|�|�|�|d�|�||g�|�|d	�|g|dd�<|�|d�t	|g�|dd�<|�|d�dS)
NrHr�r�r�zattrib aliasingrzz!<tag><subtag key="value" /></tag>�<tag />zM<tag><subtag key="value" /><subtag key="value" /><subtag key="value" /></tag>)
r2rjZmakeelement�assertIsNotrhr�rxr�r��tuple)r.r@rh�subelemrrr�test_makeelement�s$


�z ElementTreeTest.test_makeelementcCs�t�t�}t��}|j|dd�|�|��d�t�t�}t��}|j|dd�|�|��d�t	t��}|�
�}Wd�n1sCwYt��}|�|j
d�|�|�|�|��d�t��}tj|d�}|�|�|�|��d�dS)Nr8�r9zi<root>
   <element key="value">text</element>
   <element>text</element>tail
   <empty-element />
</root>z�<ns0:root xmlns:ns0="namespace">
   <ns0:element key="value">text</ns0:element>
   <ns0:element>text</ns0:element>tail
   <ns0:empty-element />
</ns0:root>z^Expat ��target)r2�parser�r:r<r=rkr>�SIMPLE_NS_XMLFILE�open�read�	XMLParserr��version�feedrx�close�TreeBuilder)r.rD�stream�fr#�parserr�rrr�test_parsefile�s6

�

�

�

�

�zElementTreeTest.test_parsefilecCs�t�d�}|�tj|dd�d�t�d�}|�tj|dd�d�gd�}t�|�}|�t�|�d�|�d�t�|��d�|�t�|d�d�t�d�\}}|�t	|�d	�t�d
�\}}|�t	|�d�|�|dj
d�dS)
N�<html><body>text</body></html>r8r�)z<html><body>ztext</boz
dy></html>�<html><body>text</body></html>��asciisE<?xml version='1.0' encoding='ascii'?>
<html><body>text</body></html>rz(<html><body id='body'>text</body></html>r��body)r2r�rkr�r�Zfromstringlist�join�tostringlistZXMLIDrlrH)r.r�Zsequence�_Zidsrrr�test_parseliteral�s0
�
�
���z!ElementTreeTest.test_parseliteralc	Cs4tj}|t�}t|�\}}|�||jfd�|�dd�|D�gd��|�|jjd�|t�}|�dd�|D�gd��d}|t|�}|�d	d�|D�g�d}|t|d
�}|�dd�|D�g�d}|t|�}|�d
d�|D�gd��d}|t|�}|�dd�|D�gd��d}|t�	d�|�}dd�|D�}|�|ddg�d}t
td��(}|�t��
}|||�Wd�n1s�wY|�
|j�Wd�n1s�wY|�t|j�d�t�|��,|�t��
}|t|�Wd�n1s�wY|�t|j�d�~Wd�n	1�swYt�d�}	d}||	|�}|�dd�|D�ddg�t�	d�}	||	�}
t|
�\}}|�||jfd �|�tj��}t|
�Wd�n	1�scwY|�t|j�d!�|�tjt�t
td"��
}|�d#�Wd�n	1�s�wY|t�}
t|
�\}}|�||jfd �t�|��.|�tj��}t|
�Wd�n	1�s�wY|�t|j�d!�~~
Wd�n	1�s�wYt�|��
|t�}
~
Wd�n	1�s�wY|�t��
|d$�Wd�dS1�swYdS)%N��endr�cS�g|]	\}}||jf�qSrrG�rJ�actionr@rrrrK�z2ElementTreeTest.test_iterparse.<locals>.<listcomp>)r��r�r��r��rootrcSr�rrGrrrrrK%r)�r��{namespace}elementr�r��{namespace}empty-element�r��{namespace}rootrcSr�rrGrrrrrK.r��eventscSr�rrGrrrrrK2r��startr�cSr�rrGrrrrrK6r��rr�rr�r�rr�)rr�rr)rr��start-ns�end-nscSs*g|]\}}|dvr||jfn||f�qS)rrGrrrrrKCs
��)
�r)��	namespace�rr�rrrrr�rr	rr
�rN�rrz<root xmlns=''/>cSsg|]\}}|�qSrrrrrrrKTsrr�rr�Zbogus�rbzunknown event 'bogus's�<?xml version='1.0' encoding='iso-8859-1'?>
<body xmlns='http://&#233;ffbot.org/ns'
      xmlns:cl�='http://effbot.org/ns'>text</body>
)rcSsg|]\}}||f�qSrrrrrrrKjs)r)ruhttp://éffbot.org/ns)r)uclé�http://effbot.org/nsz<document />junk)r��documentz.junk after document element: line 1, column 12�wbs<document />junkZnonexistent)r2�	iterparser��nextrkrHrr�r:r<r�r�r��assertFalse�closedr�r�rZcheck_no_resource_warningr;�
ParseError�
addCleanupr�unlinkr
r=�FileNotFoundError)r.r"�contextrr@r
�resr�r��sourcer�rrr�test_iterparses�



�������
�

���
����
$�zElementTreeTest.test_iterparsecCs�t�d�}d|_|�|d�dt�|d�_|�|d�d|_|�|d�|�dt�d	��|�|d
�t�dd�|d<|�|d
�dS)NrHrgz<tag>text</tag>�subtextr�z'<tag>text<subtag>subtext</subtag></tag>ztext<subtag>subtext</subtag>r�commentz*text<!--comment--><subtag>subtext</subtag>r�r�z)text<?key value?><subtag>subtext</subtag>)	r2rjrgrx�
SubElementrHr��Commentr��r.r@rrr�test_writefile�s
�zElementTreeTest.test_writefilecCs�tt��}|��}Wd�n1swYGdd�dt�}|�}tj|d�}|�|�|�|gd��tt��}|��}Wd�n1sIwYGdd�dt�}|�}tj|d�}|�|�|�|gd��dS)Nc@�$eZdZdd�Zdd�Zdd�ZdS)�4ElementTreeTest.test_custom_builder.<locals>.BuildercS�|�d|f�dS�Nr�r��r.rHrhrrrr�r%�:ElementTreeTest.test_custom_builder.<locals>.Builder.startcSr6�Nr�r8�r.rHrrrr��r%�8ElementTreeTest.test_custom_builder.<locals>.Builder.endcS�dSrQr�r.rgrrrr#���9ElementTreeTest.test_custom_builder.<locals>.Builder.dataN)r5r6r7rr�r#rrrr�Builder��rBr�rc@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)r5cSr6r7r8r9rrrr�r%r:cSr6r;r8r<rrrr��r%r=cSr>rQrr?rrrr#�r@rAcS�|�d||f�dS)N�pir8)r.r�r#rrrrE�ryz7ElementTreeTest.test_custom_builder.<locals>.Builder.picSr6)Nr/r8)r.r#rrrr/�r%z<ElementTreeTest.test_custom_builder.<locals>.Builder.commentcSrD)Nrr8)r.�prefix�urirrr�start_ns�ryz=ElementTreeTest.test_custom_builder.<locals>.Builder.start_nscSr6�Nrr8�r.rFrrr�end_ns�r%z;ElementTreeTest.test_custom_builder.<locals>.Builder.end_nsN)
r5r6r7rr�r#rEr/rHrKrrrrrB�s))rErEr#)r/�	 comment )rrrrrrrrrrr
�rr)	r�r�r�rmr2r�r�rkr�)r.r�r#rB�builderr�rrr�test_custom_builder�s 

�


�
z#ElementTreeTest.test_custom_buildercCsFGdd�dt�}|�}tj|d�}|�t�d��|�|gd��dS)Nc@�eZdZdd�ZdS)z@ElementTreeTest.test_custom_builder_only_end_ns.<locals>.BuildercSr6rIr8rJrrrrK�r%zGElementTreeTest.test_custom_builder_only_end_ns.<locals>.Builder.end_nsN)r5r6r7rKrrrrrB��rBr�a            <?pi data?>
            <!-- comment -->
            <root xmlns='namespace' xmlns:p='pns' xmlns:a='ans'>
               <a:element key='value'>text</a:element>
               <p:element>text</p:element>tail
               <empty-element/>
            </root>
            ))rr�)r�prM)rmr2r�r��textwrap�dedentrk)r.rBrNr�rrr�test_custom_builder_only_end_ns�s
	z/ElementTreeTest.test_custom_builder_only_end_nscCs8tjdd�}|�|jtj�t��}|�|jtj�dS)Nr�)r2r�rir�r�)r.r��parser2rrr�%test_initialize_parser_without_target�sz5ElementTreeTest.test_initialize_parser_without_targetcCs|ttd��
}t�|�}Wd�n1swY|�dd�|����D�gd�gggg�|�dd�|��D�gd�gggg�t�t�}|�t	t
|��d�|�t	t
|d��d�|�|dd�t
|��|d	}|d}|dd�=|�t	t
|��d�|�||d	�|�||d�||g|d	d�<|�||d	�|�||d�|�||d	�|��|�t
|�g�dS)
NrcS�g|]}t|��qSr�rNrIrrrrK���z1ElementTreeTest.test_children.<locals>.<listcomp>)r�r�r�cSrXrrYrIrrrrKrZ�r�r�r)
r�r�r2r�rkr�r�r�r�rlrm�assertNotEqualr�)r.r�rDr@�child1�child2rrr�
test_children�sJ�

���
���

zElementTreeTest.test_childrencCs<t�d�}|�t�|�d�t�d�}|�t�|�d�dS)Nr�r�)r2r�rkr�r�r2rrr�test_writestrings

z ElementTreeTest.test_writestringcCs�t�d�}t�|�|�t�|�d�t�d�}t�|�|�t�|�d�t�d�}t�|�|�t�|�d�t�d�}t�|�|�t�|�d�t�d�}t�|�|�t�|�d	�t�d
�}t�|�|�t�|�d�dS)Nz
<root></root>s<root />r�s"<html>
  <body>text</body>
</html>z!<html> <body>text</body>  </html>z"<html><body>text</body>tail</html>s%<html>
  <body>text</body>tail</html>z=<html><body><p>par</p>
<p>text</p>	<p><br/></p></body></html>s^<html>
  <body>
    <p>par</p>
    <p>text</p>
    <p>
      <br />
    </p>
  </body>
</html>�8<html><body><p>pre<br/>post</p><p>text</p></body></html>sJ<html>
  <body>
    <p>pre<br />post</p>
    <p>text</p>
  </body>
</html>�r2r��indentrkr�r2rrr�test_indent%s0









�

�zElementTreeTest.test_indentcCsXt�d�}tj|dd�|�t�|�d�t�d�}tj|dd�|�t�|�d�dS)Nra�	)�spacesD<html>
	<body>
		<p>pre<br />post</p>
		<p>text</p>
	</body>
</html>rs><html>
<body>
<p>pre<br />post</p>
<p>text</p>
</body>
</html>rbr2rrr�test_indent_spaceQs
�

�z!ElementTreeTest.test_indent_spacecCs�t�d�}t�|�|�dd�|��D�hd��|�dd�|��D�hd��|�tdd�|��D��tdd�|��D���dS)	Nz@<html><body><p>par</p><p>text</p><p><br/></p><p /></body></html>cS�h|]}|j�qSr�rf�rJ�elrrr�	<setcomp>nrLz<ElementTreeTest.test_indent_space_caching.<locals>.<setcomp>>�
  N�
�
    cSrhr�rgrjrrrrlrrL>rgz
      ZparNrmrocSrhrrirjrrrrlvrLcSsh|]}t|j��qSr)�idrfrjrrrrlws)r2r�rcrkr�rlr2rrr�test_indent_space_cachingjs

���z)ElementTreeTest.test_indent_space_cachingcCs�t�d�}|�t��tj|dd�Wd�n1swY|�t�|�d�tj|dd�|�t�|�d�t�d�}tj|ddd	�|�t�|�d
�dS)Nra���)�levels9<html><body><p>pre<br />post</p><p>text</p></body></html>r�s^<html>
      <body>
        <p>pre<br />post</p>
        <p>text</p>
      </body>
    </html>r�� )rtrfsI<html>
  <body>
   <p>pre<br />post</p>
   <p>text</p>
  </body>
 </html>)r2r�r�r�rcrkr�r2rrr�test_indent_levelzs&
���

�z!ElementTreeTest.test_indent_levelcCs<t�d�}|�tj|dd�d�|�tj|ddd�d�dS)N�0<body xmlns="http://effbot.org/ns"><tag/></body>r8r��A<ns0:body xmlns:ns0="http://effbot.org/ns"><ns0:tag /></ns0:body>r�r9�default_namespace�1<body xmlns="http://effbot.org/ns"><tag /></body>�r2r�rkr�r2rrr�test_tostring_default_namespace�s
��z/ElementTreeTest.test_tostring_default_namespacecC�&t�d�}|�tj|ddd�d�dS)Nrwr8�foobarryzP<ns1:body xmlns="foobar" xmlns:ns1="http://effbot.org/ns"><ns1:tag /></ns1:body>r|r2rrr�3test_tostring_default_namespace_different_namespace��

�zCElementTreeTest.test_tostring_default_namespace_different_namespacecCsPt�d�}d}|�t|��tj|ddd�Wd�dS1s!wYdS)Nr�z>^cannot use non-qualified names with default_namespace option$r8rry)r2r��assertRaisesRegexr�r�)r.r@ZEXPECTED_MSGrrr�5test_tostring_default_namespace_original_no_namespace�s

"�zEElementTreeTest.test_tostring_default_namespace_original_no_namespacecCs$t�d�}|�tj|dd�d�dS)Nr�r8r�r�r|r2rrr� test_tostring_no_xml_declaration�s

�z0ElementTreeTest.test_tostring_no_xml_declarationcCr~)Nr��utf8T�r9�xml_declarations:<?xml version='1.0' encoding='utf8'?>
<body><tag /></body>r|r2rrr�test_tostring_xml_declaration�r�z-ElementTreeTest.test_tostring_xml_declarationcCr~)Nr�r8Tr��;<?xml version='1.0' encoding='utf-8'?>
<body><tag /></body>r|r2rrr�.test_tostring_xml_declaration_unicode_encoding�r�z>ElementTreeTest.test_tostring_xml_declaration_unicode_encodingc	Cstt�d�}gd�}|D],\}}}|�d|�d|����|�tj|||d�|�Wd�n1s2wYqdS)N�<body><tag>ø</tag></body>))�<body><tag>&#248;</tag></body>NN)�<body><tag>ø</tag></body>�UTF-8N)r��US-ASCIIN)�E<?xml version='1.0' encoding='ISO-8859-1'?>
<body><tag>�</tag></body>�
ISO-8859-1N)r�r8N)r�NF)r�r�F)r�r�F)s<body><tag>�</tag></body>r�F)r�r8F)sH<?xml version='1.0' encoding='us-ascii'?>
<body><tag>&#248;</tag></body>NT)sA<?xml version='1.0' encoding='UTF-8'?>
<body><tag>ø</tag></body>r�T)sH<?xml version='1.0' encoding='US-ASCII'?>
<body><tag>&#248;</tag></body>r�T)r�r�T)uA<?xml version='1.0' encoding='utf-8'?>
<body><tag>ø</tag></body>r8Tz	encoding=z xml_declaration=r�)r2r��subTestrkr�)r.r@Z	TESTCASESZexpected_retvalr9r�rrr�#test_tostring_xml_declaration_cases�s"

������z3ElementTreeTest.test_tostring_xml_declaration_casesc	CsHt�d�}|�d�tj|dd��d�|�d�tj|ddd��d�dS)	Nrwrr8r�rxrryr{)r2r�rkr�r�r2rrr�#test_tostringlist_default_namespace�s
��z3ElementTreeTest.test_tostringlist_default_namespacecCs�t�d�}|�d�tj|dd��d�|�d�tj|dd��d	�tj|ddd
�}|�d�|�d�|�|dd
�|�gd�|dd��dS)Nr�rr8r�r�r�T)r�s><?xml version='1.0' encoding='us-ascii'?>
<body><tag /></body>r�r�rz%^<\?xml version='1.0' encoding='.+'?>)z<body�>z<tagz />z</body>r�)r2r�rkr�r�r�)r.r@Z
stringlistrrr�!test_tostringlist_xml_declaration�s 
���z1ElementTreeTest.test_tostringlist_xml_declarationc	sd�fdd�	}|dd�|dd�|dd�|d	d
�|dd�|d
d�dd���fdd�}gd�}|D]}��t�t�||���d�q5gd�}|D]}��ttj||��qLgd�}|D]
}��tjtj||��q_��ttj�d��d����ttj�d��d��dS)Nrcs>d||f}��t�|�|��j|���t�|�j|�dS)Nz0<?xml version='1.0' encoding='%s'?><xml>%s</xml>)rkr2r�r"rg)r9r��xmlr�rr�checks
�z,ElementTreeTest.test_encoding.<locals>.checkr�r��us-ascii�
iso-8859-1�½ziso-8859-15u€�cp437u√�	mac-romanu˚cSsd|S)Nz*<?xml version='1.0' encoding='%s'?><xml />rr�rrrr��z*ElementTreeTest.test_encoding.<locals>.xmlcs�|��|�SrQ)r"r�)r�rr�bxml rOz+ElementTreeTest.test_encoding.<locals>.bxml)Cr�rz	utf-8-sig�utf-16�utf-16be�utf-16lez	iso8859-1z	iso8859-2z	iso8859-3z	iso8859-4z	iso8859-5z	iso8859-6z	iso8859-7z	iso8859-8z	iso8859-9z
iso8859-10z
iso8859-13z
iso8859-14z
iso8859-15z
iso8859-16r�Zcp720Zcp737�cp775�cp850�cp852�cp855Zcp856�cp857�cp858�cp860�cp861�cp862�cp863�cp865�cp866�cp869Zcp874Zcp1006�cp1125�cp1250�cp1251�cp1252�cp1253�cp1254�cp1255�cp1256�cp1257�cp1258zmac-cyrillicz	mac-greekzmac-icelandz
mac-latin2r�zmac-turkishz
iso2022-jpziso2022-jp-1ziso2022-jp-2ziso2022-jp-2004ziso2022-jp-3ziso2022-jp-extzkoi8-rzkoi8-tzkoi8-u�kz1048�hz�ptcp154s<xml />)�big5�	big5hkscs�cp932�cp949�cp950zeuc-jpzeuc-jis-2004zeuc-jisx0213zeuc-kr�gb2312�gbk�gb18030z
iso2022-kr�johabz	shift-jiszshift-jis-2004zshift-jisx0213zutf-7)
�cp037�cp424�cp500�cp864Zcp875�cp1026�cp1140�utf_32�	utf_32_be�	utf_32_leZ	undefinedZxxx)r)	rkr2r�r�r�r�r&r"�LookupError)r.r�r�Zsupported_encodingsr9Z&unsupported_ascii_compatible_encodingsZ(unsupported_ascii_incompatible_encodingsr�r.r�r�
test_encodings(





	zElementTreeTest.test_encodingcCstt�d�}d|_|�t|�d�|�t|dd�d�|�t|dd�d�|�t|dd�d�|�t|dd�d	�dS)
Nz-<html><link/><script>1 &lt; 2</script></html>rnz/<html><link /><script>1 &lt; 2</script></html>
r�r��htmlz*<html><link><script>1 < 2</script></html>
rgz1 < 2
)r2r�rfrkrE�r.r�rrr�test_methodsLs

����zElementTreeTest.test_methodscCs2t�d�}|�t|�d�|�t|dd�d�dS)Nz(<html><CamelCase>text</CamelCase></html>r�r��r2r�rkrEr�rrr�test_issue18347[s

��zElementTreeTest.test_issue18347cCs6t�d�}|�t|dd�d�|�|d�|�tj��
}t�d�Wd�n1s+wY|�t|j�d�|�tj��
}t�t	�Wd�n1sOwY|�t|j�d�t�
�}d	|jd
<|�t	�|�
�}|�|d�|�tj��
}t�t�Wd�n1s�wY|�t|j�d�dS)
Nz*<document title='&#x8230;'>test</document>r�r�s*<document title="&#33328;">test</document>u%<document title="舰">test</document>z<document>&entity;</document>z#undefined entity: line 1, column 10z,undefined entity &entity;: line 5, column 10rg�entityz<document>text</document>z,undefined entity &entity;: line 4, column 10)r2r�rkrErxr�r&r�r��
ENTITY_XMLr�r�r�r��EXTERNAL_ENTITY_XML)r.r�r�r�rrrr�test_entitybs8
�����

��zElementTreeTest.test_entitycCsrt�d�}|�|d�t�d�}|�|d�t�d�}|�|d�t�d�}|�|d�t�t�}|�|d	�dS)
Nz<tag xml:lang='en' />z<tag xml:lang="en" />zC<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' />zC<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" />z7<html:html xmlns:html='http://www.w3.org/1999/xhtml' />z7<html:html xmlns:html="http://www.w3.org/1999/xhtml" />zG<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope' />zE<ns0:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope" />z�<ns0:body xmlns:ns0="http://effbot.org/ns">
  <ns0:tag>text</ns0:tag>
  <ns0:tag />
  <ns0:section>
    <ns0:tag>subtext</ns0:tag>
  </ns0:section>
</ns0:body>)r2r�rx�
SAMPLE_XML_NSr2rrr�test_namespace�s$

�
�
�
�zElementTreeTest.test_namespacecCs�t�d�}|�|d�t�t�d��}|�|d�t�t�dd��}|�|d�t�t�dd��}t�|t�dd��}t�|t�dd��}|�|d�|��d|jd	<|�|d
�|��d|jt�d	�<|�|d
�|��d|jd	<|�|d�|��t�d�|jd	<|�|d
�|��t�d�}t�d�|jd<|�|�|�|�|�|d�|�t	t�dd��d�|�t	t�d��d�t�dd�}t�dd�}|�||�t�dd�}|�
||�|�
|d�|�|d�dS)Nz{uri}tagz<ns0:tag xmlns:ns0="uri" />rGrHZtag1r�z;<ns0:tag xmlns:ns0="uri"><ns0:tag1 /><ns0:tag2 /></ns0:tag>r�z{uri}keyz+<ns0:tag xmlns:ns0="uri" ns0:key="value" />z
{uri}valuez0<ns0:tag xmlns:ns0="uri" ns0:key="{uri}value" />z/<ns0:tag xmlns:ns0="uri" ns0:key="ns0:value" />z{uri2}valuez	{uri1}keyz{<ns0:tag xmlns:ns0="uri" xmlns:ns1="uri1" xmlns:ns2="uri2"><tag ns1:key="ns2:value" /><tag ns1:key="ns2:value" /></ns0:tag>�nsz{ns}tagz	other-tagzns:tag)r2rjrx�QNamer0r�rhr�rkr�r\)r.r@r�Zq1Zq2rrr�
test_qname�sb
�
��
��


�zElementTreeTest.test_qnamecCst�d�}dS)Nz�<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>text</html>)r2r�r2rrr�test_doctype_public�sz#ElementTreeTest.test_doctype_publiccs�ddlm�d?��fdd�	}|ddg�|dddg�|d	d
dg�|dd
dg�|d
gd��|dgd��|dgd��|dgd��|dgd��|dddg�|dgd��|ddg�|dgd��|ddg�|d gd!��|d"gd#��|d$gd%��|d&d
d'g�|d(d(g�|d)gd*��|d+gd,��|d-d-g�|d.d.g�|d/d/g�|d0d0g�|d1gd2��|d3gd4�d5d6i�|d7d8gd9d6i�|d:d
d8gd5d6i�|d;d
d7gd9d6i�|d<d
d=gd9d6i�|d&d
d'gd6d6d>��dS)@Nrr+cs"��dd���||�D�|�dS)NcSsg|]\}}|p	|�qSrr)rJ�oprHrrrrK�s�zGElementTreeTest.test_xpath_tokenizer.<locals>.check.<locals>.<listcomp>)rkZxpath_tokenizer)rRrw�
namespaces�r,r.rrr��s


��z3ElementTreeTest.test_xpath_tokenizer.<locals>.checkr�ztext()rg�()z@name�@r_z@*zpara[1])�para�[�1�]zpara[last()])r�r�Zlastr�r�z*/para)r��/r�z/doc/chapter[5]/section[2])r��docr��chapterr��5r�r��sectionr��2r�z
chapter//para)r��//r�z//parar�r�z//olist/item)r�Zolistr��item�.z.//para)r�r�r��..z../@lang)r�r�r��langzchapter[title])r�r��titler�z#employee[@secretary and @assistant])
Zemployeer�r�Z	secretaryr�andrr�Z	assistantr�z	@{ns}attrz{ns}attr�{http://spam}eggz
./spam.egg)r�r�zspam.eggz.//{http://spam}egg)r�r�r�z{ns}*�{}*�{*}tag�{*}*z	.//{*}tag)r�r�r�z
./xsd:type)r�r��&{http://www.w3.org/2001/XMLSchema}typeZxsdz http://www.w3.org/2001/XMLSchema�typer�rz	@xsd:typez@typez@{*}typez{*}type)rr�rQ)r-r,)r.r�rr�r�test_xpath_tokenizer�sd�
��
�
�
�
��z$ElementTreeTest.test_xpath_tokenizercCsn|�t�t�dd��d�|�t�t�dd��d�|�t�t�dd��d�|�t�t�dd�d�d�dS)	NrZinstructions<?test instruction?>z
<testing&>s<?test <testing&>?>u<testing&>ãzlatin-1s=<?xml version='1.0' encoding='latin-1'?>
<?test <testing&>�?>)rkr2r�r�r�r�rrr�test_processinginstruction+s����z*ElementTreeTest.test_processinginstructioncCspdD]3}||��fD]*}d|}tt�d|�dd�}|�||�tt�d||f�dd�}|�||�q
qdS)N)
ZAREAZBASEZBASEFONTZBRZCOL�FRAMEZHRZIMGZINPUTZISINDEXZLINKZMETAZPARAMz<%s>z<%s />r�r�z	<%s></%s>)�lowerrEr2r�rk)r.r�r@rwZ
serializedrrr�#test_html_empty_elems_serialization;s���z3ElementTreeTest.test_html_empty_elems_serializationcCsVtjdddd�}t���
}t�|�Wd�n1swY|�|��d�dS)N�
cirriculum�public�example��statusZcompanyz1<cirriculum status="public" company="example" />
)r2rjr�captured_stdout�dumprkr>)r.r��stdoutrrr�test_dump_attribute_orderHs
�
�z)ElementTreeTest.test_dump_attribute_ordercCs8tjdddd�}|�t|�d�|�t|dd�d�dS)	Nrrrrz0<cirriculum status="public" company="example" />r�r�z;<cirriculum status="public" company="example"></cirriculum>)r2rjrkrE�r.rrrr�test_tree_write_attribute_orderPs
��z/ElementTreeTest.test_tree_write_attribute_ordercCs$t�t�}|�|djddi�dS)Nrz*{http://www.w3.org/XML/1998/namespace}langZeng)r2r��ATTLIST_XMLrkrhrrrr�test_attlist_defaultXs
�z$ElementTreeTest.test_attlist_defaultN)0r5r6r7rxr�r�r�r�r�r�r�r�r�r�r�r-r3rOrUrWr_r`rdrgrrrvr}r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr
rrrrrrrv�s\C,
6-x=	%, ,;%!A:
rvc@s�eZdZd+dd�Zd,dd�Zd,dd�Zd,d	d
�Zd+dd�Zd
d�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�ZdS)-�XMLPullParserTestNFcCsT|dur
|�|�ntdt|�|�D]
}|�||||��q|r(|��dSdS�Nr)r�r�rl�flush)r.r�r#�
chunk_sizerr�rrr�_feedas�zXMLPullParserTest._feedcCs$|�dd�t|��|�D�|�dS)NcSs g|]\}}||j|jff�qSr)rHrg)rJ�eventr@rrrrKls�z3XMLPullParserTest.assert_events.<locals>.<listcomp>)rkr�read_events�r.r�rw�
max_eventsrrr�
assert_eventsjs��zXMLPullParserTest.assert_eventscCs|�tt|��|��|�dSrQ)rkrmrrrrrr�assert_event_tuplesps�z%XMLPullParserTest.assert_event_tuplescCs(t|��|�}|�dd�|D�|�dS)NcSr�rrGrrrrrKwrz7XMLPullParserTest.assert_event_tags.<locals>.<listcomp>)rrrk)r.r�rwrr
rrr�assert_event_tagsus�z#XMLPullParserTest.assert_event_tagscCs�t��}|�|g�|�|d||�|�|g�|�|d||�|�|g�|�|d||�|�|dg�|�|d||�|�|d||�|�|ddg�|�|d||�|�|d	g�|�|���dS)
N�<!-- comment -->
z+<root>
  <element key='value'>text</element�>
r��<element>text</element>tail
�<empty-element/>
r�</root>
r�r2�
XMLPullParserrrr�r�)r.rrr�rrr�test_simple_xmlzs(��z!XMLPullParserTest.test_simple_xmlcC�|jddd�dS)Nr�T�rr�r"r�rrr�test_simple_xml_chunk_1�r%z)XMLPullParserTest.test_simple_xml_chunk_1cCr#)N�Tr$r%r�rrr�test_simple_xml_chunk_5�r%z)XMLPullParserTest.test_simple_xml_chunk_5cCs|jdd�dS)N�)rr%r�rrr�test_simple_xml_chunk_22��z*XMLPullParserTest.test_simple_xml_chunk_22cCs�t��}|��}|�|d�t|�\}}|�||jfd�|�|d�t|�\}}|�||jfd�|�t��
t|�Wd�dS1sGwYdS)Nz-<root>
  <element key='value'>text</element>
r�rr)	r2r!rrr#rkrHr��
StopIteration)r.r�r�rr@rrr�test_feed_while_iterating�s
"�z+XMLPullParserTest.test_feed_while_iteratingcCs�t��}|�|g�|�|d�|�|g�|�|d�|�|g�|�|d�|�|g�|�|d�|�|dg�|�|d�|�|d�|�|ddg�|�|d	�|�|d
g�|�|���dS)Nr�<root xmlns='namespace'>
�"<element key='value'>text</elementrrrrrrr
r �r.r�rrr�test_simple_xml_with_ns�s&�z)XMLPullParserTest.test_simple_xml_with_nscCs�tjdd�}|�|d�|�|d�|�t|���dg�|�|d�|�|d�|�|d�|�|d	�|�|d
�|�t|���dg�|�|���dS)Nrrrr.rr/rrrrr)r2r!rrkrmrr�r�r0rrr�test_ns_events�s
�z XMLPullParserTest.test_ns_eventscCs�tjdd�}|�|d�|j|ddgdd�|j|dgd	d�|�|d
�|�|ddg�|�|d
�|��|�|dg�dS)N)rrr�r� <tag xmlns='abc' xmlns:p='xyz'>
�r)r�abc�r)rRZxyzr��r�r�{abc}tagr��
<child />
�r�
{abc}child�r�r<�</tag>
�r�r9�r2r!rrrr�r0rrr�test_ns_events_start�s.�����
�z&XMLPullParserTest.test_ns_events_startcCs�tjdd�}|�|d�|j|ddgdd�|j|dgd	d�|�|d
�|�|ddg�|�|d
�|��|j|dgd	d�|�|ddg�dS)N)rrr�rrr3r4r6r�r7r8r�r:r;r=r>r?rr@r0rrr�test_ns_events_start_end�s:�������
�z*XMLPullParserTest.test_ns_events_start_endcCs�tjdd�}|�|d�|�|g�tjdd�}|�|d�|�|g�tjdd�}|�|d�|�|dg�|�|d�|�|d	g�|�|d
�|�|dg�|�|d�|�|gd
��|�|d�|�|���|�|dg�tjdd�}|�|d�|�|g�|�|d�|�|dg�|�|d�|�|d	g�|�|d
�|�|g�|�|d�|�|ddg�|�|d�|�|���dS)Nrrz<root/>
r�<!-- text here -->
z<root>
rr/rrr�z8<element xmlns='foo'>text<empty-element/></element>tail
)�r�{foo}element�r�{foo}empty-element)r�rG)r�rEz</root>r)rrrDrF)r2r!rrrr�r�r0rrr�test_events�sL���zXMLPullParserTest.test_eventscCstjdd�}|�|d�|�|dtjdffg�|�|d�|�|dtjdffg�|�|d�|�|d	g�|�|d
�|�|dtjdffg�|�|d�|�|d
g�|�|d�|�|dtjdffg�tjdd�}|�|d�|�|dtjdffg�dS)N)rr/r�rrCr/z text here z<!-- more text here -->
z more text here z<root-tag>text)r�root-tagz<!-- inner comment-->
z inner commentz</root-tag>
)r�rIz<!-- outer comment -->
z outer comment )r/)r2r!rrr1rr0rrr�test_events_comment(s z%XMLPullParserTest.test_events_commentcCsdtjdd�}|�|d�|�|dtjdffg�tjdd�}|�|d�|�|dtjdffg�dS)	N)rrEr�rz
<?pitarget?>
rE�pitarget)rEz<?pitarget some text ?>
zpitarget some text )r2r!rrr�r0rrr�test_events_pi;sz XMLPullParserTest.test_events_picCslddh}tj|d�}|�|d�|�|ddg�Gdd�d�}tj|�d�}|�|d�|�|ddg�dS)	Nr�rrz<foo>bar</foo>)rr�)r�r�c@r4)z9XMLPullParserTest.test_events_sequence.<locals>.DummyItercSstgd��|_dS)N)rr�r)r�r
r�rrr�__init__Kr%zBXMLPullParserTest.test_events_sequence.<locals>.DummyIter.__init__cSs|SrQrr�rrr�__iter__Mr@zBXMLPullParserTest.test_events_sequence.<locals>.DummyIter.__iter__cSs
t|j�SrQ)r#r
r�rrrr�O�
zBXMLPullParserTest.test_events_sequence.<locals>.DummyIter.__next__N)r5r6r7rMrNr�rrrr�	DummyIterJrCrP)r2r!rr)r.Zeventsetr�rPrrr�test_events_sequenceCsz&XMLPullParserTest.test_events_sequencecCs<|�t��tjdd�Wd�dS1swYdS)Nrr)r�r�r2r!r�rrr�test_unknown_eventVs"�z$XMLPullParserTest.test_unknown_eventcCs�tjdkr|�dtj�d��tjdd�}dD]}|�|�q|�|g�ttur2|�|j	j	�
��|��|�|dg�tturJ|�|j	j	�
��|�d�|��|�|d	g�dS)
N�r��rzExpat z" does not support reparse deferralrr�z<docr��rr��</doc>�r�r�)
�pyexpat�version_info�skipTestr2r!r�rrRr|�_parser�GetReparseDeferralEnabledrr��r.r��chunkrrr�#test_flush_reparse_deferral_enabledZs

z5XMLPullParserTest.test_flush_reparse_deferral_enabledcCs�tjdd�}dD]}|�|�qtjdkr%ttur|�d�|jj�d�|�	|g�ttur8|�
|jj���|��|�	|dg�tturP|�
|jj���|�d�|�
�|�	|d	g�dS)
NrrrUrSzDXMLParser.(Get|Set)ReparseDeferralEnabled methods not available in CFrVrWrX)r2r!r�rYrZrRr[r\ZSetReparseDeferralEnabledrr$r]rr�r^rrr�$test_flush_reparse_deferral_disabledss"


z6XMLPullParserTest.test_flush_reparse_deferral_disabled�NFrQ)r5r6r7rrrrr"r&r(r*r-r1r2rArBrHrJrLrQrRr`rarrrrr_s*

	


.rz�<?xml version='1.0'?>
<document xmlns:xi="http://www.w3.org/2001/XInclude">
  <p>120 Mz is adequate for an average home user.</p>
  <xi:include href="disclaimer.xml"/>
</document>
�C1.xmlz�<?xml version='1.0'?>
<disclaimer>
  <p>The opinions represented herein represent those of the individual
  and should not be interpreted as official policy endorsed by this
  organization.</p>
</disclaimer>
zdisclaimer.xmlz�<?xml version='1.0'?>
<document xmlns:xi="http://www.w3.org/2001/XInclude">
  <p>This document has been accessed
  <xi:include href="count.txt" parse="text"/> times.</p>
</document>
�C2.xmlZ324387z	count.txtz�<?xml version='1.0'?>
<document xmlns:xi="http://www.w3.org/2001/XInclude">
  <p>This document has been <em>accessed</em>
  <xi:include href="count.txt" parse="text"/> times.</p>
</document>
�C2b.xmlz�<?xml version='1.0'?>
<document xmlns:xi="http://www.w3.org/2001/XInclude">
  <p>The following is the source of the "data.xml" resource:</p>
  <example><xi:include href="data.xml" parse="text"/></example>
</document>
�C3.xmlzQ<?xml version='1.0'?>
<data>
  <item><![CDATA[Brooks & Shields]]></item>
</data>
zdata.xmlaW<?xml version='1.0'?>
<div xmlns:xi="http://www.w3.org/2001/XInclude">
  <xi:include href="example.txt" parse="text">
    <xi:fallback>
      <xi:include href="fallback-example.txt" parse="text">
        <xi:fallback><a href="mailto:bob@example.org">Report error</a></xi:fallback>
      </xi:include>
    </xi:fallback>
  </xi:include>
</div>
�C5.xmlz�<?xml version='1.0'?>
<document xmlns:xi="http://www.w3.org/2001/XInclude">
  <p>Example.</p>
  <xi:include href="{}"/>
</document>
�default.xmla
<?xml version='1.0'?>
<document xmlns:xi="http://www.w3.org/2001/XInclude">
  <p>The following is the source code of Recursive1.xml:</p>
  <xi:include href="C1.xml"/>
  <xi:include href="C1.xml"/>
  <xi:include href="C1.xml"/>
  <xi:include href="C1.xml"/>
</document>
�include_c1_repeated.xmlz�<?xml version='1.0'?>
<document xmlns:xi="http://www.w3.org/2001/XInclude">
  <p>120 Mz is adequate for an average home user.</p>
  <xi:include href="disclaimer.xml" parse="BAD_TYPE"/>
</document>
�B1.xmlzn<?xml version='1.0'?>
<div xmlns:xi="http://www.w3.org/2001/XInclude">
    <xi:fallback></xi:fallback>
</div>
�B2.xmlz�<?xml version='1.0'?>
<document xmlns:xi="http://www.w3.org/2001/XInclude">
  <p>The following is the source code of Recursive2.xml:</p>
  <xi:include href="Recursive2.xml"/>
</document>
�Recursive1.xmlz�<?xml version='1.0'?>
<document xmlns:xi="http://www.w3.org/2001/XInclude">
  <p>The following is the source code of Recursive3.xml:</p>
  <xi:include href="Recursive3.xml"/>
</document>
zRecursive2.xmlz�<?xml version='1.0'?>
<document xmlns:xi="http://www.w3.org/2001/XInclude">
  <p>The following is the source code of Recursive1.xml:</p>
  <xi:include href="Recursive1.xml"/>
</document>
zRecursive3.xmlc@sHeZdZddd�Zddd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dS)�XIncludeTestr�NcCs:zt|}Wntytd��w|dkrt�|�}|S)N�resource not foundr�)�XINCLUDE�KeyError�OSErrorr2r�)r.�hrefr�r9r#rrr�xinclude_loaders�
zXIncludeTest.xinclude_loadercCr>rQr)r.rrr�r9rrr�none_loaderr@zXIncludeTest.none_loadercCsH|dkr"t|d��}t�|���Wd�S1swYdSdS)Nr�r)r�r2r�r�)r.rrr�r�rrr�
_my_loader s
$�zXIncludeTest._my_loadercCs8ddlm}|�d�}|�||j�|�t|�d�dS)Nrr)rhz�<document>
  <p>Example.</p>
  <root>
   <element key="value">text</element>
   <element>text</element>tail
   <empty-element />
</root>
</document>)r-r*rs�includerurkrE)r.r*r�rrr�test_xinclude_default)s

�z"XIncludeTest.test_xinclude_defaultcCsddlm}|�d�}|�||j�|�t|�d�|�d�}|�||j�|�t|�d�|�d�}|�||j�|�t|�d�|�d	�}|�||j�|�t|�d
�|�d�}|�t��}|�||j�Wd�n1srwY|�t|j	�d�|�t|�d
�dS)Nrr)rca<document>
  <p>120 Mz is adequate for an average home user.</p>
  <disclaimer>
  <p>The opinions represented herein represent those of the individual
  and should not be interpreted as official policy endorsed by this
  organization.</p>
</disclaimer>
</document>rdzO<document>
  <p>This document has been accessed
  324387 times.</p>
</document>rezX<document>
  <p>This document has been <em>accessed</em>
  324387 times.</p>
</document>rfz�<document>
  <p>The following is the source of the "data.xml" resource:</p>
  <example>&lt;?xml version='1.0'?&gt;
&lt;data&gt;
  &lt;item&gt;&lt;![CDATA[Brooks &amp; Shields]]&gt;&lt;/item&gt;
&lt;/data&gt;
</example>
</document>rgrnaI<div xmlns:ns0="http://www.w3.org/2001/XInclude">
  <ns0:include href="example.txt" parse="text">
    <ns0:fallback>
      <ns0:include href="fallback-example.txt" parse="text">
        <ns0:fallback><a href="mailto:bob@example.org">Report error</a></ns0:fallback>
      </ns0:include>
    </ns0:fallback>
  </ns0:include>
</div>)
r-r*rsrvrkrEr�rqr�r��r.r*r r�rrr�
test_xinclude7s:

�

�

�

�
�
�zXIncludeTest.test_xincludecCs>ddlm}|�d�}|�||j�|�dt|�d���dS)Nrr)rir�z.//p)r-r*rsrvrkrlr�)r.r*r rrr�test_xinclude_repeatedws
z#XIncludeTest.test_xinclude_repeatedcCs�ddlm}t�td�}|�|j��}|j||jd�Wd�n1s&wY|�	t
|j�d�t�td�}|�|j��}|j||jd�Wd�n1sTwY|�	t
|j�d�t�td�}|�|j��}|j||jd�Wd�n1s�wY|�	t
|j�d	�t�td
�}|�|j��}|j||jd�Wd�n1s�wY|�	t
|j�d�|�
d�}|�|j��}|�||j
�Wd�n1s�wY|�	t
|j�d
�|�
d�}|�|j��}|j||j
dd�Wd�n	1�s	wY|�	t
|j�d
�|�
d�}|�|j��}|j||j
dd�Wd�n	1�s7wY|�	t
|j�d�|�
d�}|�|j��}|j||j
dd�Wd�n	1�sewY|�	t
|j�d�|�
d�}|�|j��}|j||j
dd�Wd�n	1�s�wY|�	t
|j�d�|�
d�}|�|j��}|j||j
dd�Wd�n	1�s�wY|�	t
|j�d
�dS)Nrr)rc)raz%cannot load 'disclaimer.xml' as 'xml'rdz!cannot load 'count.txt' as 'text'rjz1unknown parse type in xi:include tag ('BAD_TYPE')rkzYxi:fallback tag must be child of xi:include ('{http://www.w3.org/2001/XInclude}fallback')rlz#recursive include of Recursive2.xml)Z	max_depthzAmaximum xinclude depth reached when including file Recursive2.xmlr�zAmaximum xinclude depth reached when including file Recursive3.xmlr�zAmaximum xinclude depth reached when including file Recursive1.xmlr[)r-r*r2r�ror�ZFatalIncludeErrorrvrtrkr�r��XINCLUDE_BADrsZLimitedRecursiveIncludeErrorrxrrr�test_xinclude_failures~s���������
��
��
��
��
��
��z#XIncludeTest.test_xinclude_failures)r�NrQ)
r5r6r7rsrtrurwryrzr|rrrrrms

		@rmc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Ze�
e��d�dd��Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Z d6d7�Z!d8d9�Z"d:S);�BugsTestcs��fdd�}t�d�}||�t�d�}d|_||�t�d�}d|_||�t�d�}|�dd�||�t�d�}|�dd�||�dS)NcsH��t��}t|�Wd�n1swY��t|j�d�dS)Nzcannot serialize 123 (type int))r��	TypeErrorrErkr�r�)r@r�r�rrr��s
��z-BugsTest.test_bug_xmltoolkit21.<locals>.check�{r@Z123)r2rjrgrfr�)r.r�r@rr�r�test_bug_xmltoolkit21�s




zBugsTest.test_bug_xmltoolkit21cCs<t�t�}t�|�}|�|�d�d�|�|�d�d�dS)NrHrgr�r.)r2r�r�r(rkr�)r.r@rDrrr�test_bug_xmltoolkit25�s

zBugsTest.test_bug_xmltoolkit25cCs<t�d�}|�t|�d��g�|�t|�d��dg�dS)N�"<doc><table><tbody/></table></doc>z.//theadz.//tbodyZtbody)r2r�rkrNr��r.rDrrr�test_bug_xmltoolkit28�s
zBugsTest.test_bug_xmltoolkit28cCsRt�d�}t���}t�|�|�|��d�Wd�dS1s"wYdS)Nr�z$<doc><table><tbody /></table></doc>
)r2r�rrrrkr>)r.rDr	rrr�test_bug_xmltoolkitX1�s



"�zBugsTest.test_bug_xmltoolkitX1cCs�t�d�}|�t�|d�d�t�d�}|�|jddi�|�t�|d�d�t�d�}|�t�|d�d	�t�d
�}|�t�|d�d�t�d�}|�dd�|�t�|d�d�dS)Ns2<?xml version='1.0' encoding='iso-8859-1'?><t�g />rs<täg />sD<?xml version='1.0' encoding='iso-8859-1'?><tag �ttr='v&#228;lue' />uättruvälues<tag ättr="välue" />s:<?xml version='1.0' encoding='iso-8859-1'?><t�g>text</t�g>s<täg>text</täg>r�rH)r2r�rkr�rhrjr�r�rrr�test_bug_xmltoolkit39�s$

�
�

�zBugsTest.test_bug_xmltoolkit39cCs2t�d�}|�t|dd�d�|�t|�d�dS)Nz=<!DOCTYPE doc [<!ENTITY ldots '&#x8230;'>]><doc>&ldots;</doc>r�r�s<doc>&#33328;</doc>u<doc>舰</doc>r�r�rrr�test_bug_xmltoolkit54s

�zBugsTest.test_bug_xmltoolkit54cCsL|�tj��
}t�d�Wd�n1swY|�t|j�d�dS)Ns?<!DOCTYPE doc SYSTEM 'doc.dtd'><doc>&ldots;&ndots;&rdots;</doc>z+undefined entity &ldots;: line 1, column 36)r�r2r&r�rkr�r�)r.r�rrr�test_bug_xmltoolkit55s��zBugsTest.test_bug_xmltoolkit55cCs$Gdd�d�}|�ttj|��dS)Nc@rP)z5BugsTest.test_bug_xmltoolkit60.<locals>.ExceptionFilecSst�rQ)rq�r.rsrrrr�,r@z:BugsTest.test_bug_xmltoolkit60.<locals>.ExceptionFile.readN)r5r6r7r�rrrr�
ExceptionFile+rQr�)r�rqr2r�)r.r�rrr�test_bug_xmltoolkit60(szBugsTest.test_bug_xmltoolkit60cCsHddd�}t��}|j�|�|�d�|��}|�|�d�jd�dS)Nu’u‘)ZrsquoZlsquoaF<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE patent-application-publication SYSTEM "pap-v15-2001-01-31.dtd" []>
<patent-application-publication>
<subdoc-abstract>
<paragraph id="A-0001" lvl="0">A new cultivar of Begonia plant named &lsquo;BCT9801BEG&rsquo;.</paragraph>
</subdoc-abstract>
</patent-application-publication>z.//paragraphu7A new cultivar of Begonia plant named ‘BCT9801BEG’.)	r2r�r��updater�r�rkr�rg)r.ZENTITIESr��trrr�test_bug_xmltoolkit621s

�zBugsTest.test_bug_xmltoolkit62zSkips under coverage.cCsBdd�}|�t�d�}td�D]}|�q|�t�d�|�dS)NcSs,t��}|�di�|�d�|�d�dS)NrHrg)r2r�rr#r�)rDrrr�xmltoolkit63Es
z4BugsTest.test_bug_xmltoolkit63.<locals>.xmltoolkit63i�)rW�getrefcountr�rk)r.r��countr�rrr�test_bug_xmltoolkit63Bs
zBugsTest.test_bug_xmltoolkit63c	Cs`tjddd�}|�t�|�d�|�t�t�|���d�d�|�t�t�t�|���d�dS)NZSomeTagzdef _f():
  return 3
rps0<SomeTag text="def _f():&#10;  return 3&#10;" />rg)r2rjrkr�r�r]r�rrr�test_bug_200708_newlineQs���z BugsTest.test_bug_200708_newlinecCs`t��}|�d�|�|��jd�Gdd�d�}tj|�d�}|�d�|�|��jd�dS)Nz<element>some text</element>r�c@rP)z2BugsTest.test_bug_200708_close.<locals>.EchoTargetcSs
t�d�S)Nr��r2rjr�rrrr�drOz8BugsTest.test_bug_200708_close.<locals>.EchoTarget.closeN�r5r6r7r�rrrr�
EchoTargetcrQr�r�)r2r�r�rkr�rH)r.r�r�rrr�test_bug_200708_close\s

zBugsTest.test_bug_200708_closecCs�t�d�}t�|d�}|�t|dd�d�t�d�}t�|d�}t�|d�}|�t|dd�d�t�d�}t�|d�}t�|d�}|�t��}t|dd�Wd�n1sWwY|�t|j�d�dS)	Nz
{default}elemr�)rzz%<elem xmlns="default"><elem /></elem>z{not-default}elemzI<elem xmlns="default" xmlns:ns1="not-default"><elem /><ns1:elem /></elem>r@z<cannot use non-qualified names with default_namespace option)	r2rjr0rkrEr�r�r�r�)r.r��sr�rrr�!test_bug_200709_default_namespacejs(
�
�
��z*BugsTest.test_bug_200709_default_namespacecCsdt�d�}|�t�|�d�t�dd�t�d�}|�t�|�d�t�d�}|�t�|�d�dS)Nz/{http://namespace.invalid/does/not/exist/}titlesB<ns0:title xmlns:ns0="http://namespace.invalid/does/not/exist/" />r�z(http://namespace.invalid/does/not/exist/sB<foo:title xmlns:foo="http://namespace.invalid/does/not/exist/" />z'{http://purl.org/dc/elements/1.1/}titles8<dc:title xmlns:dc="http://purl.org/dc/elements/1.1/" />)r2rjrkr��register_namespacer�rrr�"test_bug_200709_register_namespace�s
�
�
�z+BugsTest.test_bug_200709_register_namespacecCs`t�d�}|�t�d��|�|djtj�t�d�}|�t�d��|�|djtj�dS)Nr�r�r)r2rjr�r1rkrHr�)r.r�rrr�test_bug_200709_element_comment�s

z(BugsTest.test_bug_200709_element_commentcCspt�d�}t�|d�}t�|d�}t�d�}|�d|�|�t|�gd��|�d|�|�t|�gd��dS)	Nr�r�r�r�r)r�r�r�rs)r�r�r�r�)r2rjr0r�rkrN�r.r�r�r�r�rrr�test_bug_200709_element_insert�s

z'BugsTest.test_bug_200709_element_insertcCsJt�d�}t�|d�}t�d�}|�|�|�t|�tj��tjg�dS)Nr�r�zTEST-b)r2rjr0r1r�rkrNr�)r.r�r�Z	comment_brrr�test_bug_200709_iter_comment�s



 z%BugsTest.test_bug_200709_iter_commentcCsDt��}|�d�}|�di�}|�d�}|��}|�t|�d�dS)Nr#rHr�)r2r�r#rr�r�rkrE)r.rrr�rrr�test_bug_1534630�s

zBugsTest.test_bug_1534630cCs@t�d�}|�t�|d�d�t�d�}|�t�|d�d�dS)Ns7<?xml version='1.0' encoding='utf-8'?><body>tãg</body>r�s<<?xml version='1.0' encoding='ascii'?>
<body>t&#227;g</body>s;<?xml version='1.0' encoding='iso-8859-1'?><body>t�g</body>r|r�rrr�test_issue6233�s
�
�zBugsTest.test_issue6233cCsRt�d�}|�t|�dg�t�t�}|dd�|dd�<|�t|�gd��dS)Nr�rH�rHrHr�)r2r�rkrNr�)r.r@Znewelemrrr�test_issue6565�s


zBugsTest.test_issue6565cCst�dd�t�dd�dS)NZ	test10777z
http://myuri/)r2r�r�rrr�test_issue10777�szBugsTest.test_issue10777cs`G�fdd�d�}t�d��|��_���}t|�}|�||�|��jt�|��jd�dS)Nc�eZdZ�fdd�ZdS)z%BugsTest.test_lost_text.<locals>.Textcs
d�_dS)N�changedTrpr��r�rr�__bool__�sz.BugsTest.test_lost_text.<locals>.Text.__bool__N�r5r6r7r�rr�rrr���r�rHr�)r2rjrgr�r#rir�rk�r.r�r�r�rr�r�test_lost_text�s
zBugsTest.test_lost_textcs|G�fdd�d�}t�d����t�d��|��d_���}t|�}|�||�|��djt�|��djd�dS)Ncr�)z%BugsTest.test_lost_tail.<locals>.Textcsd�d_dS�Nr�rTrir�r�rrr���
z.BugsTest.test_lost_tail.<locals>.Text.__bool__Nr�rr�rrr��r�r�rrHrr�)	r2rjr�rfr�r#rir�rkr�rr�r�test_lost_tail�s
zBugsTest.test_lost_tailcs�G��fdd�d�}t�d����t�|�����t�d����d��zt��}Wnty9|�d�Ynw|�|j|�|��djt	�|�
�djd�dS)NcseZdZ��fdd�ZdS)z$BugsTest.test_lost_elem.<locals>.Tagcst�d��d<t��dSr�)r2rjr#)r.r��r�r�rr�__eq__�sz+BugsTest.test_lost_elem.<locals>.Tag.__eq__N�r5r6r7r�rr�rrr��sr�rrHzgenerators are not reentrantrr�)r2rjr�r�r#r�r[rirHr�rk)r.r�r�rr�r�test_lost_elem�s

�zBugsTest.test_lost_elemcCs.d|}t�|�}|�|�d�|�d��dS)Ns<a b="%s"/>r�r)r2r�rkr]�decode)r.rgr�rrrr�check_expat224_utf8_bug	s
z BugsTest.check_expat224_utf8_bugcCs d}|�|�d}|�|�dS)Nsààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààsxàààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààààà)r�r?rrr�test_expat224_utf8_bug
	s
zBugsTest.test_expat224_utf8_bugcCs�ttd��}|��}Wd�n1swYt�|�}|�d�}|�d���}|�dd�}|dd�}|�	|�d�|�dS)Nrr�rr�rurT���)
r��UTF8_BUG_XMLFILEr�r2r�r]r��striprrk)r.�fp�rawrZxmlattrrgrrr�test_expat224_utf8_bug_file	s
�

z$BugsTest.test_expat224_utf8_bug_filecCs.|�tt��jd�|�tt��jdd�dS)NrH)r�r~r2r�rr�rrr�test_39495_treebuilder_start#	sz%BugsTest.test_39495_treebuilder_startN)#r5r6r7r�r�r�r�r�r�r�r�r��unittestZskipIfrW�gettracer�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr}�s<			



r}c@�\eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�BasicElementTestcCs�d}ddi}t�||�}|�|tj�|�dt|��|�dt|��|�dt|��|�dt|��|�|j|�|�|j�|�|j	�|�
|j|�|�|j|�d|d	<|�
|j|�|�|j|�dS)
Nr��zix�wyprHrhrgrf�bazr�)
r2rjrirr}rkrHr�rgrfr�rhr\)r.rHrh�element_foorrr�
test___init__.	s zBasicElementTest.test___init__cCs�dttj�vrt�d��t�dddi�}|�t�dddi��|�t��|��}Wd�n1s3wY|�	||�|�
|j|j�|�
|j|j�|�
|j
|j
�|�
t|�t|��t�||�D]
\}}|�||�qf|�
|j|j�dS)	Nr�zElement.copy() not presentr�r�r�r�r��qix)r}r2rjr��SkipTestr�ZassertWarns�DeprecationWarningr�r�rkrHrgrfrl�	itertools�zip_longest�assertIsrh�r.r�Zelement_foo2r]r^rrrr�I	s

�zBasicElementTest.test_copycCs�t�dddi�}|�t�dddi��t�|�}|�||�|�|j|j�|�|j|j�|�|j|j�|�t	|�t	|��t
�||�D]
\}}|�||�qF|�|j
|j
�dS�Nr�r�r�r�r�r�)r2rjr�r�r�rkrHrgrfrlr�r�r�rhr�rrr�
test___copy__f	s
zBasicElementTest.test___copy__cCs�t�dddi�}|�t�dddi��t�|�}|�||�|�|j|j�|�|j|j�|�|j	|j	�|�t
|�t
|��t�||�D]
\}}|�||�qF|�|j
|j
�|�|j
|j
�d|j
d<|�|j
|j
�|�|j
|j
�dSr�)r2rjr�r�r�r�rkrHrgrfrlr�r�rhr\r�rrr�test___deepcopy__~	s

z"BasicElementTest.test___deepcopy__cCs>t�d�}|�t|jd�|�t|jt�d�dg�|�t|jdd�t�d�g|dd�<|�t��d|d<Wd�n1sAwY|�t��t�d�dg|dd�<Wd�n1sawYt|d�r|ddgdd	d
d�}|�t|j|�t|d�r�Gd
d�dtj�}|d�g|dd�<|�tt	j
|�dSdS)N�joer�r�r�r�__setstate__rHr�rfrg)rH�	_childrenrhrfrg�__deepcopy__c@rP)z9BasicElementTest.test_augmentation_type_errors.<locals>.EcSr>rQr)r.�memorrrr��	r@zFBasicElementTest.test_augmentation_type_errors.<locals>.E.__deepcopy__N)r5r6r7r�rrrr�E�	rQr�)r2rjr�r~r�r�r�r~r�r�r�)r.r��stater�rrr�test_augmentation_type_errors�	s0

��
�
�z.BasicElementTest.test_augmentation_type_errorscCs�Gdd�d�}|�}tjd|d�|_t�|�}~t�|�|��t�d�}|�}||_t�|�}tj|d|d�}~~~t�|�|��t�d�}t�d�}t�d�}|�|�|�|�|�|�t�|�}~~~t�|�|��dS)	Nc@�eZdZdS)z.BasicElementTest.test_cyclic_gc.<locals>.DummyN�r5r6r7rrrr�Dummy�	�r�r�)r�r�r�r�r�)	r2rjZdummyref�weakref�refr	r�r0r�)r.r�r��wrefr�r�r�r�rrr�test_cyclic_gc�	s2









zBasicElementTest.test_cyclic_gccs\d��fdd�}t�d�}t�||�}|�|�jd�~t�|��d�|�|�d�dS)NFcsd�dS�NTr)�w��flagrr�wref_cb�	sz.BasicElementTest.test_weakref.<locals>.wref_cbr�T)r2rjr�r�rkrHr	)r.r�r�r�rr�r�test_weakref�	s
zBasicElementTest.test_weakrefcCsBtjddddd�}|�|jddd�d�|�|jd	dd�d�dS)
Nr�r�r�r[)rsrt�zrs�)r�r�)r2rjrkr])r.r�rrr�test_get_keyword_args�	sz&BasicElementTest.test_get_keyword_argsc	Cs�tdtjd�D]a}t|jdd�D]W\}}|jddd�}d|_d|_|�|d	��	|�d
��|�	|�d	��|�
d�d�d
d�|�|d|||�}|�
|jd�|�
|jdd�|�
t|�d�|�||�qqdS)Nr�r���repeatr��*)r�ztext goes herezopposite of head�childZ
grandchildz
.//grandchildrr�zother valuer0r�)r�rX�HIGHEST_PROTOCOLrrSrjrgrfr0r�r�r�rerkrHrhrlro)r.rbr`rar�r�rrr�test_pickle�	s"���zBasicElementTest.test_picklec	Cs�tdtjd�D]=}t|jdd�D]3\}}d}|�|�}t|d�r+|�|��dd�|�	|d|||�}|�|j
d�|�|d	j
d
�qqdS)Nr�r�r�z\<?xml version="1.0"?>
                    <group><dogs>4</dogs>
                    </group>�__getstate__rH�groupr0rZdogs)r�rXr�rrSr�r~rkr�rerH)r.rbr`raZXMLTEXTr�r�rrr�test_pickle_issue18997
s

���z'BasicElementTest.test_pickle_issue18997N)
r5r6r7r�r�r�r�r�r�r�r�r�r�rrrrr�,	s#
r�c@r�)�BadElementTestcs|G�fdd�d�}|�g�t�d�}z|���Wn	ty"YnwGdd�d|tj�}|d�g�t�d�}|���dS)Nc�eZdZe�fdd��ZdS)z2BadElementTest.test_extend_mutable_list.<locals>.Xcst�d�g�dd�<tjS)Nr�r�r���Lrr�	__class__
sz<BadElementTest.test_extend_mutable_list.<locals>.X.__class__N�r5r6r7�propertyr�rr�rr�X
�r�r�c@r�)z2BadElementTest.test_extend_mutable_list.<locals>.YNr�rrrr�Y
r�r�rs�r2rjr�r~�r.r�r�r�rr�r�test_extend_mutable_list
s
�

z'BadElementTest.test_extend_mutable_listcs�G�fdd�d�}|�t�d�g�t�d�}z|���Wn	ty&YnwGdd�d|tj�}|d�t�d�g�t�d�}|���dS)Ncr�)z3BadElementTest.test_extend_mutable_list2.<locals>.Xcs�dd�=tjSrQr�r�r�rrr�%
s
z=BadElementTest.test_extend_mutable_list2.<locals>.X.__class__Nr�rr�rrr�$
r�r�r�r�c@r�)z3BadElementTest.test_extend_mutable_list2.<locals>.YNr�rrrrr�0
r�r�r�r�r�rr�r�test_extend_mutable_list2#
s
�
z(BadElementTest.test_extend_mutable_list2cszG�fdd�dtj�}t�d����|d�g�|�t�jt�d��t�d����t�d�g�|�t�j|d��dS)Ncr�)z3BadElementTest.test_remove_with_mutating.<locals>.Xc��dd�=dSrbr�r.�or�rrr�8
r�z:BadElementTest.test_remove_with_mutating.<locals>.X.__eq__Nr�rr�rrr�7
r�r�r�r�r�)r2rjr�r�r�r��r.r�rr�r�test_remove_with_mutating6
s

z(BadElementTest.test_remove_with_mutatingc	Cs~t�d�}t|d|��*|�t��t|�Wd�n1s wYWd�dSWd�dS1s8wYdS)Nr�rH)r2rjr
r��RuntimeErrorr�r�rrr�test_recursive_reprC
s

��"�z"BadElementTest.test_recursive_reprcsnG�fdd�dt�}t��}|�di�|�d�|�|d��|�d�|�d�|���|��jd�dS)Ncr�)z/BadElementTest.test_element_get_text.<locals>.Xcs"z�jWdStyYdSwrQ)rg�	NameErrorr��r@rr�__del__M
s
�z7BadElementTest.test_element_get_text.<locals>.X.__del__N�r5r6r7r
rr	rrr�L
r�r�rH�ABCD�EFGH�IJKL�ABCDEFGHIJKL)	r�r2r�rr#r�r�rkrg�r.r�r�rr	r�test_element_get_textJ
s


z$BadElementTest.test_element_get_textcs�G�fdd�dt�}t��}|�di�|�di�|�d�|�d�|�|d��|�d�|�d�|���|��djd	�dS)
Ncr�)z/BadElementTest.test_element_get_tail.<locals>.Xcs&z�djWdStyYdSwr)rfrr�r	rrr
`
s
�z7BadElementTest.test_element_get_tail.<locals>.X.__del__Nrrr	rrr�_
r�r�rrHrr
rrr)	r�r2r�rr�r#r�rkrfrrr	r�test_element_get_tail]
s



z$BadElementTest.test_element_get_tailcs^G�fdd�d�}t�d����t�d���d|����t�d���dd|��dS)Ncr�)z%BadElementTest.test_subscr.<locals>.Xcr�Nr�rr�r�rr�	__index__u
r�z/BadElementTest.test_subscr.<locals>.X.__index__N�r5r6r7rrr�rrr�t
r�r�r@r�rr�)r2rjr�rrr�r�test_subscrr
s
zBadElementTest.test_subscrcsPG�fdd�d�}t�d��td�D]}��dt�d��qg�dd|��<dS)Ncr�)z)BadElementTest.test_ass_subscr.<locals>.Xcsg�dd�<dSrrr�r�rrr�
�z3BadElementTest.test_ass_subscr.<locals>.X.__index__Nrrr�rrr��
r�r�r@r�rr�)r2rjr�r�)r.r�r�rr�r�test_ass_subscr�
s

zBadElementTest.test_ass_subscrcCsHdd�}tj|d�}|�di�|�d�|�t|jdi�~t�dS)NcS�gSrQr�rsrtrrr�element_factory�
r@z>BadElementTest.test_treebuilder_start.<locals>.element_factory�rrHrr�)r2r�rr#r��AttributeErrorr	�r.rr�rrr�test_treebuilder_start�
s

z%BadElementTest.test_treebuilder_startcCsFdd�}tj|d�}|�di�|�d�|�t|jd�~t�dS)NcSrrQrrrrrr�
r@z<BadElementTest.test_treebuilder_end.<locals>.element_factoryrrHr)r2r�rr#r�rr�r	rrrr�test_treebuilder_end�
s

z#BadElementTest.test_treebuilder_endN)
r5r6r7r�rrrrrrrrr rrrrr�
s

r�c@r&)�MutatingElementPathcGstj|g|�R�}||_|SrQ)r��__new__r@)rTr@rr.rrrr"�
szMutatingElementPath.__new__cCs|jdd�=dSr�r	rrrrr��
rzMutatingElementPath.__eq__N)r5r6r7r"r�rrrrr!�
sr!c@rP)�BadElementPathcCsdd�)Nr�rrrrrrr��
r�zBadElementPath.__eq__Nr�rrrrr#�
rQr#csXeZdZ�fdd�Z�fdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
�ZS)�BadElementPathTestcs(t���ddlm}|j|_i|_dS�Nrr+)�super�setUpr-r,r��
path_cache�r.r,�r�rrr'�
s

zBadElementPathTest.setUpcs"ddlm}|j|_t���dSr%)r-r,r(r�r&�tearDownr)r*rrr+�
szBadElementPathTest.tearDowncC�0t�d�}|�t�d�g�|�t|d��dS�Nr�r�rs)r2rjr�r�r!r�rrr�test_find_with_mutating�
�
z*BadElementPathTest.test_find_with_mutatingcC�Ft�d�}|�t�d�g�z
|�td��WdSty"YdSwr-)r2rjr�r�r#�ZeroDivisionErrorr�rrr�test_find_with_error�
�
�z'BadElementPathTest.test_find_with_errorcCr,r-)r2rjr�r�r!r�rrr�test_findtext_with_mutating�
r/z.BadElementPathTest.test_findtext_with_mutatingcCr0r-)r2rjr�r�r#r1r�rrr�test_findtext_with_error�
r3z+BadElementPathTest.test_findtext_with_errorcCr,r-)r2rjr�r�r!r�rrr�test_findall_with_mutating�
r/z-BadElementPathTest.test_findall_with_mutatingcCr0r-)r2rjr�r�r#r1r�rrr�test_findall_with_error�
r3z*BadElementPathTest.test_findall_with_error)r5r6r7r'r+r.r2r4r5r6r7�
__classcell__rrr*rr$�
sr$c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�ElementTreeTypeTestcCsX|�tjt�|�tjt�|�tjt�|�tjt�|�tjt�|�tjt�dSrQ)	rir2r&r�r�r(rjr�r�r�rrr�test_istype�
szElementTreeTypeTest.test_istypecCsZGdd�dtj�}|d�}|�|tj�|�||�|�|jd�d|_|�|jd�dS)Nc@r�)zDElementTreeTypeTest.test_Element_subclass_trivial.<locals>.MyElementNr�rrrr�	MyElement�
r�r;r�r�)r2rjrirkrHrg�r.r;�myerrr�test_Element_subclass_trivial�
sz1ElementTreeTypeTest.test_Element_subclass_trivialcsVG�fdd�dtj���dddd�ddd	�}|�|jd
�|�t|���gd��dS)Ncs"eZdZif��fdd�	Z�ZS)zHElementTreeTypeTest.test_Element_subclass_constructor.<locals>.MyElementcs"t�|�j|d|fi|��dS)N�__)r&rM)r.rHrh�extra)r;r�rrrMs"zQElementTreeTypeTest.test_Element_subclass_constructor.<locals>.MyElement.__init__)r5r6r7rMr8r�r;r*rr;sr;r�r�r�)r�r�r[�)r�r�Zfoo__))r�r�)r�r�)r�r[)r�rB)r2rjrkrHr�r�)r.r=rrAr�!test_Element_subclass_constructor�
s�z5ElementTreeTypeTest.test_Element_subclass_constructorcCs.Gdd�dtj�}|d�}|�|��d�dS)Nc@rP)zGElementTreeTypeTest.test_Element_subclass_new_method.<locals>.MyElementcS�|jSrQrGr�rrr�	newmethod�zQElementTreeTypeTest.test_Element_subclass_new_method.<locals>.MyElement.newmethodN)r5r6r7rErrrrr;
rQr;r�)r2rjrkrEr<rrr� test_Element_subclass_new_method	sz4ElementTreeTypeTest.test_Element_subclass_new_methodcCs�Gdd�dtj�}t�d�}d|_|d�}d|_|�|�|�|�d�d�|�|�d�jd�t|�	d��}|�t
|�d|�|�|djd�dS)	Nc@r�)zAElementTreeTypeTest.test_Element_subclass_find.<locals>.MyElementNr�rrrrr;r�r;r�rgr�r.r�r)r2rjrgr�rkr�r�rHrmr�rl)r.r;r��sub�foundrrr�test_Element_subclass_finds

z.ElementTreeTypeTest.test_Element_subclass_findN)r5r6r7r:r>rCrGrJrrrrr9�
s

r9c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�ElementFindTestcCs�t�t�}|�|�d�jd�|�|�d�jd�|�|�d�jd�t�t�|d<|�|�d�jd�|�|�d�d�|�|�d�d�|�|�d�d	�|�|�dd
�d	�|�|�d��|�|�dd
�d
�|�t�d��d
�d	�dS)NrHr��./tagr�zsection/nexttag�nexttagrgr.rr��togz<tag><empty /></tag>�empty)	r2r�r�rkr�rH�SAMPLE_SECTIONr�r�r�rrr�test_find_simple"s
z ElementFindTest.test_find_simplecCs�d}t�|�}|�|�d�jdd�|�|�d�jdd�|�|�d�jdd�|�|�d	�jdd
�|�|�d�jdd�|�td|jd
�|�td|jd�|�td|jd�|�td|jd�dS)Nz�
        <body>
            <tag class='a'/>
            <tag class='b'/>
            <tag class='c'/>
            <tag class='d'/>
        </body>z./tag[1]�classr�z./tag[2]r�z
./tag[last()]r�z./tag[last()-1]r�z./tag[last()-2]ZXPathz./tag[0]z	./tag[-1]z./tag[last()-0]z./tag[last()+1])r2r�rkr�rhr��SyntaxError)r.Z
LINEAR_XMLr�rrr�test_find_xpath9s
zElementFindTest.test_find_xpathcCspt�t�}t�t�|d<|�t|�d��dg�|�t|�d��ddg�|�t|�d��g�|�t|�d��g�|�t|�d��gd��|�t|�d	��dgd
�|�t|�d��dg�|�t|�d��dgd�|�t|�d
��gd��|�t|�d��gd��|�t|�d��gd��|�t|�d��gd��|�t|�d��gd��|�t|�d��dg�|�t|�d��dg�|�t|�d��dgd�|�t|�d��dgd�|�t|�d��dgd�|�t|�d��dg�|�t|�d��dgd�|�t|�d��dgd�|�t|�d��dg�|�t|�d��dg�|�t|�d��d g�|�t|�d!��g�|�t|�d"��g�|�t|�d#��dgd�|�|�d$�|�d��|�t|�d%��d g�|�t|�d&��d g�|�t|�d'��d g�|�t|�d(��d g�|�t|�d)��d g�|�t|�d*��g�|�t|�d+��g�|�t|�d,��g�|�t|�d-��g�|�t|�d.��g�|�t|�d/��dg�|�t|�d0��dg�|�t|�d1��dg�|�t|�d2��dg�|�t|�d3��dg�|�t|�d4��g�|�t|�d5��g�|�t|�d6��dgd�|�t|�d7��dgd�|�t|�d8��dgd�|�t|�d9��dgd�|�t|�d:��dgd�|�t|�d;��dgd
�|�t|�d<��dgd
�|d|d=<|�t|�d(��d d g�|�t|�d3��ddg�dS)>Nr�r�r�rHrNztog/foor�r�z.//tagrBr�zsection//tagz	section/*)rHrM�nextsectionz
section//*)rHrMrUrHzsection/.//*z*/*z*//*z*/tagz*/./tagrLz././tagz.//tag[@class]r[z.//tag[@class="a"]z.//tag[@class!="a"]z.//tag[@class="b"]z.//tag[@class!="b"]z.//tag[@id]z.//section[tag]r�z.//section[element]z../tagzsection/../tagz	section//z.//section[tag='subtext']z.//section[tag ='subtext']z.//section[tag= 'subtext']z.//section[tag = 'subtext']z.//section[ tag = 'subtext' ]z.//section[tag!='subtext']z.//section[tag !='subtext']z.//section[tag!= 'subtext']z.//section[tag != 'subtext']z.//section[ tag != 'subtext' ]z.//tag[.='subtext']z.//tag[. ='subtext']z.//tag[.= "subtext"]z.//tag[ . = "subtext" ]z.//tag[. = 'subtext']z.//tag[. = 'subtext ']z.//tag[.= ' subtext']z.//tag[.!='subtext']z.//tag[. !='subtext']z.//tag[.!= "subtext"]z.//tag[ . != "subtext" ]z.//tag[. != 'subtext']z.//tag[. != 'subtext ']z.//tag[.!= ' subtext']r�)r2r�r�rPrkrNr�r�rrr�test_findallOs
�����������������������������������������zElementFindTest.test_findallcCs\t�t�}|�t|�d��g�|�t|�d��dgd�|�t|�d��dgd�dS)NrHz{http://effbot.org/ns}tagr�z.//{http://effbot.org/ns}tagr[)r2r�r�rkrNr�r�rrr�test_test_find_with_ns�s
��z&ElementFindTest.test_test_find_with_nscCs�t�d�}ddi}|�t|jd|d��d�|�t|jd|d��d�ddi}|�t|jd|d��d	�|�t|jd|d��d�ddd
�}|�t|jd|d��d�|�t|jd|d��d	�dS)N��
            <a xmlns:x="X" xmlns:y="Y">
                <x:b><c/></x:b>
                <b/>
                <c><x:b/><b/></c><y:b/>
            </a>�xxr�z.//xx:b)r�r��.//br�r�)rYr)r2r�rkrlr�)r.r�nsmaprrr�test_findall_different_nsmaps�s

z-ElementFindTest.test_findall_different_nsmapscCs�t�d�}|�t�d��|�t|�d��gd��|�t|�d��dg�|�t|�d��dg�|�t|�d	��d
g�|�t|�d��ddg�|�t|�d
��dg�|�t|�d
��t|�d���|�t|�d��gd��|�t|�d�|dg�t|�d���|�t|�d��gd��|�t|�d��ddg�|�t|�d��ddg�|�t|�d��d
g�|�t|�d��gd��|�t|�d��ddg�|�t|�d��t|�d���dS)NrXrz{*}b)�{X}br��{Y}bz{*}cr�z{X}*r]z{Y}*r^r�r�z{}br�)r]r�r�r^rsr�z.//{*}b)r]r�r]r�r^z.//{*}cz.//{X}*z.//{Y}*z.//{}*)r�r�r�r�z.//{}brZ)r2r�r�r1rkrNr�rrrr�test_findall_wildcard�sd
����������������z%ElementFindTest.test_findall_wildcardcCsFt�t�}|�td��|�d�Wd�dS1swYdS)Nzcannot use absolute pathz/tag)r2r�r�r�rSr�r�rrr�
test_bad_finds
"�zElementFindTest.test_bad_findcCs�t�t�}|�t�|��d�jd�|�t�|��d�d�|�tt�|��	d��dgd�d}|�
t|��t�|��	d�}Wd�n1sJwY|�t|�dgd�dS)NrHrgr�z�This search is broken in 1.3 and earlier, and will be fixed in a future version.  If you rely on the current behaviour, change it to '.+'z//tagr[)r2r�r�rkr(r�rHr�rNr��assertWarnsRegex�
FutureWarning)r.r�r{r�rrr�test_find_through_ElementTrees
��z-ElementFindTest.test_find_through_ElementTreeN)r5r6r7rQrTrVrWr\r_r`rcrrrrrK!sp
,rKc@s>eZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�ZdS)�ElementIterTestNcCst|�|��SrQ)rNr�)r.r@rHrrr�_ilistrOzElementIterTest._ilistcCs4t�d�}|�|�|�gd��|�|�|�d��ddg�|�t|���jd�|�d�|�	��d�|�d�|�d��	��d�|�t|�	��d	�t
|d
d�}|�tt�|��dd
�t
|d
d�}tjt�
�d�}|�ttj||d��dd
�t�d�}|�t|j�t�d�}|�d�|�	��d�dS)Nz7<html><body>this is a <i>paragraph</i>.</body>..</html>)r�r�r�r�r�r�rzthis is a paragraph...zthis is a paragraph.z
this is a F)rArr�r�)r�z*<root>a&amp;<sub>b&amp;</sub>c&amp;</root>za&b&c&)r2r�rkrer�r#r�rHr�r�rEr"r�r�r(r�r)r.r�Z
sourcefiler�rDrrr�
test_basics(
��

zElementIterTest.test_basiccCs�t�d�}|�|�|�dg�t�|d�}|�|�|�ddg�t�|d�}|�|�|�gd��t�|d�}|�|�|�gd��|d|d<|d=|�|�|�ddg�dS)	Nr�r�r�)r�r�r�r�)r�r�r�r�r�r)r2rjrkrer0r�rrr�test_corners9s
zElementIterTest.test_cornerscCs�t�d�}|�|�|d�dgd�|�|�|d�dgd�|�t|jdd��dgd�gd�}|�t|���|�|�|�|�|�|�|�|d�|�dS)	NaJ
            <document>
                <house>
                    <room>bedroom1</room>
                    <room>bedroom2</room>
                </house>
                <shed>nothing here
                </shed>
                <house>
                    <room>bedroom8</room>
                </house>
            </document>�roomr[�houser�rG)r rirhrhZshedrirhr�)r2r�rkrerNr�)r.r�Zall_tagsrrr�test_iter_by_tagOs

�z ElementIterTest.test_iter_by_tagcCsLt�d�}|��}|�t��t�|�Wd�dS1swYdS)Nr�)r2rjr�r�r~r�)r.r�r�rrrr�ls

"�zElementIterTest.test_copyc	Csft�d�}|��}ttjd�D] }|�ttjf��t�	||�Wd�n1s+wYqdS)Nr�r�)
r2rjr�r�rXr�r�r~r[rY)r.r�r�rbrrrr�rs
���zElementIterTest.test_picklerQ)	r5r6r7rerfrgrjr�r�rrrrrds
rdc@s�eZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!S)"�TreeBuilderTestz�<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>text<div>subtext</div>tail</html>z<toplevel>sometext</toplevel>cCs�|�|jd�|�|jd�|�|jd�|�|ji�t|�}|�t|�d�|d}|�|jd�|�|jd�|�|jd�|�|ji�dS)Nr�rgr�rZdivr.rf)rkrHrgrfrhrmrl)r.r��childrenr�rrr�_check_sample1_element�sz&TreeBuilderTest._check_sample1_elementcCs�Gdd�d�}Gdd�d|�}tj|�d�}|�|j�|�|��d�tj|�d�}|�|j�|�|��d�tjt�d�}|�|j�|�|���dS)Nc@rP)z<TreeBuilderTest.test_dummy_builder.<locals>.BaseDummyBuildercS�dS)Nr�rr�rrrr��r@zBTreeBuilderTest.test_dummy_builder.<locals>.BaseDummyBuilder.closeNr�rrrr�BaseDummyBuilder�rQroc@seZdZdd�ZZZdS)z8TreeBuilderTest.test_dummy_builder.<locals>.DummyBuildercWr>rQr)r�rrr�<lambda>��zATreeBuilderTest.test_dummy_builder.<locals>.DummyBuilder.<lambda>N)r5r6r7r#rr�rrrr�DummyBuilder�srrr�r�)r2r�r��sample1rkr��objectr�)r.rorrr�rrr�test_dummy_builder�sz"TreeBuilderTest.test_dummy_buildercCs�t��}|�|�d�jtj�|�|�d�jd�tjtjd�}|�|�d�jtj�|�|�d�jd�tjtd�}|�|�d�td��dS)NZctext)�comment_factory)r2r�rkr/rHr1rgrl�r.r�rrr�test_treebuilder_comment�sz(TreeBuilderTest.test_treebuilder_commentcCs�t��}|�|�dd�jtj�|�|�dd�jd�tjtjd�}|�|�d�jtj�|�|�d�jd�|�|�dd�jtj�|�|�dd�jd�tjdd�d�}|�|�d�td�df�|�|�dd�td�df�dS)Nr�)�
pi_factoryrKz text zpitarget  text cSst|�|fSrQ)rl)r�rgrrrrp�sz5TreeBuilderTest.test_treebuilder_pi.<locals>.<lambda>)r2r�rkrErHr�rgrlrwrrr�test_treebuilder_pi�s z#TreeBuilderTest.test_treebuilder_picCs�Gdd�dtj�}d}t�|�}|�|jd�tj|�d�}|�|�|��}|�|jd�d}t�|�}|�|jd�d}tj|�d�}|�|�|��}|�|jd�dS)Nc@r�)z;TreeBuilderTest.test_late_tail.<locals>.TreeBuilderSubclassNr�rrrr�TreeBuilderSubclass�r�r{z<a>text<!-- comment -->tail</a>Ztexttailr�z<a>text<?pi data?>tail</a>)r2r�r�rkrgr�r�r�)r.r{r�r�r�rrr�test_late_tail�s 



zTreeBuilderTest.test_late_tailcCszGdd�dtj�}d}tjtjdd�d�}|�|�|��}|�|djd�|�|djd	�|�|jd
�tj|dd�d�}|�|�|��}|�|djd�|�|djd	�|�|jd
�d}tjtjdd�d�}|�|�|��}|�|djd
�|�|djd�|�|jd�tj|dd�d�}|�|�|��}|�|djd
�|�|djd�|�|jd�dS)Nc@r�)zKTreeBuilderTest.test_late_tail_mix_pi_comments.<locals>.TreeBuilderSubclassNr�rrrrr{�r�r{z/<a>text<?pi1?> <!-- comment -->
<?pi2?>tail</a>T)Zinsert_commentsr�rrLz
tailztext z+<a>text<!-- comment -->
<?pi data?>tail</a>)Z
insert_piszpi datarfztext
)r2r�r�r�r�rkrgrf)r.r{r�r�r�rrr�test_late_tail_mix_pi_comments�s6



z.TreeBuilderTest.test_late_tail_mix_pi_commentscCs6tjtjdd�d�}|�|j�|��}|�|�dS�Nrr�)r2r�r�r�rsr�rm�r.r�r�rrr�$test_treebuilder_elementfactory_none�sz4TreeBuilderTest.test_treebuilder_elementfactory_nonecCsXGdd�dtj�}|�}|�|�d�d�tj|d�}|�|j�|��}|�|�dS)Nc@rP)z4TreeBuilderTest.test_subclass.<locals>.MyTreeBuildercS�|dS�Nr�rr�rrrr
r�z;TreeBuilderTest.test_subclass.<locals>.MyTreeBuilder.foobarN�r5r6r7rrrrr�
MyTreeBuilder
rQr�r�r�r�)	r2r�rkrr�r�rsr�rm�r.r��tbr�r�rrr�
test_subclass
szTreeBuilderTest.test_subclasscCslGdd�dtj�}|tjtjd�}|�|�d�d�tj|d�}|�|j�|�d�|�	�}|�
|�dS)Nc@rP)z?TreeBuilderTest.test_subclass_comment_pi.<locals>.MyTreeBuildercSr�r�rr�rrrr
r�zFTreeBuilderTest.test_subclass_comment_pi.<locals>.MyTreeBuilder.foobarNr�rrrrr�
rQr�)rvryr�r�r�z<!-- a comment--><?and a pi?>)r2r�r1r�rkrr�r�rsr�rmr�rrr�test_subclass_comment_pi
s
z(TreeBuilderTest.test_subclass_comment_picsNg��fdd�}tj|d�}tj|d�}|�|j�|��|��dg�dS)Ncs��|�t�||�SrQ)r�r2rj)rHrh�Zlstrr�	myfactory
s
z7TreeBuilderTest.test_element_factory.<locals>.myfactoryrr�Ztoplevel)r2r�r�r��sample2r�rk)r.r�r�r�rr�r�test_element_factory
sz$TreeBuilderTest.test_element_factorycCsFtj|d�}tj|d�}|�|j�|��}|�||�|�|�dSr~)r2r�r�r�rsr�rirm)r.rTr�r�r�rrr�_check_element_factory_class+
sz,TreeBuilderTest._check_element_factory_classcCs Gdd�dtj�}|�|�dS)Nc@r�)z@TreeBuilderTest.test_element_factory_subclass.<locals>.MyElementNr�rrrrr;5
r�r;)r2rjr�)r.r;rrr�test_element_factory_subclass4
sz-TreeBuilderTest.test_element_factory_subclasscCs4tj}|�|jd�Gdd�d|t�}|�|�dS)Nr0c@r�)zLTreeBuilderTest.test_element_factory_pure_python_subclass.<locals>.MyElementNr�rrrrr;B
r�r;)r2Z_Element_Pyrkr6r�r�)r.�baser;rrr�)test_element_factory_pure_python_subclass9
sz9TreeBuilderTest.test_element_factory_pure_python_subclasscCs<Gdd�d�}tj|�d�}|�|j�|�|��d�dS)Nc@s eZdZdZdd�Zdd�ZdS)z3TreeBuilderTest.test_doctype.<locals>.DoctypeParserNcSs|||f|_dSrQ��_doctype�r.r_Zpubid�systemrrr�doctypeJ
r+z;TreeBuilderTest.test_doctype.<locals>.DoctypeParser.doctypecSrDrQr�r�rrrr�M
rFz9TreeBuilderTest.test_doctype.<locals>.DoctypeParser.close)r5r6r7r�r�r�rrrr�
DoctypeParserG
sr�r��r�z&-//W3C//DTD XHTML 1.0 Transitional//ENz7http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd)r2r�r�rsrkr�)r.r�r�rrr�test_doctypeF
s	
�zTreeBuilderTest.test_doctypec	Cs�Gdd�d�}tj|�d�dD] }|�t|��tj||�d�Wd�n1s+wYqtj|td�d�dD]}tj||td�d�}|�|j�|�|���q<dS)Nc@s"eZdZdefdd�Zdd�ZdS)zBTreeBuilderTest.test_builder_lookup_errors.<locals>.RaisingBuilderNcSs||_||_dSrQ��raise_in�what)r.r�r�rrrrMY
s
zKTreeBuilderTest.test_builder_lookup_errors.<locals>.RaisingBuilder.__init__cSs"||jkr|�|j��dd�}|S)NcWr>rQr)rrrr�handle`
r@z^TreeBuilderTest.test_builder_lookup_errors.<locals>.RaisingBuilder.__getattr__.<locals>.handler�)r.r_r�rrr�__getattr__]
s
zNTreeBuilderTest.test_builder_lookup_errors.<locals>.RaisingBuilder.__getattr__)r5r6r7r�rMr�rrrr�RaisingBuilderX
sr�r�)rr#r�r/rE)r�)	r2r�r�r�rr�rsr�r�)r.r�rr�rrr�test_builder_lookup_errorsW
s���z*TreeBuilderTest.test_builder_lookup_errorsN)r5r6r7rsr�rmrurxrzr|r}r�r�r�r�r�r�r�r�r�rrrrrkzs$
$	
rkc@sPeZdZdZdZdZdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�ZdS)�
XMLParserTests<file><line>22</line></file>s�<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>text</html>uX<?xml version="1.0" encoding="iso-8859-1"?>
<money value="$£€𐅻">$£€𐅻</money>cCs6|�|jd�|�|djd�|�|djd�dS)NrCr�lineZ22)rkrHrgr�rrr�_check_sample_elementz
sz#XMLParserTest._check_sample_elementcCs0tjdt��d�}|�|j�|�|���dS)Nr)r9r�)r2r�r�r�rsr�r�)r.rVrrr�test_constructor_args
s
�z#XMLParserTest.test_constructor_argscCs6Gdd�dtj�}|�}|�|j�|�|���dS)Nc@r�)z-XMLParserTest.test_subclass.<locals>.MyParserNr�rrrr�MyParser�
r�r�)r2r�r�rsr�r�)r.r�r�rrrr��
szXMLParserTest.test_subclasscCsVt���t�dt�t��}|�|j�|��Wd�dS1s$wYdS)N�error)	�warnings�catch_warnings�simplefilterr�r2r�r�r�r�r0rrr�test_doctype_warning�
s

"�z"XMLParserTest.test_doctype_warningcsd�G�fdd�dtj�}|�}|�td��|�|j�Wd�n1s'wY|��|���d��t�	��9t�
dt�t�
dt�G�fdd�d�}||�d�}|�|j�|��|���|��d�Wd�dS1sywYdS)	Ncr�)z@XMLParserTest.test_subclass_doctype.<locals>.MyParserWithDoctypecs||f�dSrQr)r.rrr�rrr��
szHXMLParserTest.test_subclass_doctype.<locals>.MyParserWithDoctype.doctypeN�r5r6r7r�rr�rr�MyParserWithDoctype�
r�r�r�r�cr�)z:XMLParserTest.test_subclass_doctype.<locals>.DoctypeParsercs|||f�dSrQrr���	_doctype2rrr��
rVzBXMLParserTest.test_subclass_doctype.<locals>.DoctypeParser.doctypeNr�rr�rrr��
r�r�r�r�)
r2r�ra�RuntimeWarningr�r�r�r�r�r�r�r�rk)r.r�r�r�r)r�r�r�test_subclass_doctype�
s*�


�"�z#XMLParserTest.test_subclass_doctypecCsrt���+t�dt�t�dt�Gdd�dtj�}|�}|�|j�|�	�Wd�dS1s2wYdS)z:Ensure that ordinary usage is not deprecated (Issue 19176)r�c@r�)zDXMLParserTest.test_inherited_doctype.<locals>.MyParserWithoutDoctypeNr�rrrr�MyParserWithoutDoctype�
r�r�N)
r�r�r�r�r�r2r�r�r�r�)r.r�r�rrr�test_inherited_doctype�
s

"�z$XMLParserTest.test_inherited_doctypecCsVtjt��d�}|�|j�|��}|�|jd�|�|jdd�|�|j	d�dS)Nr�Zmoneyr�u
$£€𐅻)
r2r�r�r��sample3r�rkrHrhrgrrrr�test_parse_string�
szXMLParserTest.test_parse_stringN)
r5r6r7rsr�r�r�r�r�r�r�r�r�rrrrr�q
sr�c@rP)�NamespaceParseTestcCs`ddd�}t�t�}|�t|�d|��d�|�t|�d|��d�|�t|�d|��d�dS)	NZhellor�)�hr�z{hello}tabler�z.//{hello}tdr�z.//{foo}name)r2r��SAMPLE_XML_NS_ELEMSrkrlr�)r.r[r�rrr�test_find_with_namespace�
s


z+NamespaceParseTest.test_find_with_namespaceN)r5r6r7r�rrrrr��
rQr�c@sleZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�ElementSlicingTestcCsdd�|D�S)NcSrFrrG)rJr�rrrrK�
rLz1ElementSlicingTest._elem_tags.<locals>.<listcomp>r)r.Zelemlistrrr�
_elem_tags�
rOzElementSlicingTest._elem_tagscCs|�t|��SrQ)r�rmr2rrr�
_subelem_tags�
rOz ElementSlicingTest._subelem_tagscCs,t�d�}t|�D]
}t�|d|�q	|S)zxCreate an Element with a tag 'a', with the given amount of children
           named 'a0', 'a1' ... and so on.

        r�za%s)r2rjr�r0)r.Znumchildrenr�r�rrr�_make_elem_with_children�
s
z+ElementSlicingTest._make_elem_with_childrencsZ|�d��|��djd�|��djd�|�t�fdd��|�t�fdd��dS)	Nr�r��a1����a8c��dS)N�rrr�rrrp�
�z?ElementSlicingTest.test_getslice_single_index.<locals>.<lambda>cr�)Ni�rrr�rrrp�
r�)r�rkrHr��
IndexErrorr�rr�r�test_getslice_single_index�
s

z-ElementSlicingTest.test_getslice_single_indexcCs�|�d�}|�|�|dd��gd��|�|�|dd��gd��|�|�|dd��gd��|�|�|dd��ddg�|�|�|dd��ddg�|�|�|dd	��d
dg�dS)NrTr[)�a3�a4�a5�r'r�r�rsr��a0r�)r�rkr�r�rrr�test_getslice_range�
s
"z&ElementSlicingTest.test_getslice_rangec	Cs�|�d�}|�|�|ddd��ddg�|�|�|ddd��gd��|�|�|ddd��ddg�|�|�|ddd��d	dg�|�|�|ddtj��d
g�|�|�|ddtjd>��d
g�dS)Nr��r�r��a9r[)r�r�Za6r�r�r�r��@�r�rkr�rW�maxsizer�rrr�test_getslice_steps�
s
     (z&ElementSlicingTest.test_getslice_stepsc	Cs�|�d�}|�|�|ddd��gd��|�|�|ddd��ddg�|�|�|ddtj��dg�|�|�|ddtjd��dg�|�|�|ddtjd	>��dg�dS)
NrBrs)r��a2r�r�r�r�r�r[r�r�r�r�rrr�test_getslice_negative_steps�
s
  "&*z/ElementSlicingTest.test_getslice_negative_stepscCs�|�d�}|dd�=|�|�|�ddg�|�d�}|dd�=|�|�|�g�|�d�}|ddd�=|�|�|�g�|�d�}|ddd�=|�|�|�ddg�|�d�}|d	dd�=|�|�|�ddg�|�d�}|ddd�=|�|�|�d
g�dS)NrBrr�r�r�rsr�r�r�r�)r�rkr�r�rrr�
test_delslices$







z ElementSlicingTest.test_delslicecCs�|�d�}t�d�|d<|�|�|�gd��t�d�|d<|�|�|�gd��|�t��t�d�|d	<Wd�n1s@wY|�t��t�d�|d
<Wd�n1s\wY|�|�|�gd��dS)NrBr�r��r�r�r�r�r�r�)r�r�r�r�r�r'���)r�r2rjrkr�r�r�r�rrr�test_setslice_single_indexs
��z-ElementSlicingTest.test_setslice_single_indexcCs�|�d�}dd�td�D�|dd�<|�|�|�gd��|�d�}t�d�g|dd�<|�|�|�gd	��|�d�}d
d�td�D�|dd�<|�|�|�gd��dS)NrBcS�g|]	}t�d|��qS�zb%sr��rJr�rrrrK/rz:ElementSlicingTest.test_setslice_range.<locals>.<listcomp>r�r�r[)r��b0�b1r�r�)r�r�r�cSr�r�r�r�rrrrK7r)r�r�r��b2r�)r�r�rkr�r2rjr�rrr�test_setslice_range-s


z&ElementSlicingTest.test_setslice_rangecCs�|�d�}dd�td�D�|ddd�<|�|�|�gd��|�d�}|�t��t�d�g|ddd�<Wd�n1s>wY|�t��d	d�td
�D�|ddd�<Wd�n1sawY|�t��g|ddd�<Wd�n1s}wY|�|�|�gd��|�d�}t�d�g|ddtj	�<|�|�|�gd
��t�d�g|ddtj	d>�<|�|�|�gd��dS)NrTcSr�r�r�r�rrrrK<rz:ElementSlicingTest.test_setslice_steps.<locals>.<listcomp>r�r�r')r�r�r�r�r�r�r�cSr�r�r�r�rrrrKCrr[)r�r�r�r�r�r�rBr�r�r��r�r�r�r��
r�r�rkr�r�r�r2rjrWr�r�rrr�test_setslice_steps:s&

���
z&ElementSlicingTest.test_setslice_stepscCs�|�d�}dd�td�D�|ddd�<|�|�|�gd��|�d�}|�t��t�d�g|ddd�<Wd�n1s>wY|�t��d	d�td
�D�|ddd�<Wd�n1sawY|�t��g|ddd�<Wd�n1s}wY|�|�|�gd��|�d�}t�d�g|ddtj	�<|�|�|�gd
��t�d�g|ddtj	d�<|�|�|�gd��t�d�g|ddtj	d>�<|�|�|�gd��dS)NrBcSr�r�r�r�rrrrKPrzCElementSlicingTest.test_setslice_negative_steps.<locals>.<listcomp>r�rrs)r�r�r�r�r�cSr�r�r�r�rrrrKWrr[)r�r�r�r�r�r�r�r�r�r�)r�r�r�r�r�r�rrr�test_setslice_negative_stepsNs*

���
z/ElementSlicingTest.test_setslice_negative_stepsN)r5r6r7r�r�r�r�r�r�r�r�r�r�r�r�rrrrr��
s
	

	
r�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZGdd�d�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)S)*�IOTestc	Cs�t�d�}d|_|�t|�d�dD]-}|�|��|�t||d�d�|�t||��d�d�Wd�n1s:wYqdD]9}|�|��*|�t||d�d|�|��|��}|�t||d�d|�|��Wd�n1svwYqBt�d�}d	|_|�t|�d
�|�t|dd�d�|�t|d
d�d�dD]}|�t||d�d|�|��q�t�d�}d	|jd<|�t|�d�|�t|dd�d�|�t|d
d�d�dD]}|�t||d�d|�|��q�t�d�}d|_|�t|�d�|�t|dd�d�|�t|d
d�d�dD]}|�t||d�d|�|���qt�d�}d|jd<|�t|�d�|�t|dd�d�|�t|d
d�d�dD]}|�t||d�d|�|���qOdS)NrHr5z<tag>abc</tag>)rr�r�s<tag>abc</tag>)r�r��utf-32z2<?xml version='1.0' encoding='%s'?>
<tag>abc</tag>z<&"'>z<tag>&lt;&amp;"'&gt;</tag>rs<tag>&lt;&amp;"'&gt;</tag>r�z><?xml version='1.0' encoding='%s'?>
<tag>&lt;&amp;"'&gt;</tag>r�z"<tag key="&lt;&amp;&quot;'&gt;" />s"<tag key="&lt;&amp;&quot;'&gt;" />zF<?xml version='1.0' encoding='%s'?>
<tag key="&lt;&amp;&quot;'&gt;" />uåöö<>u<tag>åöö&lt;&gt;</tag>s<tag>åöö&lt;&gt;</tag>s%<tag>&#229;&#246;&#246;&lt;&gt;</tag>u=<?xml version='1.0' encoding='%s'?>
<tag>åöö&lt;&gt;</tag>u<tag key="åöö&lt;&gt;" />s<tag key="åöö&lt;&gt;" />s(<tag key="&#229;&#246;&#246;&lt;&gt;" />)r�r�r�r�r�u@<?xml version='1.0' encoding='%s'?>
<tag key="åöö&lt;&gt;" />)	r2rjrgrkrEr��upperr"rh)r.r@�encr�rrrr�fs�
����������
	����

����
����

�����zIOTest.test_encodingcCsh|�tjt�t�t�d��}|�t�ttd��}|�	|�
�d�Wd�dS1s-wYdS)N�<site>ø</site>r�<site>&#248;</site>)r'rr(r
r2r(r�r=r�rkr��r.rDr�rrr�test_write_to_filename�s
"�zIOTest.test_write_to_filenamecCs�|�tjt�t�t�d��}|jtdd�ttd��}|�	|�
�d�Wd�n1s.wY|jtdd�ttd��}|�	|�
�td��Wd�dS1sUwYdS)Nr�rr�r�<site>ø</site>r��:<?xml version='1.0' encoding='ISO-8859-1'?>
<site>�</site>)r'rr(r
r2r(r�r=r�rkr�r$r�rrr�$test_write_to_filename_with_encoding�s��"�z+IOTest.test_write_to_filename_with_encodingcCs�|�tjt�ttd��}|j}Wd�n1swYt�t�t�t�d��}|j	tdd�ttd��}|�
|��d�Wd�dS1sLwYdS)Nr�r�r8r�rr�)r'rr(r
r�r9r2r(r�r=rkr�)r.r�r9rDrrr�!test_write_to_filename_as_unicode�s�
"�z(IOTest.test_write_to_filename_as_unicodecCs�|�tjt�t�t�d��}ttddd��}|j|dd�|�	|j
�Wd�n1s.wYttd��}|�|��d�Wd�n1sKwYttddd	d
��}|j|dd�|�	|j
�Wd�n1spwYttd��}|�|��d�Wd�n1s�wYttddd��}|j|dd�|�	|j
�Wd�n1s�wYttd��}|�|��d
�Wd�dS1s�wYdS)Nr�r�rr�r8rr�r��xmlcharrefreplace)r9�errorsr�r�s<site>�</site>�
r'rr(r
r2r(r�r�r=r$r%rkr�r�rrr�test_write_to_text_file�s.�����"�zIOTest.test_write_to_text_filecCs�|�tjt�t�t�d��}ttd��}|�|�|�	|j
�Wd�n1s*wYttd��}|�|��d�Wd�dS1sHwYdS)Nr�r!rr�r�r�rrr�test_write_to_binary_file�s
�"�z IOTest.test_write_to_binary_filecCs |�tjt�t�t�d��}ttd��}|j|dd�|�	|j
�Wd�n1s,wYttd��}|�|��d�Wd�n1sIwYttd��}|j|dd�|�	|j
�Wd�n1skwYttd��}|�|��d�Wd�dS1s�wYdS)	Nr�r!rr�rr�r�r�r�r�rrr�'test_write_to_binary_file_with_encoding�s$���
�"�z.IOTest.test_write_to_binary_file_with_encodingcCs0|�tjt�t�t�d��}ttd��}|j|dd�|�	|j
�Wd�n1s,wYttd��}|�|��d�
d��Wd�n1sLwYttddd��}|j|dd�|�	|j
�Wd�n1spwYttd��}|�|��d�
d��Wd�dS1s�wYdS)	Nr�r!r�r�ru7<?xml version='1.0' encoding='utf-16'?>
<site>ø</site>r)�	buffering)r'rr(r
r2r(r�r�r=r$r%rkr�r"r�rrr�"test_write_to_binary_file_with_bom�s,�
���
�"�z)IOTest.test_write_to_binary_file_with_bomcC�2t��}t�d�}|�|�|�|��jd�dS�Nz"<?xml version="1.0"?><site></site>�site)r2r(r:r<r�rkr�rH�r.rDr�rrr�test_read_from_stringio
�

zIOTest.test_read_from_stringiocCs:t�t�d��}t��}|j|dd�|�|��d�dS�Nr�r8r�)r2r(r�r:r<r=rkr>r�rrr�test_write_to_stringioszIOTest.test_write_to_stringiocCr��Ns"<?xml version="1.0"?><site></site>r�)r2r(r:r;r�rkr�rH�r.rDr�rrr�test_read_from_bytesior�zIOTest.test_read_from_bytesiocCs6t�t�d��}t��}|�|�|�|��d�dS�Nr�r�)r2r(r�r:r;r=rkr>r�rrr�test_write_to_bytesios
zIOTest.test_write_to_bytesioc@r�)zIOTest.dummyNr�rrrr�dummy%r�rcCsBt�d�}|��}|j|_t��}|�|�|�|��j	d�dSr�)
r:r<rr�r2r(r�rkr�rH)r.r��readerrDrrr�test_read_from_user_text_reader(s

z&IOTest.test_read_from_user_text_readercCsJt�t�d��}t��}|��}|j|_|j|dd�|�|��d�dSr�)	r2r(r�r:r<rr=rkr>)r.rDr��writerrrr�test_write_to_user_text_writer0sz%IOTest.test_write_to_user_text_writercCsJt�d�}|��}|j|_t��}|�|�|�|��j	d�t��}dSr�)
r:r;rr�r2r(r�rkr�rH)r.r�rrDrrr�!test_read_from_user_binary_reader8s

z(IOTest.test_read_from_user_binary_readercCsFt�t�d��}t��}|��}|j|_|�|�|�|��d�dSr)	r2r(r�r:r;rr=rkr>�r.rDr�rrrr� test_write_to_user_binary_writerAs
z'IOTest.test_write_to_user_binary_writercCsbt�t�d��}t��}|��}|j|_dd�|_|j|_|j|dd�|�	|�
�d�d��dS)Nz<site />cSrnr�rrrrrrpNrqzBIOTest.test_write_to_user_binary_writer_with_bom.<locals>.<lambda>r�r�z0<?xml version='1.0' encoding='utf-16'?>
<site />)r2r(r�r:r;rr=�seekable�tellrkr>r"rrrr�)test_write_to_user_binary_writer_with_bomIs

�z0IOTest.test_write_to_user_binary_writer_with_bomc	CsRt�d�}|�t�|d�d�t�|d���|�t�|d�d�t�|d���dS)Nz<tag>foo</tag>r8rr�r�)r2r�rkr�r�r�rrrr�test_tostringlist_invariantUs

�
�z"IOTest.test_tostringlist_invariantcCsRt�d�}|�t�|d�d�|�tj|ddd�d�|�tj|ddd�d�dS)Nz<tag>a<x />b<y></y>c</tag>r8z<tag>a<x />b<y />c</tag>T)Zshort_empty_elementsFz<tag>a<x></x>b<y></y>c</tag>)r2r�rkr�rrrr�test_short_empty_elements^s

���z IOTest.test_short_empty_elementsN)r5r6r7r�r�r�r�r�r�r�r�r�r�r�rrrrrr	rr
rrrrrr�es*E
			r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ParseErrorTestcCs|�t��t�dSrQ)rir2r&rSr�rrrr�lryzParseErrorTest.test_subclassc
Cs<zt�|�WdStjy}z|WYd}~Sd}~wwrQ)r2r�r&)r.r�r�rrr�
_get_erroros��zParseErrorTest._get_errorcCs@|�|�d�jd�|�|�d�jd�|�|�d�jd�dS)Nr�)r�rz<tag>&foo;</tag>)r�r'zfoobar<)r�rT)rkrZpositionr�rrr�test_error_positionusz"ParseErrorTest.test_error_positioncCs8ddlmmm}|�|�d�j|j|j�dS)Nrr�)	Zxml.parsers.expat.errors�parsersZexpatr�rkr�codeZcodesZXML_ERROR_SYNTAX)r.ZERRORSrrr�test_error_codezs
�zParseErrorTest.test_error_codeN)r5r6r7r�rrrrrrrrks
rc@rP)�KeywordArgsTestc
Cs�t�d�}|�|�dd�|jddd��|�|�ddd�|jdddd��|�|�dd�|jddd��|�t|�dd��t|jddd���|�t�d�j	i�t�dt
ddd��tjdt
ddd�d�tjdt
dd	�dd
�tjdddd�tjdt
ddd�ddd�g}|D]}|�|jd�|�|j	t
ddd��q�tj|ddd
did�}|�|j	d
d�|�
td��t�dd�Wd�n1s�wY|�
td��tjddd�Wd�dS1s�wYdS)Nz
<a>foo</a>r�)�pathr�)rr�r��#r�)rrrq)rh)rr)rqrrZkey1Zvalue1zmust be dict, not strzI'm not a dict)r2r�rkr�r�r�rmr�rjrhr\rHr0r�r~)r.rs�elementsr�r�rrr�test_issue14818�s>
������"�zKeywordArgsTest.test_issue14818N)r5r6r7rrrrrr�src@r&)�NoAcceleratorTestcCstst�d��dS)Nzonly for the Python version)rRr�r�r�rrrr'�s
�zNoAcceleratorTest.setUpcCs(|�tjjtj�|�tjjtj�dSrQ)rirRrjrM�types�FunctionTyper�r�rrr�test_correct_import_pyET�sz*NoAcceleratorTest.test_correct_import_pyETN)r5r6r7r'rrrrrr�srcKstj|fi|��SrQ)rR�canonicalize)r�rBrrr�c14n_roundtrip�r%rc@s(eZdZdZdd�Zdd�Zdd�ZdS)�C14NTestNcCs|�td�d�|�td�d�|�td�d�|�td�d�|�td	�d
�|�td�d�|�td
�d�|�td�d�|�td�d�|�td�d�|�td�d�|�td�d�d}|�t|�|�d}|�t|�|�d}|�t|�|�dS)Nz<doc/>z<doc></doc>z<doc xmlns='uri'/>z<doc xmlns="uri"></doc>z <prefix:doc xmlns:prefix='uri'/>z,<prefix:doc xmlns:prefix="uri"></prefix:doc>z+<doc xmlns:prefix='uri'><prefix:bar/></doc>z7<doc><prefix:bar xmlns:prefix="uri"></prefix:bar></doc>z�<elem xmlns:wsu='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' />z
<elem></elem>z*<doc>Hello, world!<!-- Comment 1 --></doc>z<doc>Hello, world!</doc>z<value>&#x32;</value>z<value>2</value>zG<compute><![CDATA[value>"0" && value<"10" ?"valid":"error"]]></compute>zI<compute>value&gt;"0" &amp;&amp; value&lt;"10" ?"valid":"error"</compute>zS<compute expr='value>"0" &amp;&amp; value&lt;"10" ?"valid":"error"'>valid</compute>z{<compute expr="value>&quot;0&quot; &amp;&amp; value&lt;&quot;10&quot; ?&quot;valid&quot;:&quot;error&quot;">valid</compute>z7<norm attr=' &apos;   &#x20;&#13;&#xa;&#9;   &apos; '/>z/<norm attr=" '    &#xD;&#xA;&#x9;   ' "></norm>z6<normNames attr='   A   &#x20;&#13;&#xa;&#9;   B   '/>z=<normNames attr="   A    &#xD;&#xA;&#x9;   B   "></normNames>z7<normId id=' &apos;   &#x20;&#13;&#xa;&#9;   &apos; '/>z1<normId id=" '    &#xD;&#xA;&#x9;   ' "></normId>z5<X xmlns="http://nps/a"><Y targets="abc,xyz"></Y></X>zJ<X xmlns="http://nps/a"><Y xmlns="http://nsp/b" targets="abc,xyz"></Y></X>zN<X xmlns="http://nps/a"><Y xmlns:b="http://nsp/b" b:targets="abc,xyz"></Y></X>)rkrr�rrr�test_simple_roundtrip�sP
�
�
�
�
�
�
�
�
�
�
�zC14NTest.test_simple_roundtripcCs�t�d�}|�t|dd�d�|�t|ddgd�d�|�t|ddgd	�d
�|�t|ddgdgd�d�|�t|dd
dgd	�d�|�t|d
dgd�d�|�t|dddgd	�d�|�t|ddgd�d�dS)Nz�        <root xmlns:x="http://example.com/x">
            <a x:attr="attrx">
                <b>abtext</b>
            </a>
            <b>btext</b>
            <c>
                <x:d>dtext</x:d>
            </c>
        </root>
        T)�
strip_textz�<root><a xmlns:x="http://example.com/x" x:attr="attrx"><b>abtext</b></a><b>btext</b><c><x:d xmlns:x="http://example.com/x">dtext</x:d></c></root>z{http://example.com/x}attr)r"�
exclude_attrszc<root><a><b>abtext</b></a><b>btext</b><c><x:d xmlns:x="http://example.com/x">dtext</x:d></c></root>z{http://example.com/x}d)r"�exclude_tagszb<root><a xmlns:x="http://example.com/x" x:attr="attrx"><b>abtext</b></a><b>btext</b><c></c></root>)r"r#r$z4<root><a><b>abtext</b></a><b>btext</b><c></c></root>r�r�zC<root><c><x:d xmlns:x="http://example.com/x">dtext</x:d></c></root>)r$za<root>
    
    
    <c>
        <x:d xmlns:x="http://example.com/x">dtext</x:d>
    </c>
</root>zI<root><a xmlns:x="http://example.com/x" x:attr="attrx"></a><c></c></root>zu<root>
    <a xmlns:x="http://example.com/x" x:attr="attrx">
        
    </a>
    
    <c>
        
    </c>
</root>)rSrTrkrr�rrr�test_c14n_exclusion�sF

���
����	��zC14NTest.test_c14n_exclusioncs�tddd�}ttjj|��dd�tt�|��D��dd��D�}�fdd��D����fd	d�|D�}|�d
tdd�|�	�D���d/dd
�}|�
�D�]+\}}|D�]#\}}||d�dk}	||d�dk}
||d�dk}d|vr�dd�|dd�d�D�}dd�|dd�d�D�}
nd}
}d�dd�t|�
��D��}|�|�d|�d����|dkr�|s�|�
d|���|d kr�|s�|�
d|���d|vr�|dd�d!�dur�|�
d"|����|d#�}|d$k�r$t�d%�d&��+}t|d&��}t�|���d'|����}Wd�n	1�swYWd�n	1�swYtj||	|
||
|d(�}t�|d#�d)d*d+��}|��}|d,k�rP|�d-d.�}|�d-d.�}Wd�n	1�s[wY|�||�Wd�n	1�sqwYqRqKdS)0Nzc14n-20rrcSs"g|]
}|�d�r|dd��qS)�.xmlNr�)�endswith�rJ�filenamerrrrK:s�z+C14NTest.test_xml_c14n2.<locals>.<listcomp>cSsg|]	}|�d�r|�qS)�in)�
startswithr(rrrrK<s��cs8i|]}|�d�r|dd�t��|�d���D��qS)Zc14ncSs,i|]}|j�d�d|jpd��|f�qS)�}rsr)rH�splitrgr�)rJ�optionrrr�
<dictcomp>As��z6C14NTest.test_xml_c14n2.<locals>.<dictcomp>.<dictcomp>r&)r+r2r�r�r()�	full_pathrrr/@s���z+C14NTest.test_xml_c14n2.<locals>.<dictcomp>cs"i|]
����fdd��D��qS)csJg|]!}|�d��d��r#|�dd�d�vr|�|�dd�df�qS)Zout_r�r�rs)r+�rsplitr()�configs�
input_filerrrKKs��z6C14NTest.test_xml_c14n2.<locals>.<dictcomp>.<listcomp>r)rJ)r2�files)r3rr/Js����cSsg|]	}|D]}|�qqSrr)rJ�output_files�output_filerrrrKUs���cSs|�||df�dS)Nrr�r])�configZoption_namer�rrr�
get_optionYryz+C14NTest.test_xml_c14n2.<locals>.get_optionZIgnoreComments�trueZ
TrimTextNodesZ
PrefixRewriteZ
sequentialZ
QNameAwarecS�(g|]}d|�d��d|�d����qS��{ZNSr,�Namer8rjrrrrKe���r�z/{http://www.w3.org/2010/xml-c14n2}QualifiedAttrcSr<r=r8rjrrrrKjr@z){http://www.w3.org/2010/xml-c14n2}Element�,css:�|]\}\}}|�d|pd�dd�|D����VqdS)�=rAcss �|]}|j�d�dVqdS)r,rsN)rHr-)rJr�rrr�	<genexpr>ts�z4C14NTest.test_xml_c14n2.<locals>.<genexpr>.<genexpr>N)r�)rJr_r�rlrrrrCss
�
 �
�z*C14NTest.test_xml_c14n2.<locals>.<genexpr>�(�)Z
inNsRedeclz2Redeclared namespace handling is not supported in ZinNsSuperfluousz.{http://www.w3.org/2010/xml-c14n2}XPathElementz2QName rewriting in XPath text is not supported in r&ZinC14N5z	world.txtrs&ent2;)Z	from_fileZ
with_commentsr"�rewrite_prefixesZqname_aware_tagsZqname_aware_attrs�rr�r�ZinC14N3z attr="default"rrQ)rrr rr�r��listdirrkrl�valuesr�r�r�r[r�r�r:r;r�rr2r)r.ZdatadirZinput_filesZtestsr:r3r6r7r9Z
keep_commentsr"rFZqattrsZqtagsZconfig_descrr�Zentity_filergrwr)r2r4r0r�test_xml_c14n26s��
�
�
�
����������

������
����
������zC14NTest.test_xml_c14n2)r5r6r7ZmaxDiffr!r%rJrrrrr �s
(Pr cCs6tddgd�a|dur
t}|attttttt	t
ttt
tttttttg}ttur-|�tg�ddlm}tjj}|��}|j}|��|_ttd�rQt�tjtj �}nd}z't!j"|�Wddlm}|�#�|�$|�||_|durutj|�daadSddlm}|�#�|�$|�||_|dur�tj|�daaw)Nr0r1)Zblockedrr+�_set_factories)%rrRr2r'r�r�r�r$rvr�rrmr9rKrdrkr�rr}rr r�rr-r,r�Z_namespace_mapr�r�r~rKr1r�rZrun_unittestr�r�)�moduleZtest_classesr,r[Z
nsmap_copyr(Z
old_factoriesrrr�	test_main�sj���



�


rM�__main__)Tr8rQ)Sr�rr�r:r�rpr rXrYrWrSrr�r�r�rrrrrZtest.supportrrrr	r
rZtest.support.import_helperrZtest.support.os_helperr
rRr2r�r"�UnicodeEncodeErrorr�r�r�r�rPr�r�r�r�r
rr$ZTestCaser'rErNrPrvrro�format�escaper{rmr}r�r�r�r!�__hash__r#r$r9rKrdrkr�r�r�r�rrrrr rMr5rrrr�<module>s�
�



	


 !4	
�	7fd48z`xT
$
f
E
�