
    tfxu                        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dS )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                @    d                     d | D                       S )Nr   c              3  :   K   | ]}d t          |          z  V  dS )z%%%02XN)ord).0cs     [/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/python/test/test_url.py	<genexpr>z<lambda>.<locals>.<genexpr>L   s-      ==a3q66 1======    )join)ss    r   <lambda>r!   L   s!    ==1===== r   c                  &    e Zd Zedd            ZdS )_HasExceptionreturnBaseExceptionc                    d S )N selfs    r   	exceptionz_HasException.exceptionP   s    r   N)r$   r%   )__name__
__module____qualname__propertyr*   r'   r   r   r#   r#   O   s2           X  r   r#   c                  v   e Zd ZdZd?dZ	 d@dAdZdBdZdBdZdBdZdBdZ	dBdZ
dBdZdBdZdBdZdBdZdBdZdBdZdBdZdBd ZdBd!ZdBd"ZdBd#ZdBd$ZdBd%ZdBd&ZdBd'ZdBd(ZdBd)ZdBd*ZdBd+ZdBd,ZdBd-ZdBd.Z dBd/Z!dBd0Z"dBd1Z#dBd2Z$dBd3Z%dBd4Z&dBd5Z'dBd6Z(dBd7Z)dBd8Z*dBd9Z+dBd:Z,dBd;Z-dBd<Z.dBd=Z/d>S )CTestURLz
    Tests for L{URL}.
    ur	   r$   Nonec                `   |                      |j        t          t          |                     |                      |j        t          t          |                     |j        D ]+}|                      |t          t          |                     ,|j        D ]h\  }}|                      |t          t          |                     |                     |du pt          |t                    t          |                     i|                      |j	        t          t          |                     dS )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)   r1   segkvs        r   assertUnicodedzTestURL.assertUnicodedZ   s    	ahT!WW555afc4773336 	5 	5C!!#sDGG4444G 	F 	FDAq!!!S$q''222OOAI;As););T!WWEEEEaj#tAww77777r   r   r5   r6   r8   r9   Iterable[str]r:    Iterable[tuple[str, str | None]]r=   port
int | Noneuserinfoc	                    |j         |j        |j        |j        |j        |j        |j        f}	||t          |          t          |          |||j        f}
|                     |	|
           dS )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)	r5   r8   r9   r:   r=   rD   rF   tupleassertEqual)r)   r1   r5   r8   r9   r:   r=   rD   rF   actualexpecteds              r   	assertURLzTestURL.assertURLi   sd    < (AFAFAGQZTD%++uU||XtQZX*****r   c           	          d	 fd} |t          dd                      |t          ddg g                       |t          ddg g d                     dS )
z@
        L{URL} should have appropriate default values.
        r1   r	   r$   r2   c           
     j                         |                                | ddg g ddd           d S )Nhttpr   P   )rA   rL   )r1   r)   s    r   checkz(TestURL.test_initDefaults.<locals>.check   s=    """NN1fb"b"b"=====r   rO   r   Nr1   r	   r$   r2   r   )r)   rQ   s   ` r   test_initDefaultszTestURL.test_initDefaults   s    
	> 	> 	> 	> 	> 	> 	c&"ooc&"b"%%&&&c&"b"b))*****r   c           	         t          dddgddgd          }|                     |           |                     |dddgddgdd           |                     t          dd	d
gdgd          dd	d
gdgdd           dS )z=
        L{URL} should accept L{unicode} parameters.
        r    hpr?   r@   )r?   NfNrO      à   é)u   λu   πu   ⊥rP   r	   rA   rL   r)   r1   s     r   	test_initzTestURL.test_init   s     S3%*k!:C@@Aq#sSEJ+Dc4PPP+?*@(KKH!"	
 	
 	
 	
 	
r   c           	         t          dddgddgd          }|                     |           |                     |dddgddgdd           dS )zN
        L{URL} should accept (and not interpret) percent characters.
        r    z%68z%70)%6Bz%76)r_   Nz%66Nr[   r\   s     r   test_initPercentzTestURL.test_initPercent   sj     UUGnm%DeLLAsEE7^]$CUD	
 	
 	
 	
 	
r   c                    |                      t          t          dddgddgd                    d                    t          d	                               d
S )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.
        rO   foobar)bazNrW   frob)r5   r8   r9   r:   r=   zURL.from_text({})zhttp://foo/bar?baz&k=v#frobN)rI   r7   r	   formatr(   s    r   	test_reprzTestURL.test_repr   sw     	!(*5#     &&t,I'J'JKK	
 	
 	
 	
 	
r   c                    t          j        t                    }|                     t          |                                           dS )zb
        Round-tripping L{URL.fromText} with C{str} results in an equivalent
        URL.
        N)r	   fromTexttheurlrI   asTextr)   urlpaths     r   test_fromTextzTestURL.test_fromText   s9    
 ,v&&!1!122222r   c                    d}|D ]>}t          j        |                                          }|                     ||           ?dS )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	   ri   rk   rI   )r)   teststestresults       r   test_roundtripzTestURL.test_roundtrip   sX    
   	+ 	+D\$''..00FT6****	+ 	+r   c                    t          j        t                    }|                     |t          j        t                               |                     |t          j        d                     dS )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	   ri   rj   rI   assertNotEqualrl   s     r   test_equalityzTestURL.test_equality   sj     ,v&&#,v"6"6777LO 	
 	
 	
 	
 	
r   c                    |                      t          d          t                                 |                      t          j        d          t          j        d                     dS )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/#rp   N)rI   r	   ri   r(   s    r   test_fragmentEqualityzTestURL.test_fragmentEquality   sf    
 	b)))355111L-..=P0Q0Q	
 	
 	
 	
 	
r   c                   t          j        t                    }|                     d|                    d                                                     |                     d|                    d                                                     |                     d|                    d                                                     |                     d|                    d                                                     d	S )
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	   ri   rj   rI   childrk   rl   s     r   
test_childzTestURL.test_child   s    
 ,v&&<MM&!!((**	
 	
 	
 	?MM'""))++	
 	
 	
 	EMM-((//11	
 	
 	
 	HMM.))0022	
 	
 	
 	
 	
r   c                    |                      t          j        d                              ddd                                          d           dS )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)rI   r	   ri   r|   rk   r(   s    r   test_multiChildzTestURL.test_multiChild  sU    
 	L12288c3GGNNPP*	
 	
 	
 	
 	
r   c                    t          d                              d          }|                     |j                   |                     d|                                           dS )zo
        L{URL.child} of a L{URL} without a path produces a L{URL} with a single
        path segment.
        www.foo.comr8   r   zhttp://www.foo.com/cN)r	   r|   r;   rootedrI   rk   )r)   childURLs     r   test_childInitRootzTestURL.test_childInitRoot!  s]    
 M***0055(((/1B1BCCCCCr   c                P   t          j        t                    }|                     d|                    d                                                     d}t          j        |          }|                     d|                    d                                                     dS )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	   ri   rj   rI   siblingrk   )r)   rm   theurl2s      r   test_siblingzTestURL.test_sibling*  s    
 ,v&&>OOH%%,,..	
 	
 	

 >,w''9OOH%%,,..	
 	
 	
 	
 	
r   c                   t          j        t                    }|                     d|                    d                                                     |                     d|                    d                                                     |                     d|                    d                                                     |                     d|                    d                                                     |                     d	|                    d
                                                     t          j        d          }|                     d|                    d                                                     t          j        d          }|                     |                    d                                          d           dS )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	   ri   rj   rI   r   rk   assertNotIn)r)   rm   r1   s      r   
test_clickzTestURL.test_click<  s   
 ,v&&8'--:K:K:R:R:T:T	
 	
 	
 	2GMM'4J4J4Q4Q4S4S	
 	
 	
 	3W]]85L5L5S5S5U5UVVV2GMM'4J4J4Q4Q4S4S	
 	
 	

 	&ABBIIKK	
 	
 	
 L899/9J1K1K1R1R1T1T	
 	
 	
 L788GG+,,33557N	
 	
 	
 	
 	
r   c                    t          j        t                    }t          D ]@\  }}|                     |                    |                                          |           AdS )zQ
        L{URL.click} should correctly resolve the examples in RFC 3986.
        N)r	   ri   relativeLinkBaseForRFC3986relativeLinkTestsForRFC3986rI   r   rk   )r)   baserefrK   s       r   test_clickRFC3986zTestURL.test_clickRFC3986d  sd     |6778 	A 	AMCTZZ__3355x@@@@	A 	Ar   c                    t          j        t                    }|                     t          |j        d           |                     t          |j        d           dS )zM
        L{URL.click} should not accept schemes with relative paths.
        zg:hzhttp:hN)r	   ri   r   assertRaisesNotImplementedErrorr   )r)   r   s     r   test_clickSchemeRelPathzTestURL.test_clickSchemeRelPathl  sP     |677-tz5AAA-tz8DDDDDr   c           
        t          j        d          }|                     |                    |j        |j        |j        |j        |j        |j	                  |           |                     |                                |           dS )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	   ri   rI   replacer5   r8   r9   r:   r=   rD   rl   s     r   test_cloneUnchangedzTestURL.test_cloneUnchangedt  s    
 ,455OO   
	
 
	
 
	
 	**G44444r   c                R   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 ]z\  }}}t          j        |                              |                                          }|                     ||d                    |t          |          ||                     {dS )zd
        L{URL.click} collapses C{.} and C{..} according to RFC 3986 section
        5.2.4.
        )rp   r   rp   )rp   r   rp   )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   rJ   rK   N)r	   ri   r   rk   rI   rf   r7   )r)   rq   r   r   rK   rJ   s         r   test_clickCollapsezTestURL.test_clickCollapse  s    <;;<<<DDDCCCKKKJJJHHHIIIPPPHHHKKKUUUKKK
 ', 	 	"E5(\%((..u55<<>>FCJJu++!%	 K  	 	 	 		 	r   c                2   |                      dt          j        d                              dd                                                     |                      dt          d                              dd                                                     t          j        t
                    }|                      d|                    d	                                                     |                      d
|                    d	d                                                     |                      d|                    d	d                              d                                                     |                      d|                    d                              d	d                                                     |                      d|                    d	d                              dd                                                     dS )z3
        L{URL.add} adds query parameters.
        z'http://www.foo.com/a/nice/path/?foo=barzhttp://www.foo.com/a/nice/path/rb   rc   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)rI   r	   ri   addrk   rj   rl   s     r   test_queryAddzTestURL.test_queryAdd  s    	5L:;;??uMMTTVV	
 	
 	
 	)]###''u55<<>>	
 	
 	
 ,v&&=KK&&((	
 	
 	
 	AKK&&--//	
 	
 	
 	FKK&&**62299;;	
 	
 	

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

 	HKK&&**5$77>>@@	
 	
 	
 	
 	
r   c                   t          j        t                    }|                     d|                    dd                                                     |                     d|                    d                              dd                                                     |                     d|                    dd                              dd                                                     dS )	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	   ri   rj   rI   setrk   r   rl   s     r   test_querySetzTestURL.test_querySet  s     ,v&&8KKt$$++--	
 	
 	

 	>KK""5*55<<>>	
 	
 	
 	8KKu%%))%66==??	
 	
 	
 	
 	
r   c                    t          j        d          }|                     |                    d          t          j        d                     dS )zK
        L{URL.remove} removes all instances of a query parameter.
        z*https://example.com/a/b/?foo=1&bar=2&foo=3rb   zhttps://example.com/a/b/?bar=2N)r	   ri   rI   remover)   urls     r   test_queryRemovezTestURL.test_queryRemove  sR     lGHHJJus|,LMM	
 	
 	
 	
 	
r   c                n    |                      t                                                      d           dS )zG
        An empty L{URL} should serialize as the empty string.
        r   N)rI   r	   rk   r(   s    r   
test_emptyzTestURL.test_empty  s,     	,,,,,r   c                x    t          dg          }|                     |                                d           dS )zP
        An L{URL} with query text should serialize as just query text.
        helloworldr:   z?hello=worldN)r	   rI   rk   r\   s     r   test_justQueryTextzTestURL.test_justQueryText  s<     )*+++^44444r   c                Z    t          j        d          }|                     ||           dS )z2
        L{URL} compares equal to itself.
        rp   Nr	   ri   rI   r\   s     r   test_identicalEqualzTestURL.test_identicalEqual  s0     L,--Ar   c                    t          j        d          }t          j        d          }|                     ||           dS )zG
        URLs with equivalent components should compare equal.
        rp   Nr   r)   u1u2s      r   test_similarEqualzTestURL.test_similarEqual  s@     \-..\-..R     r   c                    t          j        d          }t          j        d          }|                     ||k    |d|           |                     ||           dS )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	   ri   assertFalserv   r   s      r   test_differentNotEqualzTestURL.test_differentNotEqual  sh    
 \.//\.//rb#6#6#6#6777B#####r   c                   t          j        d          }|                     |dk    d           |                     |t                      k    d           |                     |d           |                     |t                                 dS )z=
        L{URL} is not equal (C{==}) to other types.
        rp   *   zURL must not equal a number.zURL must not equal an object.N)r	   ri   r   objectrv   r\   s     r   test_otherTypesNotEqualzTestURL.test_otherTypesNotEqual  s     L,--b"@AAAfhh(GHHHAr"""Avxx(((((r   c                h    t          j        d          }|                     ||k    d|z             dS )zJ
        Identical L{URL}s are not unequal (C{!=}) to each other.
        rp   z%r == itselfNr	   ri   r   r\   s     r   test_identicalNotUnequalz TestURL.test_identicalNotUnequal  s9     L,--a!!344444r   c                    t          j        d          }t          j        d          }|                     ||k    |d|           dS )zU
        Structurally similar L{URL}s are not unequal (C{!=}) to each other.
        rp    == Nr   r   s      r   test_similarNotUnequalzTestURL.test_similarNotUnequal!  sR     \-..\-..rb#6#6#6#677777r   c                    t          j        d          }t          j        d          }|                     ||k    |d|           dS )zS
        Structurally different L{URL}s are unequal (C{!=}) to each other.
        r   r   r   N)r	   ri   r;   r   s      r   test_differentUnequalzTestURL.test_differentUnequal)  sP     \.//\.//bR"5"5r"5"566666r   c                    t          j        d          }|                     |dk    d           |                     |t                      k    d           dS )z;
        L{URL} is unequal (C{!=}) to other types.
        rp   r   zURL must differ from a number.z"URL must be differ from an object.N)r	   ri   r;   r   r\   s     r   test_otherTypesUnequalzTestURL.test_otherTypesUnequal1  sP     L,--R!ABBBVXX'KLLLLLr   c                   d}t          j        |          }|                                }|                     |j        d           |                     |j        d         d           |                     |                                |           d}|                                }|                     |||d|           dS )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	   ri   asURIrI   r8   r9   rk   )r)   unicodeyiriuriexpectedURI	actualURIs         r   
test_asURIzTestURL.test_asURI9  s    B 	 l8$$iikk#LMMMHQKM	
 	
 	
 	x000FJJLL	KI1T1T[1T1TUUUUUr   c                   d}t          j        |          }|                                }|                     |j        d           |                     |j        d         d           |                     |                                |           d}|                                }|                     |||d|           dS )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	   ri   asIRIrI   r8   r9   rk   )r)   asciiishr   r   expectedIRI	actualIRIs         r   
test_asIRIzTestURL.test_asIRIP  s    
 Dl8$$iikk=111!h///x0003 	 JJLL	KI1T1T[1T1TUUUUUr   c                    d}t          j        |          }|                                }d}|                                }|                     |||d|           dS )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	   ri   r   rk   rI   )r)   urlWithBinaryr   r   r   r   s         r   test_badUTF8AsIRIzTestURL.test_badUTF8AsIRIe  sj    
 ;l=))iikk2 	
 JJLL	KI1T1T[1T1TUUUUUr   c                    d}t          j        |          }|                                }|                     |                                |           dS )zT
        A L{URL} composed of non-ASCII text will result in non-ASCII text.
        r   N)r	   ri   r   rI   rk   )r)   r   r   alsoIRIs       r   test_alreadyIRIAsIRIzTestURL.test_alreadyIRIAsIRIu  sQ    
B 	 l8$$))++))844444r   c                    d}t          j        |          }|                                                                }|                     ||           dS )zH
        A L{URL} composed of encoded text will remain encoded.
        r   N)r	   ri   r   rk   rI   )r)   r   r   r   s       r   test_alreadyURIAsURIzTestURL.test_alreadyURIAsURI  sN     Gl;''IIKK&&((	K00000r   c                   t          j        d          }|                     |                    d          d           |                     |                    d          d           |                     |j        d           |                     |j        d           |                     |                                d           |                     |                    d	                                          d
           dS )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)rF   z/http://someuser@example.com/some-segment@ignoreN)r	   ri   rI   	authorityrF   userrk   r   r   s     r   test_userinfozTestURL.test_userinfo  s    
 lJ
 
 	t,,.QRRRu--/FGGG'>???:...JJLLL	
 	
 	
 	KKK,,3355=	
 	
 	
 	
 	
r   c                    t          j        d          }|                     |j        d           |                     |                                d           dS )zI
        L{URL.fromText} parses custom port numbers as integers.
        zhttp://www.example.com:8080/i  N)r	   ri   rI   rD   rk   )r)   portURLs     r   test_portTextzTestURL.test_portText  sS     ,=>>t,,,))+IJJJJJr   c                z    |                      t          j        d                                          d           dS )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)rI   r	   ri   rk   r(   s    r   test_mailtozTestURL.test_mailto  sC     	L233::<<>W	
 	
 	
 	
 	
r   c                b    t          ddgg          }|                     |j        d           dS )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	   rI   r:   r   s     r   test_queryIterablezTestURL.test_queryIterable  s;     '6*+,,,$899999r   c                `    t          ddg          }|                     |j        d           dS )zr
        When a L{URL} is created with a C{path} argument, the C{path} is
        converted into a tuple.
        r   r   r9   r   N)r	   rI   r9   r   s     r   test_pathIterablezTestURL.test_pathIterable  s8    
 )***#56666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                                t                    5 }t	                       g           ddd           n# 1 swxY w Y    ||d                                t                    5 }t	          d             fg           ddd           n# 1 swxY w Y    ||dz   d                                t                    5 }t	                       dfg           ddd           n# 1 swxY w Y    ||d                                t                    5  t	                       g           ddd           n# 1 swxY w Y                        t
                    5  t	          dg           ddd           n# 1 swxY w Y                        t
                    5  t	          dg           ddd           n# 1 swxY w Y   t	          j        d           }                     t                    5 }|                                            ddd           n# 1 swxY w Y    ||d                                t                    5 }|                                            ddd           n# 1 swxY w Y    ||d                                t                    5 }|	                                            ddd           n# 1 swxY w Y    ||d!           dS )$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dS )1TestURL.test_invalidArguments.<locals>.Unexpectedr$   r6   c                    dS )Nwrongr'   r(   s    r   __str__z9TestURL.test_invalidArguments.<locals>.Unexpected.__str__  s    wr   c                    dS )N<unexpected>r'   r(   s    r   __repr__z:TestURL.test_invalidArguments.<locals>.Unexpected.__repr__  s    %~r   N)r$   r6   )r+   r,   r-   r	  r  r'   r   r   
Unexpectedr    s<           & & & & & &r   r  unicoder6   raisedr#   expectationnamer$   r2   c                                         t          | j                  d                    ||d                     d S )Nzexpected {} for {}, got {}r  )rI   r6   r*   rf   )r  r  r  r)   s      r   assertRaisedz3TestURL.test_invalidArguments.<locals>.assertRaised  sH    F$%%,33K~VV    r   paramc                                         t                    5 }t          di |              i d d d            n# 1 swxY w Y    |||            d S )Nr'   )r   	TypeErrorr	   )r  r  r  r  r  r)   s      r   rQ   z,TestURL.test_invalidArguments.<locals>.check  s    ""9-- -,,ujjll+,,,- - - - - - - - - - - - - - -Le44444s   ?AAr5   r8   r=   r   boolrF   rD   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  r6   r  r6   r$   r2   )r  r6   r  r6   r$   r2   )
bytesr6   r   r  r	   
ValueErrorri   r|   r   r   )r)   defaultExpectationrQ   r  r   r  r  s   `    @@r   test_invalidArgumentszTestURL.test_invalidArguments  sB   	& 	& 	& 	& 	& 	& 	& 	& +03,,YYE	 	 	 	 	 	 2D 	5 	5 	5 	5 	5 	5 	5 	5 	5
 	hfjhjf'(((y)) 	VJLL   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	V/@@@y)) 	VZZ\\*   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	&79P	
 	
 	
 y)) 	VZ\\7+   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	V/1GHHH y)) 	& 	&zz||n%%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&z** 	* 	*'())))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*z** 	  	 vh	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  l788y)) 	$VIIjjll###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$V/@@@y)) 	&VKK

%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&V/@@@y)) 	$VIIjjll###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$V/@@@@@s   B77B;>B;)DDDE..E25E2 GG
G
+H		HH.IIIJ//J36J3!LLL=M''M+.M+c                   |                      t                    5 }t          d           ddd           n# 1 swxY w Y   |                     t	          |j                  d                    t          d                               dS )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.
        rb   r  Nz+expected iterable of text for path, not: {})r   r  r	   rI   r6   r*   rf   r7   )r)   r  s     r   !test_technicallyTextIsIterableButz)TestURL.test_technicallyTextIsIterableBut  s     y)) 	VUOOOO	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 !!9@@eMM	
 	
 	
 	
 	
s   8<<NrR   )r   )r1   r	   r5   r6   r8   r6   r9   rB   r:   rC   r=   r6   rD   rE   rF   r6   r$   r2   r$   r2   )0r+   r,   r-   __doc__rA   rL   rS   r]   r`   rg   rn   rt   rw   ry   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   r   r0   r0   U   s        8 8 8 80  +  +  +  +  +D+ + + +
 
 
 
$
 
 
 

 
 
 
&3 3 3 3+ + + +0
 
 
 

 
 
 

 
 
 
.
 
 
 
D D D D
 
 
 
$&
 &
 &
 &
PA A A AE E E E5 5 5 5&   B"
 "
 "
 "
H
 
 
 
*
 
 
 
- - - -5 5 5 5   ! ! ! !$ $ $ $) ) ) )5 5 5 58 8 8 87 7 7 7M M M MV V V V.V V V V*V V V V 5 5 5 51 1 1 1
 
 
 
(K K K K	
 	
 	
 	
: : : :7 7 7 7OA OA OA OAb
 
 
 
 
 
r   r0   c                      e Zd ZdZddZdS )URLDeprecationTestsz.
    L{twisted.python.url} is deprecated.
    r$   r2   c                    ddl m} | |                     | j        g          }|                     dt          |                     |                     d|d         d                    dS )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_urlDeprecationrI   len)r)   r   warningsShowns      r   r)  z'URLDeprecationTests.test_urlDeprecation)  s     	'&&&&&**D,D+EFFC..///; !Y'	
 	
 	
 	
 	
r   Nr   )r+   r,   r-   r!  r)  r'   r   r   r#  r#  $  s2         
 
 
 
 
 
r   r#  N)r!  
__future__r   typingr   typing_extensionsr   twisted.trial.unittestr   r   r	   rj   r   r   _percentencr#   r0   r#  r'   r   r   <module>r1     s(  
  # " " " " "       & & & & & & 6 6 6 6 6 6      	5 2 4 4 4 n >=    H   L
 L
 L
 L
 L
! L
 L
 L
^
 
 
 
 
- 
 
 
 
 
r   