o
    ¯b q  ã                   @   sX   d 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
dS )z"
Tests for L{twisted.python.url}.
é    )Ú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   ú>/usr/lib/python3/dist-packages/twisted/python/test/test_url.pyÚ	<genexpr>G   s   € z<lambda>.<locals>.<genexpr>)Újoin)Úsr   r   r   Ú<lambda>G   s    r   c                   @   sr  e Zd ZdZdd„ Zd\dd„Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Zd9d:„ Zd;d<„ Z d=d>„ Z!d?d@„ Z"dAdB„ Z#dCdD„ Z$dEdF„ Z%dGdH„ Z&dIdJ„ Z'dKdL„ Z(dMdN„ Z)dOdP„ Z*dQdR„ Z+dSdT„ Z,dUdV„ Z-dWdX„ Z.dYdZ„ Z/d[S )]ÚTestURLz
    Tests for L{URL}.
    c                 C   sº   |   t|jtƒp|jdu t|ƒ¡ |   t|jtƒp|jdu t|ƒ¡ |jD ]}|  |tt|ƒ¡ q%|jD ]\}}|  |tt|ƒ¡ |   |du pKt|tƒt|ƒ¡ q4|  |j	tt|ƒ¡ dS )zl
        The given L{URL}'s components should be L{unicode}.

        @param u: The L{URL} to test.
        N)
Ú
assertTrueÚ
isinstanceÚschemeÚstrÚreprÚhostÚpathÚassertIsInstanceÚqueryÚfragment)ÚselfÚuÚsegÚkÚvr   r   r   ÚassertUnicodedO   s   ""
 zTestURL.assertUnicodedr   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)	r   r"   r#   r%   r&   ÚportÚuserinfoÚtupleÚassertEqual)r'   r(   r   r"   r#   r%   r&   r-   r.   ÚactualÚexpectedr   r   r   Ú	assertURL^   s    zTestURL.assertURLc                    sD   ‡ 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.
        c              
      s&   ˆ   | ¡ ˆ  | ddg g ddd¡ d S )NÚhttpr   éP   )r,   r3   )r(   ©r'   r   r   Úcheck{   s   
z(TestURL.test_initDefaults.<locals>.checkr4   r   Nr   )r'   r7   r   r6   r   Útest_initDefaultsv   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ÚfNr4   õ   Ã õ   Ã©)u   Î»u   Ï€u   âŠ¥r5   ©r   r,   r3   ©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)rB   Nz%66Nr?   r@   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.
        r4   ÚfooÚbar)ÚbazNr;   Úfrob)r   r"   r#   r%   r&   zURL.from_text({})zhttp://foo/bar?baz&k=v#frobN)r0   r!   r   Úformatr6   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Útheurlr0   Ú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   rJ   rL   r0   )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   rJ   rK   r0   ÚassertNotEqualrM   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   )r&   zhttp://localhost/#rP   N)r0   r   rJ   r6   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   rJ   rK   r0   ÚchildrL   rM   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)r0   r   rJ   rY   rL   r6   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©r"   r   zhttp://www.foo.com/cN)r   rY   r   Úrootedr0   rL   )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   rJ   rK   r0   ÚsiblingrL   )r'   rN   Ú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   rJ   rK   r0   rg   rL   ÚassertNotIn)r'   rN   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   rJ   ÚrelativeLinkBaseForRFC3986ÚrelativeLinkTestsForRFC3986r0   rg   rL   )r'   ÚbaseÚrefr2   r   r   r   Útest_clickRFC3986O  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   rJ   rj   ÚassertRaisesÚNotImplementedErrorrg   )r'   rl   r   r   r   Útest_clickSchemeRelPathW  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   rJ   r0   Úreplacer   r"   r#   r%   r&   r-   rM   r   r   r   Útest_cloneUnchanged_  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.
        )rP   r   rP   )rP   r   rP   )úhttp://localhost/a/b/cr   zhttp://localhost/a/b/)rt   r   zhttp://localhost/a/)rt   z./d/ezhttp://localhost/a/b/d/e)rt   ú../d/eúhttp://localhost/a/d/e)rt   z/./d/eúhttp://localhost/d/e)rt   z/../d/erw   )zhttp://localhost/a/b/c/z
../../d/e/zhttp://localhost/a/d/e/)zhttp://localhost/a/./cru   rw   )zhttp://localhost/a/./c/ru   rv   )zhttp://localhost/a/b/c/dz./e/../f/../gzhttp://localhost/a/b/c/g)rt   zd//ezhttp://localhost/a/b/d//ez1{start}.click({click}) => {actual} not {expected})Ústartrg   r1   r2   N)r   rJ   rg   rL   r0   rH   r!   )r'   rQ   rx   rg   r2   r1   r   r   r   Útest_clickCollapser  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/rD   rE   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)r0   r   rJ   ÚaddrL   rK   rM   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   rJ   rK   r0   ÚsetrL   r   rM   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=3rD   zhttps://example.com/a/b/?bar=2N)r   rJ   r0   Ú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)r0   r   rL   r6   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©r%   z?hello=worldN)r   r0   rL   r@   r   r   r   Útest_justQueryTextÛ  s   zTestURL.test_justQueryTextc                 C   s   t  d¡}|  ||¡ dS )z2
        L{URL} compares equal to itself.
        rP   N©r   rJ   r0   r@   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.
        rP   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   rJ   ÚassertFalserU   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.
        rP   é*   zURL must not equal a number.zURL must not equal an object.N)r   rJ   r˜   ÚobjectrU   r@   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.
        rP   z%r == itselfN©r   rJ   r˜   r@   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.
        rP   ú == 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   rJ   r   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.
        rP   rš   zURL must differ from a number.z"URL must be differ from an object.N)r   rJ   r   r›   r@   r   r   r   Útest_otherTypesUnequal  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   rJ   ÚasURIr0   r"   r#   rL   )r'   ÚunicodeyÚiriÚuriÚexpectedURIÚ	actualURIr   r   r   Ú
test_asURI$  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   rJ   ÚasIRIr0   r"   r#   rL   )r'   Úasciiishrª   r©   ÚexpectedIRIÚ	actualIRIr   r   r   Ú
test_asIRI;  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   rJ   r®   rL   r0   )r'   ÚurlWithBinaryrª   r©   r°   r±   r   r   r   Útest_badUTF8AsIRIP  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   rJ   r®   r0   rL   )r'   r¨   r©   ÚalsoIRIr   r   r   Útest_alreadyIRIAsIRI`  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   rJ   r§   rL   r0   )r'   r«   rª   r¬   r   r   r   Útest_alreadyURIAsURIo  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   rJ   r0   Ú	authorityr.   ÚuserrL   rr   r†   r   r   r   Útest_userinfox  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   rJ   r0   r-   rL   )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)r0   r   rJ   rL   r6   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   r0   r%   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Œ   ©r#   rŠ   N)r   r0   r#   r†   r   r   r   Útest_pathIterable§  s   zTestURL.test_pathIterablec                    sÈ  G dd„ dƒ‰ t tu rdnd}‡fdd„‰|f‡ ‡‡fdd„	}|d	ƒ |d
ƒ |dƒ |ddƒ |dƒ |ddƒ ˆ t¡}tˆ ƒ gd W d  ƒ n1 sPw   Y  ˆ||dƒ ˆ t¡}tdˆ ƒ fgd W d  ƒ n1 stw   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 s5w   Y  ˆ||dƒ ˆ t¡}| 	ˆ ƒ ¡ W d  ƒ n	1 sWw   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efdd„Zdefdd„ZdS )z1TestURL.test_invalidArguments.<locals>.UnexpectedÚreturnc                 S   ó   dS )NÚwrongr   r6   r   r   r   Ú__str__»  ó   z9TestURL.test_invalidArguments.<locals>.Unexpected.__str__c                 S   rÅ   )Nú<unexpected>r   r6   r   r   r   Ú__repr__¾  rÈ   z:TestURL.test_invalidArguments.<locals>.Unexpected.__repr__N)Ú__name__Ú
__module__Ú__qualname__r    rÇ   rÊ   r   r   r   r   Ú
Unexpectedº  s    rÎ   Úunicoder    c                    s    ˆ   t| jƒd ||d¡¡ d S )Nzexpected {} for {}, got {}rÉ   )r0   r    Ú	exceptionrH   )ÚraisedÚexpectationÚnamer6   r   r   ÚassertRaisedÃ  s   þz3TestURL.test_invalidArguments.<locals>.assertRaisedc                    sN   ˆ  t¡}tdi | ˆ ƒ i¤Ž W d   ƒ n1 sw   Y  ˆ||| ƒ d S )Nr   )ro   Ú	TypeErrorr   )ÚparamrÒ   rÑ   ©rÎ   rÔ   r'   r   r   r7   É  s   ÿz,TestURL.test_invalidArguments.<locals>.checkr   r"   r&   r`   Úboolr.   r-   zint or NoneTyperÂ   Nzpath segmentrÓ   r   z or NoneTypezquery parameter valueÚvaluezquery parameter name)r*   r+   Úvv)r*   zhttps://valid.example.com/zrelative URL)
Úbytesr    ro   rÕ   r   Ú
ValueErrorrJ   rY   rd   rg   )r'   ÚdefaultExpectationr7   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.
        rD   rÂ   Nz+expected iterable of text for path, not: {})ro   rÕ   r   r0   r    rÐ   rH   r!   )r'   rÑ   r   r   r   Ú!test_technicallyTextIsIterableBut   s   ÿþz)TestURL.test_technicallyTextIsIterableButN)r   )0rË   rÌ   rÍ   Ú__doc__r,   r3   r8   rA   rC   rI   rO   rT   rV   rW   rZ   r]   rb   rf   ri   rn   rq   rs   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   J   s\    



	(!$	

	Qr   c                   @   s   e Zd ZdZdd„ ZdS )ÚURLDeprecationTestsz.
    L{twisted.python.url} is deprecated.
    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_urlDeprecationr0   Úlen)r'   r‡   ÚwarningsShownr   r   r   ræ     s   
ûz'URLDeprecationTests.test_urlDeprecationN)rË   rÌ   rÍ   rà   ræ   r   r   r   r   rá     s    rá   N)rà   Útwisted.trial.unittestr   r‡   r   rK   rj   rk   Ú_percentencr   rá   r   r   r   r   Ú<module>   s   7     I