o
    ¼>hxu  ã                   @  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g d
¢Zdd„ ZG dd„ deƒZG dd„ deƒZG d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                 C  s   d  dd„ | D ƒ¡S )Nr   c                 s  s    | ]	}d t |ƒ V  qdS )z%%%02XN)Úord)Ú.0Úc© r   ú|/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/twisted/python/test/test_url.pyÚ	<genexpr>L   s   € z<lambda>.<locals>.<genexpr>)Újoin)Úsr   r   r   Ú<lambda>L   s    r   c                   @  s   e Zd Zeddd„ƒZdS )Ú_HasExceptionÚreturnÚBaseExceptionc                 C  s   d S )Nr   ©Úselfr   r   r   Ú	exceptionP   s   z_HasException.exceptionN)r    r!   )Ú__name__Ú
__module__Ú__qualname__Úpropertyr$   r   r   r   r   r   O   s    r   c                   @  sÌ  e Zd ZdZdkdd„Z	dldmdd„Zdndd„Zdndd„Zdndd„Zdndd„Z	dndd„Z
dnd d!„Zdnd"d#„Zdnd$d%„Zdnd&d'„Zdnd(d)„Zdnd*d+„Zdnd,d-„Zdnd.d/„Zdnd0d1„Zdnd2d3„Zdnd4d5„Zdnd6d7„Zdnd8d9„Zdnd:d;„Zdnd<d=„Zdnd>d?„Zdnd@dA„ZdndBdC„ZdndDdE„ZdndFdG„ZdndHdI„ZdndJdK„Z dndLdM„Z!dndNdO„Z"dndPdQ„Z#dndRdS„Z$dndTdU„Z%dndVdW„Z&dndXdY„Z'dndZd[„Z(dnd\d]„Z)dnd^d_„Z*dnd`da„Z+dndbdc„Z,dnddde„Z-dndfdg„Z.dndhdi„Z/djS )oÚTestURLz
    Tests for L{URL}.
    Úur   r    ÚNonec                 C  sž   |   |jtt|ƒ¡ |   |jtt|ƒ¡ |jD ]}|   |tt|ƒ¡ q|jD ]\}}|   |tt|ƒ¡ |  |du p=t|tƒt|ƒ¡ q&|   |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#   r*   ÚsegÚkÚvr   r   r   ÚassertUnicodedZ   s   
 zTestURL.assertUnicodedr   r-   r.   r0   r1   úIterable[str]r2   ú Iterable[tuple[str, str | None]]r5   Úportú
int | NoneÚuserinfoc	                 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)	r-   r0   r1   r2   r5   r<   r>   ÚtupleÚassertEqual)r#   r*   r-   r0   r1   r2   r5   r<   r>   ÚactualÚexpectedr   r   r   Ú	assertURLi   s    zTestURL.assertURLc                   sF   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    r+   c              
     s&   ˆ   | ¡ ˆ  | ddg g ddd¡ d S )NÚhttpr   éP   )r9   rC   )r*   r"   r   r   Úcheck   s   
z(TestURL.test_initDefaults.<locals>.checkrD   r   N©r*   r   r    r+   r   )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©r7   r8   )r7   NÚfNrD   õ   Ã õ   Ã©)u   Î»u   Ï€u   âŠ¥rE   ©r   r9   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)rR   Nz%66NrO   rP   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)ÚbazNrK   Úfrob)r-   r0   r1   r2   r5   zURL.from_text({})zhttp://foo/bar?baz&k=v#frobN)r@   r/   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   rZ   r\   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   rZ   r[   r@   ÚassertNotEqualr]   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   )r5   zhttp://localhost/#r`   N)r@   r   rZ   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&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   rZ   r[   r@   Úchildr\   r]   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   rZ   ri   r\   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©r0   r   zhttp://www.foo.com/cN)r   ri   r3   Úrootedr@   r\   )r#   Ú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&zutÚsisterz)http://www.foo.com/a/nice/path?zot=23&zutz+http://www.foo.com/a/nice/sister?zot=23&zutN)r   rZ   r[   r@   Úsiblingr\   )r#   r^   Ú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   rZ   r[   r@   rw   r\   ÚassertNotIn)r#   r^   r*   r   r   r   Ú
test_click<  s,   
ÿÿÿÿ
ÿ
ÿ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   rZ   ÚrelativeLinkBaseForRFC3986ÚrelativeLinkTestsForRFC3986r@   rw   r\   )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   rZ   rz   ÚassertRaisesÚNotImplementedErrorrw   )r#   r|   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   rZ   r@   Úreplacer-   r0   r1   r2   r5   r<   r]   r   r   r   Útest_cloneUnchangedt  s   
ú÷zTestURL.test_cloneUnchangedc                 C  sš   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 ]\}}}t  |¡ |¡ ¡ }|  ||dj|t|ƒ||d¡ q+dS )zd
        L{URL.click} collapses C{.} and C{..} according to RFC 3986 section
        5.2.4.
        )r`   r   r`   )r`   r   r`   )ú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})Ústartrw   rA   rB   N)r   rZ   rw   r\   r@   rX   r/   )r#   ra   rˆ   rw   rB   rA   r   r   r   Útest_clickCollapse‡  s6   óüýþ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/rT   rU   zhttp://www.foo.com/?foo=barrn   ro   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)r@   r   rZ   Úaddr\   r[   r]   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=itworkedÚzutÚitworkedr‹   N)r   rZ   r[   r@   Úsetr\   r   r]   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=3rT   zhttps://example.com/a/b/?bar=2N)r   rZ   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   r\   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©r2   z?hello=worldN)r   r@   r\   rP   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   rZ   r@   rP   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   rZ   ÚassertFalsere   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   rZ   r¨   Úobjectre   rP   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   rZ   r¨   rP   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!  ó   

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   rZ   r3   r¡   r   r   r   Útest_differentUnequal)  r±   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   rZ   r3   r«   rP   r   r   r   Útest_otherTypesUnequal1  s   
zTestURL.test_otherTypesUnequalc                 C  ón   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   rZ   ÚasURIr@   r0   r1   r\   )r#   ÚunicodeyÚiriÚuriÚexpectedURIÚ	actualURIr   r   r   Ú
test_asURI9  s   ÿ

ÿzTestURL.test_asURIc                 C  r´   )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   rZ   ÚasIRIr@   r0   r1   r\   )r#   Ú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   rZ   r¾   r\   r@   )r#   Ú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   rZ   r¾   r@   r\   )r#   r¸   r¹   Ú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   rZ   r·   r\   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:somepasswordÚsomeuserz0http://someuser:@example.com/some-segment@ignore)r>   z/http://someuser@example.com/some-segment@ignoreN)r   rZ   r@   Ú	authorityr>   Úuserr\   r‚   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   rZ   r@   r<   r\   )r#   Ú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   rZ   r\   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@   r2   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œ   ©r1   rš   N)r   r@   r1   r–   r   r   r   Útest_pathIterable½  s   zTestURL.test_pathIterablec                   sÌ  G dd„ dƒ‰ t tu rdnd}d$‡fdd„‰|fd%‡ ‡‡fdd„}|dƒ |dƒ |dƒ |ddƒ |dƒ |ddƒ ˆ t¡}tˆ ƒ gd W d  ƒ n1 sRw   Y  ˆ||dƒ ˆ t¡}tdˆ ƒ fgd W d  ƒ n1 svw   Y  ˆ||d dƒ ˆ t¡}tˆ ƒ dfgd W d  ƒ n1 sœw   Y  ˆ||dƒ ˆ t¡ tˆ ƒ gd W d  ƒ n1 s¾w   Y  ˆ t¡ td gd W d  ƒ n1 sÙw   Y  ˆ t¡ td!gd W d  ƒ n1 sôw   Y  t d"¡}ˆ t¡}| ˆ ƒ ¡ W d  ƒ n	1 sw   Y  ˆ||dƒ ˆ t¡}| ˆ ƒ ¡ W d  ƒ n	1 s7w   Y  ˆ||dƒ ˆ t¡}| 	ˆ ƒ ¡ W d  ƒ n	1 sYw   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                   @  s    e Zd Zddd„Zddd„ZdS )	z1TestURL.test_invalidArguments.<locals>.Unexpectedr    r.   c                 S  ó   dS )NÚwrongr   r"   r   r   r   Ú__str__Ñ  ó   z9TestURL.test_invalidArguments.<locals>.Unexpected.__str__c                 S  rÔ   )Nú<unexpected>r   r"   r   r   r   Ú__repr__Ô  r×   z:TestURL.test_invalidArguments.<locals>.Unexpected.__repr__N)r    r.   )r%   r&   r'   rÖ   rÙ   r   r   r   r   Ú
UnexpectedÐ  s    
rÚ   Úunicoder.   Úraisedr   ÚexpectationÚnamer    r+   c                   s    ˆ   t| jƒd ||d¡¡ d S )Nzexpected {} for {}, got {}rØ   )r@   r.   r$   rX   )rÜ   rÝ   rÞ   r"   r   r   ÚassertRaisedÙ  s   þz3TestURL.test_invalidArguments.<locals>.assertRaisedÚparamc                   sN   ˆ  t¡}tdi | ˆ ƒ i¤Ž W d   ƒ n1 sw   Y  ˆ||| ƒ d S )Nr   )r   Ú	TypeErrorr   )rà   rÝ   rÜ   ©rÚ   rß   r#   r   r   rF   ß  s   ÿz,TestURL.test_invalidArguments.<locals>.checkr-   r0   r5   rp   Úboolr>   r<   zint or NoneTyperÒ   Nzpath segmentr   z or NoneTypezquery parameter valueÚvaluezquery parameter name)r7   r8   Úvv)r7   zhttps://valid.example.com/zrelative URL)rÜ   r   rÝ   r.   rÞ   r.   r    r+   )rà   r.   rÝ   r.   r    r+   )
Úbytesr.   r   rá   r   Ú
ValueErrorrZ   ri   rt   rw   )r#   ÚdefaultExpectationrF   rÜ   r—   r   râ   r   Útest_invalidArgumentsÅ  sn   

ÿÿÿÿÿÿ
ÿÿÿÿÿÿÿ
ÿÿÿzTestURL.test_invalidArgumentsc                 C  sT   |   t¡}tdd W d  ƒ n1 s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.
        rT   rÒ   Nz+expected iterable of text for path, not: {})r   rá   r   r@   r.   r$   rX   r/   )r#   rÜ   r   r   r   Ú!test_technicallyTextIsIterableBut  s   ÿþz)TestURL.test_technicallyTextIsIterableButNrG   )r   )r*   r   r-   r.   r0   r.   r1   r:   r2   r;   r5   r.   r<   r=   r>   r.   r    r+   ©r    r+   )0r%   r&   r'   Ú__doc__r9   rC   rH   rQ   rS   rY   r_   rd   rf   rg   rj   rm   rr   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   r   r)   U   s^    
÷
"













	

(



!
$

	
















	



	
Qr)   c                   @  s   e Zd ZdZ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)Útwisted.pythonr—   ÚflushWarningsÚtest_urlDeprecationr@   Úlen)r#   r—   ÚwarningsShownr   r   r   rò   )  s   
ûz'URLDeprecationTests.test_urlDeprecationNrë   )r%   r&   r'   rì   rò   r   r   r   r   rí   $  s    rí   N)rì   Ú
__future__r   Útypingr   Útyping_extensionsr   Útwisted.trial.unittestr   r—   r   r[   rz   r{   Ú_percentencr   r)   rí   r   r   r   r   Ú<module>   s$   7     T