
    Vh'                         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	y)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y)_BaseURLPathTestsz5
    Tests for instantiated L{urlpath.URLPath}s.
    c                    | j                  | j                  j                  t               | j                  | j                  j                  t               | j                  | j                  j                  t               | j                  | j                  j
                  t               | j                  | j                  j                  t               y)zQ
        All of the attributes of L{urlpath.URLPath} should be L{bytes}.
        NassertIsInstancepathschemebytesnetlocqueryfragmentselfs    P/home/dcms/DCMS/lib/python3.12/site-packages/twisted/python/test/test_urlpath.pytest_partsAreBytesz$_BaseURLPathTests.test_partsAreBytes        	dii..6dii..6diinne4diioou5dii00%8    c                 r    | j                  t        | j                  j                               t               y)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   s&     	dii//12C8r   c                 \    |d      | j                   _        | j                  t        | j                         d        |d      | j                   _        | j                  t        | j                         d        |d      | j                   _         | j                  t        | j                         d        |d      | j                   _        | j                  t        | j                         d        |d	      | j                   _        | j                  t        | j                         d
       y)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.				NN	
 &&?@				NJ	
 $H-				NX	
 %%AB				N	

 (1				N	
r   c                 (    | j                  d        y)zC
        Same as L{test_mutabilityWithText} but for bytes.
        c                 $    | j                  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     	$$%@Ar   c                    | j                  | j                  j                  t               | j                  | j                  j                  t               | j                  | j                  j                  t               | j                  | j                  j
                  t               | j                  | j                  j                  t               y)z<
        A created L{URLPath} has bytes attributes.
        Nr   r   s    r   test_allAttributesAreBytesz,_BaseURLPathTests.test_allAttributesAreBytesL   r   r   c                 N    | j                  t        | j                        d       y)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   s     
 			NM	
r   c                 ^   | j                  t        | j                  j                  d            d       | j                  t        | j                  j                  d      j                  d            d       | j                  t        | j                  j                  dd            d       y)	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5/	
 			D9:<	
r   c                 ^   | j                  t        | j                  j                  d            d       | j                  t        | j                  j                  dd            d       | j                  t        | j                  j	                  d      j                  d            d       y)	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    
 	TYY..v679UV		!!&D!9:6	
 			$,,V457W	
r   c                    | j                  t        | j                  j                               d       | j                  t        | j                  j                  d            d       | j                  t        | j                  j	                  d      j                               d       | j                  t        | j                  j	                  d      j                               d       | j                  t        | j                  j                         j                         j                         j                         j                               d       y)	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   s     	TYY--/02GH		  4 013V	
 	TYY__S188:;=VW		'..013L	
 			  "))+224;;=DDFG!	
r   c                 X   | j                  t        | j                  j                               d       | j                  t        | j                  j                  d            d       | j                  t        | j                  j	                  d      j                               d       y)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~     	TYY^^-.0IJ		./1X	
 			$))+,.K	
r   c                     | j                  t        | j                  j                  d            j	                  d      d       y)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   s5     			0188A-	
r   c                 n   | j                  | j                  j                  d      j                         g d       | j                  | j                  j                  d      j                  d      g d       | j                  | j                  j                  d      j                  d      g d       y)	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     	IIOOL)224/	
 	IIOOL)222>/	
 	IIOOL)224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      sJ    99 25 "
HB9

"
&
(
	

r   r   c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)BytesURLPathTestszL
    Tests for interacting with a L{URLPath} created with C{fromBytes}.
    c                 L    t         j                  j                  d      | _        y )Ns/   http://example.com/foo/bar?yes=no&no=yes#footer)r   URLPath	fromBytesr
   r   s    r   setUpzBytesURLPathTests.setUp   s    OO-->
	r   c                 (   | j                  t              5  t        j                  j	                  d       ddd       | j                  t              5  t        j                  j	                  d       ddd       y# 1 sw Y   GxY w# 1 sw Y   yxY w)zE
        L{URLPath.fromBytes} must take a L{bytes} argument.
        Nsomeurl)assertRaises
ValueErrorr   rP   rQ   r   s    r   test_mustBeBytesz"BytesURLPathTests.test_mustBeBytes   su     z* 	,OO%%d+	, z* 	1OO%%i0	1 	1	, 	,	1 	1    A< B<BBc                 b    t        j                         }| j                  t        |      d       y)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   s%    
 ooS#67r   c                    t         j                  j                  d      }| j                  |j                  d       | j                  |j
                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  t        |      d       y)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     oo''(<=W-]34(s+C(S#78r   c                 x    t         j                  j                  d      }| j                  t	        |      d       y)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.     oo''(FGS#>?r   N)	rH   rI   rJ   rK   rR   rW   r\   r_   ra   rL   r   r   rN   rN      s!    

189@r   rN   c                       e Zd ZdZd Zd Zy)StringURLPathTestsg
    Tests for interacting with a L{URLPath} created with C{fromString} and a
    L{str} argument.
    c                 L    t         j                  j                  d      | _        y Nr+   r   rP   
fromStringr
   r   s    r   rR   zStringURLPathTests.setUp      OO..=
	r   c                 (   | j                  t              5  t        j                  j	                  d       ddd       | j                  t              5  t        j                  j	                  d       ddd       y# 1 sw Y   GxY w# 1 sw Y   yxY w)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  su     z* 	-OO&&t,	- z* 	3OO&&z2	3 	3	- 	-	3 	3rX   N)rH   rI   rJ   rK   rR   rk   rL   r   r   rc   rc      s    


3r   rc   c                       e Zd ZdZd Zd Zy)UnicodeURLPathTestsrd   c                 L    t         j                  j                  d      | _        y rf   rg   r   s    r   rR   zUnicodeURLPathTests.setUp  ri   r   c                 x    t         j                  j                  d      }| j                  t	        |      d       y)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.     oo(()FGS#ABr   N)rH   rI   rJ   rK   rR   rp   rL   r   r   rm   rm     s    


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