U
    P|jxu  ã                (   @  sØ   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d
dddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1g(Zd2d3„ ZG d4d5„ d5eƒZG d6d7„ d7eƒZG d8d9„ d9eƒ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                 C  s   d  dd„ | D ƒ¡S )Nr   c                 s  s   | ]}d t |ƒ V  qdS )z%%%02XN)Úord)Ú.0Úc© r   ú@/tmp/pip-unpacked-wheel-audpp6lv/twisted/python/test/test_url.pyÚ	<genexpr>L   s     z<lambda>.<locals>.<genexpr>)Újoin)Úsr   r   r   Ú<lambda>L   ó    r   c                   @  s   e Zd Zeddœdd„ƒZdS )Ú_HasExceptionÚBaseException©Úreturnc                 C  s   d S ©Nr   ©Úselfr   r   r   Ú	exceptionP   s    z_HasException.exceptionN)Ú__name__Ú
__module__Ú__qualname__Úpropertyr'   r   r   r   r   r    O   s   r    c                   @  sŒ  e Zd ZdZdddœdd„Zdedddd	d
dddddœ	dd„Zddœdd„Zddœdd„Zddœdd„Zddœdd„Z	ddœdd„Z
ddœdd„Zddœdd„Zddœdd„Zddœd d!„Zddœd"d#„Zddœd$d%„Zddœd&d'„Zddœd(d)„Zddœd*d+„Zddœd,d-„Zddœd.d/„Zddœd0d1„Zddœd2d3„Zddœd4d5„Zddœd6d7„Zddœd8d9„Zddœd:d;„Zddœd<d=„Zddœd>d?„Zddœd@dA„ZddœdBdC„ZddœdDdE„Z ddœdFdG„Z!ddœdHdI„Z"ddœdJdK„Z#ddœdLdM„Z$ddœdNdO„Z%ddœdPdQ„Z&ddœdRdS„Z'ddœdTdU„Z(ddœdVdW„Z)ddœdXdY„Z*ddœdZd[„Z+ddœd\d]„Z,ddœd^d_„Z-ddœd`da„Z.ddœdbdc„Z/ddS )fÚTestURLz
    Tests for L{URL}.
    r   ÚNone©Úur#   c                 C  sž   |   |jtt|ƒ¡ |   |jtt|ƒ¡ |jD ]}|   |tt|ƒ¡ q.|jD ]8\}}|   |tt|ƒ¡ |  |dkpzt|tƒt|ƒ¡ qL|   |j	tt|ƒ¡ dS )zl
        The given L{URL}'s components should be L{unicode}.

        @param u: The L{URL} to test.
        N)
ZassertIsInstanceÚschemeÚstrÚreprÚhostÚpathÚqueryÚ
assertTrueÚ
isinstanceÚfragment)r&   r/   ÚsegÚkÚvr   r   r   ÚassertUnicodedZ   s    
 zTestURL.assertUnicodedr   r1   zIterable[str]z Iterable[tuple[str, str | None]]z
int | None)	r/   r0   r3   r4   r5   r8   ÚportÚuserinfor#   c	                 C  sL   |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)	r0   r3   r4   r5   r8   r=   r>   ÚtupleÚassertEqual)r&   r/   r0   r3   r4   r5   r8   r=   r>   ÚactualÚexpectedr   r   r   Ú	assertURLi   s     zTestURL.assertURLr"   c                   sL   dddœ‡ fd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.
        r   r-   r.   c              
     s&   ˆ   | ¡ ˆ  | ddg g ddd¡ d S )NÚhttpr   éP   )r<   rC   )r/   r%   r   r   Úcheck�   s    
z(TestURL.test_initDefaults.<locals>.checkrD   r   Nr   )r&   rF   r   r%   r   Útest_initDefaults‹   s    zTestURL.test_initDefaultsc              	   C  sj   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ÚfNrD   õ   Ã õ   Ã©)u   Î»u   Ï€u   âŠ¥rE   ©r   r<   rC   ©r&   r/   r   r   r   Ú	test_init˜   s    
ùzTestURL.test_initc              	   C  s@   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)rQ   Nz%66NrN   rO   r   r   r   Útest_initPercentª   s    
      ÿzTestURL.test_initPercentc              
   C  s2   |   ttdddgddgd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.
        rD   ÚfooÚbar)ZbazNrJ   Zfrob)r0   r3   r4   r5   r8   zURL.from_text({})zhttp://foo/bar?baz&k=v#frobN)r@   r2   r   Úformatr%   r   r   r   Ú	test_repr´   s    ûÿ	özTestURL.test_reprc                 C  s   t  t¡}|  t| ¡ ¡ dS )zb
        Round-tripping L{URL.fromText} with C{str} results in an equivalent
        URL.
        N)r   ÚfromTextÚtheurlr@   ÚasText©r&   Úurlpathr   r   r   Útest_fromTextÇ   s    
zTestURL.test_fromTextc                 C  s,   d}|D ]}t  |¡ ¡ }|  ||¡ q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   rW   rY   r@   )r&   ÚtestsÚtestÚresultr   r   r   Útest_roundtripÏ   s    zTestURL.test_roundtripc                 C  s2   t  t¡}|  |t  t¡¡ |  |t  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   rW   rX   r@   ÚassertNotEqualrZ   r   r   r   Útest_equalityç   s    
ÿþzTestURL.test_equalityc                 C  s0   |   tdd�tƒ ¡ |   t d¡t 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   )r8   zhttp://localhost/#r]   N)r@   r   rW   r%   r   r   r   Útest_fragmentEqualityö   s
     ÿzTestURL.test_fragmentEqualityc                 C  sf   t  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&zutZ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   rW   rX   r@   ÚchildrY   rZ   r   r   r   Ú
test_child   s"    
þþþþzTestURL.test_childc                 C  s$   |   t 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)r@   r   rW   re   rY   r%   r   r   r   Útest_multiChild  s    þzTestURL.test_multiChildc                 C  s0   t d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©r3   r   zhttp://www.foo.com/cN)r   re   r6   Úrootedr@   rY   )r&   ZchildURLr   r   r   Útest_childInitRoot!  s    zTestURL.test_childInitRootc                 C  sH   t  t¡}|  d| d¡ ¡ ¡ d}t  |¡}|  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&zutZsisterz)http://www.foo.com/a/nice/path?zot=23&zutz+http://www.foo.com/a/nice/sister?zot=23&zutN)r   rW   rX   r@   ÚsiblingrY   )r&   r[   Ztheurl2r   r   r   Útest_sibling*  s    
þ
þzTestURL.test_siblingc                 C  s¼   t  t¡}|  d| d¡ ¡ ¡ |  d| d¡ ¡ ¡ |  d| d¡ ¡ ¡ |  d| d¡ ¡ ¡ |  d	| d
¡ ¡ ¡ t  d¡}|  d| d¡ ¡ ¡ t  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   rW   rX   r@   rp   rY   ZassertNotIn)r&   r[   r/   r   r   r   Ú
test_click<  s8    
 ÿ ÿ ÿ ÿ
 ÿ
 ÿzTestURL.test_clickc                 C  s2   t  t¡}tD ]\}}|  | |¡ ¡ |¡ qdS )zQ
        L{URL.click} should correctly resolve the examples in RFC 3986.
        N)r   rW   ÚrelativeLinkBaseForRFC3986ÚrelativeLinkTestsForRFC3986r@   rp   rY   )r&   ÚbaseÚrefrB   r   r   r   Útest_clickRFC3986d  s    
zTestURL.test_clickRFC3986c                 C  s.   t  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   rW   rr   ÚassertRaisesÚNotImplementedErrorrp   )r&   rt   r   r   r   Útest_clickSchemeRelPathl  s    
zTestURL.test_clickSchemeRelPathc              
   C  sF   t  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   rW   r@   Úreplacer0   r3   r4   r5   r8   r=   rZ   r   r   r   Útest_cloneUnchangedt  s    
ú÷zTestURL.test_cloneUnchangedc                 C  s´   dddgdddgdddgdddgdddgdd	d
gdddgdddgdddgdd	dgdd	d
gdddgdddgg}|D ]>\}}}t  |¡ |¡ ¡ }|  ||dj|t|ƒ||d�¡ qpdS )zd
        L{URL.click} collapses C{.} and C{..} according to RFC 3986 section
        5.2.4.
        r]   r   r   zhttp://localhost/a/b/czhttp://localhost/a/b/zhttp://localhost/a/z./d/ezhttp://localhost/a/b/d/ez../d/ezhttp://localhost/a/d/ez/./d/ezhttp://localhost/d/ez/../d/ezhttp://localhost/a/b/c/z
../../d/e/zhttp://localhost/a/d/e/zhttp://localhost/a/./czhttp://localhost/a/./c/zhttp://localhost/a/b/c/dz./e/../f/../gzhttp://localhost/a/b/c/gzd//ezhttp://localhost/a/b/d//ez1{start}.click({click}) => {actual} not {expected})Ústartrp   rA   rB   N)r   rW   rp   rY   r@   rU   r2   )r&   r^   r|   rp   rB   rA   r   r   r   Útest_clickCollapse‡  s4    óüýzTestURL.test_clickCollapsec                 C  sÔ   |   dt d¡ dd¡ ¡ ¡ |   dtdd� dd¡ ¡ ¡ t 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/rS   rT   zhttp://www.foo.com/?foo=barrj   rk   z/http://www.foo.com/a/nice/path/?zot=23&zut&burpZburpz3http://www.foo.com/a/nice/path/?zot=23&zut&burp=xxxÚxxxz8http://www.foo.com/a/nice/path/?zot=23&zut&burp=xxx&zingZ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)r@   r   rW   ÚaddrY   rX   rZ   r   r   r   Útest_queryAdd¨  s:    þþ
þþþþþzTestURL.test_queryAddc                 C  sd   t  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=itworkedZzutZitworkedr~   N)r   rW   rX   r@   ÚsetrY   r�   rZ   r   r   r   Útest_querySetÌ  s    
þþþzTestURL.test_querySetc                 C  s&   t  d¡}|  | d¡t  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=3rS   zhttps://example.com/a/b/?bar=2N)r   rW   r@   Úremove©r&   Úurlr   r   r   Útest_queryRemoveá  s
    
 ÿzTestURL.test_queryRemovec                 C  s   |   tƒ  ¡ d¡ dS )zG
        An empty L{URL} should serialize as the empty string.
        r   N)r@   r   rY   r%   r   r   r   Ú
test_emptyê  s    zTestURL.test_emptyc                 C  s    t dgd�}|  | ¡ d¡ dS )zP
        An L{URL} with query text should serialize as just query text.
        ©ÚhelloÚworld©r5   z?hello=worldN)r   r@   rY   rO   r   r   r   Útest_justQueryTextð  s    zTestURL.test_justQueryTextc                 C  s   t  d¡}|  ||¡ dS )z2
        L{URL} compares equal to itself.
        r]   N©r   rW   r@   rO   r   r   r   Útest_identicalEqual÷  s    
zTestURL.test_identicalEqualc                 C  s$   t  d¡}t  d¡}|  ||¡ dS )zG
        URLs with equivalent components should compare equal.
        r]   Nr�   ©r&   Úu1Úu2r   r   r   Útest_similarEqualþ  s    

zTestURL.test_similarEqualc                 C  s>   t  d¡}t  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   rW   ÚassertFalserb   r‘   r   r   r   Útest_differentNotEqual  s    

zTestURL.test_differentNotEqualc                 C  sJ   t  d¡}|  |dkd¡ |  |tƒ kd¡ |  |d¡ |  |tƒ ¡ dS )z=
        L{URL} is not equal (C{==}) to other types.
        r]   é*   zURL must not equal a number.zURL must not equal an object.N)r   rW   r˜   Úobjectrb   rO   r   r   r   Útest_otherTypesNotEqual  s
    
zTestURL.test_otherTypesNotEqualc                 C  s"   t  d¡}|  ||kd| ¡ dS )zJ
        Identical L{URL}s are not unequal (C{!=}) to each other.
        r]   z%r == itselfN©r   rW   r˜   rO   r   r   r   Útest_identicalNotUnequal  s    
z TestURL.test_identicalNotUnequalc                 C  s2   t  d¡}t  d¡}|  ||k|›d|›�¡ dS )zU
        Structurally similar L{URL}s are not unequal (C{!=}) to each other.
        r]   ú == Nr�   r‘   r   r   r   Útest_similarNotUnequal!  s    

zTestURL.test_similarNotUnequalc                 C  s2   t  d¡}t  d¡}|  ||k|›d|›�¡ dS )zS
        Structurally different L{URL}s are unequal (C{!=}) to each other.
        r•   r–   rŸ   N)r   rW   r6   r‘   r   r   r   Útest_differentUnequal)  s    

zTestURL.test_differentUnequalc                 C  s0   t  d¡}|  |dkd¡ |  |tƒ kd¡ dS )z;
        L{URL} is unequal (C{!=}) to other types.
        r]   rš   zURL must differ from a number.z"URL must be differ from an object.N)r   rW   r6   r›   rO   r   r   r   Útest_otherTypesUnequal1  s    
zTestURL.test_otherTypesUnequalc                 C  sn   d}t  |¡}| ¡ }|  |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   rW   ÚasURIr@   r3   r4   rY   )r&   ÚunicodeyÚiriÚuriÚexpectedURIÚ	actualURIr   r   r   Ú
test_asURI9  s    ÿ
 ÿzTestURL.test_asURIc                 C  sn   d}t  |¡}| ¡ }|  |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   rW   ÚasIRIr@   r3   r4   rY   )r&   Zasciiishr¨   r§   ÚexpectedIRIÚ	actualIRIr   r   r   Ú
test_asIRIP  s    
ÿzTestURL.test_asIRIc                 C  s>   d}t  |¡}| ¡ }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   rW   r¬   rY   r@   )r&   ZurlWithBinaryr¨   r§   r­   r®   r   r   r   Útest_badUTF8AsIRIe  s    
ÿzTestURL.test_badUTF8AsIRIc                 C  s*   d}t  |¡}| ¡ }|  | ¡ |¡ dS )zT
        A L{URL} composed of non-ASCII text will result in non-ASCII text.
        r£   N)r   rW   r¬   r@   rY   )r&   r¦   r§   ZalsoIRIr   r   r   Útest_alreadyIRIAsIRIu  s
    ÿ
zTestURL.test_alreadyIRIAsIRIc                 C  s*   d}t  |¡}| ¡  ¡ }|  ||¡ dS )zH
        A L{URL} composed of encoded text will remain encoded.
        r¤   N)r   rW   r¥   rY   r@   )r&   r©   r¨   rª   r   r   r   Útest_alreadyURIAsURI„  s    
zTestURL.test_alreadyURIAsURIc                 C  sv   t  d¡}|  | d¡d¡ |  | d¡d¡ |  |jd¡ |  |jd¡ |  | ¡ d¡ |  |j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:somepasswordZsomeuserz0http://someuser:@example.com/some-segment@ignore)r>   z/http://someuser@example.com/some-segment@ignoreN)r   rW   r@   Ú	authorityr>   ÚuserrY   rz   r†   r   r   r   Útest_userinfo�  s    ÿ ÿþzTestURL.test_userinfoc                 C  s,   t  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   rW   r@   r=   rY   )r&   ZportURLr   r   r   Útest_portText¡  s    
zTestURL.test_portTextc                 C  s   |   t 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)r@   r   rW   rY   r%   r   r   r   Útest_mailto©  s     ÿzTestURL.test_mailtoc                 C  s"   t ddggd�}|  |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   r@   r5   r†   r   r   r   Útest_queryIterable´  s    zTestURL.test_queryIterablec                 C  s    t ddgd�}|  |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Œ   ©r4   rŠ   N)r   r@   r4   r†   r   r   r   Útest_pathIterable½  s    zTestURL.test_pathIterablec              	     s$  G dd„ dƒ‰ t tkrdnd}dddddœ‡fdd	„‰|fdddd
œ‡ ‡‡fdd„}|dƒ |dƒ |dƒ |ddƒ |dƒ |ddƒ ˆ t¡�}tˆ ƒ gd� W 5 Q R X ˆ||dƒ ˆ t¡�}tdˆ ƒ fgd� W 5 Q R X ˆ||d dƒ ˆ t¡�}tˆ ƒ dfgd� W 5 Q R X ˆ||dƒ ˆ t¡� tˆ ƒ gd� W 5 Q R X ˆ t¡� tdgd� W 5 Q R X ˆ t¡� tdgd� W 5 Q R X t d¡}ˆ t¡�}| ˆ ƒ ¡ W 5 Q R X ˆ||dƒ ˆ t¡�}| ˆ ƒ ¡ W 5 Q R X ˆ||dƒ ˆ t¡�}| 	ˆ ƒ ¡ W 5 Q R X ˆ||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                   @  s(   e Zd Zddœdd„Zddœdd„ZdS )z1TestURL.test_invalidArguments.<locals>.Unexpectedr1   r"   c                 S  s   dS )NZwrongr   r%   r   r   r   Ú__str__Ñ  s    z9TestURL.test_invalidArguments.<locals>.Unexpected.__str__c                 S  s   dS )Nú<unexpected>r   r%   r   r   r   Ú__repr__Ô  s    z:TestURL.test_invalidArguments.<locals>.Unexpected.__repr__N)r(   r)   r*   r½   r¿   r   r   r   r   Ú
UnexpectedÐ  s   rÀ   Úunicoder1   r    r-   )ÚraisedÚexpectationÚnamer#   c                   s    ˆ   t| jƒd ||d¡¡ d S )Nzexpected {} for {}, got {}r¾   )r@   r1   r'   rU   )rÂ   rÃ   rÄ   r%   r   r   ÚassertRaisedÙ  s    þz3TestURL.test_invalidArguments.<locals>.assertRaised)ÚparamrÃ   r#   c              	     s6   ˆ  t¡�}tf | ˆ ƒ iŽ W 5 Q R X ˆ||| ƒ d S r$   )rw   Ú	TypeErrorr   )rÆ   rÃ   rÂ   ©rÀ   rÅ   r&   r   r   rF   ß  s    z,TestURL.test_invalidArguments.<locals>.checkr0   r3   r8   rl   Úboolr>   r=   zint or NoneTyper»   zpath segmentrÄ   r�   z or NoneTypezquery parameter valueÚvaluezquery parameter name)r:   r;   Úvv)r:   zhttps://valid.example.com/zrelative URLN)
Úbytesr1   rw   rÇ   r   Ú
ValueErrorrW   re   rn   rp   )r&   ZdefaultExpectationrF   rÂ   r‡   r   rÈ   r   Útest_invalidArgumentsÅ  s`    

ÿÿÿÿ  ÿÿÿ
zTestURL.test_invalidArgumentsc              	   C  s@   |   t¡�}tdd� W 5 Q R X |  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.
        rS   r»   z+expected iterable of text for path, not: {}N)rw   rÇ   r   r@   r1   r'   rU   r2   )r&   rÂ   r   r   r   Ú!test_technicallyTextIsIterableBut  s    þz)TestURL.test_technicallyTextIsIterableButN)r   )0r(   r)   r*   Ú__doc__r<   rC   rG   rP   rR   rV   r\   ra   rc   rd   rf   ri   rm   ro   rq   rv   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,   U   s\    ÷ "


	(!$	

		Qr,   c                   @  s   e Zd ZdZddœdd„ZdS )ÚURLDeprecationTestsz.
    L{twisted.python.url} is deprecated.
    r-   r"   c                 C  sF   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)Ztwisted.pythonr‡   ZflushWarningsÚtest_urlDeprecationr@   Úlen)r&   r‡   ZwarningsShownr   r   r   rÔ   )  s    
ûz'URLDeprecationTests.test_urlDeprecationN)r(   r)   r*   rÐ   rÔ   r   r   r   r   rÑ   $  s   rÑ   N)rÐ   Ú
__future__r   Útypingr   Ztyping_extensionsr   Ztwisted.trial.unittestr   r‡   r   rX   rr   rs   Z_percentencr    r,   rÑ   r   r   r   r   Ú<module>   sr   Ð7     T