
    Vh?                         d dl mZ d dlZd dlZd dlmZmZmZmZm	Z	m
Z
 ddlmZ ddlmZmZ ddlmZmZ ej&                  d    dk(  Z ed	      Zd
ZdZg dZdZ G d de      Zy)    )unicode_literalsN)AnyIterableOptionalTextTuplecast   )HyperlinkTestCase   )URLURLParseError)	inet_ptonSCHEME_PORT_MAP *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   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/../x)6zhttp://localhosthttp://localhost/zhttp://127.0.0.1/zhttp://[::127.0.0.1]/zhttp://[::1]/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)zG?sslrootcert=/Users/glyph/Downloads/rds-ca-2015-root.pem&sslmode=verifyz%http://googlewebsite.com/e-shops.aspxz?http://example.com:8080/search?q=123&business=Nothing%20Specialz*http://hatnote.com:9000/?arg=1&arg=2&arg=3https://xn--bcher-kva.chz"http://xn--ggbla1c4e.xn--ngbc5azd/z.http://tools.ietf.org/html/rfc3986#section-3.4z:ftp://ftp.rfc-editor.org/in-notes/tar/RFCs0001-0500.tar.gzz.http://[1080:0:0:0:8:800:200C:417A]/index.htmlzssh://192.0.2.16:2222/z$https://[::101.45.75.219]:80/?hi=byez7ldap://[::192.9.5.5]/dc=example,dc=com??sub?(sn=Jensen)zFmailto:me@example.com?to=me@example.com&body=hi%20http://wikipedia.orgznews:alt.rec.motorcycleztel:+1-800-867-5309zurn:oasis:member:A00024:xa  magnet:?xt=urn:btih:1a42b9e04e122b97a5254e3df77ab3c4b7da725f&dn=Puppy%20Linux%20precise-5.7.1.iso&tr=udp://tracker.openbittorrent.com:80&tr=udp://tracker.publicbt.com:80&tr=udp://tracker.istole.it:6969&tr=udp://tracker.ccc.de:80&tr=udp://open.demonii.com:1337zhttps://%3A@example.com/zhttps://%40@example.com/zhttps://%2f@example.com/zhttps://a:%3a@example.com/zhttps://a:%40@example.com/zhttps://a:%2f@example.com/zhttps://a:%3f@example.com/zhttps://example.com/%2F/zhttps://example.com/%3F/zhttps://example.com/%23/zhttps://example.com/?%23=bzhttps://example.com/?%3D=bzhttps://example.com/?%26=bzhttps://example.com/?a=%23zhttps://example.com/?a=%26zhttps://example.com/?a=%3Dz https://example.com/?foo+bar=bazz https://example.com/?foo=bar+bazzChttp://(%2525):(%2525)@example.com/(%2525)/?(%2525)=(%2525)#(%2525)z8first_seg_rel_path__colon%3Anotok/second_seg__colon%3Aokc                      e Zd ZdZd Z	 dNdZd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&d% Z'd& Z(d' Z)d( Z*d) Z+d* Z,d+ Z-d, Z.d- Z/d. Z0d/ Z1d0 Z2d1 Z3d2 Z4d3 Z5d4 Z6d5 Z7d6 Z8d7 Z9d8 Z:d9 Z;d: Z<d; Z=d< Z>d= Z?d> Z@d? ZAd@ ZBdA ZCdB ZDdC ZEdD ZFdE ZGdF ZHdG ZIdH ZJdI ZKdJ ZLdK ZMdL ZNyM)OTestURLz
    Tests for L{URL}.
    c                    | j                  t        |j                  t              xs |j                  du t	        |             | j                  t        |j
                  t              xs |j
                  du t	        |             |j                  D ]+  }| j                  t        |      t        t	        |             - |j                  D ]]  \  }}| j                  t              t        t	        |             | j                  |du xs t        |t              t	        |             _ | j                  t        |j                        t        t	        |             y)zl
        The given L{URL}'s components should be L{unicode}.

        @param u: The L{URL} to test.
        N)
assertTrue
isinstanceschemeunicodereprhostpathassertEqualtypequeryfragment)selfuseg_kvs        G/home/dcms/DCMS/lib/python3.12/site-packages/hyperlink/test/test_url.pyassertUnicodedzTestURL.assertUnicoded   s    	qxx)=QXX-=tAw	
 	
16673Eqvv~tAwO66 	:CT#Ya9	:ww 	JGRT#Ya9OOAI?Aw)?aI	J 	ajj)7DG<    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)	r%   r(   r)   r,   r-   portuserinfotupler*   )r.   r/   r%   r(   r)   r,   r-   r7   r8   actualexpecteds              r3   	assertURLzTestURL.assertURL   sy    @ HHFFFFGGJJFFJJ
 $K%LJJ
 	*r5   c           	            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   )r4   r<   )r/   r.   s    r3   checkz(TestURL.test_initDefaults.<locals>.check   s+    "NN1fb"b"b"=r5   r?   r   N)r   )r.   rA   s   ` r3   test_initDefaultszTestURL.test_initDefaults   s@    	>
 	c&"oc&"b"%&c&"b"b)*r5   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.
        shpkr2   )rH   NfNr?      à   é)u   λu   πu   ⊥r@   r   r4   r<   r.   r/   s     r3   	test_initzTestURL.test_init   s    
 S3%*k!:C@Aq#sSEJ+Dc4P+?*@(KH!"	
r5   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.
        rD   z%68z%70)%6Bz%76)rP   Nz%66NrL   rM   s     r3   test_initPercentzTestURL.test_initPercent   sM    
 UUGnm%DeLAsEE7^]$CUD	
r5   c                 v    | j                  t        t        dddgddgd            dt        d	      d
       y)z
        L{URL.__repr__} will display the canonical form of the URL, wrapped in
        a L{URL.from_text} invocation, so that it is C{eval}-able but still
        easy to read.
        r?   foobar)bazNrG   frobr%   r(   r)   r,   r-   zURL.from_text(zhttp://foo/bar?baz&k=v#frob)N)r*   r'   r   r.   s    r3   	test_reprzTestURL.test_repr  sF     	!(*5# $((E#FH	
r5   c                 ~    t        j                  t              }| j                  t        |j	                                y)zc
        Round-tripping L{URL.from_text} with C{str} results in an equivalent
        URL.
        N)r   	from_text	BASIC_URLr*   to_textr.   urlpaths     r3   test_from_textzTestURL.test_from_text  s)     --	*GOO$56r5   c                     t         D ]9  }t        j                  |      j                  d      }| j	                  ||       ; y)z@
        L{URL.to_text} should invert L{URL.from_text}.
        Twith_passwordN)ROUNDTRIP_TESTSr   r\   r^   r*   )r.   testresults      r3   test_roundtripzTestURL.test_roundtrip%  s?    
 $ 	+D]]4(00t0DFT6*	+r5   c                     t         D ]i  }t        j                  |      }|j                         }|j                         }||k(  sJ |j	                  d      }|j	                  d      }||k(  riJ  y )NTrc   )re   r   r\   to_irir^   )r.   rf   urliri
double_iriiri_textdouble_iri_texts          r3   test_roundtrip_double_iriz!TestURL.test_roundtrip_double_iri.  sy    # 	/D--%C**,CJ*$$${{{6H(00t0DO...	/ 	r5   c                     t        j                  t              }| j                  |t        j                  t                     | j	                  |t        j                  d             y)z
        Two URLs decoded using L{URL.from_text} 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   r\   r]   r*   assertNotEqualr_   s     r3   test_equalityzTestURL.test_equality;  sK     --	*#--	":;MMO	
r5   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/#r   N)r*   r   r\   rY   s    r3   test_fragmentEqualityzTestURL.test_fragmentEqualityK  sC     	b)351MM./MM-.	
r5   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   r\   r]   r*   childr^   r_   s     r3   
test_childzTestURL.test_childW  s     --	*<MM&!))+	
 	?MM'"**,	
 	EMM-(002	
 	HMM.)113	
r5   c                     t        j                  d      }| j                  |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/bcdezhttp://example.com/a/b/c/d/eN)r   r\   r*   rx   r^   r.   rk   s     r3   test_multiChildzTestURL.test_multiChildo  s=     mm45IIc3$,,.0N	
r5   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r(   r{   zhttp://www.foo.com/cN)r   rx   r#   rootedr*   r^   )r.   childURLs     r3   test_childInitRootzTestURL.test_childInitRootz  sC     M*005(/1A1A1CDr5   c                 \    t        d      }| j                  |j                         |       y)zT
        L{URL.child} without any new segments returns the original L{URL}.
        r   r   N)r   r*   rx   r~   s     r3   test_emptyChildzTestURL.test_emptyChild  s$    
 }%c*r5   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   r\   r]   r*   siblingr^   )r.   r`   url_texts      r3   test_siblingzTestURL.test_sibling  ss     --	*>OOH%--/	

 ?--)9OOH%--/	
r5   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                         v       t        j                  d      }| j                  d|j	                  d      j                                t        j                  d      }| j                  |j	                  d      j                         d       t        j                  d      }d}| j                  |j	                  d      j                         |       | j                  |j	                         j                         |       t        j                  d      }t        j                  d      }|j	                  |      }| j                  |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.orgz$http://hatnote.com/a/b/../c/./d/e/..zhttp://hatnote.com/a/c/d/zhttp://localhost/foo/?abc=defrT   zhttp://localhost/foo/barN)r   r\   r]   r*   r   r^   r#   fromText)r.   r`   r/   resu2u3s         r3   
test_clickzTestURL.test_click  s    --	*8MM"%%'	

 	2MM'"**,	

 	&h(?(G(G(I	
 	2MM'"**,	
 	==!<=EEGH	
 MM9:/GG%&..0	
 MM89GG+,4468O	

 MM@A),,.4 	**,c2 LL89]]5!WWR['ABr5   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   r\   relativeLinkBaseForRFC3986relativeLinkTestsForRFC3986r*   r   r^   )r.   baserefr;   s       r3   test_clickRFC3986zTestURL.test_clickRFC3986  sI    
 }}78: 	BOS(TZZ_446A	Br5   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   r\   r   assertRaisesNotImplementedErrorr   )r.   r   s     r3   test_clickSchemeRelPathzTestURL.test_clickSchemeRelPath  sA    
 }}78-tzz5A-tzz8Dr5   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   r\   r*   replacer%   r(   r)   r,   r-   r7   r_   s     r3   test_cloneUnchangedzTestURL.test_cloneUnchanged  sw     -- 56OO   
	
 	*G4r5   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.
        )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})startr   r:   r;   N)r   r\   r   r^   r*   formatr'   )r.   testsr   r   r;   r:   s         r3   test_clickCollapsezTestURL.test_clickCollapse  s     <<DCKJHI
 IK
 L+
. ', 	"E5(]]5)//6>>@FCJJu+!%	 K 		r5   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/rS   rT   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)r*   r   r\   addr^   r]   r_   s     r3   test_queryAddzTestURL.test_queryAdd-  sg   
 	5MM;<SWY		
 	)]#''u5==?	
 --	*=KK'')	
 	AKK&..0	
 	FKK&**62::<	

 	FKK##FE2::<	

 	HKK&**5$7??A	
r5   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   r\   r]   r*   setr^   r   r_   s     r3   test_querySetzTestURL.test_querySetT  s    
 --	*8KKt$,,.	

 	>KK""5*5==?	
 	8KKu%))%6>>@	
r5   c                    t        j                  d      }| j                  |j                  d      t        j                  d             | j                  |j                  dd      t        j                  d             | j                  |j                  dd      t        j                  d             | j                  |j                  ddd	
      t        j                  d             y)zG
        L{URL.remove} removes instances of a query parameter.
        z*https://example.com/a/b/?foo=1&bar=2&foo=3rS   zhttps://example.com/a/b/?bar=21)namevaluez$https://example.com/a/b/?bar=2&foo=3r
   )r   limitr   )r   r   r   N)r   r\   r*   remover~   s     r3   test_queryRemovezTestURL.test_queryRemovej  s    
 mmHIJJus}}-MN	
 	JJEJ-MM@A	

 	JJEJ+MM@A	

 	JJEAJ6MMFG	
r5   c                 B   t        j                  d      }| j                  |j                  d      dg       | j                  |j	                         d       t        j                  d      }| j                  |j
                  d       | j                  |j	                         d       t        j                  d      }|j                         }| j                  |j                  d      dg       | j                  |j                         j                  d      dg       y	)
z
        Every C{=}-sign after the first in a query parameter is simply included
        in the value of the parameter.
        zhttp://localhost/?=x=x=xr   x=x=xz!http://localhost/?foo=x=x=x&bar=y))rS   r   )rT   yz7https://example.com/?argument=3&argument=4&operator=%3Doperator=N)r   r\   r*   getr^   r,   rj   to_uri)r.   r/   rl   s      r3   test_parseEqualSignInParamValuez'TestURL.test_parseEqualSignInParamValue  s     MM45rWI.&@AMM=>"BC&IJMME
 hhj,se4))*5u=r5   c                 T    | j                  t               j                         d       y)zG
        An empty L{URL} should serialize as the empty string.
        r   N)r*   r   r^   rY   s    r3   
test_emptyzTestURL.test_empty  s    
 	"-r5   c                 ^    t        dg      }| j                  |j                         d       y)zP
        An L{URL} with query text should serialize as just query text.
        helloworldr,   z?hello=worldN)r   r*   r^   rM   s     r3   test_justQueryTextzTestURL.test_justQueryText  s(    
 )*+n5r5   c                 R    t        j                  d      }| j                  ||       y)z2
        L{URL} compares equal to itself.
        r   Nr   r\   r*   rM   s     r3   test_identicalEqualzTestURL.test_identicalEqual  s#    
 MM-.Ar5   c                 |    t        j                  d      }t        j                  d      }| j                  ||       y)zG
        URLs with equivalent components should compare equal.
        %http://u@localhost:8080/p/a/t/h?q=p#fNr   r.   u1r   s      r3   test_similarEqualzTestURL.test_similarEqual  s2    
 ]]BC]]BCR r5   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   r\   assertFalserr   r   s      r3   test_differentNotEqualzTestURL.test_differentNotEqual  sK     ]]/0]]/0rR#89B#r5   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.
        r   *   zURL must not equal a number.zURL must not equal an object.N)r   r\   r   objectrr   rM   s     r3   test_otherTypesNotEqualzTestURL.test_otherTypesNotEqual  sa    
 MM-.b"@Afh(GHAr"Avx(r5   c                 ^    t        j                  d      }| j                  ||k7  d|z         y)zJ
        Identical L{URL}s are not unequal (C{!=}) to each other.
        r   z%r == itselfNr   r\   r   rM   s     r3   test_identicalNotUnequalz TestURL.test_identicalNotUnequal  s,    
 MMABa!!34r5   c                     t        j                  d      }t        j                  d      }| j                  ||k7  |d|       y)zU
        Structurally similar L{URL}s are not unequal (C{!=}) to each other.
        r    == Nr   r   s      r3   test_similarNotUnequalzTestURL.test_similarNotUnequal  s;    
 ]]BC]]BCrR#89r5   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   r\   r#   r   s      r3   test_differentUnequalzTestURL.test_differentUnequal  s9    
 ]]/0]]/0bB"78r5   c                     t        j                  d      }| j                  |dk7  d       | j                  |t               k7  d       y)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   r\   r#   r   rM   s     r3   test_otherTypesUnequalzTestURL.test_otherTypesUnequal  s;    
 MM-.R!ABVX'KLr5   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   r\   asURIr*   r(   r)   r^   )r.   unicodeyrl   uriexpectedURI	actualURIs         r3   
test_asURIzTestURL.test_asURI  s    B 	 mmH%iik#LMHHQKM	
 	1FKKM	{)[$I	
r5   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   r\   asIRIr*   r(   r)   r^   )r.   asciiishr   rl   expectedIRI	actualIRIs         r3   
test_asIRIzTestURL.test_asIRI  s     DmmH%iik=1!h/13 	 KKM	{)[$I	
r5   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   r\   r   r^   r*   )r.   urlWithBinaryr   rl   r   r   s         r3   test_badUTF8AsIRIzTestURL.test_badUTF8AsIRI#  sS     ;mmM*iik2 	
 KKM	{)[$I	
r5   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   r\   r   r*   r^   )r.   r   rl   alsoIRIs       r3   test_alreadyIRIAsIRIzTestURL.test_alreadyIRIAsIRI6  s?    B 	 mmH%))+*H5r5   c                     d}t        j                  |      }|j                         j                         }| j	                  ||       y)zH
        A L{URL} composed of encoded text will remain encoded.
        r   N)r   r\   r   r^   r*   )r.   r   r   r   s       r3   test_alreadyURIAsURIzTestURL.test_alreadyURIAsURIF  s<    
 GmmK(IIK'')	K0r5   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)z{
        L{URL.from_text} 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r8   z/http://someuser@example.com/some-segment@ignoreN)r   r\   r*   	authorityr8   userr^   r   r~   s     r3   test_userinfozTestURL.test_userinfoP  s     mmJ
 	MM$!D	
 	u-/FG'>?:.KKMM	
 	KKK,446=	
r5   c                     t        j                  d      }| j                  |j                  d       | j                  |j	                         d       y)zJ
        L{URL.from_text} parses custom port numbers as integers.
        zhttp://www.example.com:8080/i  N)r   r\   r*   r7   r^   )r.   portURLs     r3   test_portTextzTestURL.test_portTextg  s?    
 -- >?t,*,JKr5   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.from_text}/L{URL.to_text} round-trips cleanly for a C{mailto:}
        URL representing an email address.
        zmailto:user@example.comN)r*   r   r\   r^   rY   s    r3   test_mailtozTestURL.test_mailtop  s+     	MM34<<>%	
r5   c                    t        j                  d      }| j                  |j                  d       | j                  |j                  d       | j                  |j
                  d       | j                  |j                         d       y)zj
        An HTTP URL without a hostname, but with a path, should also round-trip
        cleanly.
        zhttp:relative-pathr   )zrelative-pathFN)r   r\   r*   r(   r)   uses_netlocr^   )r.   without_hosts     r3   test_httpWithoutHostzTestURL.test_httpWithoutHost}  sp     }}%9:**B/**,>?1159--/1EFr5   c                     d}t        dg      }| j                  |j                  |       t        ddi      }| j                  |j                  |       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, sensibly
        handling dictionaries.
        )alphabetar  r   r  r  N)r   r*   r,   )r.   r;   rk   s      r3   test_queryIterablezTestURL.test_queryIterable  sN     (*+,H-&)*H-r5   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   r)   r   N)r   r*   r)   r~   s     r3   test_pathIterablezTestURL.test_pathIterable  s(     )*#56r5   c           	      
     G d dt               t        t        u rdnd} fd|f fd	} |d        |d        |d	        |d
d        |d        |dd        j                  t              5 }t        t        t                      g       ddd        |d        j                  t              5 }t        dt        t                      fg       ddd        ||dz   d        j                  t              5 }t        t        t                      dfg       ddd        ||d        j                  t              5  t        t        t        t        t        f                 g       ddd        j                  t              5  t        t        t        t        t        f   d      g       ddd        j                  t              5  t        t        t        t        t        f   d      g       ddd       t        j                  d      } j                  t              5 }|j                  t        t                             ddd        ||d        j                  t              5 }|j                  t        t                             ddd        ||d        j                  t              5 }|j                  t        t                             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   xY w# 1 sw Y   ~xY w# 1 sw Y   Ex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 Zd Zy)1TestURL.test_invalidArguments.<locals>.Unexpectedc                      y)Nwrong rY   s    r3   __str__z9TestURL.test_invalidArguments.<locals>.Unexpected.__str__  s    r5   c                      y)N<unexpected>r  rY   s    r3   __repr__z:TestURL.test_invalidArguments.<locals>.Unexpected.__repr__  s    %r5   N)__name__
__module____qualname__r  r!  r  r5   r3   
Unexpectedr    s    &r5   r%  r&   strc                 r    j                  t        | j                        dj                  ||d             y )Nzexpected {0} for {1}, got {2}r   )r*   r&  	exceptionr   )raisedexpectationr   r.   s      r3   assertRaisedz3TestURL.test_invalidArguments.<locals>.assertRaised  s4    F$$%/66~r5   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      r3   rA   z,TestURL.test_invalidArguments.<locals>.check  sH    ""9- -,ujl+,- e4- -s	   =Ar%   r(   r-   r   boolr8   r7   zint or NoneTyper  Nzpath segmentr   r   z or NoneTypezquery parameter valuer   zquery parameter name)rH   r2   vv)rH   zhttps://valid.example.com/zrelative URL)r   bytesr&  r   r-  r   r	   r   r   
ValueErrorr\   rx   r   r   )r.   defaultExpectationrA   r)  rk   r%  r+  s   `    @@r3   test_invalidArgumentszTestURL.test_invalidArguments  s   	& 	& +03,YE	 &8 	5 	hfjhjf'(y) 	1Vd4./0	1 	V/@y) 	<VT:< 89:;	< 	&79P	
 y) 	=VT:<0':;<	= 	V/1GH y) 	?tE$*-z|<=>	? z* 	CtE$*-/?@AB	C z* 	9tE$*-v678	9 mm89y) 	0VIId4./	0V/@y) 	2VKKT:<01	2V/@y) 	0VIId4./	0V/@K	1 	1
	< 	<	= 	=	? 	?	C 	C	9 	9	0 	0	2 	2	0 	0sl   8!L #L #L-.L:")M()M%M!%M-%M9L L*-L7:MMM!M*-M69N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.from_text("f/o/o")} is never what
        you want.
        rS   r  Nz,expected iterable of text for path, not: {0})r   r-  r   r*   r&  r(  r   r'   )r.   r)  s     r3   !test_technicallyTextIsIterableButz)TestURL.test_technicallyTextIsIterableBut  s^     y) 	VUO	  !:AA$u+N	
	 	s   A))A2c                    t        d      }| j                  |j                  d       | j                  |j                         d       | j                  t        j                  d      j                  d       | j                  t        j                  d      j                  d       | j                  t        j                  d      j                  d       t        dd      }| j                  |j                  d       | j                  |j                         d       t        d	      }| j                  |j                  d       | j                  |j                         d
       t        d      }| j                  |j                  d       | j                  |j                         d       t        d      }| j                  |j                  d        | j                  |j                         d       t        j                  d      }| j                  |j                  d       t        j                  d      }| j                  |j                  d       y )Nhttpsr%   Tzhttps://zhttps:Fzhttps:/)r%   r  z	git+httpszgit+https://mailtozmailto:ztpzztp:zztp://test.comzztp:test:com)r   r*   r  r^   r\   r~   s     r3   test_netloczTestURL.test_netloc  s   !$/
3x0<<eDy1==uEz2>>Ee4%01%$/7"%0	2$//mm,-$/mmN+%0r5   c                     d}t        j                  |      }|j                  dk(  sJ |j                  dk(  sJ t        |j
                     |j                  k7  sJ y )Nz5https://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80/z'2001:0db8:85a3:0000:0000:8a2e:0370:7334r@   )r   r\   r(   r7   r   r%   )r.   trk   s      r3   test_ipv6_with_portzTestURL.test_ipv6_with_port$  sS    CmmAxxDDDDxx2~~szz*chh666r5   c                 H   d}t        j                  |      }|j                  dk(  sJ |j                  dk(  sJ |j                  dk(  sJ |j
                  dk(  sJ |j                  dk(  sJ d}t        j                  |      }|j                  dk(  sJ |j                  dk(  sJ |j                  dk(  sJ |j
                  dk(  sJ d	}t        j                  |      }|j                  dk(  sJ |j                  dk(  sJ |j                  d
k(  sJ |j
                  dk(  sJ y )Nz3https://user:pass@example.com/path/to/here?k=v#nicer8  	user:passexample.com)r)   toherenicez1https://user:pass@127.0.0.1/path/to/here?k=v#nicez	127.0.0.1z-https://user:pass@[::1]/path/to/here?k=v#nicez::1)r   r\   r%   r8   r(   r)   r-   r.   textrk   s      r3   
test_basiczTestURL.test_basic,  s(   DmmD!zzW$$$||{***xx=(((xx1111||v%%%BmmD!zzW$$$||{***xx;&&&xx1111>mmD!zzW$$$||{***xx5   xx1111r5   c                 N    | j                  t        t        j                  d       y )Nz#

r   r   r   r\   rY   s    r3   test_invalid_urlzTestURL.test_invalid_urlD  s    -@r5   c                 N    | j                  t        t        j                  d       y )Nzhttp://abc:

/#rJ  rY   s    r3   test_invalid_authority_urlz"TestURL.test_invalid_authority_urlH  s    -8KLr5   c                     g d}|D ]c  }d|z   dz   }| j                  t        j                  t        t        j                  |       | j                  t
        t        j                  |       e y )N)z2001::0234:C1ab::A0:aabc:003Fz2001::1::3F:z::::z::256.0.0.1zhttp://[])r   socketerrorr   AF_INET6r   r   r\   )r.   invalid_ipv6_ipsipr   s       r3   test_invalid_ipv6zTestURL.test_invalid_ipv6L  s]    
 # 	FB!B,HfllIvKmS]]HE	Fr5   c                     | j                  t        t        j                  d       | j                  t        t        j                  d       y )Nzftp://portmouth:smashz+http://reader.googlewebsite.com:neverforget)r   r   r   r\   r2  rY   s    r3   test_invalid_portzTestURL.test_invalid_portZ  s4    -8OPMM9	
r5   c                     t        j                  d      }| j                  |j                  d       | j                  |j	                         d       | j                  |j                         j	                         d       t        j                  d      }| j                  |j                  d       | j                  |j	                         d       | j                  |j                         j	                         d       y )Nu   http://bücher.chu
   bücher.chzhttp://xn--bcher-kva.chr   zxn--bcher-kva.chu   https://bücher.ch)r   r\   r*   r(   r^   r   rj   r   s      r3   	test_idnazTestURL.test_idnac  s    ]]./,/':;,,.0IJ]]56"45'AB,,.0DEr5   c                    t        j                  d      }| j                  |j                  d       | j                  |j	                         d       t        j                  d      }| j                  |j                  d       | j                  |j	                         d       t        j                  d      }| j                  |j                  d       | j                  |j	                         d       t        j                  d      }| j                  |j                  d       | j                  |j	                         d       t        j                  d	      }| j                  |j                  d
       | j                  |j	                         d	       t        j                  d      }| j                  |j                  d       | j                  |j	                         d       t        ddd      }| j                  |j	                         d       t        d
ddd      }| j                  |j	                         d       t        j                  d      }|j                  d      }| j                  |j	                         d       d}t        j                  |      }|j                  d      }| j                  |j	                         d       |j                  d      }| j                  |j	                         |       y )Nzmailto:mahmoud@hatnote.comr:  zhttp://hatnote.comr?   znewscheme:a:b:c	newschemeznewerscheme://a/b/cnewerschemez%git+ftp://gitstub.biz/glyph/lefkowitzzgit+ftpz'what+mailto:freerealestate@enotuniq.orgzwhat+mailtor;  )xr   zT)r%   r)   r   z
ztp:/x/y/z)r^  r   r_  r   )r%   r)   r   r  zgit+ftp:///x/y/z/zfile:///path/to/heckr9  zmailto:/path/to/heckzunregisteredscheme:///a/b/cF)r  zunregisteredscheme:/a/b/c)r   r\   r*   r%   r^   r   )r.   rk   url2r   no_netloc_url
netloc_urls         r3   test_netloc_slasheszTestURL.test_netloc_slasheso  s_    mm89X.(DEmm01V,(<= mm-.[1(9:mm12]3(=> mmCDY/(OPmmEF]3KKMD	
 _TB5 $	
 	(;< mm23{{({+)?@0mmH%6..02MN[[T[2
++-x8r5   c                     t        dg      }| j                  |j                         d       |j                  d      }| j                  |j                         d       | j	                  ||       y)z
        On host-relative URLs, the C{rooted} flag can be updated to indicate
        that the path should no longer be treated as absolute.
        r   r  T)r   z/helloN)r   r*   r^   r   rr   )r.   abs      r3   test_rooted_to_relativezTestURL.test_rooted_to_relative  s\     gYg.IITI"h/Aq!r5   c                    t        ddgd      }| j                  |j                  d       t        dgd      }| j                  |j                  d       | j                  ||       t        ddgd      }t        ddg      }| j                  ||       | j                  |j                  d       | j                  |j                  d       y	)
a	  
        The C{rooted} flag can be updated in some cases, but it cannot be made
        to conflict with other facts surrounding the URL; for example, all URLs
        involving an authority (host) are inherently rooted because it is not
        syntactically possible to express otherwise; also, once an unrooted URL
        gains a path that starts with an empty string, that empty string is
        elided and it becomes rooted, because these cases are syntactically
        indistinguisable in real URL text.
        r   rS   F)r)   r   TrT   )r(   r)   r   )r(   r)   N)r   r*   r   )r.   relative_path_rootedrelative_flag_rootedattempt_unrooted_absolutenormal_absolutes        r3   test_autorootedzTestURL.test_autorooted  s      #UEB-44d;"=-44d;-/CD$'U%$O!5w72OD//62994@r5   c                    t        ddd      }t        dd      }t        ddd      }| j                  |j                  d       | j                  |j                  d       | j                  |j                  d       t        j                  d      }| j                  t	        |      t	        |             | j                  t	        |      t	        |             | j                  |j                         |j                                | j                  ||       | j                  ||       | j                  ||       | j                  ||       | j                  ||       y)	a  
        URLs which include a ``://`` netloc-separator for any reason are
        inherently rooted, regardless of the value or presence of the
        ``rooted`` constructor argument.

        They may include a netloc-separator because their constructor was
        directly invoked with an explicit host or port, or because they were
        parsed from a string which included the literal ``://`` separator.
        udpi$  F)r%   r7   r   )r%   r7   Tzudp://:4900N)r   r*   r   r\   r&  asText)r.   directly_constructeddirectly_constructed_implictdirectly_constructed_rootedparseds        r3   !test_rooted_with_port_but_no_hostz)TestURL.test_rooted_with_port_but_no_host  s-     #%d5I'*%d'C$&)T$&O#-44d;5<<dC4;;TB}-12CK@9:CKH-446H-v6-/KL-/JK5v>4f=r5   c                     | j                  t              5  t        t               d d d        | j                  t              5  t        d       d d d        y # 1 sw Y   3xY w# 1 sw Y   y xY w)NHTTP_____more_like_imHoTTeP)r   r2  r   r]   rY   s    r3   test_wrong_constructorzTestURL.test_wrong_constructor  s_    z* 		N	 z* 	/-.	/ 	/	 		/ 	/s   AA$A!$A-c                 :   t        j                  d      }|j                  dk(  sJ |j                  d      }|j	                         }|j                  d      dk(  sJ |j                  d      d	k(  sJ |j                         j                  d      d
k(  sJ y )Nzhttp://user:pass@example.comrA  zus%20her:passr  Trc   zhttp://us her:pass@example.comFzhttp://us her:@example.comz http://us%20her:pass@example.com)r   r\   r8   r   rj   r^   r   r.   rk   rl   s      r3   test_encoded_userinfozTestURL.test_encoded_userinfo  s    mm:;||{***kk?k3jjlKKdK+/OO	
O{{{/3OOOOJJL  t 412	
2r5   c                 v   i }t        j                  d      }t        |      t        |      k(  sJ d||<   t        j                  d      }|j                  dd      }d||<   t	        |      dk(  sJ t        |j                               dgk(  sJ t        t                     t        t                     k(  sJ y )Nz.http://blog.hatnote.com/ask?utm_source=geocityr
   zhttp://blog.hatnote.com/ask
utm_sourcegeocityr   )r   r\   hashr   lenlistvalues)r.   url_mapurl1r`  s       r3   	test_hashzTestURL.test_hash   s    }}MNDzT$Z'''}}:;xxi07|q   GNN$%!,,,CE{d35k)))r5   c                 ~    t               }t        |      }t        |      dkD  sJ d|vsJ d|vsJ d|vsJ d|vsJ y )N   r   rp  r   r   )r   dirr  )r.   rk   r   s      r3   test_dirzTestURL.test_dir  sZ    e#h3x"}}$$$s"""c!!!c!!!r5   c                     t        j                  d      }|j                         dk(  sJ |j                         j                         dk(  sJ y )Nu"   http://example.com/a%20té%C3%A9stz&http://example.com/a%20t%C3%A9%C3%A9st)r   r   rp  r   r~   s     r3   test_twisted_compatzTestURL.test_twisted_compat  sD    ll?@zz|CCCCyy{!!#'OOOOr5   c                     t        j                  d      }|j                  dd      }|j                  dd      }|j	                         dk(  sJ y )Nzhttp://example.com/?a=b&cr^  r   z!http://example.com/?a=b&x=x&c&x=y)r   r\   r   r   r^   r~   s     r3   test_set_orderingzTestURL.test_set_ordering%  sH     mm78ggc3ggc3{{} CCCCr5   c                    t        j                  d      }t        j                  |j                               }||k(  sJ t        j                  |j                         j                               }||k(  sJ ||k(  sJ t        j                  d      }|j                         }|j                         dk(  sJ t        j                  |j                               j	                         }||k(  sJ y)zSee issue #4z#urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoobz1first-segment/urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoobz'first-segment/urn:ietf:wg:oauth:2.0:oobN)r   r\   r^   rj   r   )r.   r   r   r   u4u5u6s          r3   test_schemeless_pathzTestURL.test_schemeless_path0  s     ]]@A]]2::<(Rxx]]299;..01RxxRxx ]]NOYY[zz|HHHH]]2::<(//1Rxxr5   c                 n    t        j                  d      }|j                         }|j                          y)z4See issue #7, affecting only narrow builds (2.6-3.3)zhttps://xn--vi8hiv.wsN)r   r\   rj   r^   rz  s      r3   test_emoji_domainzTestURL.test_emoji_domainC  s'     mm34jjlr5   c                     | j                  t        t        dd       | j                  t        t        d       | j                  t        t        d       | j                  t        t        d       y	)
zPer issue #6 and #8r?   za/c)r%   r(   )?r  )#)&rf   r   N)r   r2  r   rY   s    r3   test_delim_in_paramzTestURL.test_delim_in_paramK  sZ     	*c&uE*c7*c7*c-Ar5   c                    t        j                  d      }t        j                  d      }||k(  sJ t        j                  d      }t        j                  d      }||k(  sJ t        j                  d      }t        j                  d      }||k(  sJ t        j                  d      }t        j                  d      }||k(  sJ y )Nzhttp://example.com/zhttp://example.com)r   r\   r   s      r3   test_empty_paths_eqzTestURL.test_empty_paths_eqS  s    ]]01]]/0Rxx]]/0]]/0Rxx]]/0]]01Rxx]]01]]01Rxxr5   c                     t        j                  d      j                  dk(  sJ | j                  t        t         j                  d       | j                  t        t         j                  t                      y )Nz#okoks   bytes://x.y.z)r   r\   r-   r   r-  r   rY   s    r3   test_from_text_typezTestURL.test_from_text_typei  sN    }}U#,,444)S]]4DE)S]]FH=r5   c                 
   | j                  t        t        j                  d       | j                  t        t        j                  d       | j                  t        t        j                  d       | j                  t        t        j                  d       | j                  t        t        j                  d       | j                  t        t        j                  d       | j                  t        t        j                  d       y )Nzhttp://[::1/zhttp://::1]/zhttp://[[::1]/zhttp://[::1]]/zhttp://127.0.0.1:zhttp://127.0.0.1:hizhttp://127.0.0.1::80rJ  rY   s    r3   test_from_text_bad_authorityz$TestURL.test_from_text_bad_authorityo  s     	-G-G-8HI-8HI 	-8KL-8MN-8NOr5   c                 4   t        j                  d      }|j                  d      g k(  sJ |j                  d      dgk(  sJ t        |j                        dk(  sJ |j                         }|j                  dk(  sJ |j                  dk(  sJ |j                  dk(  sJ |j                  d      d	gk(  sJ |j                  d
k(  sJ |j                         dk(  sJ |j                  ddddd      }||k(  sJ t        j                  d      }|j                         }|j                         dk(  sJ t        j                  d      }|j                         }|j                         dk(  sJ t        d      j                  d      j                         dk(  sJ t        d      j                         j                         dk(  sJ t        dddgdgdd      }|j                  d      d k(  sJ |j                         j                  d      d!k(  sJ y )"Nz0HTTP://Example.com/A%61/./../A%61?B%62=C%63#D%64BbzB%62zC%63   r?   rB  )AaCcDdzhttp://example.com/Aa?Bb=Cc#DdFrW   zhttp://example.iozhttp://example.io/z/a%2fb/cd%3f?k%3d=v%23#testz/a%2Fb/cd%3F?k%3D=v%23#test)r   z%te%stsr  )percentsz/%te%stsz/%25te%25stsftpz%%%z%a%b)%z%%r  z%:%)r%   r)   r,   r-   r8   Trc   zftp://%:%@/%%%/%a%b?%=%%#%z0ftp://%25:%25@/%25%25%25/%25a%25b?%25=%25%25#%25)
r   r\   r   r  r)   	normalizer%   r(   r-   r^   )	r.   rk   norm_urlnoop_norm_urlslashless_urlslashful_urldelimited_urlnorm_delimited_urlpercenty_urls	            r3   test_normalizezTestURL.test_normalize  sJ   mmNOwwt}"""wwv6(***388}!!! ==?&(((}}---}}'''||D!dV+++  D(((!%EEEE u5 & 
 ### &9:$..0##%)==== &CD*446!))+/LLLL _%///?GGI	
 (224<<>.PPP-
   t 4+,	
, ""$,,4,@AB	
Br5   c                 X   d}t        j                  |      }t        |      |k(  sJ t        |      dk(  sJ t        r7t        t        |      t              sJ t        t        |      t              sJ y t        t        |      t              sJ t        t        |      t              sJ y )Nu&   http://example.com/á/y%20a%20y/?b=%25s*   http://example.com/%C3%A1/y%20a%20y/?b=%25)r   r\   r&   r1  PY2r$   r&  rF  s      r3   test_strzTestURL.test_str  s     8mmD!s|t###SzJJJJc#h...gclG444c#h000eCj%000r5   c                 .   t        j                  d      }|j                         j                  dk(  sJ |j	                         j                  dk(  sJ t        j                  d      }|j                         j                  dk(  sJ |j	                         j                  dk(  sJ |j	                         j                         j                  dk(  sJ d}t        j                  |      j	                         j                         j                  dk(  sJ y )	Nu   http://abé.com/u   abé.comzxn--ab-cja.comu(   http://ドメイン.テスト.co.jp#testu   ドメイン.テスト.co.jpzxn--eckwd4c7c.xn--zckzah.co.jpzhttp://Example.comrB  )r   r\   rj   r(   r   get_decoded_url)r.   rk   rG  s      r3   test_idna_cornerszTestURL.test_idna_corners  s    mm./zz|  J...zz|  $4444mmFGzz|  $BBBBzz|  $DDDDzz|++-226TTTT#MM$&&(88:??=P	
Pr5   N)r   )Or"  r#  r$  __doc__r4   r<   rB   rN   rQ   rZ   ra   rh   rp   rs   ru   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  r4  r6  r<  r?  rH  rK  rM  rV  rX  rZ  rc  rg  rm  ru  rx  r{  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r5   r3   r!   r!      s   =6 1+f+
&	

(7+
 


0	
E+
&<C|BE5((T%
N
,
2>*.6!	$	)5:9M
4
0
&6 1
.L

G.7SAj
 1D720AMF

F9v
"A.>6/
*$
"PD&B,>P 7
r1 
r5   r!   )
__future__r   sysrQ  typingr   r   r   r   r   r	   commonr   r   r   r   _urlr   r   version_infor  r+   r&   r]   r   r   re   r!   r  r5   r3   <module>r     so    ( 
  = = % ! - 
qQ
r( 9	 2 1 hAHF
 F
r5   