
    <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                 2   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 )z&Minimal test of DOMEventStream.parse()rbN)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     -((,---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 )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+   s4    #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                 0   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 )
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   s6   #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 )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   s[     #L11 	4 	4FCgo%% & II233333r5   c                 4   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)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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    2A4 4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                   F    e Zd ZdZd Zej        d             Zd ZddZ	dS )	ThoroughTestCasez(Test the hard-to-reach parts of pulldom.c                 p    |                      t          j        dt                                           dS )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/    GM$|~~FFFGGGGGr5   c                 j    t          dt                      d          }|                     |           dS )z2SAX2DOM can"t handle a PI before the root element.N   )SAX2DOMTestHelperrX   rW   r   pds     r   test_sax2dom_failz"ThoroughTestCase.test_sax2dom_fail   s3     t\^^R88Br5   c                 l    t          dt                      d          }|                     |d           dS )z0Test some of the hard-to-reach parts of SAX2DOM.Nr\   F)r]   SAX2DOMExerciserrW   r^   s     r   test_thorough_sax2domz&ThoroughTestCase.test_thorough_sax2dom   s6    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 )	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   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   __doc__rZ   rQ   rR   r`   rc   rW   rS   r5   r   rU   rU      sn        22H H H      
' ' '
,4 ,4 ,4 ,4 ,4 ,4r5   rU   c                   ,    e Zd ZdZd Zd Zd ZeZeZdS )rX   znA fake sax parser that calls some of the harder-to-reach sax methods to
    ensure it emits the correct eventsc                     || _         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   )	rn   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 )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      sQ        * *       (   KJJJr5   rX   c                       e Zd ZdZd ZdS )rb   zThe same as SAXExerciser, but without the processing instruction and
    comment before the root element, because S2D can"t handle itc                    | j         }|                                 |                    dt          i                      |                    d           |                    dd           |                    dt          ddi                     |                    d           |                    d           |                    d           |                                 d S )	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    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   rj   r   rS   r5   r   rb   rb     s/        D D
 
 
 
 
r5   rb   c                       e Zd ZdZd ZdS )r]   z1Allows us to drive SAX2DOM from a DOMEventStream.c                     t          j                    | _         | j                            t          j        j        j        d           | j                            | j                    d S )Nr7   )	r   SAX2DOMr?   r   xmlsaxr   feature_namespacesro   rY   s    r   resetzSAX2DOMTestHelper.reset!  sN    ((swA1EEE%%dl33333r5   N)rN   rO   rP   rj   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 rm   )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 )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#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B44B8;B8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 )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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   