Ë
    ojmu  ã                  óœ   — d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 dZ
d	Zg d
¢Zd„ Z G d„ de«      Z G d„ de«      Z G d„ de«      Zy)z"
Tests for L{twisted.python.url}.
é    )Úannotations)ÚIterable)ÚProtocol)ÚSynchronousTestCaseé   ©ÚURLú*http://www.foo.com/a/nice/path/?zot=23&zutúhttp://a/b/c/d;p?q)()Úgúhttp://a/b/c/g)z./gr   )zg/úhttp://a/b/c/g/)z/gú
http://a/g)z//gzhttp://g)z?yzhttp://a/b/c/d;p?y)zg?yzhttp://a/b/c/g?y)z#szhttp://a/b/c/d;p?q#s)zg#szhttp://a/b/c/g#s)zg?y#szhttp://a/b/c/g?y#s)z;xzhttp://a/b/c/;x)zg;xzhttp://a/b/c/g;x)zg;x?y#szhttp://a/b/c/g;x?y#s)Ú r   )ú.úhttp://a/b/c/)z./r   )ú..úhttp://a/b/)z../r   )z../gúhttp://a/b/g)z../..ú	http://a/)z../../r   )z../../gr   )z
../../../gr   )z../../../../gr   )z/./gr   )z/../gr   )zg.zhttp://a/b/c/g.)z.gzhttp://a/b/c/.g)zg..zhttp://a/b/c/g..)z..gzhttp://a/b/c/..g)z./../gr   )z./g/.r   )zg/./hzhttp://a/b/c/g/h)zg/../hzhttp://a/b/c/h)z	g;x=1/./yzhttp://a/b/c/g;x=1/y)z
g;x=1/../yzhttp://a/b/c/y)zg?y/./xzhttp://a/b/c/g?y/./x)zg?y/../xzhttp://a/b/c/g?y/../x)zg#s/./xzhttp://a/b/c/g#s/./x)zg#s/../xzhttp://a/b/c/g#s/../xc                ó2   — dj                  d„ | D «       «      S )Nr   c              3  ó8   K  — | ]  }d t        |«      z  –— Œ y­w)z%%%02XN)Úord)Ú.0Úcs     ú>/usr/lib/python3/dist-packages/twisted/python/test/test_url.pyú	<genexpr>z<lambda>.<locals>.<genexpr>L   s   è ø€ Ò=°a ¬3¨q«6Õ 1Ñ=ùs   ‚)Újoin)Úss    r   ú<lambda>r    L   s   € ˜Ÿ™Ñ=¸1Ô=Ó=€ ó    c                  ó   — e Zd Zedd„«       Zy)Ú_HasExceptionc                 ó   — y )N© ©Úselfs    r   Ú	exceptionz_HasException.exceptionP   s   € àr!   N)ÚreturnÚBaseException)Ú__name__Ú
__module__Ú__qualname__Úpropertyr(   r%   r!   r   r#   r#   O   s   „ Øòó ñr!   r#   c                  ó–  — e Zd ZdZd/d„Z	 d0	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d1d„Zd2d„Zd2d„Zd2d„Zd2d„Z	d2d„Z
d2d	„Zd2d
„Zd2d„Zd2d„Zd2d„Zd2d„Zd2d„Zd2d„Zd2d„Zd2d„Zd2d„Zd2d„Zd2d„Zd2d„Zd2d„Zd2d„Zd2d„Zd2d„Zd2d„Zd2d„Zd2d„Zd2d„Z d2d„Z!d2d „Z"d2d!„Z#d2d"„Z$d2d#„Z%d2d$„Z&d2d%„Z'd2d&„Z(d2d'„Z)d2d(„Z*d2d)„Z+d2d*„Z,d2d+„Z-d2d,„Z.d2d-„Z/y.)3ÚTestURLz
    Tests for L{URL}.
    c                ó(  — | j                  |j                  t        t        |«      «       | j                  |j                  t        t        |«      «       |j
                  D ]"  }| j                  |t        t        |«      «       Œ$ |j                  D ]T  \  }}| j                  |t        t        |«      «       | j                  |du xs t        |t        «      t        |«      «       ŒV | j                  |j                  t        t        |«      «       y)zl
        The given L{URL}'s components should be L{unicode}.

        @param u: The L{URL} to test.
        N)
ÚassertIsInstanceÚschemeÚstrÚreprÚhostÚpathÚqueryÚ
assertTrueÚ
isinstanceÚfragment)r'   ÚuÚsegÚkÚvs        r   ÚassertUnicodedzTestURL.assertUnicodedZ   sÎ   € ð 	×Ñ˜aŸh™h¬¬T°!«WÔ5Ø×Ñ˜aŸf™f¤c¬4°«7Ô3Ø—6‘6ò 	5ˆCØ×!Ñ! #¤s¬D°«GÕ4ð	5à—G‘Gò 	F‰DˆAˆqØ×!Ñ! !¤S¬$¨q«'Ô2Ø�O‰O˜A ˜IÒ;¬°A´sÓ);¼TÀ!»WÕEð	Fð 	×Ñ˜aŸj™j¬#¬t°A«wÕ7r!   c	                ó  — |j                   |j                  |j                  |j                  |j                  |j
                  |j                  f}	||t        |«      t        |«      |||j                  f}
| j                  |	|
«       y)aª  
        The given L{URL} should have the given components.

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

        @param scheme: The expected scheme.

        @param host: The expected host.

        @param path: The expected path.

        @param query: The expected query.

        @param fragment: The expected fragment.

        @param port: The expected port.

        @param userinfo: The expected userinfo.
        N)	r3   r6   r7   r8   r;   ÚportÚuserinfoÚtupleÚassertEqual)r'   r<   r3   r6   r7   r8   r;   rB   rC   ÚactualÚexpecteds              r   Ú	assertURLzTestURL.assertURLi   sd   € ð< —(‘(˜AŸF™F A§F¡F¨A¯G©G°Q·Z±ZÀÇÁÈÏÉÐTˆØ˜D¤%¨£+¬u°U«|¸XÀtÈQÏZÉZÐXˆØ×Ñ˜ Õ*r!   c           	     óˆ   ‡ — dˆ fd„} |t        dd«      «        |t        ddg g «      «        |t        ddg g d«      «       y)z@
        L{URL} should have appropriate default values.
        c           
     óX   •— ‰j                  | «       ‰j                  | ddg g ddd«       y )NÚhttpr   éP   )r@   rH   )r<   r'   s    €r   Úcheckz(TestURL.test_initDefaults.<locals>.check�   s+   ø€ Ø×Ñ Ô"Ø�N‰N˜1˜f b¨"¨b°"°b¸"Õ=r!   rK   r   N©r<   r	   r)   ÚNoner   )r'   rM   s   ` r   Útest_initDefaultszTestURL.test_initDefaults‹   s@   ø€ õ
	>ñ 	Œc�&˜"‹oÔÙŒc�&˜"˜b "Ó%Ô&ÙŒc�&˜"˜b " bÓ)Õ*r!   c           	     óÎ   — t        dddgddgd«      }| j                  |«       | j                  |dddgddgdd«       | j                  t        dd	d
gdgd«      dd	d
gdgdd«       y)z=
        L{URL} should accept L{unicode} parameters.
        r   ÚhÚp©r>   r?   )r>   NÚfNrK   õ   Ã õ   Ã©)u   Î»u   Ï€u   âŠ¥rL   ©r	   r@   rH   ©r'   r<   s     r   Ú	test_initzTestURL.test_init˜   sƒ   € ô ��S˜3˜% *¨kÐ!:¸CÓ@ˆØ×Ñ˜AÔØ�‰�q˜#˜s S E¨J¸Ð+DÀcÈ4ÔPà�‰Ü�˜  Ð+?Ð*@À(ÓKØØØˆHØ!Ð"ØØõ	
r!   c           	     ó~   — t        dddgddgd«      }| j                  |«       | j                  |dddgddgdd«       y)zN
        L{URL} should accept (and not interpret) percent characters.
        r   z%68z%70)ú%6Bz%76)r\   Nz%66NrX   rY   s     r   Útest_initPercentzTestURL.test_initPercentª   sM   € ô ��U˜U˜G n°mÐ%DÀeÓLˆØ×Ñ˜AÔØ�‰Øˆs�E˜E˜7 ^°]Ð$CÀUÈDõ	
r!   c                óŒ   — | j                  t        t        dddgddgd¬«      «      dj                  t        d	«      «      «       y
)z¹
        L{URL.__repr__} will display the canonical form of the URL, wrapped in
        a L{URL.fromText} invocation, so that it is C{eval}-able but still easy
        to read.
        rK   ÚfooÚbar)ÚbazNrT   Úfrob)r3   r6   r7   r8   r;   zURL.from_text({})zhttp://foo/bar?baz&k=v#frobN)rE   r5   r	   Úformatr&   s    r   Ú	test_reprzTestURL.test_repr´   sN   € ð 	×ÑÜÜØ!ØØ˜Ø(¨*Ð5Ø#ôóð  ×&Ñ&¤tÐ,IÓ'JÓKõ	
r!   c                ó~   — t        j                  t        «      }| j                  t        |j	                  «       «       y)zb
        Round-tripping L{URL.fromText} with C{str} results in an equivalent
        URL.
        N)r	   ÚfromTextÚtheurlrE   ÚasText©r'   Úurlpaths     r   Útest_fromTextzTestURL.test_fromTextÇ   s)   € ô
 —,‘,œvÓ&ˆØ×Ñœ §¡Ó!1Õ2r!   c                ó€   — d}|D ]7  }t        j                  |«      j                  «       }| j                  ||«       Œ9 y)z>
        L{URL.asText} should invert L{URL.fromText}.
        )zhttp://localhostúhttp://localhost/zhttp://localhost/foozhttp://localhost/foo/zhttp://localhost/foo!!bar/zhttp://localhost/foo%20bar/zhttp://localhost/foo%2Fbar/zhttp://localhost/foo?nzhttp://localhost/foo?n=vzhttp://localhost/foo?n=/a/bz%http://example.com/foo!@$bar?b!@z=123z$http://localhost/asd?a=asd%20sdf/345z6http://(%2525)/(%2525)?(%2525)&(%2525)=(%2525)#(%2525)z<http://(%C3%A9)/(%C3%A9)?(%C3%A9)&(%C3%A9)=(%C3%A9)#(%C3%A9)N)r	   rf   rh   rE   )r'   ÚtestsÚtestÚresults       r   Útest_roundtripzTestURL.test_roundtripÏ   sA   € ð
ˆð  ò 	+ˆDÜ—\‘\ $Ó'×.Ñ.Ó0ˆFØ×Ñ˜T 6Õ*ñ	+r!   c                óÒ   — t        j                  t        «      }| j                  |t        j                  t        «      «       | j	                  |t        j                  d«      «       y)z¶
        Two URLs decoded using L{URL.fromText} will be equal (C{==}) if they
        decoded same URL string, and unequal (C{!=}) if they decoded different
        strings.
        z:ftp://www.anotherinvaliddomain.com/foo/bar/baz/?zot=21&zutN)r	   rf   rg   rE   ÚassertNotEqualri   s     r   Útest_equalityzTestURL.test_equalityç   sK   € ô —,‘,œvÓ&ˆØ×Ñ˜¤#§,¡,¬vÓ"6Ô7Ø×ÑØÜ�L‰LØOóõ	
r!   c                ó¼   — | j                  t        d¬«      t        «       «       | j                  t        j                  d«      t        j                  d«      «       y)zŒ
        An URL created with the empty string for a fragment compares equal
        to an URL created with an unspecified fragment.
        r   )r;   zhttp://localhost/#rm   N)rE   r	   rf   r&   s    r   Útest_fragmentEqualityzTestURL.test_fragmentEqualityö   sB   € ð
 	×Ñœ bÔ)¬3«5Ô1Ø×ÑÜ�L‰LÐ-Ó.´·±Ð=PÓ0Qõ	
r!   c                ó®  — t        j                  t        «      }| j                  d|j	                  d«      j                  «       «       | j                  d|j	                  d«      j                  «       «       | j                  d|j	                  d«      j                  «       «       | j                  d|j	                  d«      j                  «       «       y	)
zm
        L{URL.child} appends a new path segment, but does not affect the query
        or fragment.
        z.http://www.foo.com/a/nice/path/gong?zot=23&zutÚgongz1http://www.foo.com/a/nice/path/gong%2F?zot=23&zutzgong/z7http://www.foo.com/a/nice/path/gong%2Fdouble?zot=23&zutzgong/doublez:http://www.foo.com/a/nice/path/gong%2Fdouble%2F?zot=23&zutzgong/double/N)r	   rf   rg   rE   Úchildrh   ri   s     r   Ú
test_childzTestURL.test_child   s°   € ô
 —,‘,œvÓ&ˆØ×ÑØ<Ø�M‰M˜&Ó!×(Ñ(Ó*ô	
ð 	×ÑØ?Ø�M‰M˜'Ó"×)Ñ)Ó+ô	
ð 	×ÑØEØ�M‰M˜-Ó(×/Ñ/Ó1ô	
ð 	×ÑØHØ�M‰M˜.Ó)×0Ñ0Ó2õ	
r!   c                óŒ   — | j                  t        j                  d«      j                  ddd«      j	                  «       d«       y)zg
        L{URL.child} receives multiple segments as C{*args} and appends each in
        turn.
        zhttp://example.com/a/br   ÚdÚezhttp://example.com/a/b/c/d/eN)rE   r	   rf   ry   rh   r&   s    r   Útest_multiChildzTestURL.test_multiChild  s:   € ð
 	×ÑÜ�L‰LÐ1Ó2×8Ñ8¸¸cÀ3ÓG×NÑNÓPØ*õ	
r!   c                ó°   — t        d¬«      j                  d«      }| j                  |j                  «       | j	                  d|j                  «       «       y)zo
        L{URL.child} of a L{URL} without a path produces a L{URL} with a single
        path segment.
        úwww.foo.com©r6   r   zhttp://www.foo.com/cN)r	   ry   r9   ÚrootedrE   rh   )r'   ÚchildURLs     r   Útest_childInitRootzTestURL.test_childInitRoot!  sA   € ô
 ˜MÔ*×0Ñ0°Ó5ˆØ�‰˜Ÿ™Ô(Ø×ÑÐ/°·±Ó1BÕCr!   c                ó   — t        j                  t        «      }| j                  d|j	                  d«      j                  «       «       d}t        j                  |«      }| j                  d|j	                  d«      j                  «       «       y)z
        L{URL.sibling} of a L{URL} replaces the last path segment, but does not
        affect the query or fragment.
        z0http://www.foo.com/a/nice/path/sister?zot=23&zutÚsisterz)http://www.foo.com/a/nice/path?zot=23&zutz+http://www.foo.com/a/nice/sister?zot=23&zutN)r	   rf   rg   rE   Úsiblingrh   )r'   rj   Útheurl2s      r   Útest_siblingzTestURL.test_sibling*  ss   € ô
 —,‘,œvÓ&ˆØ×ÑØ>Ø�O‰O˜HÓ%×,Ñ,Ó.ô	
ð
 >ˆÜ—,‘,˜wÓ'ˆØ×ÑØ9Ø�O‰O˜HÓ%×,Ñ,Ó.õ	
r!   c                ó  — t        j                  t        «      }| j                  d|j	                  d«      j                  «       «       | j                  d|j	                  d«      j                  «       «       | j                  d|j	                  d«      j                  «       «       | j                  d|j	                  d«      j                  «       «       | j                  d	|j	                  d
«      j                  «       «       t        j                  d«      }| j                  d|j	                  d«      j                  «       «       t        j                  d«      }| j                  |j	                  d«      j                  «       d«       y)z¦
        L{URL.click} interprets the given string as a relative URI-reference
        and returns a new L{URL} interpreting C{self} as the base absolute URI.
        r
   r   z$http://www.foo.com/a/nice/path/clickÚclickzhttp://www.foo.com/clickz/clickz$http://www.foo.com/a/nice/path/?burpz?burpz//foobarzhttp://www.foo.com/foobarzhttp://www.foo.com/me/noqueryz!http://www.foo.com/me/17?spam=158z/me/17?spam=158zhttp://localhost/foo?abc=defzhttp://www.python.orgN)r	   rf   rg   rE   r‹   rh   ÚassertNotIn)r'   rj   r<   s      r   Ú
test_clickzTestURL.test_click<  s?  € ô
 —,‘,œvÓ&ˆà×ÑØ8¸'¿-¹-ÈÓ:K×:RÑ:RÓ:Tô	
ð 	×ÑØ2°G·M±MÀ'Ó4J×4QÑ4QÓ4Sô	
ð 	×ÑÐ3°W·]±]À8Ó5L×5SÑ5SÓ5UÔVà×ÑØ2°G·M±MÀ'Ó4J×4QÑ4QÓ4Sô	
ð
 	×ÑØ˜Ÿ™Ð&AÓB×IÑIÓKô	
ô �L‰LÐ8Ó9ˆØ×ÑØ/°·±Ð9JÓ1K×1RÑ1RÓ1Tô	
ô �L‰LÐ7Ó8ˆØ×ÑØ�G‰GÐ+Ó,×3Ñ3Ó5Ð7Nõ	
r!   c                ó°   — t        j                  t        «      }t        D ]4  \  }}| j	                  |j                  |«      j                  «       |«       Œ6 y)zQ
        L{URL.click} should correctly resolve the examples in RFC 3986.
        N)r	   rf   ÚrelativeLinkBaseForRFC3986ÚrelativeLinkTestsForRFC3986rE   r‹   rh   )r'   ÚbaseÚrefrG   s       r   Útest_clickRFC3986zTestURL.test_clickRFC3986d  sI   € ô �|‰|Ô6Ó7ˆÜ8ò 	A‰MˆC�Ø×Ñ˜TŸZ™Z¨›_×3Ñ3Ó5°xÕ@ñ	Ar!   c                óº   — t        j                  t        «      }| j                  t        |j
                  d«       | j                  t        |j
                  d«       y)zM
        L{URL.click} should not accept schemes with relative paths.
        zg:hzhttp:hN)r	   rf   r�   ÚassertRaisesÚNotImplementedErrorr‹   )r'   r‘   s     r   Útest_clickSchemeRelPathzTestURL.test_clickSchemeRelPathl  sA   € ô �|‰|Ô6Ó7ˆØ×ÑÔ-¨t¯z©z¸5ÔAØ×ÑÔ-¨t¯z©z¸8ÕDr!   c           
     ó2  — t        j                  d«      }| j                  |j                  |j                  |j
                  |j                  |j                  |j                  |j                  «      |«       | j                  |j                  «       |«       y)zf
        Verify that L{URL.replace} doesn't change any of the arguments it
        is passed.
        zhttps://x:1/y?z=1#AN)
r	   rf   rE   Úreplacer3   r6   r7   r8   r;   rB   ri   s     r   Útest_cloneUnchangedzTestURL.test_cloneUnchangedt  sw   € ô
 —,‘,Ð4Ó5ˆØ×ÑØ�O‰OØ—‘Ø—‘Ø—‘Ø—‘Ø× Ñ Ø—‘óð ô
	
ð 	×Ñ˜Ÿ™Ó*¨GÕ4r!   c                ó.  — g d¢g d¢g d¢g d¢g d¢g d¢g d¢g d¢g d	¢g d
¢g d¢g d¢g d¢g}|D ]g  \  }}}t        j                  |«      j                  |«      j                  «       }| j	                  ||dj                  |t        |«      ||¬«      «       Œi y)zd
        L{URL.click} collapses C{.} and C{..} according to RFC 3986 section
        5.2.4.
        )rm   r   rm   )rm   r   rm   )úhttp://localhost/a/b/cr   zhttp://localhost/a/b/)rœ   r   zhttp://localhost/a/)rœ   z./d/ezhttp://localhost/a/b/d/e)rœ   ú../d/eúhttp://localhost/a/d/e)rœ   z/./d/eúhttp://localhost/d/e)rœ   z/../d/erŸ   )zhttp://localhost/a/b/c/z
../../d/e/zhttp://localhost/a/d/e/)zhttp://localhost/a/./cr�   rŸ   )zhttp://localhost/a/./c/r�   rž   )zhttp://localhost/a/b/c/dz./e/../f/../gzhttp://localhost/a/b/c/g)rœ   zd//ezhttp://localhost/a/b/d//ez1{start}.click({click}) => {actual} not {expected})Ústartr‹   rF   rG   N)r	   rf   r‹   rh   rE   rc   r5   )r'   rn   r    r‹   rG   rF   s         r   Útest_clickCollapsezTestURL.test_clickCollapse‡  s¤   € ò <Ú<ÚDÚCÚKÚJÚHÚIÚPÚHÚKÚUÚKð
ˆð ',ò 	Ñ"ˆE�5˜(Ü—\‘\ %Ó(×.Ñ.¨uÓ5×<Ñ<Ó>ˆFØ×ÑØØØC×JÑJØÜ˜u›+Ø!Ø%ð	 Kó õ	ñ	r!   c                ój  — | j                  dt        j                  d«      j                  dd«      j	                  «       «       | j                  dt        d¬«      j                  dd«      j	                  «       «       t        j                  t
        «      }| j                  d|j                  d	«      j	                  «       «       | j                  d
|j                  d	d«      j	                  «       «       | j                  d|j                  d	d«      j                  d«      j	                  «       «       | j                  d|j                  d«      j                  d	d«      j	                  «       «       | j                  d|j                  d	d«      j                  dd«      j	                  «       «       y)z3
        L{URL.add} adds query parameters.
        z'http://www.foo.com/a/nice/path/?foo=barzhttp://www.foo.com/a/nice/path/r_   r`   zhttp://www.foo.com/?foo=barr€   r�   z/http://www.foo.com/a/nice/path/?zot=23&zut&burpÚburpz3http://www.foo.com/a/nice/path/?zot=23&zut&burp=xxxÚxxxz8http://www.foo.com/a/nice/path/?zot=23&zut&burp=xxx&zingÚzingz8http://www.foo.com/a/nice/path/?zot=23&zut&zing&burp=xxxz:http://www.foo.com/a/nice/path/?zot=23&zut&burp=xxx&zot=32ÚzotÚ32N)rE   r	   rf   Úaddrh   rg   ri   s     r   Útest_queryAddzTestURL.test_queryAdd¨  sj  € ð 	×ÑØ5Ü�L‰LÐ:Ó;×?Ñ?ÀÀuÓM×TÑTÓVô	
ð 	×ÑØ)Ü�]Ô#×'Ñ'¨¨uÓ5×<Ñ<Ó>ô	
ô —,‘,œvÓ&ˆØ×ÑØ=Ø�K‰K˜Ó×&Ñ&Ó(ô	
ð 	×ÑØAØ�K‰K˜ Ó&×-Ñ-Ó/ô	
ð 	×ÑØFØ�K‰K˜ Ó&×*Ñ*¨6Ó2×9Ñ9Ó;ô	
ð
 	×ÑØFØ�K‰K˜Ó×#Ñ# F¨EÓ2×9Ñ9Ó;ô	
ð
 	×ÑØHØ�K‰K˜ Ó&×*Ñ*¨5°$Ó7×>Ñ>Ó@õ	
r!   c                ó”  — t        j                  t        «      }| j                  d|j	                  dd«      j                  «       «       | j                  d|j	                  d«      j	                  dd«      j                  «       «       | j                  d|j                  dd«      j	                  dd«      j                  «       «       y)	z?
        L{URL.set} replaces query parameters by name.
        z*http://www.foo.com/a/nice/path/?zot=32&zutr¦   r§   z0http://www.foo.com/a/nice/path/?zot&zut=itworkedÚzutÚitworkedr¤   N)r	   rf   rg   rE   Úsetrh   r¨   ri   s     r   Útest_querySetzTestURL.test_querySetÌ  s¦   € ô —,‘,œvÓ&ˆØ×ÑØ8Ø�K‰K˜˜tÓ$×+Ñ+Ó-ô	
ð
 	×ÑØ>Ø�K‰K˜Ó×"Ñ" 5¨*Ó5×<Ñ<Ó>ô	
ð 	×ÑØ8Ø�K‰K˜˜uÓ%×)Ñ)¨%°Ó6×=Ñ=Ó?õ	
r!   c                ó–   — t        j                  d«      }| j                  |j                  d«      t        j                  d«      «       y)zK
        L{URL.remove} removes all instances of a query parameter.
        z*https://example.com/a/b/?foo=1&bar=2&foo=3r_   zhttps://example.com/a/b/?bar=2N)r	   rf   rE   Úremove©r'   Úurls     r   Útest_queryRemovezTestURL.test_queryRemoveá  s9   € ô �l‰lÐGÓHˆØ×ÑØ�J‰J�uÓœsŸ|™|Ð,LÓMõ	
r!   c                óT   — | j                  t        «       j                  «       d«       y)zG
        An empty L{URL} should serialize as the empty string.
        r   N)rE   r	   rh   r&   s    r   Ú
test_emptyzTestURL.test_emptyê  s   € ð 	×Ñœ›Ÿ™›¨Õ,r!   c                ó^   — t        dg¬«      }| j                  |j                  «       d«       y)zP
        An L{URL} with query text should serialize as just query text.
        ©ÚhelloÚworld©r8   z?hello=worldN)r	   rE   rh   rY   s     r   Útest_justQueryTextzTestURL.test_justQueryTextð  s(   € ô Ð)Ð*Ô+ˆØ×Ñ˜Ÿ™› ^Õ4r!   c                óR   — t        j                  d«      }| j                  ||«       y)z2
        L{URL} compares equal to itself.
        rm   N©r	   rf   rE   rY   s     r   Útest_identicalEqualzTestURL.test_identicalEqual÷  s#   € ô �L‰LÐ,Ó-ˆØ×Ñ˜˜AÕr!   c                ó|   — t        j                  d«      }t        j                  d«      }| j                  ||«       y)zG
        URLs with equivalent components should compare equal.
        rm   Nr½   ©r'   Úu1Úu2s      r   Útest_similarEqualzTestURL.test_similarEqualþ  s2   € ô �\‰\Ð-Ó.ˆÜ�\‰\Ð-Ó.ˆØ×Ñ˜˜RÕ r!   c                ó°   — t        j                  d«      }t        j                  d«      }| j                  ||k(  |›d|›�«       | j                  ||«       y)z|
        L{URL}s that refer to different resources are both unequal (C{!=}) and
        also not equal (not C{==}).
        úhttp://localhost/aúhttp://localhost/bú != N)r	   rf   ÚassertFalsers   rÀ   s      r   Útest_differentNotEqualzTestURL.test_differentNotEqual  sQ   € ô
 �\‰\Ð.Ó/ˆÜ�\‰\Ð.Ó/ˆØ×Ñ˜˜r™ b V¨4°¨vÐ#6Ô7Ø×Ñ˜B Õ#r!   c                óê   — t        j                  d«      }| j                  |dk(  d«       | j                  |t        «       k(  d«       | j	                  |d«       | j	                  |t        «       «       y)z=
        L{URL} is not equal (C{==}) to other types.
        rm   é*   zURL must not equal a number.zURL must not equal an object.N)r	   rf   rÈ   Úobjectrs   rY   s     r   Útest_otherTypesNotEqualzTestURL.test_otherTypesNotEqual  sa   € ô �L‰LÐ,Ó-ˆØ×Ñ˜˜b™Ð"@ÔAØ×Ñ˜œf›h™Ð(GÔHØ×Ñ˜A˜rÔ"Ø×Ñ˜Aœv›xÕ(r!   c                ó^   — t        j                  d«      }| j                  ||k7  d|z  «       y)zJ
        Identical L{URL}s are not unequal (C{!=}) to each other.
        rm   z%r == itselfN©r	   rf   rÈ   rY   s     r   Útest_identicalNotUnequalz TestURL.test_identicalNotUnequal  s,   € ô �L‰LÐ,Ó-ˆØ×Ñ˜˜a™ °!Ñ!3Õ4r!   c                óŒ   — t        j                  d«      }t        j                  d«      }| j                  ||k7  |›d|›�«       y)zU
        Structurally similar L{URL}s are not unequal (C{!=}) to each other.
        rm   ú == NrÏ   rÀ   s      r   Útest_similarNotUnequalzTestURL.test_similarNotUnequal!  sA   € ô �\‰\Ð-Ó.ˆÜ�\‰\Ð-Ó.ˆØ×Ñ˜˜r™ b V¨4°¨vÐ#6Õ7r!   c                óŒ   — t        j                  d«      }t        j                  d«      }| j                  ||k7  |›d|›�«       y)zS
        Structurally different L{URL}s are unequal (C{!=}) to each other.
        rÅ   rÆ   rÒ   N)r	   rf   r9   rÀ   s      r   Útest_differentUnequalzTestURL.test_differentUnequal)  s?   € ô �\‰\Ð.Ó/ˆÜ�\‰\Ð.Ó/ˆØ�‰˜˜b™ R F¨$¨r¨fÐ"5Õ6r!   c                ó’   — t        j                  d«      }| j                  |dk7  d«       | j                  |t        «       k7  d«       y)z;
        L{URL} is unequal (C{!=}) to other types.
        rm   rË   zURL must differ from a number.z"URL must be differ from an object.N)r	   rf   r9   rÌ   rY   s     r   Útest_otherTypesUnequalzTestURL.test_otherTypesUnequal1  s;   € ô �L‰LÐ,Ó-ˆØ�‰˜˜R™Ð!AÔBØ�‰˜œV›X™Ð'KÕLr!   c                ó\  — d}t        j                  |«      }|j                  «       }| j                  |j                  d«       | j                  |j
                  d   d«       | j                  |j                  «       |«       d}|j                  «       }| j                  |||›d|›�«       y)z‹
        L{URL.asURI} produces an URI which converts any URI unicode encoding
        into pure US-ASCII and returns a new L{URL}.
        õ   http://Ã©.com/eÌ�?aÌ�=iÌ�#uÌ�u   Ã©.comr   u   eÌ�ú.http://xn--9ca.com/%C3%A9?%C3%A1=%C3%AD#%C3%BArÇ   N)r	   rf   ÚasURIrE   r6   r7   rh   )r'   ÚunicodeyÚiriÚuriÚexpectedURIÚ	actualURIs         r   Ú
test_asURIzTestURL.test_asURI9  sž   € ðBð 	ô �l‰l˜8Ó$ˆØ�i‰i‹kˆØ×Ñ˜Ÿ™Ð#LÔMØ×ÑØ�H‰H�Q‰KÐMô	
ð 	×Ñ˜Ÿ™› xÔ0ØFˆØ—J‘J“Lˆ	Ø×Ñ˜ K°I°=ÀÀ[ÀOÐ1TÕUr!   c                ó\  — d}t        j                  |«      }|j                  «       }| j                  |j                  d«       | j                  |j
                  d   d«       | j                  |j                  «       |«       d}|j                  «       }| j                  |||›d|›�«       y)zœ
        L{URL.asIRI} decodes any percent-encoded text in the URI, making it
        more suitable for reading by humans, and returns a new L{URL}.
        rÚ   zxn--9ca.comr   z%C3%A9u   http://Ã©.com/Ã©?Ã¡=Ã­#ÃºrÇ   N)r	   rf   ÚasIRIrE   r6   r7   rh   )r'   ÚasciiishrÞ   rÝ   ÚexpectedIRIÚ	actualIRIs         r   Ú
test_asIRIzTestURL.test_asIRIP  s™   € ð
 DˆÜ�l‰l˜8Ó$ˆØ�i‰i‹kˆØ×Ñ˜Ÿ™ =Ô1Ø×Ñ˜Ÿ™ !™ hÔ/Ø×Ñ˜Ÿ™› xÔ0ð3ð 	ð —J‘J“Lˆ	Ø×Ñ˜ K°I°=ÀÀ[ÀOÐ1TÕUr!   c                ó¦   — d}t        j                  |«      }|j                  «       }d}|j                  «       }| j	                  |||›d|›�«       y)zœ
        Bad UTF-8 in a path segment, query parameter, or fragment results in
        that portion of the URI remaining percent-encoded in the IRI.
        z http://xn--9ca.com/%00%FF/%C3%A9u   http://Ã©.com/%00%FF/Ã©rÇ   N)r	   rf   rã   rh   rE   )r'   ÚurlWithBinaryrÞ   rÝ   rå   ræ   s         r   Útest_badUTF8AsIRIzTestURL.test_badUTF8AsIRIe  sV   € ð
 ;ˆÜ�l‰l˜=Ó)ˆØ�i‰i‹kˆð2ð 	ð
 —J‘J“Lˆ	Ø×Ñ˜ K°I°=ÀÀ[ÀOÐ1TÕUr!   c                ó’   — d}t        j                  |«      }|j                  «       }| j                  |j	                  «       |«       y)zT
        A L{URL} composed of non-ASCII text will result in non-ASCII text.
        rÙ   N)r	   rf   rã   rE   rh   )r'   rÜ   rÝ   ÚalsoIRIs       r   Útest_alreadyIRIAsIRIzTestURL.test_alreadyIRIAsIRIu  s?   € ð
Bð 	ô �l‰l˜8Ó$ˆØ—)‘)“+ˆØ×Ñ˜Ÿ™Ó)¨8Õ4r!   c                ó’   — d}t        j                  |«      }|j                  «       j                  «       }| j	                  ||«       y)zH
        A L{URL} composed of encoded text will remain encoded.
        rÚ   N)r	   rf   rÛ   rh   rE   )r'   rß   rÞ   rà   s       r   Útest_alreadyURIAsURIzTestURL.test_alreadyURIAsURI„  s<   € ð GˆÜ�l‰l˜;Ó'ˆØ—I‘I“K×&Ñ&Ó(ˆ	Ø×Ñ˜ KÕ0r!   c                óÂ  — t        j                  d«      }| j                  |j                  d«      d«       | j                  |j                  d«      d«       | j                  |j                  d«       | j                  |j
                  d«       | j                  |j                  «       d«       | j                  |j                  d¬	«      j                  «       d
«       y)zz
        L{URL.fromText} will parse the C{userinfo} portion of the URI
        separately from the host and port.
        z<http://someuser:somepassword@example.com/some-segment@ignoreTz!someuser:somepassword@example.comFzsomeuser:@example.comzsomeuser:somepasswordÚsomeuserz0http://someuser:@example.com/some-segment@ignore)rC   z/http://someuser@example.com/some-segment@ignoreN)r	   rf   rE   Ú	authorityrC   Úuserrh   r™   r±   s     r   Útest_userinfozTestURL.test_userinfo�  s¸   € ô
 �l‰lØJó
ˆð 	×Ñ˜Ÿ™ tÓ,Ð.QÔRØ×Ñ˜Ÿ™ uÓ-Ð/FÔGØ×Ñ˜Ÿ™Ð'>Ô?Ø×Ñ˜Ÿ™ :Ô.Ø×ÑØ�J‰J‹LÐLô	
ð 	×ÑØ�K‰K ˆKÓ,×3Ñ3Ó5Ø=õ	
r!   c                ó¦   — t        j                  d«      }| j                  |j                  d«       | j                  |j	                  «       d«       y)zI
        L{URL.fromText} parses custom port numbers as integers.
        zhttp://www.example.com:8080/i�  N)r	   rf   rE   rB   rh   )r'   ÚportURLs     r   Útest_portTextzTestURL.test_portText¡  s?   € ô —,‘,Ð=Ó>ˆØ×Ñ˜Ÿ™ tÔ,Ø×Ñ˜Ÿ™Ó)Ð+IÕJr!   c                ój   — | j                  t        j                  d«      j                  «       d«       y)a  
        Although L{URL} instances are mainly for dealing with HTTP, other
        schemes (such as C{mailto:}) should work as well.  For example,
        L{URL.fromText}/L{URL.asText} round-trips cleanly for a C{mailto:} URL
        representing an email address.
        zmailto:user@example.comN)rE   r	   rf   rh   r&   s    r   Útest_mailtozTestURL.test_mailto©  s+   € ð 	×ÑÜ�L‰LÐ2Ó3×:Ñ:Ó<Ð>Wõ	
r!   c                óZ   — t        ddgg¬«      }| j                  |j                  d«       y)zŒ
        When a L{URL} is created with a C{query} argument, the C{query}
        argument is converted into an N-tuple of 2-tuples.
        ÚalphaÚbetarº   ))rû   rü   N)r	   rE   r8   r±   s     r   Útest_queryIterablezTestURL.test_queryIterable´  s+   € ô ˜' 6Ð*Ð+Ô,ˆØ×Ñ˜Ÿ™Ð$8Õ9r!   c                óX   — t        ddg¬«      }| j                  |j                  d«       y)zr
        When a L{URL} is created with a C{path} argument, the C{path} is
        converted into a tuple.
        r¸   r¹   ©r7   r·   N)r	   rE   r7   r±   s     r   Útest_pathIterablezTestURL.test_pathIterable½  s(   € ô
 ˜ Ð)Ô*ˆØ×Ñ˜Ÿ™Ð#5Õ6r!   c                óº  ‡ ‡‡—  G d„ d«      Št         t        u rdnd}dˆ fd„Š|fdˆˆˆ fd„} |d«        |d	«        |d
«        |dd«        |d«        |dd«       ‰ j                  t        «      5 }t	         ‰«       g¬«       ddd«        ‰|d«       ‰ j                  t        «      5 }t	        d ‰«       fg¬«       ddd«        ‰||dz   d«       ‰ j                  t        «      5 }t	         ‰«       dfg¬«       ddd«        ‰||d«       ‰ j                  t        «      5  t	         ‰«       g¬«       ddd«       ‰ j                  t
        «      5  t	        dg¬«       ddd«       ‰ j                  t
        «      5  t	        dg¬«       ddd«       t	        j                  d«      }‰ j                  t        «      5 }|j                   ‰«       «       ddd«        ‰||d«       ‰ j                  t        «      5 }|j                   ‰«       «       ddd«        ‰||d«       ‰ j                  t        «      5 }|j                   ‰«       «       ddd«        ‰||d«       y# 1 sw Y   �ŒåxY w# 1 sw Y   �Œ¶xY w# 1 sw Y   �Œ„xY w# 1 sw Y   �ŒWxY w# 1 sw Y   �Œ9xY w# 1 sw Y   �ŒxY w# 1 sw Y   ŒÞxY w# 1 sw Y   Œ¬xY w# 1 sw Y   ŒzxY w)a¤  
        Passing an argument of the wrong type to any of the constructor
        arguments of L{URL} will raise a descriptive L{TypeError}.

        L{URL} typechecks very aggressively to ensure that its constitutent
        parts are all properly immutable and to prevent confusing errors when
        bad data crops up in a method call long after the code that called the
        constructor is off the stack.
        c                  ó   — e Zd Zdd„Zdd„Zy)ú1TestURL.test_invalidArguments.<locals>.Unexpectedc                 ó   — y)NÚwrongr%   r&   s    r   Ú__str__z9TestURL.test_invalidArguments.<locals>.Unexpected.__str__Ñ  s   € Ør!   c                 ó   — y)Nú<unexpected>r%   r&   s    r   Ú__repr__z:TestURL.test_invalidArguments.<locals>.Unexpected.__repr__Ô  s   € Ø%r!   N)r)   r4   )r+   r,   r-   r  r	  r%   r!   r   Ú
Unexpectedr  Ð  s   „ óô&r!   r
  Úunicoder4   Únamec                ór   •— ‰j                  t        | j                  «      dj                  ||d«      «       y )Nzexpected {} for {}, got {}r  )rE   r4   r(   rc   )ÚraisedÚexpectationr  r'   s      €r   ÚassertRaisedz3TestURL.test_invalidArguments.<locals>.assertRaisedÙ  s1   ø€ Ø×ÑÜ�F×$Ñ$Ó%Ø,×3Ñ3°KÀÀ~ÓVõr!   c                ó’   •— ‰j                  t        «      5 }t        di |  ‰«       i¤Ž d d d «        ‰|| «       y # 1 sw Y   ŒxY w)Nr%   )r•   Ú	TypeErrorr	   )Úparamr  r  r
  r  r'   s      €€€r   rM   z,TestURL.test_invalidArguments.<locals>.checkß  sF   ø€ Ø×"Ñ"¤9Ó-ð -°ÜÑ,�u™j›lÐ+Ò,÷-á˜ ¨eÕ4÷-ð -ús	   —=½Ar3   r6   r;   r‚   ÚboolrC   rB   zint or NoneTyperÿ   Nzpath segmentrº   z or NoneTypezquery parameter valueÚvaluezquery parameter name)r>   r?   Úvv)r>   zhttps://valid.example.com/zrelative URL)r  r#   r  r4   r  r4   r)   rO   )r  r4   r  r4   r)   rO   )
Úbytesr4   r•   r  r	   Ú
ValueErrorrf   ry   r‡   r‹   )r'   ÚdefaultExpectationrM   r  r²   r
  r  s   `    @@r   Útest_invalidArgumentszTestURL.test_invalidArgumentsÅ  s®  ú€ ÷	&ñ 	&ô +0´3©,™Y¸EÐõ	ð 2D÷ 	5ð 	5ñ
 	ˆhŒÙˆfŒÙˆjÔÙˆh˜ÔÙˆjÔÙˆfÐ'Ô(à×ÑœyÓ)ð 	¨VÜá“Lðõ÷	ñ 	�VÐ/°Ô@Ø×ÑœyÓ)ð 	¨VÜà™Z›\Ð*ðõ÷	ñ 	ØÐ&¨Ñ7Ð9Pô	
ð ×ÑœyÓ)ð 	¨VÜá“\ 7Ð+ðõ÷	ñ 	�VÐ/Ð1GÔHð ×ÑœyÓ)ñ 	&Ü‘z“|�nÕ%÷	&à×ÑœzÓ*ñ 	*ÜÐ'Ð(Õ)÷	*à×ÑœzÓ*ñ 	 Ü�v�hÕ÷	 ô �l‰lÐ7Ó8ˆØ×ÑœyÓ)ð 	$¨VØ�I‰I‘j“lÔ#÷	$á�VÐ/°Ô@Ø×ÑœyÓ)ð 	&¨VØ�K‰K™
›Ô%÷	&á�VÐ/°Ô@Ø×ÑœyÓ)ð 	$¨VØ�I‰I‘j“lÔ#÷	$á�VÐ/°Õ@÷S	ñ 	ú÷	ñ 	ú÷	ñ 	ú÷	&ñ 	&ú÷	*ñ 	*ú÷	 ñ 	 ú÷	$ð 	$ú÷	&ð 	&ú÷	$ð 	$úsl   Á5I+Â/I8Ã.JÄ*JÅJÆJ,ÇJ9ÈKÉKÉ+I5É8JÊJÊJÊJ)Ê,J6Ê9KËKËKc                óê   — | j                  t        «      5 }t        d¬«       ddd«       | j                  t	        j
                  «      dj                  t        d«      «      «       y# 1 sw Y   ŒGxY w)z·
        Technically, L{str} (or L{unicode}, as appropriate) is iterable, but
        C{URL(path="foo")} resulting in C{URL.fromText("f/o/o")} is never what
        you want.
        r_   rÿ   Nz+expected iterable of text for path, not: {})r•   r  r	   rE   r4   r(   rc   r5   )r'   r  s     r   Ú!test_technicallyTextIsIterableButz)TestURL.test_technicallyTextIsIterableBut  s^   € ð ×ÑœyÓ)ð 	¨VÜ�U�O÷	à×ÑÜ�× Ñ Ó!Ø9×@Ñ@ÄÀeÃÓMõ	
÷	ð 	ús   –A)Á)A2NrN   )r   )r<   r	   r3   r4   r6   r4   r7   zIterable[str]r8   z Iterable[tuple[str, str | None]]r;   r4   rB   z
int | NonerC   r4   r)   rO   ©r)   rO   )0r+   r,   r-   Ú__doc__r@   rH   rP   rZ   r]   rd   rk   rq   rt   rv   rz   r~   r„   r‰   r�   r“   r—   rš   r¡   r©   r®   r³   rµ   r»   r¾   rÃ   rÉ   rÍ   rÐ   rÓ   rÕ   r×   rá   rç   rê   rí   rï   rô   r÷   rù   rý   r   r  r  r%   r!   r   r0   r0   U   sO  „ ñó8ð0 ð +àð +ð ð +ð ð	 +ð
 ð +ð 0ð +ð ð +ð ð +ð ð +ð 
ó +óD+ó
ó$
ó
ó&3ó+ó0
ó
ó
ó.
óDó
ó$&
óPAóEó5ó&óB"
óH
ó*
ó-ó5óó!ó$ó)ó5ó8ó7óMóVó.Vó*Vó 5ó1ó
ó(Kó	
ó:ó7óOAôb
r!   r0   c                  ó   — e Zd ZdZdd„Zy)ÚURLDeprecationTestsz.
    L{twisted.python.url} is deprecated.
    c                ó²   — ddl m} | | j                  | j                  g«      }| j	                  dt        |«      «       | j	                  d|d   d   «       y)zK
        L{twisted.python.url} is deprecated since Twisted 17.5.0.
        r   )r²   é   z\twisted.python.url was deprecated in Twisted 17.5.0: Please use hyperlink from PyPI instead.ÚmessageN)Útwisted.pythonr²   ÚflushWarningsÚtest_urlDeprecationrE   Úlen)r'   r²   ÚwarningsShowns      r   r&  z'URLDeprecationTests.test_urlDeprecation)  sZ   € õ 	'áà×*Ñ*¨D×,DÑ,DÐ+EÓFˆØ×Ñ˜œC Ó.Ô/Ø×Ñð;ð ˜!Ñ˜YÑ'õ	
r!   Nr  )r+   r,   r-   r  r&  r%   r!   r   r   r   $  s   „ ñô
r!   r   N)r  Ú
__future__r   Útypingr   r   Útwisted.trial.unittestr   r²   r	   rg   r�   r�   Ú_percentencr#   r0   r   r%   r!   r   ú<module>r-     sa   ðñ
õ #å å å 6Ý à	5€ð 2Ð ò4Ð ñn >€ô�Hô ôL
Ð!ô L
ô^
Ð-õ 
r!   