
    tf'                         d Z ddlmZ ddlmZ  G d d          Z G d deej                  Z G d d	eej                  Z G d
 deej                  Z	dS )z&
Tests for L{twisted.python.urlpath}.
    )urlpath)unittestc                   ^    e Zd ZdZd Zd ZefdZd Zd Z	d Z
d Zd	 Zd
 Zd Zd Zd ZdS )_BaseURLPathTestsz5
    Tests for instantiated L{urlpath.URLPath}s.
    c                 x   |                      | j        j        t                     |                      | j        j        t                     |                      | j        j        t                     |                      | j        j        t                     |                      | j        j        t                     dS )zQ
        All of the attributes of L{urlpath.URLPath} should be L{bytes}.
        NassertIsInstancepathschemebytesnetlocqueryfragmentselfs    _/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/python/test/test_urlpath.pytest_partsAreBytesz$_BaseURLPathTests.test_partsAreBytes        	di.666di.666dine444diou555di0%88888    c                     |                      t          | j                                                  t                     dS )zQ
        Calling C{str()} with a L{URLPath} will always return a L{str}.
        N)assertEqualtyper
   __str__strr   s    r   test_strReturnsStrz$_BaseURLPathTests.test_strReturnsStr   s6     	di//1122C88888r   c                 h    |d          | j         _        |                     t          | j                   d            |d          | j         _        |                     t          | j                   d            |d          | j         _         |                     t          | j                   d            |d          | j         _        |                     t          | j                   d            |d	          | j         _        |                     t          | j                   d
           dS )a?  
        Setting attributes on L{urlpath.URLPath} should change the value
        returned by L{str}.

        @param stringType: a callable to parameterize this test for different
            text types.
        @type stringType: 1-argument callable taking L{str} and returning
            L{str} or L{bytes}.
        httpsz0https://example.com/foo/bar?yes=no&no=yes#footerzanother.example.invalidz<https://another.example.invalid/foo/bar?yes=no&no=yes#footerz/helloz:https://another.example.invalid/hello?yes=no&no=yes#footerzalpha=omega&opposites=samezGhttps://another.example.invalid/hello?alpha=omega&opposites=same#footerheaderzGhttps://another.example.invalid/hello?alpha=omega&opposites=same#headerN)r
   r   r   r   r   r   r   )r   
stringTypes     r   test_mutabilityWithTextz)_BaseURLPathTests.test_mutabilityWithText"   s<    &:g..		NNN	
 	
 	
 &:&?@@		NNJ	
 	
 	
 $H--		NNX	
 	
 	
 %*%ABB		NN	
 	
 	

 (Z11		NN	
 	
 	
 	
 	
r   c                 2    |                      d            dS )zC
        Same as L{test_mutabilityWithText} but for bytes.
        c                 ,    |                      d          S )Nascii)encode)xs    r   <lambda>z<_BaseURLPathTests.test_mutabilityWithBytes.<locals>.<lambda>J   s    qxx/@/@ r   N)r    r   s    r   test_mutabilityWithBytesz*_BaseURLPathTests.test_mutabilityWithBytesF   s"     	$$%@%@AAAAAr   c                 x   |                      | j        j        t                     |                      | j        j        t                     |                      | j        j        t                     |                      | j        j        t                     |                      | j        j        t                     dS )z<
        A created L{URLPath} has bytes attributes.
        Nr   r   s    r   test_allAttributesAreBytesz,_BaseURLPathTests.test_allAttributesAreBytesL   r   r   c                 V    |                      t          | j                  d           dS )zs
        Calling C{str()} with a L{URLPath} will return the same URL that it was
        constructed with.
        /http://example.com/foo/bar?yes=no&no=yes#footerN)r   r   r
   r   s    r   test_stringConversionz'_BaseURLPathTests.test_stringConversionV   s4    
 		NNM	
 	
 	
 	
 	
r   c                    |                      t          | j                            d                    d           |                      t          | j                            d                              d                    d           |                      t          | j                            dd                    d           dS )	z
        Calling C{str()} with a C{URLPath.child()} will return a URL which is
        the child of the URL it was instantiated with.
        s   helloz http://example.com/foo/bar/hellor   z!http://example.com/foo/bar/hello/T	keepQueryz.http://example.com/foo/bar/hello?yes=no&no=yesN)r   r   r
   childr   s    r   test_childStringz"_BaseURLPathTests.test_childString_   s    
 		))**,N	
 	
 	
 		))//4455/	
 	
 	
 		D99::<	
 	
 	
 	
 	
r   c                    |                      t          | j                            d                    d           |                      t          | j                            dd                    d           |                      t          | j                            d                              d                    d           dS )	z
        Calling C{str()} with a C{URLPath.sibling()} will return a URL which is
        the sibling of the URL it was instantiated with.
           bazzhttp://example.com/foo/bazTr.   z(http://example.com/foo/baz?yes=no&no=yesr   zhttp://example.com/foo/bar/bazN)r   r   r
   siblingr0   r   s    r   test_siblingStringz$_BaseURLPathTests.test_siblingStringp   s    
 	TY..v66779UVVV	!!&D!99::6	
 	
 	
 		$$,,V44557W	
 	
 	
 	
 	
r   c                 *   |                      t          | j                                                  d           |                      t          | j                            d                    d           |                      t          | j                            d                                                    d           |                      t          | j                            d                                                    d           |                      t          | j                                                                                                                                                                                  d           dS )	z
        Calling C{str()} with a C{URLPath.parent()} will return a URL which is
        the parent of the URL it was instantiated with.
        zhttp://example.com/Tr.   z!http://example.com/?yes=no&no=yesr   http://example.com/foo/r3   N)r   r   r
   parentr0   r   s    r   test_parentStringz#_BaseURLPathTests.test_parentString   sU    	TY--//002GHHH	  4 00113V	
 	
 	
 	TY__S1188::;;=VWWW	''..00113L	
 	
 	
 		  ""))++2244;;==DDFFGG!	
 	
 	
 	
 	
r   c                    |                      t          | j                                                  d           |                      t          | j                            d                    d           |                      t          | j                            d                                                    d           dS )z
        Calling C{str()} with a C{URLPath.here()} will return a URL which is
        the URL that it was instantiated with, without any file, query, or
        fragment.
        r7   Tr.   z%http://example.com/foo/?yes=no&no=yesr   zhttp://example.com/foo/bar/N)r   r   r
   herer0   r   s    r   test_hereStringz!_BaseURLPathTests.test_hereString   s     	TY^^--..0IJJJ	..//1X	
 	
 	
 		$$))++,,.K	
 	
 	
 	
 	
r   c                     |                      t          | j                            d                                        d          d           dS )z
        Calling L{urlpath.URLPath.click} on a L{urlpath.URLPath} with a
        trailing slash with a relative URL containing a leading slash will
        result in a URL with a single slash at the start of the path portion.
        s   /hello/worldr#   s   http://example.com/hello/worldN)r   r   r
   clickr$   r   s    r   test_doubleSlashz"_BaseURLPathTests.test_doubleSlash   sP     		001188AA-	
 	
 	
 	
 	
r   c                    |                      | j                            d                                          g d           |                      | j                            d                              d          g d           |                      | j                            d                              d          g d           dS )	zL
        L{urlpath.URLPath.pathList} returns a L{list} of L{bytes}.
        	   %00%01%02)r      foo   barrA   F)copyT)unquote)r   rB   rC   s    N)r   r
   r0   pathListr   s    r   test_pathListz_BaseURLPathTests.test_pathList   s     	IOOL))2244///	
 	
 	
 	IOOL))222>>///	
 	
 	
 	IOOL))2242@@222	
 	
 	
 	
 	
r   N)__name__
__module____qualname____doc__r   r   r   r    r'   r)   r,   r1   r5   r9   r<   r?   rG    r   r   r   r      s         9 9 99 9 9 25 "
 "
 "
 "
HB B B9 9 9
 
 

 
 
"
 
 
&
 
 
(
 
 
	
 	
 	

 
 
 
 
r   r   c                   0    e Zd ZdZd Zd Zd Zd Zd ZdS )BytesURLPathTestszL
    Tests for interacting with a L{URLPath} created with C{fromBytes}.
    c                 N    t           j                            d          | _        d S )Ns/   http://example.com/foo/bar?yes=no&no=yes#footer)r   URLPath	fromBytesr
   r   s    r   setUpzBytesURLPathTests.setUp   s"    O-->
 
			r   c                 L   |                      t                    5  t          j                            d           ddd           n# 1 swxY w Y   |                      t                    5  t          j                            d           ddd           dS # 1 swxY w Y   dS )zE
        L{URLPath.fromBytes} must take a L{bytes} argument.
        Nsomeurl)assertRaises
ValueErrorr   rP   rQ   r   s    r   test_mustBeBytesz"BytesURLPathTests.test_mustBeBytes   s    z** 	, 	,O%%d+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, z** 	1 	1O%%i000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1#    AAA, BB Bc                 r    t          j                    }|                     t          |          d           dS )zp
        An instantiation with no arguments creates a usable L{URLPath} with
        default arguments.
        zhttp://localhost/N)r   rP   r   r   r   urls     r   test_withoutArgumentsz'BytesURLPathTests.test_withoutArguments   s4    
 oS#677777r   c                    t           j                            d          }|                     |j        d           |                     |j        d           |                     |j        d           |                     |j        d           |                     |j        d           |                     t          |          d           dS )z
        Leaving some optional arguments unfilled makes a L{URLPath} with those
        optional arguments filled with defaults.
        s   http://google.coms   https
   google.com   /r   zhttp://google.com/N)
r   rP   rQ   r   r   r   r
   r   r   r   rZ   s     r   test_partialArgumentsz'BytesURLPathTests.test_partialArguments   s     o''(<==W---]3334(((s+++C(((S#788888r   c                     t           j                            d          }|                     t	          |          d           dS )zW
        L{URLPath.fromBytes} can interpret non-ASCII bytes as percent-encoded
        s   http://example.com/ zhttp://example.com/%FF%00N)r   rP   rQ   r   r   rZ   s     r   test_nonASCIIBytesz$BytesURLPathTests.test_nonASCIIBytes   s=     o''(FGGS#>?????r   N)	rH   rI   rJ   rK   rR   rW   r\   r_   ra   rL   r   r   rN   rN      sn         
 
 

1 1 18 8 89 9 9@ @ @ @ @r   rN   c                       e Zd ZdZd Zd ZdS )StringURLPathTestsg
    Tests for interacting with a L{URLPath} created with C{fromString} and a
    L{str} argument.
    c                 N    t           j                            d          | _        d S Nr+   r   rP   
fromStringr
   r   s    r   rR   zStringURLPathTests.setUp  "    O..=
 
			r   c                 L   |                      t                    5  t          j                            d           ddd           n# 1 swxY w Y   |                      t                    5  t          j                            d           ddd           dS # 1 swxY w Y   dS )zN
        C{URLPath.fromString} must take a L{str} or L{str} argument.
        Ns   someurl)rU   rV   r   rP   rh   r   s    r   test_mustBeStrz!StringURLPathTests.test_mustBeStr  s    z** 	- 	-O&&t,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- z** 	3 	3O&&z222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3rX   N)rH   rI   rJ   rK   rR   rk   rL   r   r   rc   rc      s<         

 
 

3 3 3 3 3r   rc   c                       e Zd ZdZd Zd ZdS )UnicodeURLPathTestsrd   c                 N    t           j                            d          | _        d S rf   rg   r   s    r   rR   zUnicodeURLPathTests.setUp  ri   r   c                     t           j                            d          }|                     t	          |          d           dS )zF
        L{URLPath.fromString} can load non-ASCII characters.
        u   http://example.com/ÿ zhttp://example.com/%C3%BF%00N)r   rP   rh   r   r   rZ   s     r   test_nonASCIICharactersz+UnicodeURLPathTests.test_nonASCIICharacters  s=     o(()FGGS#ABBBBBr   N)rH   rI   rJ   rK   rR   rp   rL   r   r   rm   rm     sA         

 
 

C C C C Cr   rm   N)
rK   twisted.pythonr   twisted.trialr   r   TestCaserN   rc   rm   rL   r   r   <module>rt      s  
  # " " " " " " " " " " "x
 x
 x
 x
 x
 x
 x
 x
v0@ 0@ 0@ 0@ 0@)8+< 0@ 0@ 0@f3 3 3 3 3*H,= 3 3 3,C C C C C+X-> C C C C Cr   