
    <eT1                     j   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j                     dS dS )    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                   f    e Zd Zd Zd Zd Zej        d             Zej        d             Z	d Z
dS )PullDOMTestCasec                 4   	 t          j        t                    }|                     |j        j                   t          |           t          t          d          5 }t          t          j        |                     d d d            d S # 1 swxY w Y   d S )Nrb)r   parsetstfile
addCleanupstreamcloselistopen)selfhandlerfins      (/usr/lib/python3.11/test/test_pulldom.py
test_parsezPullDOMTestCase.test_parse   s    4 -((,---W '4   	%Cs##$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%s   "BBBc                 
   	 t          j        t                    }t          |          \  }}|                     t          |d                     |                     t           j        |           t          |          \  }}|                     t           j        |           |                     d|j	                   |                     dt          |j                             |                     |j                            d          j        d           t          |          \  }}|                     t           j        |           t          |          \  }}|                     t           j        |           t          |          \  }}|                     d|j	                   |}t          |          \  }}|                     t           j        |           |                     d|j                   t          |          \  }}|                     t           j        |           |                     d|j	                   |                     ||u            t          |          \  }}|                     t           j        |           t          |          \  }}|                     t           j        |           |                     d|j	                   t          |          \  }}|                     t           j        |           |                     d|j	                   t          |          \  }}|                     t           j        |           t          |          \  }}|                     t           j        |           |                     d	|j	                   t          |          \  }}|                     t           j        |           |                     d
|j	                   t          |          \  }}|                     t           j        |           t          |          \  }}|                     t           j        |           |                     d
|j	                   t          |          \  }}|                     t           j        |           t          |          \  }}|                     t           j        |           t          |          \  }}|                     t           j        |           d S )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+   s5   4#L11KK	To66777/555KK	T.444...C0011155kBBH(	* 	* 	*KK	T+S111KK	T 	+S111KK	T$,///
KK	T+S111.	:::KK	T,c222$,///
d*+++KK	T+S111KK	T.444t|,,,KK	T,c222t|,,,KK	T+S111KK	T.444dl+++KK	T.444t|444KK	T+S111KK	T,c222t|444KK	T,c222KK	T+S111KK	T,c22222    c                 2   	 t          j        t                    }|D ]_\  }}|t           j        k    rJ|j        dk    r?|                    |           |                     dt          |j                              n`| 	                    d           |D ]\  }}|t           j        k    r n|                     d|j        d           |                    |           |                     t          |          d         t           j                   t          |          \  }}|                     |j        d           |                    |           t          |           t          |          \  }}|                     |j        d           |                     t                    5  t          |           d d d            n# 1 swxY w Y   |                                 |                     |j                   |                     |j                   d S )	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   s9   2#L11 	H 	HICg+++0G0G  &&&  C$8$8999IIFGGG 	 	ICg+++ ,t|K	M 	M 	M 	eQ);<<<KK	Ts+++UKK	Tv...}-- 	 	KKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	%,'''%,'''''s   (GGGc                     	 t          j        t                    }|D ]\  }}|t           j        k    r d S |                     d           d S )NzNo comment was encountered)r   r    r!   COMMENTr:   )r   r0   r1   _s       r   test_commentzPullDOMTestCase.test_comment   s\    8#L11 	4 	4FCgo%% & II233333r5   c                 6   	 t          j        t                    }|D ]"\  }}|t           j        k    r|j        dk    r n#	 t          |          \  }}|                     t           j        |           d S # t          $ r | 	                    d           Y d S 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1 	 	ICg)))dlf.D.D	LUICW1377777 	L 	L 	LIIJL L L L L L	Ls   2A5 5BBc                     t          j        t                    }|j        }|                    t
                    }|                     |d           d S )NF)r   r    r!   r?   
getFeaturer   r%   )r   r?   	saxparsergess       r   test_external_ges_defaultz)PullDOMTestCase.test_external_ges_default   sI    $\22M	""#788e$$$$$r5   N)__name__
__module____qualname__r   r4   rA   unittestexpectedFailurerE   rH   rM    r5   r   r
   r
      s        % % % 93 93 93|( ( (@ 4 4 4 L L L% % % % %r5   r
   c                   D    e Zd Z	 d Zej        d             Zd ZddZdS )ThoroughTestCasec                 r    	 |                      t          j        d t                                           d S )N)r?   )_test_thoroughr   r   SAXExerciserr   s    r   test_thorough_parsez$ThoroughTestCase.test_thorough_parse   s2    >GM$|~~FFFGGGGGr5   c                 l    	 t          d t                      d          }|                     |           d S )N   )SAX2DOMTestHelperrX   rW   r   pds     r   test_sax2dom_failz"ThoroughTestCase.test_sax2dom_fail   s4    @t\^^R88Br5   c                 n    	 t          d t                      d          }|                     |d           d S )Nr\   F)r]   SAX2DOMExerciserrW   r^   s     r   test_thorough_sax2domz&ThoroughTestCase.test_thorough_sax2dom   s9    >t%5%7%7<<B&&&&&r5   Tc                    	 t          |          \  }}|                     t          j        |           |                     t          |d                     |rt          |          \  }}|                     t          j        |           |                     d|j                   t          |          \  }}|                     t          j        |           |                     d|j	                   |                     d|j                   t          |          \  }}|                     t          j
        |           |                     d|j                   t          |          \  }}|                     t          j        |           |                     d|j                   t          |          \  }}|                     t          j        |           |                     d|j	                   |                     d|j                   t          |          \  }}|                     t          j
        |           |                     d|j                   t          |          \  }}|                     t          j        |           |                     d|j                   t          |          \  }}|                     t          j        |           |                     d|j                   t          |          \  }}|                     t          j        |           |                     d|j                   t          |          \  }}|                     t          j        |           d S )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   s   	 HH	T/555o66777 	0RICW_c222[$)444RICW;SAAAXt{333VTY///HH	T.444...HH	T#...di000HH	T7===4;///+++HH	T.444dl+++HH	T+S111+++HH	T,c222dl+++HH	T,c222...HH	T-s33333r5   N)T)	rN   rO   rP   rZ   rQ   rR   r`   rc   rW   rS   r5   r   rU   rU      sk        2H H H      
' ' '
,4 ,4 ,4 ,4 ,4 ,4r5   rU   c                   *    e Zd Z	 d Zd Zd ZeZeZdS )rX   c                     || _         d S N)_handler)r   r   s     r   setContentHandlerzSAXExerciser.setContentHandler   s    r5   c                    | j         }|                                 |                    d           |                    dd           |                    dt          i                      |                    d           |                    dd           |                    dt          ddi                     |                    d           |                    d           |                    d           |                                 d S )	Nre   rf   r.   r   r   class	paraclassrg   )	rm   startDocumentcommentprocessingInstructionstartElementr   
characters
endElementendDocumentr   rD   hs      r   r   zSAXExerciser.parse   s    M	 	
		+	&111	v~b11222			+	&111	sNG[+ABBCCC	V	S	V	r5   c                     	 d S rl   rS   )r   argskwargss      r   stubzSAXExerciser.stub  s
    (r5   N)rN   rO   rP   rn   r   r~   setProperty
setFeaturerS   r5   r   rX   rX      sL        *       (   KJJJr5   rX   c                       e Zd Z	 d ZdS )rb   c                    | j         }|                                 |                    dt          i                      |                    d           |                    dd           |                    dt          ddi                     |                    d           |                    d           |                    d           |                                 d S )	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    M		v~b11222			+	&111	sNG[+ABBCC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dS )r]   c                     t          j                    | _         | j                            t          j        j        j        d           | j                            | j                    d S )Nr7   )	r   SAX2DOMr?   r   xmlsaxr   feature_namespacesrn   rY   s    r   resetzSAX2DOMTestHelper.reset!  sN    ((swA1EEE%%dl33333r5   N)rN   rO   rP   r   rS   r5   r   r]   r]     s&        ;4 4 4 4 4r5   r]   c                   "    e Zd ZddZd Zd ZdS )SAX2DOMTestCaseTestc                 2    |                      ||           d S rl   )r#   )r   testtestnames      r   confirmzSAX2DOMTestCase.confirm*  s    h'''''r5   c                    	 t          j        t                    5 }t          |t          j                                        t          t                              }|D ]"\  }}|t          j	        k    r|j
        dk    r n#|                     t          |j                  d           d d d            d S # 1 swxY w Y   d S )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#46 6B  	T'///DLF4J4JE s4?33Q777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8s   BB55B9<B9c                    	 t          j                    }|                                 |                    di            |                    d           |                    di            |                    d           |                    d           |                    d           |                    d           |                                 |j        }|j        }|j	        \  }}}|j	        d         }| 
                    |j                   |                     |j        |           |                     |j        |           |                     |j        |           |                     |j        |           | 
                    |j                   | 
                    |j                   | 
                    |j                   |                     |j        |           |                     |j        |           |                     |j        |           |                     |j        |           |                     |j        |           |                                 d S )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00e'...d*E222d&...e+T222%+,,,%/000%+,,,dos+++e&---dot,,,e&---e&---

r5   N)r   )rN   rO   rP   r   r   r   rS   r5   r   r   r   (  sF        ( ( ( (
8 
8 
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 0 0 0 0 0       ! ! ! ! ! ! (:m
4
4
4N% N% N% N% N%h' N% N% N%b>4 >4 >4 >4 >4x( >4 >4 >4B    6   D    |   "4 4 4 4 4. 4 4 41 1 1 1 1h' 1 1 1h zHMOOOOO r5   