
    dafT1                     f   d dl Z d dlZd dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZ  edd      Zd	Z G d
 dej                        Z G d dej                        Z G d de      Z G d de      Z G d de	j(                        Z G d dej                        Zedk(  r ej0                          yy)    N)AttributesImpl)feature_external_ges)pulldom)findfileztest.xmlxmltestdata)subdira  <?xml version="1.0"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xdc="http://www.xml.com/books">
<!-- A comment -->
<title>Introduction to XSL</title>
<hr/>
<p><xdc:author xdc:attrib="prefixed attribute" attrib="other attrib">A. Namespace</xdc:author></p>
</html>c                   l    e Zd Zd Zd Zd Zej                  d        Zej                  d        Z	d Z
y)PullDOMTestCasec                    t        j                  t              }| j                  |j                  j
                         t        |       t        t        d      5 }t        t        j                  |             ddd       y# 1 sw Y   yxY w)z&Minimal test of DOMEventStream.parse()rbN)r   parsetstfile
addCleanupstreamcloselistopen)selfhandlerfins      ,/root/Python-3.12.4/Lib/test/test_pulldom.py
test_parsezPullDOMTestCase.test_parse   sc     --(,,-W '4  	%Cs#$	% 	% 	%s   BBc                 z	   t        j                  t              }t        |      \  }}| j	                  t        |d             | j                  t         j                  |       t        |      \  }}| j                  t         j                  |       | j                  d|j                         | j                  dt        |j                               | j                  |j                  j                  d      j                  d       t        |      \  }}| j                  t         j                  |       t        |      \  }}| j                  t         j                  |       t        |      \  }}| j                  d|j                         |}t        |      \  }}| j                  t         j                  |       | j                  d|j                         t        |      \  }}| j                  t         j                   |       | j                  d|j                         | j	                  ||u        t        |      \  }}| j                  t         j                  |       t        |      \  }}| j                  t         j                  |       | j                  d|j                         t        |      \  }}| j                  t         j                   |       | j                  d|j                         t        |      \  }}| j                  t         j                  |       t        |      \  }}| j                  t         j                  |       | j                  d	|j                         t        |      \  }}| j                  t         j                  |       | j                  d
|j                         t        |      \  }}| j                  t         j                  |       t        |      \  }}| j                  t         j                   |       | j                  d
|j                         t        |      \  }}| j                  t         j                   |       t        |      \  }}| j                  t         j                  |       t        |      \  }}| j                  t         j                   |       y)z&Test DOMEventStream parsing semantics.createElementhtml   z	xmlns:xdczhttp://www.xml.com/bookstitlezIntroduction to XSLhrpz
xdc:authorN)r   parseStringSMALL_SAMPLEnext
assertTruehasattrassertEqualSTART_DOCUMENTSTART_ELEMENTtagNamelen
attributesgetNamedItemvalue
CHARACTERSdataEND_ELEMENT)r   itemsevtnode
title_nodes        r   test_parse_semanticsz$PullDOMTestCase.test_parse_semantics+   s    ##L1K	To67//5K	T..4.C0155kBHH(	*K	T++S1K	T 	++S1K	T$,,/
K	T++S1.		:K	T,,c2$,,/
d*+K	T++S1K	T..4t||,K	T,,c2t||,K	T++S1K	T..4dll+K	T..4t||4K	T++S1K	T,,c2t||4K	T,,c2K	T++S1K	T,,c2    c                    t        j                  t              }|D ]`  \  }}|t         j                  k(  s|j                  dk(  s*|j                  |       | j                  dt        |j                                n | j                  d       |D ]  \  }}|t         j                  k(  s n | j                  dj                  d       |j                  |       | j                  t        |      d   t         j                         t        |      \  }}| j                  |j                  d       |j                  |       t        |       t        |      \  }}| j                  |j                  d       | j                  t              5  t        |       d	d	d	       |j                          | j                  |j                          | j                  |j"                         y	# 1 sw Y   PxY w)
z$Ensure expandItem works as expected.r      z,No "title" element detected in SMALL_SAMPLE!r   z=expandNode did not leave DOMEventStream in the correct state.r   r   r   N)r   r    r!   r'   r(   
expandNoder%   r)   
childNodesfailr"   r-   assertRaisesStopIterationclearassertIsNoneparserr   )r   r0   r1   itemr2   s        r   test_expandItemzPullDOMTestCase.test_expandItemi   s   ##L1 	HICg+++0G  &  C$89		H IIFG 	ICg+++	 	t||K	M 	eQ););<K	Ts+UK	Tv.}- 	K	%,,'%,,'		 	s   G))G2c                     t        j                  t              }|D ]  \  }}|t         j                  k(  s y | j	                  d       y)z*PullDOM does not receive "comment" events.zNo comment was encounteredN)r   r    r!   COMMENTr:   )r   r0   r1   _s       r   test_commentzPullDOMTestCase.test_comment   sE     ##L1 	4FCgoo%	4 II23r5   c                 2   t        j                  t              }|D ]*  \  }}|t         j                  k(  s|j                  dk(  s* n 	 t        |      \  }}| j                  t         j                  |       y# t        $ r | j                  d       Y yw xY w)z/PullDOM does not receive "end-document" events.r   z8Ran out of events, but should have received END_DOCUMENTN)
r   r    r!   r/   r(   r"   r%   END_DOCUMENTr<   r:   )r   r0   r1   r2   s       r   test_end_documentz!PullDOMTestCase.test_end_document   s     ##L1 	ICg)))dllf.D		LUICW1137 	LIIJL	Ls   
.A9 9BBc                     t        j                  t              }|j                  }|j	                  t
              }| j                  |d       y )NF)r   r    r!   r?   
getFeaturer   r%   )r   r?   	saxparsergess       r   test_external_ges_defaultz)PullDOMTestCase.test_external_ges_default   s<    $$\2MM	""#78e$r5   N)__name__
__module____qualname__r   r4   rA   unittestexpectedFailurerE   rH   rM    r5   r   r
   r
      sN    % 93|(@ 4 4 L L%r5   r
   c                   H    e Zd ZdZd Zej                  d        Zd ZddZ	y)ThoroughTestCasez(Test the hard-to-reach parts of pulldom.c                 `    | j                  t        j                  dt                            y)z0Test some of the hard-to-reach parts of PullDOM.N)r?   )_test_thoroughr   r   SAXExerciserr   s    r   test_thorough_parsez$ThoroughTestCase.test_thorough_parse   s    GMM$|~FGr5   c                 P    t        dt               d      }| j                  |       y)z2SAX2DOM can"t handle a PI before the root element.N   )SAX2DOMTestHelperrX   rW   r   pds     r   test_sax2dom_failz"ThoroughTestCase.test_sax2dom_fail   s"     t\^R8Br5   c                 R    t        dt               d      }| j                  |d       y)z0Test some of the hard-to-reach parts of SAX2DOM.Nr\   F)r]   SAX2DOMExerciserrW   r^   s     r   test_thorough_sax2domz&ThoroughTestCase.test_thorough_sax2dom   s$    t%5%7<B&r5   c                    t        |      \  }}| j                  t        j                  |       | j	                  t        |d             |rt        |      \  }}| j                  t        j                  |       | j                  d|j                         t        |      \  }}| j                  t        j                  |       | j                  d|j                         | j                  d|j                         t        |      \  }}| j                  t        j                  |       | j                  d|j                         t        |      \  }}| j                  t        j                  |       | j                  d|j                         t        |      \  }}| j                  t        j                  |       | j                  d|j                         | j                  d|j                         t        |      \  }}| j                  t        j                  |       | j                  d|j                         t        |      \  }}| j                  t        j                  |       | j                  d|j                         t        |      \  }}| j                  t        j                  |       | j                  d|j                         t        |      \  }}| j                  t        j                  |       | j                  d|j                         t        |      \  }}| j                  t        j                  |       y)	zPTest some of the hard-to-reach parts of the parser, using a mock
        parser.r   	a commenttargetr.   r   r   textN)r"   r%   r   r&   r#   r$   rC   r.   PROCESSING_INSTRUCTIONrf   r'   r(   r-   r/   rG   )r   r_   before_rootr1   r2   s        r   rW   zThoroughTestCase._test_thorough   ss    H	T//5o67RICW__c2[$))4RICW;;SAXt{{3VTYY/H	T..4.H	T#.dii0H	T77=4;;/+H	T..4dll+H	T++S1+H	T,,c2dll+H	T,,c2.H	T--s3r5   N)T)
rN   rO   rP   __doc__rZ   rQ   rR   r`   rc   rW   rS   r5   r   rU   rU      s/    2H    
'
,4r5   rU   c                   *    e Zd ZdZd Zd Zd ZeZeZy)rX   znA fake sax parser that calls some of the harder-to-reach sax methods to
    ensure it emits the correct eventsc                     || _         y N)_handler)r   r   s     r   setContentHandlerzSAXExerciser.setContentHandler   s	    r5   c                    | j                   }|j                          |j                  d       |j                  dd       |j	                  dt        i              |j                  d       |j                  dd       |j	                  dt        ddi             |j                  d       |j                  d       |j                  d       |j                          y )	Nre   rf   r.   r   r   class	paraclassrg   )	rn   startDocumentcommentprocessingInstructionstartElementr   
characters
endElementendDocumentr   rD   hs      r   r   zSAXExerciser.parse   s    MM	 	
		+	&1	v~b12			+	&1	sNG[+ABC	V	S	V	r5   c                      y)zStub method. Does nothing.NrS   )r   argskwargss      r   stubzSAXExerciser.stub  s    r5   N)	rN   rO   rP   rj   ro   r   r   setProperty
setFeaturerS   r5   r   rX   rX      s"    * ( KJr5   rX   c                       e Zd ZdZd Zy)rb   zThe same as SAXExerciser, but without the processing instruction and
    comment before the root element, because S2D can"t handle itc                 x   | j                   }|j                          |j                  dt        i              |j	                  d       |j                  dd       |j                  dt        ddi             |j                  d       |j                  d       |j                  d       |j                          y )	Nr   re   rf   r.   r   rq   rr   rg   )	rn   rs   rv   r   rt   ru   rw   rx   ry   rz   s      r   r   zSAX2DOMExerciser.parse  s    MM		v~b12			+	&1	sNG[+ABC	V	S	V	r5   N)rN   rO   rP   rj   r   rS   r5   r   rb   rb     s    D
r5   rb   c                       e Zd ZdZd Zy)r]   z1Allows us to drive SAX2DOM from a DOMEventStream.c                     t        j                         | _         | j                  j                  t        j
                  j                  j                  d       | j                  j                  | j                          y )Nr7   )	r   SAX2DOMr?   r   xmlsaxr   feature_namespacesro   rY   s    r   resetzSAX2DOMTestHelper.reset!  sH    (swwAA1E%%dll3r5   N)rN   rO   rP   rj   r   rS   r5   r   r]   r]     s
    ;4r5   r]   c                        e Zd ZddZd Zd Zy)SAX2DOMTestCasec                 (    | j                  ||       y rm   )r#   )r   testtestnames      r   confirmzSAX2DOMTestCase.confirm*  s    h'r5   c                 t   t        j                  t              5 }t        |t        j
                  j                         t        t                    }|D ]*  \  }}|t        j                  k(  s|j                  dk(  s* n | j                  t        j                        d       ddd       y# 1 sw Y   yxY w)z'Ensure SAX2DOM can parse from a stream.r   r   N)ioStringIOr!   r]   r   r   make_parserr)   r   r'   r(   assertGreaterr9   )r   r   sdr1   r2   s        r   
test_basiczSAX2DOMTestCase.test_basic-  s    [[& 	8#"3(;(;(=#&|#46B 	T'///DLLF4J
 s4??3Q7	8 	8 	8s   AB.-B.=(B..B7c                    t        j                         }|j                          |j                  di        |j	                  d       |j                  di        |j	                  d       |j                  d       |j	                  d       |j                  d       |j                          |j                  }|j                  }|j                  \  }}}|j                  d   }| j                  |j                         | j                  |j                  |       | j                  |j                  |       | j                  |j                  |       | j                  |j                  |       | j                  |j                         | j                  |j                         | j                  |j                         | j                  |j                  |       | j                  |j                  |       | j                  |j                  |       | j                  |j                  |       | j                  |j                  |       |j                          y)z)Ensure SAX2DOM expands nodes as expected.docrg   subelmr   N)r   r   rs   rv   rw   rx   ry   documentdocumentElementr9   r>   previousSiblingassertIsnextSibling
parentNodeunlink)r   sax2domr   roottext1elm1text2text3s           r   testSAX2DOMzSAX2DOMTestCase.testSAX2DOM9  s   //#UB'6"Xr*6"8$6"5!""#e"%//0e''.d**E2d&&.e++T2%++,%//0%++,doos+e&&-doot,e&&-e&&-

r5   N)Test)rN   rO   rP   r   r   r   rS   r5   r   r   r   (  s    (
8 r5   r   __main__)r   rQ   xml.saxr   xml.sax.xmlreaderr   xml.sax.handlerr   xml.domr   test.supportr   r   r!   TestCaser
   rU   objectrX   rb   DOMEventStreamr]   r   rN   mainrS   r5   r   <module>r      s    	   , 0  ! :m
4N%h'' N%b>4x(( >4B6 D| "4.. 41h'' 1h zHMMO r5   