
    Vhxu                        d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 dZd	Zg d
Zd Z G d de      Z G d de      Z G d de      Zy)z"
Tests for L{twisted.python.url}.
    )annotations)Iterable)Protocol)SynchronousTestCase   URL*http://www.foo.com/a/nice/path/?zot=23&zuthttp://a/b/c/d;p?q)()ghttp://a/b/c/g)z./gr   )zg/http://a/b/c/g/)z/g
http://a/g)z//gzhttp://g)z?yzhttp://a/b/c/d;p?y)zg?yzhttp://a/b/c/g?y)z#szhttp://a/b/c/d;p?q#s)zg#szhttp://a/b/c/g#s)zg?y#szhttp://a/b/c/g?y#s)z;xzhttp://a/b/c/;x)zg;xzhttp://a/b/c/g;x)zg;x?y#szhttp://a/b/c/g;x?y#s) r   ).http://a/b/c/)z./r   )..http://a/b/)z../r   )z../ghttp://a/b/g)z../..	http://a/)z../../r   )z../../gr   )z
../../../gr   )z../../../../gr   )z/./gr   )z/../gr   )zg.zhttp://a/b/c/g.)z.gzhttp://a/b/c/.g)zg..zhttp://a/b/c/g..)z..gzhttp://a/b/c/..g)z./../gr   )z./g/.r   )zg/./hzhttp://a/b/c/g/h)zg/../hzhttp://a/b/c/h)z	g;x=1/./yzhttp://a/b/c/g;x=1/y)z
g;x=1/../yzhttp://a/b/c/y)zg?y/./xzhttp://a/b/c/g?y/./x)zg?y/../xzhttp://a/b/c/g?y/../x)zg#s/./xzhttp://a/b/c/g#s/./x)zg#s/../xzhttp://a/b/c/g#s/../xc                2    dj                  d | D              S )Nr   c              3  8   K   | ]  }d t        |      z    yw)z%%%02XN)ord).0cs     L/home/dcms/DCMS/lib/python3.12/site-packages/twisted/python/test/test_url.py	<genexpr>z<lambda>.<locals>.<genexpr>L   s     =a3q6 1=s   )join)ss    r   <lambda>r    L   s    =1==     c                      e Zd Zedd       Zy)_HasExceptionc                     y )N selfs    r   	exceptionz_HasException.exceptionP   s    r!   N)returnBaseException)__name__
__module____qualname__propertyr(   r%   r!   r   r#   r#   O   s     r!   r#   c                     e Zd ZdZd/dZ	 d0	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d1dZd2dZd2dZd2dZd2dZ	d2dZ
d2d	Zd2d
Zd2dZd2dZd2dZd2dZd2dZd2dZd2dZd2dZd2dZd2dZd2dZd2dZd2dZd2dZd2dZd2dZd2dZd2dZd2dZd2dZ d2dZ!d2d Z"d2d!Z#d2d"Z$d2d#Z%d2d$Z&d2d%Z'd2d&Z(d2d'Z)d2d(Z*d2d)Z+d2d*Z,d2d+Z-d2d,Z.d2d-Z/y.)3TestURLz
    Tests for L{URL}.
    c                (   | j                  |j                  t        t        |             | j                  |j                  t        t        |             |j
                  D ]"  }| j                  |t        t        |             $ |j                  D ]T  \  }}| j                  |t        t        |             | j                  |du xs t        |t              t        |             V | j                  |j                  t        t        |             y)zl
        The given L{URL}'s components should be L{unicode}.

        @param u: The L{URL} to test.
        N)
assertIsInstanceschemestrreprhostpathquery
assertTrue
isinstancefragment)r'   usegkvs        r   assertUnicodedzTestURL.assertUnicodedZ   s     	ahhT!W5affc47366 	5C!!#sDG4	5GG 	FDAq!!!S$q'2OOAI;As);T!WE	F 	ajj#tAw7r!   c	                   |j                   |j                  |j                  |j                  |j                  |j
                  |j                  f}	||t        |      t        |      |||j                  f}
| j                  |	|
       y)a  
        The given L{URL} should have the given components.

        @param u: The actual L{URL} to examine.

        @param scheme: The expected scheme.

        @param host: The expected host.

        @param path: The expected path.

        @param query: The expected query.

        @param fragment: The expected fragment.

        @param port: The expected port.

        @param userinfo: The expected userinfo.
        N)	r3   r6   r7   r8   r;   portuserinfotupleassertEqual)r'   r<   r3   r6   r7   r8   r;   rB   rC   actualexpecteds              r   	assertURLzTestURL.assertURLi   sd    < ((AFFAFFAGGQZZTD%+uU|XtQZZX*r!   c           	          d fd} |t        dd              |t        ddg g               |t        ddg g d             y)z@
        L{URL} should have appropriate default values.
        c           
     X    j                  |        j                  | ddg g ddd       y )Nhttpr   P   )r@   rH   )r<   r'   s    r   checkz(TestURL.test_initDefaults.<locals>.check   s+    "NN1fb"b"b"=r!   rK   r   Nr<   r	   r)   Noner   )r'   rM   s   ` r   test_initDefaultszTestURL.test_initDefaults   s@    
	> 	c&"oc&"b"%&c&"b"b)*r!   c           	         t        dddgddgd      }| j                  |       | j                  |dddgddgdd       | j                  t        dd	d
gdgd      dd	d
gdgdd       y)z=
        L{URL} should accept L{unicode} parameters.
        r   hpr>   r?   )r>   NfNrK      à   é)u   λu   πu   ⊥rL   r	   r@   rH   r'   r<   s     r   	test_initzTestURL.test_init   s     S3%*k!:C@Aq#sSEJ+Dc4P+?*@(KH!"	
r!   c           	     ~    t        dddgddgd      }| j                  |       | j                  |dddgddgdd       y)zN
        L{URL} should accept (and not interpret) percent characters.
        r   z%68z%70)%6Bz%76)r\   Nz%66NrX   rY   s     r   test_initPercentzTestURL.test_initPercent   sM     UUGnm%DeLAsEE7^]$CUD	
r!   c                    | j                  t        t        dddgddgd            dj                  t        d	                   y
)z
        L{URL.__repr__} will display the canonical form of the URL, wrapped in
        a L{URL.fromText} invocation, so that it is C{eval}-able but still easy
        to read.
        rK   foobar)bazNrT   frob)r3   r6   r7   r8   r;   zURL.from_text({})zhttp://foo/bar?baz&k=v#frobN)rE   r5   r	   formatr&   s    r   	test_reprzTestURL.test_repr   sN     	!(*5#  &&t,I'JK	
r!   c                ~    t        j                  t              }| j                  t        |j	                                y)zb
        Round-tripping L{URL.fromText} with C{str} results in an equivalent
        URL.
        N)r	   fromTexttheurlrE   asTextr'   urlpaths     r   test_fromTextzTestURL.test_fromText   s)    
 ,,v&!12r!   c                    d}|D ]7  }t        j                  |      j                         }| j                  ||       9 y)z>
        L{URL.asText} should invert L{URL.fromText}.
        )zhttp://localhosthttp://localhost/zhttp://localhost/foozhttp://localhost/foo/zhttp://localhost/foo!!bar/zhttp://localhost/foo%20bar/zhttp://localhost/foo%2Fbar/zhttp://localhost/foo?nzhttp://localhost/foo?n=vzhttp://localhost/foo?n=/a/bz%http://example.com/foo!@$bar?b!@z=123z$http://localhost/asd?a=asd%20sdf/345z6http://(%2525)/(%2525)?(%2525)&(%2525)=(%2525)#(%2525)z<http://(%C3%A9)/(%C3%A9)?(%C3%A9)&(%C3%A9)=(%C3%A9)#(%C3%A9)N)r	   rf   rh   rE   )r'   teststestresults       r   test_roundtripzTestURL.test_roundtrip   sA    
   	+D\\$'..0FT6*	+r!   c                    t        j                  t              }| j                  |t        j                  t                     | j	                  |t        j                  d             y)z
        Two URLs decoded using L{URL.fromText} will be equal (C{==}) if they
        decoded same URL string, and unequal (C{!=}) if they decoded different
        strings.
        z:ftp://www.anotherinvaliddomain.com/foo/bar/baz/?zot=21&zutN)r	   rf   rg   rE   assertNotEqualri   s     r   test_equalityzTestURL.test_equality   sK     ,,v&#,,v"67LLO	
r!   c                    | j                  t        d      t                      | j                  t        j                  d      t        j                  d             y)z
        An URL created with the empty string for a fragment compares equal
        to an URL created with an unspecified fragment.
        r   )r;   zhttp://localhost/#rm   N)rE   r	   rf   r&   s    r   test_fragmentEqualityzTestURL.test_fragmentEquality   sB    
 	b)351LL-.=P0Q	
r!   c                   t        j                  t              }| j                  d|j	                  d      j                                | j                  d|j	                  d      j                                | j                  d|j	                  d      j                                | j                  d|j	                  d      j                                y	)
zm
        L{URL.child} appends a new path segment, but does not affect the query
        or fragment.
        z.http://www.foo.com/a/nice/path/gong?zot=23&zutgongz1http://www.foo.com/a/nice/path/gong%2F?zot=23&zutzgong/z7http://www.foo.com/a/nice/path/gong%2Fdouble?zot=23&zutzgong/doublez:http://www.foo.com/a/nice/path/gong%2Fdouble%2F?zot=23&zutzgong/double/N)r	   rf   rg   rE   childrh   ri   s     r   
test_childzTestURL.test_child   s    
 ,,v&<MM&!((*	
 	?MM'"))+	
 	EMM-(//1	
 	HMM.)002	
r!   c                    | j                  t        j                  d      j                  ddd      j	                         d       y)zg
        L{URL.child} receives multiple segments as C{*args} and appends each in
        turn.
        zhttp://example.com/a/br   dezhttp://example.com/a/b/c/d/eN)rE   r	   rf   ry   rh   r&   s    r   test_multiChildzTestURL.test_multiChild  s:    
 	LL1288c3GNNP*	
r!   c                    t        d      j                  d      }| j                  |j                         | j	                  d|j                                y)zo
        L{URL.child} of a L{URL} without a path produces a L{URL} with a single
        path segment.
        www.foo.comr6   r   zhttp://www.foo.com/cN)r	   ry   r9   rootedrE   rh   )r'   childURLs     r   test_childInitRootzTestURL.test_childInitRoot!  sA    
 M*005(/1BCr!   c                    t        j                  t              }| j                  d|j	                  d      j                                d}t        j                  |      }| j                  d|j	                  d      j                                y)z
        L{URL.sibling} of a L{URL} replaces the last path segment, but does not
        affect the query or fragment.
        z0http://www.foo.com/a/nice/path/sister?zot=23&zutsisterz)http://www.foo.com/a/nice/path?zot=23&zutz+http://www.foo.com/a/nice/sister?zot=23&zutN)r	   rf   rg   rE   siblingrh   )r'   rj   theurl2s      r   test_siblingzTestURL.test_sibling*  ss    
 ,,v&>OOH%,,.	

 >,,w'9OOH%,,.	
r!   c                   t        j                  t              }| j                  d|j	                  d      j                                | j                  d|j	                  d      j                                | j                  d|j	                  d      j                                | j                  d|j	                  d      j                                | j                  d	|j	                  d
      j                                t        j                  d      }| j                  d|j	                  d      j                                t        j                  d      }| j                  |j	                  d      j                         d       y)z
        L{URL.click} interprets the given string as a relative URI-reference
        and returns a new L{URL} interpreting C{self} as the base absolute URI.
        r
   r   z$http://www.foo.com/a/nice/path/clickclickzhttp://www.foo.com/clickz/clickz$http://www.foo.com/a/nice/path/?burpz?burpz//foobarzhttp://www.foo.com/foobarzhttp://www.foo.com/me/noqueryz!http://www.foo.com/me/17?spam=158z/me/17?spam=158zhttp://localhost/foo?abc=defzhttp://www.python.orgN)r	   rf   rg   rE   r   rh   assertNotIn)r'   rj   r<   s      r   
test_clickzTestURL.test_click<  s?   
 ,,v&8'--:K:R:R:T	
 	2GMM'4J4Q4Q4S	
 	3W]]85L5S5S5UV2GMM'4J4Q4Q4S	

 	&ABIIK	
 LL89/9J1K1R1R1T	
 LL78GG+,3357N	
r!   c                    t        j                  t              }t        D ]4  \  }}| j	                  |j                  |      j                         |       6 y)zQ
        L{URL.click} should correctly resolve the examples in RFC 3986.
        N)r	   rf   relativeLinkBaseForRFC3986relativeLinkTestsForRFC3986rE   r   rh   )r'   baserefrG   s       r   test_clickRFC3986zTestURL.test_clickRFC3986d  sI     ||678 	AMCTZZ_335x@	Ar!   c                    t        j                  t              }| j                  t        |j
                  d       | j                  t        |j
                  d       y)zM
        L{URL.click} should not accept schemes with relative paths.
        zg:hzhttp:hN)r	   rf   r   assertRaisesNotImplementedErrorr   )r'   r   s     r   test_clickSchemeRelPathzTestURL.test_clickSchemeRelPathl  sA     ||67-tzz5A-tzz8Dr!   c           
     2   t        j                  d      }| j                  |j                  |j                  |j
                  |j                  |j                  |j                  |j                        |       | j                  |j                         |       y)zf
        Verify that L{URL.replace} doesn't change any of the arguments it
        is passed.
        zhttps://x:1/y?z=1#AN)
r	   rf   rE   replacer3   r6   r7   r8   r;   rB   ri   s     r   test_cloneUnchangedzTestURL.test_cloneUnchangedt  sw    
 ,,45OO   
	
 	*G4r!   c                .   g dg dg dg dg dg dg dg dg d	g d
g dg dg dg}|D ]g  \  }}}t        j                  |      j                  |      j                         }| j	                  ||dj                  |t        |      ||             i y)zd
        L{URL.click} collapses C{.} and C{..} according to RFC 3986 section
        5.2.4.
        )rm   r   rm   )rm   r   rm   )http://localhost/a/b/cr   zhttp://localhost/a/b/)r   r   zhttp://localhost/a/)r   z./d/ezhttp://localhost/a/b/d/e)r   ../d/ehttp://localhost/a/d/e)r   z/./d/ehttp://localhost/d/e)r   z/../d/er   )zhttp://localhost/a/b/c/z
../../d/e/zhttp://localhost/a/d/e/)zhttp://localhost/a/./cr   r   )zhttp://localhost/a/./c/r   r   )zhttp://localhost/a/b/c/dz./e/../f/../gzhttp://localhost/a/b/c/g)r   zd//ezhttp://localhost/a/b/d//ez1{start}.click({click}) => {actual} not {expected})startr   rF   rG   N)r	   rf   r   rh   rE   rc   r5   )r'   rn   r   r   rG   rF   s         r   test_clickCollapsezTestURL.test_clickCollapse  s     <<DCKJHIPHKUK
 ', 	"E5(\\%(..u5<<>FCJJu+!%	 K 		r!   c                j   | j                  dt        j                  d      j                  dd      j	                                | j                  dt        d      j                  dd      j	                                t        j                  t
              }| j                  d|j                  d	      j	                                | j                  d
|j                  d	d      j	                                | j                  d|j                  d	d      j                  d      j	                                | j                  d|j                  d      j                  d	d      j	                                | j                  d|j                  d	d      j                  dd      j	                                y)z3
        L{URL.add} adds query parameters.
        z'http://www.foo.com/a/nice/path/?foo=barzhttp://www.foo.com/a/nice/path/r_   r`   zhttp://www.foo.com/?foo=barr   r   z/http://www.foo.com/a/nice/path/?zot=23&zut&burpburpz3http://www.foo.com/a/nice/path/?zot=23&zut&burp=xxxxxxz8http://www.foo.com/a/nice/path/?zot=23&zut&burp=xxx&zingzingz8http://www.foo.com/a/nice/path/?zot=23&zut&zing&burp=xxxz:http://www.foo.com/a/nice/path/?zot=23&zut&burp=xxx&zot=32zot32N)rE   r	   rf   addrh   rg   ri   s     r   test_queryAddzTestURL.test_queryAdd  sj    	5LL:;??uMTTV	
 	)]#''u5<<>	
 ,,v&=KK&&(	
 	AKK&--/	
 	FKK&**6299;	

 	FKK##FE299;	

 	HKK&**5$7>>@	
r!   c                   t        j                  t              }| j                  d|j	                  dd      j                                | j                  d|j	                  d      j	                  dd      j                                | j                  d|j                  dd      j	                  dd      j                                y)	z?
        L{URL.set} replaces query parameters by name.
        z*http://www.foo.com/a/nice/path/?zot=32&zutr   r   z0http://www.foo.com/a/nice/path/?zot&zut=itworkedzutitworkedr   N)r	   rf   rg   rE   setrh   r   ri   s     r   test_querySetzTestURL.test_querySet  s     ,,v&8KKt$++-	

 	>KK""5*5<<>	
 	8KKu%))%6==?	
r!   c                    t        j                  d      }| j                  |j                  d      t        j                  d             y)zK
        L{URL.remove} removes all instances of a query parameter.
        z*https://example.com/a/b/?foo=1&bar=2&foo=3r_   zhttps://example.com/a/b/?bar=2N)r	   rf   rE   remover'   urls     r   test_queryRemovezTestURL.test_queryRemove  s9     llGHJJus||,LM	
r!   c                T    | j                  t               j                         d       y)zG
        An empty L{URL} should serialize as the empty string.
        r   N)rE   r	   rh   r&   s    r   
test_emptyzTestURL.test_empty  s     	,r!   c                ^    t        dg      }| j                  |j                         d       y)zP
        An L{URL} with query text should serialize as just query text.
        helloworldr8   z?hello=worldN)r	   rE   rh   rY   s     r   test_justQueryTextzTestURL.test_justQueryText  s(     )*+^4r!   c                R    t        j                  d      }| j                  ||       y)z2
        L{URL} compares equal to itself.
        rm   Nr	   rf   rE   rY   s     r   test_identicalEqualzTestURL.test_identicalEqual  s#     LL,-Ar!   c                |    t        j                  d      }t        j                  d      }| j                  ||       y)zG
        URLs with equivalent components should compare equal.
        rm   Nr   r'   u1u2s      r   test_similarEqualzTestURL.test_similarEqual  s2     \\-.\\-.R r!   c                    t        j                  d      }t        j                  d      }| j                  ||k(  |d|       | j                  ||       y)z|
        L{URL}s that refer to different resources are both unequal (C{!=}) and
        also not equal (not C{==}).
        http://localhost/ahttp://localhost/b != N)r	   rf   assertFalsers   r   s      r   test_differentNotEqualzTestURL.test_differentNotEqual  sQ    
 \\./\\./rbV4v#67B#r!   c                    t        j                  d      }| j                  |dk(  d       | j                  |t               k(  d       | j	                  |d       | j	                  |t                      y)z=
        L{URL} is not equal (C{==}) to other types.
        rm   *   zURL must not equal a number.zURL must not equal an object.N)r	   rf   r   objectrs   rY   s     r   test_otherTypesNotEqualzTestURL.test_otherTypesNotEqual  sa     LL,-b"@Afh(GHAr"Avx(r!   c                ^    t        j                  d      }| j                  ||k7  d|z         y)zJ
        Identical L{URL}s are not unequal (C{!=}) to each other.
        rm   z%r == itselfNr	   rf   r   rY   s     r   test_identicalNotUnequalz TestURL.test_identicalNotUnequal  s,     LL,-a!!34r!   c                    t        j                  d      }t        j                  d      }| j                  ||k7  |d|       y)zU
        Structurally similar L{URL}s are not unequal (C{!=}) to each other.
        rm    == Nr   r   s      r   test_similarNotUnequalzTestURL.test_similarNotUnequal!  sA     \\-.\\-.rbV4v#67r!   c                    t        j                  d      }t        j                  d      }| j                  ||k7  |d|       y)zS
        Structurally different L{URL}s are unequal (C{!=}) to each other.
        r   r   r   N)r	   rf   r9   r   s      r   test_differentUnequalzTestURL.test_differentUnequal)  s?     \\./\\./bRF$rf"56r!   c                    t        j                  d      }| j                  |dk7  d       | j                  |t               k7  d       y)z;
        L{URL} is unequal (C{!=}) to other types.
        rm   r   zURL must differ from a number.z"URL must be differ from an object.N)r	   rf   r9   r   rY   s     r   test_otherTypesUnequalzTestURL.test_otherTypesUnequal1  s;     LL,-R!ABVX'KLr!   c                \   d}t        j                  |      }|j                         }| j                  |j                  d       | j                  |j
                  d   d       | j                  |j                         |       d}|j                         }| j                  |||d|       y)z
        L{URL.asURI} produces an URI which converts any URI unicode encoding
        into pure US-ASCII and returns a new L{URL}.
           http://é.com/é?á=í#úu   é.comr   u   é.http://xn--9ca.com/%C3%A9?%C3%A1=%C3%AD#%C3%BAr   N)r	   rf   asURIrE   r6   r7   rh   )r'   unicodeyiriuriexpectedURI	actualURIs         r   
test_asURIzTestURL.test_asURI9  s    B 	 ll8$iik#LMHHQKM	
 	x0FJJL	KI=[O1TUr!   c                \   d}t        j                  |      }|j                         }| j                  |j                  d       | j                  |j
                  d   d       | j                  |j                         |       d}|j                         }| j                  |||d|       y)z
        L{URL.asIRI} decodes any percent-encoded text in the URI, making it
        more suitable for reading by humans, and returns a new L{URL}.
        r   zxn--9ca.comr   z%C3%A9u   http://é.com/é?á=í#úr   N)r	   rf   asIRIrE   r6   r7   rh   )r'   asciiishr   r   expectedIRI	actualIRIs         r   
test_asIRIzTestURL.test_asIRIP  s    
 Dll8$iik=1!h/x03 	 JJL	KI=[O1TUr!   c                    d}t        j                  |      }|j                         }d}|j                         }| j	                  |||d|       y)z
        Bad UTF-8 in a path segment, query parameter, or fragment results in
        that portion of the URI remaining percent-encoded in the IRI.
        z http://xn--9ca.com/%00%FF/%C3%A9u   http://é.com/%00%FF/ér   N)r	   rf   r   rh   rE   )r'   urlWithBinaryr   r   r   r   s         r   test_badUTF8AsIRIzTestURL.test_badUTF8AsIRIe  sV    
 ;ll=)iik2 	
 JJL	KI=[O1TUr!   c                    d}t        j                  |      }|j                         }| j                  |j	                         |       y)zT
        A L{URL} composed of non-ASCII text will result in non-ASCII text.
        r   N)r	   rf   r   rE   rh   )r'   r   r   alsoIRIs       r   test_alreadyIRIAsIRIzTestURL.test_alreadyIRIAsIRIu  s?    
B 	 ll8$))+)84r!   c                    d}t        j                  |      }|j                         j                         }| j	                  ||       y)zH
        A L{URL} composed of encoded text will remain encoded.
        r   N)r	   rf   r   rh   rE   )r'   r   r   r   s       r   test_alreadyURIAsURIzTestURL.test_alreadyURIAsURI  s<     Gll;'IIK&&(	K0r!   c                   t        j                  d      }| j                  |j                  d      d       | j                  |j                  d      d       | j                  |j                  d       | j                  |j
                  d       | j                  |j                         d       | j                  |j                  d	      j                         d
       y)zz
        L{URL.fromText} will parse the C{userinfo} portion of the URI
        separately from the host and port.
        z<http://someuser:somepassword@example.com/some-segment@ignoreTz!someuser:somepassword@example.comFzsomeuser:@example.comzsomeuser:somepasswordsomeuserz0http://someuser:@example.com/some-segment@ignore)rC   z/http://someuser@example.com/some-segment@ignoreN)r	   rf   rE   	authorityrC   userrh   r   r   s     r   test_userinfozTestURL.test_userinfo  s    
 llJ
 	t,.QRu-/FG'>?:.JJLL	
 	KKK,335=	
r!   c                    t        j                  d      }| j                  |j                  d       | j                  |j	                         d       y)zI
        L{URL.fromText} parses custom port numbers as integers.
        zhttp://www.example.com:8080/i  N)r	   rf   rE   rB   rh   )r'   portURLs     r   test_portTextzTestURL.test_portText  s?     ,,=>t,)+IJr!   c                j    | j                  t        j                  d      j                         d       y)a  
        Although L{URL} instances are mainly for dealing with HTTP, other
        schemes (such as C{mailto:}) should work as well.  For example,
        L{URL.fromText}/L{URL.asText} round-trips cleanly for a C{mailto:} URL
        representing an email address.
        zmailto:user@example.comN)rE   r	   rf   rh   r&   s    r   test_mailtozTestURL.test_mailto  s+     	LL23::<>W	
r!   c                Z    t        ddgg      }| j                  |j                  d       y)z
        When a L{URL} is created with a C{query} argument, the C{query}
        argument is converted into an N-tuple of 2-tuples.
        alphabetar   ))r   r   N)r	   rE   r8   r   s     r   test_queryIterablezTestURL.test_queryIterable  s+     '6*+,$89r!   c                X    t        ddg      }| j                  |j                  d       y)zr
        When a L{URL} is created with a C{path} argument, the C{path} is
        converted into a tuple.
        r   r   r7   r   N)r	   rE   r7   r   s     r   test_pathIterablezTestURL.test_pathIterable  s(    
 )*#56r!   c                     G d d      t         t        u rdnd}d fd|fd fd} |d        |d	        |d
        |dd        |d        |dd        j                  t              5 }t	                g       ddd        |d        j                  t              5 }t	        d        fg       ddd        ||dz   d        j                  t              5 }t	                dfg       ddd        ||d        j                  t              5  t	                g       ddd        j                  t
              5  t	        dg       ddd        j                  t
              5  t	        dg       ddd       t	        j                  d      } j                  t              5 }|j                                 ddd        ||d        j                  t              5 }|j                                 ddd        ||d        j                  t              5 }|j                                 ddd        ||d       y# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   WxY w# 1 sw Y   9xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   zxY w)a  
        Passing an argument of the wrong type to any of the constructor
        arguments of L{URL} will raise a descriptive L{TypeError}.

        L{URL} typechecks very aggressively to ensure that its constitutent
        parts are all properly immutable and to prevent confusing errors when
        bad data crops up in a method call long after the code that called the
        constructor is off the stack.
        c                      e Zd ZddZddZy)1TestURL.test_invalidArguments.<locals>.Unexpectedc                     y)Nwrongr%   r&   s    r   __str__z9TestURL.test_invalidArguments.<locals>.Unexpected.__str__  s    r!   c                     y)N<unexpected>r%   r&   s    r   __repr__z:TestURL.test_invalidArguments.<locals>.Unexpected.__repr__  s    %r!   N)r)   r4   )r+   r,   r-   r  r	  r%   r!   r   
Unexpectedr    s    &r!   r
  unicoder4   namec                r    j                  t        | j                        dj                  ||d             y )Nzexpected {} for {}, got {}r  )rE   r4   r(   rc   )raisedexpectationr  r'   s      r   assertRaisedz3TestURL.test_invalidArguments.<locals>.assertRaised  s1    F$$%,33K~Vr!   c                    j                  t              5 }t        di |         i d d d         ||        y # 1 sw Y   xY w)Nr%   )r   	TypeErrorr	   )paramr  r  r
  r  r'   s      r   rM   z,TestURL.test_invalidArguments.<locals>.check  sF    ""9- -,ujl+,-e4- -s	   =Ar3   r6   r;   r   boolrC   rB   zint or NoneTyper   Nzpath segmentr   z or NoneTypezquery parameter valuevaluezquery parameter name)r>   r?   vv)r>   zhttps://valid.example.com/zrelative URL)r  r#   r  r4   r  r4   r)   rO   )r  r4   r  r4   r)   rO   )
bytesr4   r   r  r	   
ValueErrorrf   ry   r   r   )r'   defaultExpectationrM   r  r   r
  r  s   `    @@r   test_invalidArgumentszTestURL.test_invalidArguments  s   	& 	& +03,YE	 2D 	5 	5
 	hfjhjf'(y) 	VL	 	V/@y) 	VZ\*	 	&79P	
 y) 	V\7+	 	V/1GH y) 	&z|n%	&z* 	*'()	*z* 	 vh	  ll78y) 	$VIIjl#	$V/@y) 	&VKK
%	&V/@y) 	$VIIjl#	$V/@S	 		 		 		& 	&	* 	*	  	 	$ 	$	& 	&	$ 	$sl   5I+/I8.J*JJJ,J9KK+I58JJJJ),J69KKKc                    | j                  t              5 }t        d       ddd       | j                  t	        j
                        dj                  t        d                   y# 1 sw Y   GxY w)z
        Technically, L{str} (or L{unicode}, as appropriate) is iterable, but
        C{URL(path="foo")} resulting in C{URL.fromText("f/o/o")} is never what
        you want.
        r_   r   Nz+expected iterable of text for path, not: {})r   r  r	   rE   r4   r(   rc   r5   )r'   r  s     r   !test_technicallyTextIsIterableButz)TestURL.test_technicallyTextIsIterableBut  s^     y) 	VUO	  !9@@eM	
	 	s   A))A2NrN   )r   )r<   r	   r3   r4   r6   r4   r7   zIterable[str]r8   z Iterable[tuple[str, str | None]]r;   r4   rB   z
int | NonerC   r4   r)   rO   r)   rO   )0r+   r,   r-   __doc__r@   rH   rP   rZ   r]   rd   rk   rq   rt   rv   rz   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r%   r!   r   r0   r0   U   sO   80  + +  + 	 +
  + 0 +  +  +  + 
 +D+
$

&3+0


.
D
$&
PAE5&B"
H
*
-5!$)587MV.V*V 51
(K	
:7OAb
r!   r0   c                      e Zd ZdZddZy)URLDeprecationTestsz.
    L{twisted.python.url} is deprecated.
    c                    ddl m} | | j                  | j                  g      }| j	                  dt        |             | j	                  d|d   d          y)zK
        L{twisted.python.url} is deprecated since Twisted 17.5.0.
        r   )r      z\twisted.python.url was deprecated in Twisted 17.5.0: Please use hyperlink from PyPI instead.messageN)twisted.pythonr   flushWarningstest_urlDeprecationrE   len)r'   r   warningsShowns      r   r&  z'URLDeprecationTests.test_urlDeprecation)  sZ     	'**D,D,D+EFC./; !Y'	
r!   Nr  )r+   r,   r-   r  r&  r%   r!   r   r   r   $  s    
r!   r   N)r  
__future__r   typingr   typing_extensionsr   twisted.trial.unittestr   r   r	   rg   r   r   _percentencr#   r0   r   r%   r!   r   <module>r.     sa   
 #  & 6 	5 2 4 n >H L
! L
^
- 
r!   