
    z%iT1                     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)Nrb)r   parsetstfile
addCleanupstreamcloselistopen)selfhandlerfins      E/home/uftp/.pyenv/versions/3.12.0/lib/python3.12/test/test_pulldom.py
test_parsezPullDOMTestCase.test_parse   sf    4 --(,,-W '4  	%Cs#$	% 	% 	%s   BBc                 |	   	 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 )NcreateElementhtml   z	xmlns:xdczhttp://www.xml.com/bookstitlezIntroduction to XSLhrpz
xdc:author)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   4##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)	Nr      z,No "title" element detected in SMALL_SAMPLE!r   z=expandNode did not leave DOMEventStream in the correct state.r   r   r   )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   2##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**G3c                     	 t        j                  t              }|D ]  \  }}|t         j                  k(  s y  | j	                  d       y )NzNo comment was encountered)r   r    r!   COMMENTr:   )r   r0   r1   _s       r   test_commentzPullDOMTestCase.test_comment   sF    8##L1 	4FCgoo%	4 II23r5   c                 4   	 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)Nr   z8Ran out of events, but should have received END_DOCUMENT)
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   .A: :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                   F    e Zd Z	 d Zej
                  d        Zd ZddZy)ThoroughTestCasec                 b    	 | j                  t        j                  d t                            y )N)r?   )_test_thoroughr   r   SAXExerciserr   s    r   test_thorough_parsez$ThoroughTestCase.test_thorough_parse   s     >GMM$|~FGr5   c                 R    	 t        d t               d      }| j                  |       y )N   )SAX2DOMTestHelperrX   rW   r   pds     r   test_sax2dom_failz"ThoroughTestCase.test_sax2dom_fail   s#    @t\^R8Br5   c                 T    	 t        d t               d      }| j                  |d       y )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 )Nr   	a commenttargetr.   r   r   text)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   sx   	 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   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eZeZy)rX   c                     || _         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   )	rm   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 rl   rS   )r   argskwargss      r   stubzSAXExerciser.stub  s    (r5   N)rN   rO   rP   rn   r   r~   setProperty
setFeaturerS   r5   r   rX   rX      s"    * ( KJr5   rX   c                       e Zd Z	 d Zy)rb   c                 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   rp   rq   rg   )	rm   rr   ru   r   rs   rt   rv   rw   rx   ry   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   r   rS   r5   r   rb   rb     s    D
r5   rb   c                       e Zd Z	 d Zy)r]   c                     t        j                         | _         | j                  j                  t        j
                  j                  j                  d       | j                  j                  | j                          y )Nr7   )	r   SAX2DOMr?   r   xmlsaxr   feature_namespacesrn   rY   s    r   resetzSAX2DOMTestHelper.reset!  sH    (swwAA1E%%dll3r5   N)rN   rO   rP   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 rl   )r#   )r   testtestnames      r   confirmzSAX2DOMTestCase.confirm*  s    h'r5   c                 v   	 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)Nr   r   )ioStringIOr!   r]   r   r   make_parserr)   r   r'   r(   assertGreaterr9   )r   r   sdr1   r2   s        r   
test_basiczSAX2DOMTestCase.test_basic-  s    5[[& 	8#"3(;(;(=#&|#46B 	T'///DLLF4J
 s4??3Q7	8 	8 	8s   AB/.B/>(B//B8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 )Ndocrg   subelmr   )r   r   rr   ru   rv   rw   rx   documentdocumentElementr9   r>   previousSiblingassertIsnextSibling
parentNodeunlink)r   sax2domr   roottext1elm1text2text3s           r   testSAX2DOMzSAX2DOMTestCase.testSAX2DOM9  s   7//#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   