HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/words/test/__pycache__/test_domish.cpython-38.pyc
U


W[�N�@s�dZddlmZmZddlmZddlmZmZddl	m
Z
ddlmZddl
mZGdd	�d	ej�ZGd
d�d�ZGdd
�d
eej�ZGdd�deej�ZGdd�dej�ZdS)zF
Tests for L{twisted.words.xish.domish}, a DOM-like library for XMPP.
�)�absolute_import�division)�verifyObject)�_PY3�unicode)�
requireModule)�unittest)�domishc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zes~de_dd�Zer�de_d d!�Zd"d#�Zd$d%�Zd&S)'�ElementTestsz&
    Tests for L{domish.Element}.
    cCsttjt�d��dS)zB
        L{domish.Element} implements L{domish.IElement}.
        �N�fooN)rr	ZIElement�Element��self�r�@/usr/lib/python3/dist-packages/twisted/words/test/test_domish.py�test_interfaceszElementTests.test_interfacecCs.d}|�t�|�d�|�t�|d�d�dS)zF
        The built-in entity references are properly encoded.
        z&<>'"z&amp;&lt;&gt;'"�z&amp;&lt;&gt;&apos;&quot;N)�assertEqualr	ZescapeToXml)r�srrr�
test_escapingszElementTests.test_escapingcCst�d�}|�|jd�dS)zN
        An attribute on L{domish.Namespace} yields a qualified name.
        �testns�rrN)r	Z	Namespacerr)r�nsrrr�test_namespace's
zElementTests.test_namespacecCst�d�}|�|jd�|�|jd�|�|jd�|�|jd�t�d�}|�|jd�|�|jd�|�|jd�|�|jd�t�d�}|�|jd�|�|jd�|�|jd�|�|jd�t�dd�}|�|jd�|�|jd�|�|jd�dS)	z?
        Basic L{domish.Element} initialization tests.
        rrN��rrrrZtest2ns)r	r
r�name�uri�
defaultUri�parent�r�errr�test_elementInit/s&


zElementTests.test_elementInitcCst�d�}|�d�|�d�}d|d<d|d<|�d�|�d�|�d	�|�d
�|�|jdd�|�|j|�|j�d
�d|jd<|�|jd|j�|�|jd|j�|�|dd�|d=|�|�d�d�|�|�d�d�|�|dd�dS)z6
        Basic L{domish.Element} child tests.
        r�somecontent)�testns2�bar2Zvalue1Zattrib1Zvalue2)r%�attrib2�bar�abcZ123���Zabc123Z
subcontentZ	somevalueZ	bar2valuer�rr'N)	r	r
�
addContent�
addElementrZchildrenr&r(ZhasAttribute)rr"Zb2rrr�
test_childOpsKs(







zElementTests.test_childOpscCs8t�d�}|�d�t|�}|�d|�|�|t�dS)�:
        Extract character data using L{unicode}.
        rr$N�r	r
r,rr�assertIsInstance�r�element�textrrr�test_characterDatams


zElementTests.test_characterDatacCs8t�d�}|�d�t|�}|�d|�|�|t�dS)z<
        Extract ascii character data using L{str}.
        rr$N)r	r
r,�strrr1r2rrr�test_characterDataNativeStringys


z+ElementTests.test_characterDataNativeStringcCs8t�d�}|�d�t|�}|�d|�|�|t�dS)r/r�☃Nr0r2rrr�test_characterDataUnicode�s


z&ElementTests.test_characterDataUnicodecCs>t�d�}|�d�t|�}|�d�d�|�|�|t�dS)zA
        Extract character data as UTF-8 using L{bytes}.
        rr8zutf-8N)r	r
r,�bytesr�encoder1r2rrr�test_characterDataBytes�s


z$ElementTests.test_characterDataBytescCs<t�d�}|�d�|�d�|�d�|�dt|��dS)zV
        Mixing addChild with cdata and element, the first cdata is returned.
        rr)r(�defN)r	r
ZaddChildr-rr�rr3rrr�test_characterDataMixed�s




z$ElementTests.test_characterDataMixedcCs(t�d�}|�d�|�dt|��dS)zT
        Unicode strings passed to C{addContent} become the character data.
        rrN�r	r
r,rrr>rrr�test_addContent�s

zElementTests.test_addContentcCs(t�d�}|�d�|�dt|��dS)zY
        ASCII native strings passed to C{addContent} become the character data.
        rZnativeNr@r>rrr� test_addContentNativeStringASCII�s

z-ElementTests.test_addContentNativeStringASCIIcCst�d�}|�t|jd�dS)zV
        Byte strings passed to C{addContent} are not acceptable on Python 3.
        rsbytesN)r	r
�assertRaises�	TypeErrorr,r>rrr�test_addContentBytes�s
z!ElementTests.test_addContentBytesz7Bytes behavior of addContent only provided on Python 3.cCst�d�}|�t|jd�dS)zW
        Non-ASCII byte strings passed to C{addContent} yield L{UnicodeError}.
        rs☃N)r	r
rC�UnicodeErrorr,r>rrr�test_addContentBytesNonASCII�s
z)ElementTests.test_addContentBytesNonASCIIz7Bytes behavior of addContent only provided on Python 2.cCs,t�d�}|jddd�}|�dt|��dS)zW
        Content passed to addElement becomes character data on the new child.
        rr(r))ZcontentN)r	r
r-rr)rr3�childrrr�test_addElementContent�s
z#ElementTests.test_addElementContentcCsrt�d�}|�d�}|�d�}|�d�}|�d�}t|���}|�||�|�||�|�||�|�||�dS)z�
        Calling C{elements} without arguments on a L{domish.Element} returns
        all child elements, whatever the qualified name.
        rr�r%�baz�quux�rrN)r	r
r-�list�elements�assertIn�rr"Zc1Zc2Zc3Zc4Zeltsrrr�
test_elements�s




zElementTests.test_elementscCsvt�d�}|�d�}|�d�}|�d�}|�d�}t|�dd��}|�||�|�||�|�||�|�||�dS)z�
        Calling C{elements} with a namespace and local name on a
        L{domish.Element} returns all child elements with that qualified name.
        rrrJrLrMrN)r	r
r-rNrOrPZassertNotInrQrrr�test_elementsWithQN�s




z ElementTests.test_elementsWithQNN)�__name__�
__module__�__qualname__�__doc__rrrr#r.r5r7r9r<r?rArBrEr�skiprGrIrRrSrrrrr
s0	"		��	r
c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS)�DomishStreamTestsMixinz�
    Mixin defining tests for different stream implementations.

    @ivar streamClass: A no-argument callable which will be used to create an
        XML parser which can produce a stream of elements from incremental
        input.
    cCsFd|_d|_d|_g|_|��|_|j|j_|jj|j_	|j
|j_dS)NF)�doc_started�	doc_ended�rootrO�streamClass�stream�_docStartedZDocumentStartEvent�appendZElementEvent�	_docEndedZDocumentEndEventrrrr�setUps

zDomishStreamTestsMixin.setUpcCs||_d|_dS�NT)r\rZ)rr\rrrr_sz"DomishStreamTestsMixin._docStartedcCs
d|_dSrc)r[rrrrrasz DomishStreamTestsMixin._docEndedcCs|j�|�dS)N)r^�parse�rZxmlrrr�doTestszDomishStreamTestsMixin.doTestcCshd}|j�|�|�|jd�|�|jjd�|�|jdjd�|�|jdjd�|�|jd�dS)Ns<root><child/><child2/></root>Tr\rrHr�child2)r^rdrrZr\rrOr[rerrr�testHarnesssz"DomishStreamTestsMixin.testHarnesscCs�d}|j�|�|�|jjd�|�|jjd�|�|jdjd�|�|jdjd�|�|jddd�|�|jdjjd	�|�t|jdj�d
�dS)Ns�<stream:stream xmlns:stream='etherx' xmlns='jabber'>
  <message to='bar'>    <x xmlns='xdelay'>some&amp;data&gt;</x>  </message></stream:stream>r^�etherxr�messageZjabber�tor(Zxdelayz
some&data>)	r^rdrr\rrrO�xrrerrr�	testBasic%sz DomishStreamTestsMixin.testBasiccCs8d}|j�|�|�|jjd�|�|jdjd�dS)Ns(<stream><error xmlns='etherx'/></stream>rrri�r^rdrr\rrOrerrr�testNoRootNS5sz#DomishStreamTestsMixin.testNoRootNScCs\d}|j�|�|�|jjd�|�|jjd�|�|jdjd�|�|jdjd�dS)Ns=<stream:stream xmlns:stream='etherx'><error/></stream:stream>rirr)r^rdrr\rrrOrerrr�testNoDefaultNS<sz&DomishStreamTestsMixin.testNoDefaultNScCs8d}|j�|�|�|jjd�|�|jdjd�dS)Ns$<root xmlns='testns'><child/></root>rrrnrerrr�testChildDefaultNSEsz)DomishStreamTestsMixin.testChildDefaultNScCs*d}|j�|�|�|jdjjd�dS)Nsg<root xmlns='testns'>
                    <child1><child2 xmlns=''/></child1>
                  </root>rr)r^rdrrOrgrrerrr�testEmptyChildNSLsz'DomishStreamTestsMixin.testEmptyChildNScCs@d}|j�|�|�|jdjd�|�|jdjddi�dS)zm
        Whitespace in an xmlns value is preserved in the resulting node's C{uri}
        attribute.
        s<<root xmlns:foo=' bar baz '><foo:bar foo:baz='quux'/></root>r�	 bar baz )rsrKrLN)r^rdrrOrZ
attributesrerrr�test_namespaceWithWhitespaceUs
�z3DomishStreamTestsMixin.test_namespaceWithWhitespacecCs<d}|j�|�|�|jjdd�|�|jdjd�dS)Ns<<root xmlns='testns' xmlns:foo='testns2'><foo:child/></root>rr%r)r^rdrr\�
localPrefixesrOrrerrr�testChildPrefixasz&DomishStreamTestsMixin.testChildPrefixcCs|�tj|jjd�dS)Ns<root><error></root>)rCr	ZParserErrorr^rdrrrr�testUnclosedElemenths�z*DomishStreamTestsMixin.testUnclosedElementcCs�d}|j�|�|�d|jdj�|�d|jdj�|�d|jdj�|�ddi|jdj�|�d|jdj�|�d|jdj�|�d|jdj�|�i|jdj�d	S)
at
        Test that reuse of namespaces does affect an element's serialization.

        When one element uses a prefix for a certain namespace, this is
        stored in the C{localPrefixes} attribute of the element. We want
        to make sure that elements created after such use, won't have this
        prefix end up in their C{localPrefixes} attribute, too.
        s�<root>
                    <foo:child1 xmlns:foo='testns'/>
                    <child2 xmlns='testns'/>
                  </root>�child1rrrrrgrN)r^rdrrOrrrrurerrr�test_namespaceReusels
z*DomishStreamTestsMixin.test_namespaceReuseN)rTrUrVrWrbr_rarfrhrmrorprqrrrtrvrwryrrrrrYs
			rYc@s0eZdZdZejZeddd�dkr(dZndZdS)�DomishExpatStreamTestszd
    Tests for L{domish.ExpatElementStream}, the expat-based element stream
    implementation.
    ZpyexpatN)�defaultz1pyexpat is required for ExpatElementStream tests.)	rTrUrVrWr	ZExpatElementStreamr]rrXrrrrrz�s
rzc@seZdZdZejZdS)�DomishSuxStreamTestszo
    Tests for L{domish.SuxElementStream}, the L{twisted.web.sux}-based element
    stream implementation.
    N)rTrUrVrWr	ZSuxElementStreamr]rrrrr|�sr|c@s�eZdZdd�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�Zd1S)2�SerializerTestscCs2t�d�}|�|��d�|�|jdd�d�dS)Nrz<foo/>r)ZcloseElementz<foo>�r	r
r�toXmlr!rrr�testNoNamespace�s
zSerializerTests.testNoNamespacecCst�d�}|�|��d�dS)Nrz<foo xmlns='testns'/>r~r!rrr�testDefaultNamespace�s
z$SerializerTests.testDefaultNamespacecCs&t�dd�}|�|�ddi�d�dS)Nrr%rr(z-<bar:foo xmlns:bar='testns' xmlns='testns2'/>r~r!rrr�testOtherNamespace�s�z"SerializerTests.testOtherNamespacecCs(t�d�}|�d�|�|��d�dS)Nrr(� <foo xmlns='testns'><bar/></foo>�r	r
r-rrr!rrr�testChildDefaultNamespace�s

z)SerializerTests.testChildDefaultNamespacecCs(t�d�}|�d�|�|��d�dS)Nr�rr(r�r�r!rrr�testChildSameNamespace�s

z&SerializerTests.testChildSameNamespacecCs*t�d�}|�dd�|�|��d�dS)Nrr(rr�r�r!rrr�testChildSameDefaultNamespace�s
z-SerializerTests.testChildSameDefaultNamespacecCs*t�d�}|�dd�|�|��d�dS)Nr�r%r(r%z0<foo xmlns='testns'><bar xmlns='testns2'/></foo>r�r!rrr�testChildOtherDefaultNamespace�s
z.SerializerTests.testChildOtherDefaultNamespacecCs*t�d�}|�dd�|�|��d�dS)Nr)�ns2r(r�z<foo><bar xmlns='ns2'/></foo>r�r!rrr�testOnlyChildDefaultNamespace�s
z-SerializerTests.testOnlyChildDefaultNamespacecCs(t�d�}|�d�|�|��d�dS)Nrr(z<foo><bar/></foo>r�r!rrr�testOnlyChildDefaultNamespace2�s

z.SerializerTests.testOnlyChildDefaultNamespace2cCs*t�dd�}|�d�|�|��d�dS)Nrr%r�z<<xn0:foo xmlns:xn0='testns' xmlns='testns2'><bar/></xn0:foo>r�r!rrr�testChildInDefaultNamespace�s
z+SerializerTests.testChildInDefaultNamespacecCs&tjdddid�}|�|��d�dS)Nrr�rK�Zattribsz(<foo xmlns:xn0='testns2' xn0:bar='baz'/>r~r!rrr�testQualifiedAttribute�s�z&SerializerTests.testQualifiedAttributecCs&tjdddid�}|�|��d�dS)Nrr�rKr�z6<foo xmlns='testns' xmlns:xn0='testns' xn0:bar='baz'/>r~r!rrr�testQualifiedAttributeDefaultNS�s�z/SerializerTests.testQualifiedAttributeDefaultNScCsJt�d�}|�dd�}|�d�|�dd�}|�d�|�|��d�dS)	Nrr�r%)r%rL)Ztestns3rKZtestns4)rrLz�<foo><xn0:bar xmlns:xn0='testns' xmlns='testns2'><quux/></xn0:bar><xn1:baz xmlns:xn1='testns3' xmlns='testns4'><xn0:quux xmlns:xn0='testns'/></xn1:baz></foo>r�)rr"rxrgrrr�
testTwoChilds�s


zSerializerTests.testTwoChildscCs&tjdddid�}|�|��d�dS)Nr)z$http://www.w3.org/XML/1998/namespaceZlangZen_USr�z<foo xml:lang='en_US'/>r~r!rrr�testXMLNamespace�s��z SerializerTests.testXMLNamespacecCs,tjdddid�}|�|�ddi�d�dS)Nrr�rKr�r%�quxz(<foo xmlns:qux='testns2' qux:bar='baz'/>r~r!rrr�)testQualifiedAttributeGivenListOfPrefixes�s��z9SerializerTests.testQualifiedAttributeGivenListOfPrefixescCs8tjdddid�}|�d�}d|d<|�|��d�dS)Nrr�rKr��r%r�rLzF<foo xmlns:xn0='testns2' xn0:bar='baz'><xn0:qux xn0:bar='quux'/></foo>r��rr"�crrr�testNSPrefix�s�
zSerializerTests.testNSPrefixcCsBtjdddid�}|�d�}d|d<|�d�|�|��d�dS)	Nrr�rKr�r�rLrzY<foo xmlns:xn0='testns2' xn0:bar='baz'><xn0:qux xn0:bar='quux'><xn0:foo/></xn0:qux></foo>r�r�rrr�testDefaultNSPrefix�s�

z#SerializerTests.testDefaultNSPrefixcCs*t�d�}|�|jddidgd�d�dS)Nrrr()�prefixesZprefixesInScopez
<bar:foo/>r~r!rrr�testPrefixScope�s
��zSerializerTests.testPrefixScopecCs&tjdddid�}|�|��d�dS)Nrr(r�ruz<bar:foo xmlns:bar='testns'/>r~r!rrr�testLocalPrefixessz!SerializerTests.testLocalPrefixescCs@tjdddid�}|�d�|�|jjd�|�|��d�dS)Nrr(rr�rKz,<bar:foo xmlns:bar='testns'><baz/></bar:foo>)r	r
r-ZassertIdenticalrKrrrr!rrr�testLocalPrefixesWithChild
s
z*SerializerTests.testLocalPrefixesWithChildcCsjddi}tj|d�}|�||j�tjdddid�}|�d|j|d��t�d�}|�d	|j|d��d
S)aQ
        Test that prefixes passed to serialization are not modified.

        This test makes sure that passing a dictionary of prefixes repeatedly
        to C{toXml} of elements does not cause serialization errors. A
        previous implementation changed the passed in dictionary internally,
        causing havoc later on.
        rr)r�)r%rrLr%r�z <quux:foo xmlns:quux='testns2'/>z<foo xmlns='testns2'/>N)r	ZSerializerClassZassertNotIdenticalr�r
rr)rr�rr"rrr�test_prefixesReuses	�
�

�z"SerializerTests.test_prefixesReusecCs(t�d�}|�d�|�|��d�dS)Nrz<abc123>z<foo><abc123></foo>�r	r
Z	addRawXmlrrr!rrr�testRawXMLSerialization(s

z'SerializerTests.testRawXMLSerializationcCs(t�d�}|�d�|�|��d�dS)Nru<degree>°</degree>u<foo><degree>°</degree></foo>r�r!rrr�"testRawXMLWithUnicodeSerialization0s

z2SerializerTests.testRawXMLWithUnicodeSerializationcCs0t�d�}d|d<|�d�|�|��d�dS)Nrumy valueȡeZtestuA degree symbol...°u2<foo test='my valueȡe'>A degree symbol...°</foo>)r	r
r,rrr!rrr�testUnicodeSerialization5s


�z(SerializerTests.testUnicodeSerializationN)rTrUrVr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr}�s0	r}N)rWZ
__future__rrZzope.interface.verifyrZtwisted.python.compatrrZtwisted.python.reflectrZ
twisted.trialrZtwisted.words.xishr	ZTestCaser
rYrzr|r}rrrr�<module>so