
    VhT                     n    d Z ddlZddlmZ ddlmZ ddlmZmZm	Z	m
Z
mZ de
de
defd	Z G d
 de      Zy)zW
Tests for L{twisted.web._stan} portion of the L{twisted.web.template}
implementation.
    N)NoReturn)TestCase)CDATACharRefCommentFlattenableTagakwreturnc                  $     t        d      | i |S )z(
    Produce a new tag for testing.
    hello)r	   )r
   r   s     J/home/dcms/DCMS/lib/python3.12/site-packages/twisted/web/test/test_stan.pyprotor      s     3w<!b!!    c                   p    e Zd ZdZddZddZddZddZddZddZ	dd	Z
dd
ZddZddZddZddZy)TagTestsz
    Tests for L{Tag}.
    Nc                     t        d      }| j                  |j                  d       | j                  |j                  i        y)z
        Setting an attribute named C{render} will change the C{render} instance
        variable instead of adding an attribute.
        
myRendererrenderN)r   assertEqualr   
attributesselftags     r   test_renderAttributezTagTests.test_renderAttribute   s6    
 <(\2,r   c                     | j                  t              5 }t        d       ddd       | j                  j                  j
                  d   d       y# 1 sw Y   3xY w)z
        Attempting to set an attribute named C{render} to something other than
        a string will raise L{TypeError}.
        S   r   Nr   z0Value for "render" attribute must be str, got 83)assertRaises	TypeErrorr   r   	exceptionargs)r   es     r   test_renderAttributeNonStringz&TagTests.test_renderAttributeNonString&   sT    
 y) 	Q	KKQ!S	
	 	s   AAc                 \    t               }| j                  ||j                  d             y)z0
        L{Tag.fillSlots} returns self.
        test)r'   N)r   assertIdentical	fillSlotsr   s     r   test_fillSlotszTagTests.test_fillSlots1   s&     gS#--V-"<=r   c                 b   dg}t        d|dd      }|j                  d       d|_        d	|_        d
|_        |j                  d      }| j                  |j                  d   d       | j                  |j                  |j                         | j                  |j                  d|g       | j                  |j                  |j                         | j                  |j                  d   |       | j                  |j                  |j                         | j                  |j                  |j                         | j                  |j                  d       | j                  |j                  d	       | j                  |j                  d
       | j                  |j                  d       y)z
        L{Tag.clone} copies all attributes and children of a tag, including its
        render attribute.  If the shallow flag is C{False}, that's where it
        stops.
        
inner listHow are youworldaSampleMethodr   r   barfoofoo/bar      F)deepr      Nr   r)   filename
lineNumbercolumnNumbercloner   r   assertNotIdenticalchildrenr(   slotDatar   )r   	innerListr   r=   s       r   test_cloneShallowzTagTests.test_cloneShallow8   sR    "N	M9GOT%  		u	%))'2G< 0 0#..A-)CD=U^^A.	:u~~6enn=3))1-++R07r   c                    t        d      }dg}t        d||dd      }|j                  d       d	|_        d
|_        d|_        |j                         }| j                  |j                  d   d       | j                  |j                  |j                         | j                  |j                  |j                         | j                  |j                  d   |       | j                  |j                  d   |       | j                  |j                  d   |       | j                  |j                  d   |       | j                  |j                  |j                         | j                  |j                  |j                         | j                  |j                  d	       | j                  |j                  d
       | j                  |j                  d       | j                  |j                  d       y)z
        L{Tag.clone} copies all attributes and children of a tag, including its
        render attribute.  In its normal operating mode (where the deep flag is
        C{True}, as is the default), it will clone all sub-lists and sub-tags.
        innerr,   r-   r.   r/   r0   r1   r2   r4   r5   r6   r   r8      Nr9   )r   innerTagrA   r   r=   s        r   test_cloneDeepzTagTests.test_cloneDeepQ   s    >!N	8Ygo
 	%  		))'2G< 0 0#..A=S\\!_h7q 18<S\\!_i8q 19=u~~6enn=3))1-++R07r   c                     t        d t        d      D              }| j                  t        dt        j
                  t        j                     j                  |j                         y)z
        Cloning a tag containing a generator is unsafe. To avoid breaking
        programs that only flatten the clone or only flatten the original,
        we deprecate old behavior rather than making it an error immediately.
        c              3   2   K   | ]  }t        |        y wN)str).0ns     r   	<genexpr>z:TagTests.test_cloneGeneratorDeprecation.<locals>.<genexpr>y   s     .qCF.s   
   zCloning a Tag which contains a generator is unsafe, since the generator can be consumed only once; this is deprecated since Twisted 21.7.0 and will raise an exception in the futureN)
r   rangeassertWarnsDeprecationWarningsysmodulesr	   
__module____file__r=   r   s     r   test_cloneGeneratorDeprecationz'TagTests.test_cloneGeneratorDeprecations   sM     .E"I..) KK'00II	
r   c                 "   dt         fd} |       }t        d|d      }	 | j                  t        dt        j
                  t        j                     j                  |j                         |j                          y# |j                          w xY w)z
        Cloning a tag containing a coroutine is unsafe. To avoid breaking
        programs that only flatten the clone or only flatten the original,
        we deprecate old behavior rather than making it an error immediately.
        r   c                     K   t         wrJ   )NotImplementedError r   r   	asyncFuncz:TagTests.test_cloneCoroutineDeprecation.<locals>.asyncFunc   s     %%s   	123789zCloning a Tag which contains a coroutine is unsafe, since the coroutine can run only once; this is deprecated since Twisted 21.7.0 and will raise an exception in the futureN)r   r   rQ   rR   rS   rT   r	   rU   rV   r=   close)r   r\   coror   s       r   test_cloneCoroutineDeprecationz'TagTests.test_cloneCoroutineDeprecation   st    	& 	& {E4'	"- CNN+44		 JJLDJJLs   AA< <Bc                     t        dddd      }|j                          | j                  |j                  g        | j                  |j                  ddi       y)zk
        L{Tag.clear} removes all children from a tag, but leaves its attributes
        in place.
        z	these arer?   coolzthis-attribute)andSoIsrd   N)r   clearr   r?   r   r   s     r   
test_clearzTagTests.test_clear   sL    
 KV=MN		r*)5E)FGr   c                 v    t        d      } |       } |d       | j                  |j                  ddi       y)z
        L{Tag.__call__} accepts Python keywords with a suffixed underscore as
        the DOM attribute of that literal suffix.
        divr
   )class_classN)r	   r   r   )r   r   r   s      r   test_suffixzTagTests.test_suffix   s3    
 E
g3'38r   c                 L    | j                  t        t        d            d       y)zo
        L{Comment.__repr__} returns a value which makes it easy to see what's
        in the comment.
        zhello therezComment('hello there')N)r   reprr   r   s    r   test_commentReprPy3zTagTests.test_commentReprPy3   s    
 	gm457OPr   c                 L    | j                  t        t        d            d       y)zm
        L{CDATA.__repr__} returns a value which makes it easy to see what's in
        the comment.
        z	test datazCDATA('test data')N)r   rm   r   rn   s    r   test_cdataReprPy3zTagTests.test_cdataReprPy3   s    
 	eK013GHr   c                 b    t        d      }| j                  t        t        |            d       y)zw
        L{CharRef.__repr__} returns a value which makes it easy to see what
        character is referred to.
        u   ☃zCharRef(9731)N)ordr   rm   r   )r   snowmans     r   test_charrefReprzTagTests.test_charrefRepr   s(    
 m$gg./Ar   )r   N)__name__rU   __qualname____doc__r   r%   r*   rB   rG   rW   ra   rf   rk   ro   rq   ru   r[   r   r   r   r      sH    -	
>82 8D
"2H9QIBr   r   )rx   rS   typingr   twisted.trial.unittestr   twisted.web.templater   r   r   r   r	   r   r   r[   r   r   <module>r|      sE      + J J"k " " "mBx mBr   