U
    éìª\:¸  ã                (   @   sâ   d dl mZ d dlZd dlZddlmZ ddlmZmZ ddlm	Z	 ddl	m
Z
mZmZ ejd  dkZed	ƒZd
ZdZddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3g(Zd4ZG d5d6„ d6eƒZdS )7é    )Úunicode_literalsNé   )ÚHyperlinkTestCaseé   )ÚURLÚURLParseError)Ú_url)Ú	inet_ptonÚSCHEME_PORT_MAPÚ
parse_hostÚ ú*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)4z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=%3DzChttp://(%2525):(%2525)@example.com/(%2525)/?(%2525)=(%2525)#(%2525)z8first_seg_rel_path__colon%3Anotok/second_seg__colon%3Aokc                   @   sJ  e Zd ZdZdd„ Zd’dd„Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Zd9d:„ Zd;d<„ Z d=d>„ Z!d?d@„ Z"dAdB„ Z#dCdD„ Z$dEdF„ Z%dGdH„ Z&dIdJ„ Z'dKdL„ Z(dMdN„ Z)dOdP„ Z*dQdR„ Z+dSdT„ Z,dUdV„ Z-dWdX„ Z.dYdZ„ Z/d[d\„ Z0d]d^„ Z1d_d`„ Z2dadb„ Z3dcdd„ Z4dedf„ Z5dgdh„ Z6didj„ Z7dkdl„ Z8dmdn„ Z9dodp„ Z:dqdr„ Z;dsdt„ Z<dudv„ Z=dwdx„ Z>dydz„ Z?d{d|„ Z@d}d~„ ZAdd€„ ZBdd‚„ ZCdƒd„„ ZDd…d†„ ZEd‡dˆ„ ZFd‰dŠ„ ZGd‹dŒ„ ZHddŽ„ ZIdd„ ZJd‘S )“ÚTestURLz
    Tests for L{URL}.
    c                 C   sÆ   |   t|jtƒp|jdkt|ƒ¡ |   t|jtƒp:|jdkt|ƒ¡ |jD ]}|  t|ƒtt|ƒ¡ qJ|j	D ]<\}}|  t|ƒtt|ƒ¡ |   |dkpžt|tƒt|ƒ¡ ql|  t|j
ƒtt|ƒ¡ dS )zl
        The given L{URL}'s components should be L{unicode}.

        @param u: The L{URL} to test.
        N)Ú
assertTrueÚ
isinstanceÚschemeÚunicodeÚreprÚhostÚpathÚassertEqualÚtypeÚqueryÚfragment)ÚselfÚuZsegÚkÚv© r+   ú9/usr/lib/python3/dist-packages/hyperlink/test/test_url.pyÚassertUnicoded™   s    ÿÿ
 zTestURL.assertUnicodedr   c	                 C   sL   |j |j|j|j|j|j|jf}	||t|ƒt|ƒ|||jf}
|  |	|
¡ dS )aª  
        The given L{URL} should have the given components.

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

        @param scheme: The expected scheme.

        @param host: The expected host.

        @param path: The expected path.

        @param query: The expected query.

        @param fragment: The expected fragment.

        @param port: The expected port.

        @param userinfo: The expected userinfo.
        N)	r   r!   r"   r%   r&   ÚportÚuserinfoÚtupler#   )r'   r(   r   r!   r"   r%   r&   r.   r/   ÚactualÚexpectedr+   r+   r,   Ú	assertURLª   s      ÿ  ÿzTestURL.assertURLc                    sD   ‡ fdd„}|t ddƒƒ |t ddg g ƒƒ |t ddg g dƒƒ dS )z@
        L{URL} should have appropriate default values.
        c              
      s&   ˆ   | ¡ ˆ  | ddg g ddd¡ d S )NÚhttpr   éP   )r-   r3   )r(   ©r'   r+   r,   ÚcheckÉ   s    
z(TestURL.test_initDefaults.<locals>.checkr4   r   N)r   )r'   r7   r+   r6   r,   Útest_initDefaultsÅ   s    zTestURL.test_initDefaultsc              	   C   sj   t dddgddgdƒ}|  |¡ |  |dddgddgdd¡ |  t dd	d
gdgdƒdd	d
gdgdd¡ dS )z=
        L{URL} should accept L{unicode} parameters.
        ÚsÚhÚp©r)   r*   )r)   NÚfNr4   õ   Ã õ   Ã©)u   Î»u   Ï€u   âŠ¥r5   ©r   r-   r3   ©r'   r(   r+   r+   r,   Ú	test_initÑ   s"    
 ÿ ÿ    ýzTestURL.test_initc              	   C   s@   t dddgddgdƒ}|  |¡ |  |dddgddgdd¡ dS )zN
        L{URL} should accept (and not interpret) percent characters.
        r9   z%68z%70)ú%6Bz%76)rC   Nz%66Nr@   rA   r+   r+   r,   Útest_initPercentß   s    ÿ
   ýzTestURL.test_initPercentc              
   C   s2   |   ttdddgddgddƒdtd	ƒf ¡ d
S )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.
        r4   ÚfooÚbar)ZbazNr<   Zfrob©r   r!   r"   r%   r&   zURL.from_text(%s)zhttp://foo/bar?baz&k=v#frobN)r#   r    r   r6   r+   r+   r,   Ú	test_reprë   s    þüzTestURL.test_reprc                 C   s   t  t¡}|  t| ¡ ¡ dS )zc
        Round-tripping L{URL.from_text} with C{str} results in an equivalent
        URL.
        N)r   Ú	from_textÚ	BASIC_URLr#   Úto_text©r'   Úurlpathr+   r+   r,   Útest_from_textø   s    
zTestURL.test_from_textc                 C   s,   t D ]"}t |¡jdd}|  ||¡ qdS )z@
        L{URL.to_text} should invert L{URL.from_text}.
        T©Zwith_passwordN)ÚROUNDTRIP_TESTSr   rI   rK   r#   )r'   ÚtestÚresultr+   r+   r,   Útest_roundtrip   s    zTestURL.test_roundtripc                 C   sX   t D ]N}t |¡}| ¡ }| ¡ }||ks.t‚|jdd}|jdd}||kst‚qd S )NTrO   )rP   r   rI   Úto_iriÚAssertionErrorrK   )r'   rQ   ÚurlÚiriZ
double_iriZiri_textZdouble_iri_textr+   r+   r,   Útest_roundtrip_double_iri  s    
z!TestURL.test_roundtrip_double_iric                 C   s2   t  t¡}|  |t  t¡¡ |  |t  d¡¡ dS )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   rI   rJ   r#   ÚassertNotEqualrL   r+   r+   r,   Útest_equality  s    
þzTestURL.test_equalityc                 C   s0   |   tddtƒ ¡ |   t d¡t d¡¡ dS )zŒ
        An URL created with the empty string for a fragment compares equal
        to an URL created with an unspecified fragment.
        r   )r&   zhttp://localhost/#r   N)r#   r   rI   r6   r+   r+   r,   Útest_fragmentEquality"  s    ÿzTestURL.test_fragmentEqualityc                 C   sf   t  t¡}|  d| d¡ ¡ ¡ |  d| d¡ ¡ ¡ |  d| d¡ ¡ ¡ |  d| d¡ ¡ ¡ d	S )
zm
        L{URL.child} appends a new path segment, but does not affect the query
        or fragment.
        z.http://www.foo.com/a/nice/path/gong?zot=23&zutZgongz1http://www.foo.com/a/nice/path/gong%2F?zot=23&zutzgong/z7http://www.foo.com/a/nice/path/gong%2Fdouble?zot=23&zutzgong/doublez:http://www.foo.com/a/nice/path/gong%2Fdouble%2F?zot=23&zutzgong/double/N)r   rI   rJ   r#   ÚchildrK   rL   r+   r+   r,   Ú
test_child+  s    
ÿÿþþzTestURL.test_childc                 C   s(   t  d¡}|  | ddd¡ ¡ d¡ dS )zg
        L{URL.child} receives multiple segments as C{*args} and appends each in
        turn.
        zhttp://example.com/a/bÚcÚdÚezhttp://example.com/a/b/c/d/eN)r   rI   r#   r\   rK   ©r'   rV   r+   r+   r,   Útest_multiChild>  s    
ÿzTestURL.test_multiChildc                 C   s0   t dd d¡}|  |j¡ |  d| ¡ ¡ dS )zo
        L{URL.child} of a L{URL} without a path produces a L{URL} with a single
        path segment.
        úwww.foo.com©r!   r^   zhttp://www.foo.com/cN)r   r\   r   Úrootedr#   rK   )r'   ZchildURLr+   r+   r,   Útest_childInitRootG  s    zTestURL.test_childInitRootc                 C   s   t dd}|  | ¡ |¡ dS )zT
        L{URL.child} without any new segments returns the original L{URL}.
        rc   rd   N)r   r#   r\   ra   r+   r+   r,   Útest_emptyChildP  s    
zTestURL.test_emptyChildc                 C   sH   t  t¡}|  d| d¡ ¡ ¡ d}t  |¡}|  d| d¡ ¡ ¡ dS )z
        L{URL.sibling} of a L{URL} replaces the last path segment, but does not
        affect the query or fragment.
        z0http://www.foo.com/a/nice/path/sister?zot=23&zutZsisterz)http://www.foo.com/a/nice/path?zot=23&zutz+http://www.foo.com/a/nice/sister?zot=23&zutN)r   rI   rJ   r#   ÚsiblingrK   )r'   rM   Úurl_textr+   r+   r,   Útest_siblingW  s    
þ
þzTestURL.test_siblingc                 C   s$  t  t¡}|  d| d¡ ¡ ¡ |  d| d¡ ¡ ¡ |  d| d¡ ¡ ¡ |  d| d¡ ¡ ¡ |  d	| d
¡ ¡ k¡ t  d¡}|  d| d¡ ¡ ¡ t  d¡}|  | d¡ ¡ d¡ t  d¡}d}|  | d¡ ¡ |¡ |  | ¡  ¡ |¡ t  d¡}t  d¡}| |¡}|  | ¡ d¡ dS )z¦
        L{URL.click} interprets the given string as a relative URI-reference
        and returns a new L{URL} interpreting C{self} as the base absolute URI.
        r   r   z$http://www.foo.com/a/nice/path/clickÚclickzhttp://www.foo.com/clickz/clickz$http://www.foo.com/a/nice/path/?burpz?burpz//foobarzhttp://www.foo.com/foobarzhttp://www.foo.com/me/noqueryz!http://www.foo.com/me/17?spam=158z/me/17?spam=158zhttp://localhost/foo?abc=defzhttp://www.python.orgz$http://hatnote.com/a/b/../c/./d/e/..zhttp://hatnote.com/a/c/d/zhttp://localhost/foo/?abc=defrF   zhttp://localhost/foo/barN)r   rI   rJ   r#   rk   rK   r   ÚfromText)r'   rM   r(   ÚresÚu2Úu3r+   r+   r,   Ú
test_clicki  s@    
ÿÿÿÿÿ
ÿ
ÿ



zTestURL.test_clickc                 C   s2   t  t¡}tD ]\}}|  | |¡ ¡ |¡ qdS )zQ
        L{URL.click} should correctly resolve the examples in RFC 3986.
        N)r   rI   ÚrelativeLinkBaseForRFC3986ÚrelativeLinkTestsForRFC3986r#   rk   rK   )r'   ÚbaseÚrefr2   r+   r+   r,   Útest_clickRFC3986š  s    
zTestURL.test_clickRFC3986c                 C   s.   t  t¡}|  t|jd¡ |  t|jd¡ dS )zM
        L{URL.click} should not accept schemes with relative paths.
        zg:hzhttp:hN)r   rI   rq   ÚassertRaisesÚNotImplementedErrorrk   )r'   rs   r+   r+   r,   Útest_clickSchemeRelPath¢  s    
zTestURL.test_clickSchemeRelPathc              
   C   sF   t  d¡}|  | |j|j|j|j|j|j	¡|¡ |  | ¡ |¡ dS )zf
        Verify that L{URL.replace} doesn't change any of the arguments it
        is passed.
        zhttps://x:1/y?z=1#AN)
r   rI   r#   Úreplacer   r!   r"   r%   r&   r.   rL   r+   r+   r,   Útest_cloneUnchangedª  s    
ûúzTestURL.test_cloneUnchangedc                 C   s´   dddgdddgdddgdddgdddgdd	d
gdddgdddgdddgdd	dgdd	d
gdddgdddgg}|D ]>\}}}t  |¡ |¡ ¡ }|  ||dj|t|ƒ||d¡ qpdS )zd
        L{URL.click} collapses C{.} and C{..} according to RFC 3986 section
        5.2.4.
        r   r   r   zhttp://localhost/a/b/czhttp://localhost/a/b/zhttp://localhost/a/z./d/ezhttp://localhost/a/b/d/ez../d/ezhttp://localhost/a/d/ez/./d/ezhttp://localhost/d/ez/../d/ezhttp://localhost/a/b/c/z
../../d/e/zhttp://localhost/a/d/e/zhttp://localhost/a/./czhttp://localhost/a/./c/zhttp://localhost/a/b/c/dz./e/../f/../gzhttp://localhost/a/b/c/gzd//ezhttp://localhost/a/b/d//ez1{start}.click({click}) => {actual} not {expected})Ústartrk   r1   r2   N)r   rI   rk   rK   r#   Úformatr    )r'   Ztestsr{   rk   r2   r1   r+   r+   r,   Útest_clickCollapse¹  s<    ÿÿñüýzTestURL.test_clickCollapsec                 C   sÔ   |   dt d¡ dd¡ ¡ ¡ |   dtdd dd¡ ¡ ¡ t t¡}|   d| d	¡ ¡ ¡ |   d
| d	d¡ ¡ ¡ |   d| d	d¡ d¡ ¡ ¡ |   d| d¡ d	d¡ ¡ ¡ |   d| d	d¡ dd¡ ¡ ¡ dS )z3
        L{URL.add} adds query parameters.
        z'http://www.foo.com/a/nice/path/?foo=barzhttp://www.foo.com/a/nice/path/rE   rF   zhttp://www.foo.com/?foo=barrc   rd   z/http://www.foo.com/a/nice/path/?zot=23&zut&burpZburpz3http://www.foo.com/a/nice/path/?zot=23&zut&burp=xxxÚxxxz8http://www.foo.com/a/nice/path/?zot=23&zut&burp=xxx&zingZzingz8http://www.foo.com/a/nice/path/?zot=23&zut&zing&burp=xxxz:http://www.foo.com/a/nice/path/?zot=23&zut&burp=xxx&zot=32ÚzotÚ32N)r#   r   rI   ÚaddrK   rJ   rL   r+   r+   r,   Útest_queryAddÜ  s@    
 ÿþþ
þþþþþzTestURL.test_queryAddc                 C   sd   t  t¡}|  d| dd¡ ¡ ¡ |  d| d¡ dd¡ ¡ ¡ |  d| dd¡ dd¡ ¡ ¡ dS )	z?
        L{URL.set} replaces query parameters by name.
        z*http://www.foo.com/a/nice/path/?zot=32&zutr   r€   z0http://www.foo.com/a/nice/path/?zot&zut=itworkedZzutZitworkedr~   N)r   rI   rJ   r#   ÚsetrK   r   rL   r+   r+   r,   Útest_querySetü  s    
þþþzTestURL.test_querySetc                 C   s|   t  d¡}|  | d¡t  d¡¡ |  |jdddt  d¡¡ |  |jdddt  d¡¡ |  |jddd	d
t  d¡¡ dS )zG
        L{URL.remove} removes instances of a query parameter.
        z*https://example.com/a/b/?foo=1&bar=2&foo=3rE   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   rI   r#   Úremovera   r+   r+   r,   Útest_queryRemove  s"    
þþþþzTestURL.test_queryRemovec                 C   s˜   t  d¡}|  | d¡dg¡ |  | ¡ d¡ t  d¡}|  |jd¡ |  | ¡ d¡ t  d¡}| ¡ }|  | d¡dg¡ |  | ¡  d¡dg¡ d	S )
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))rE   r‹   )rF   Úyz7https://example.com/?argument=3&argument=4&operator=%3DÚoperatorú=N)r   rI   r#   ÚgetrK   r%   rT   Úto_uri)r'   r(   rW   r+   r+   r,   Útest_parseEqualSignInParamValue)  s    


z'TestURL.test_parseEqualSignInParamValuec                 C   s   |   tƒ  ¡ d¡ dS )zG
        An empty L{URL} should serialize as the empty string.
        r   N)r#   r   rK   r6   r+   r+   r,   Ú
test_empty;  s    zTestURL.test_emptyc                 C   s    t dgd}|  | ¡ d¡ dS )zP
        An L{URL} with query text should serialize as just query text.
        ©ÚhelloÚworld©r%   z?hello=worldN)r   r#   rK   rA   r+   r+   r,   Útest_justQueryTextA  s    zTestURL.test_justQueryTextc                 C   s   t  d¡}|  ||¡ dS )z2
        L{URL} compares equal to itself.
        r   N©r   rI   r#   rA   r+   r+   r,   Útest_identicalEqualH  s    
zTestURL.test_identicalEqualc                 C   s$   t  d¡}t  d¡}|  ||¡ dS )zG
        URLs with equivalent components should compare equal.
        ú%http://u@localhost:8080/p/a/t/h?q=p#fNr˜   ©r'   Úu1rn   r+   r+   r,   Útest_similarEqualO  s    

zTestURL.test_similarEqualc                 C   s<   t  d¡}t  d¡}|  ||kd||f ¡ |  ||¡ dS )z|
        L{URL}s that refer to different resources are both unequal (C{!=}) and
        also not equal (not C{==}).
        úhttp://localhost/aúhttp://localhost/bú%r != %rN)r   rI   ÚassertFalserY   r›   r+   r+   r,   Útest_differentNotEqualW  s    

zTestURL.test_differentNotEqualc                 C   sJ   t  d¡}|  |dkd¡ |  |tƒ kd¡ |  |d¡ |  |tƒ ¡ dS )z=
        L{URL} is not equal (C{==}) to other types.
        r   é*   zURL must not equal a number.zURL must not equal an object.N)r   rI   r¡   ÚobjectrY   rA   r+   r+   r,   Útest_otherTypesNotEquala  s
    
zTestURL.test_otherTypesNotEqualc                 C   s"   t  d¡}|  ||kd| ¡ dS )zJ
        Identical L{URL}s are not unequal (C{!=}) to each other.
        rš   z%r == itselfN©r   rI   r¡   rA   r+   r+   r,   Útest_identicalNotUnequalk  s    
z TestURL.test_identicalNotUnequalc                 C   s0   t  d¡}t  d¡}|  ||kd||f ¡ dS )zU
        Structurally similar L{URL}s are not unequal (C{!=}) to each other.
        rš   ú%r == %rNr¦   r›   r+   r+   r,   Útest_similarNotUnequalr  s    

zTestURL.test_similarNotUnequalc                 C   s0   t  d¡}t  d¡}|  ||kd||f ¡ dS )zS
        Structurally different L{URL}s are unequal (C{!=}) to each other.
        rž   rŸ   r¨   N)r   rI   r   r›   r+   r+   r,   Útest_differentUnequalz  s    

zTestURL.test_differentUnequalc                 C   s0   t  d¡}|  |dkd¡ |  |tƒ kd¡ dS )z;
        L{URL} is unequal (C{!=}) to other types.
        r   r£   zURL must differ from a number.z"URL must be differ from an object.N)r   rI   r   r¤   rA   r+   r+   r,   Útest_otherTypesUnequal‚  s    
zTestURL.test_otherTypesUnequalc                 C   sl   d}t  |¡}| ¡ }|  |jd¡ |  |jd d¡ |  | ¡ |¡ d}| ¡ }|  ||d||f ¡ dS )z‹
        L{URL.asURI} produces an URI which converts any URI unicode encoding
        into pure US-ASCII and returns a new L{URL}.
        õ   http://Ã©.com/eÌ?aÌ=iÌ#uÌu   Ã©.comr   u   eÌú.http://xn--9ca.com/%C3%A9?%C3%A1=%C3%AD#%C3%BAr    N)r   rI   ÚasURIr#   r!   r"   rK   )r'   ÚunicodeyrW   ÚuriÚexpectedURIÚ	actualURIr+   r+   r,   Ú
test_asURIŠ  s    
ÿ
ÿzTestURL.test_asURIc                 C   sl   d}t  |¡}| ¡ }|  |jd¡ |  |jd d¡ |  | ¡ |¡ d}| ¡ }|  ||d||f ¡ dS )zœ
        L{URL.asIRI} decodes any percent-encoded text in the URI, making it
        more suitable for reading by humans, and returns a new L{URL}.
        r­   zxn--9ca.comr   z%C3%A9u   http://Ã©.com/Ã©?Ã¡=Ã­#Ãºr    N)r   rI   ÚasIRIr#   r!   r"   rK   )r'   Zasciiishr°   rW   ÚexpectedIRIÚ	actualIRIr+   r+   r,   Ú
test_asIRIŸ  s    

ÿzTestURL.test_asIRIc                 C   s<   d}t  |¡}| ¡ }d}| ¡ }|  ||d||f ¡ dS )zœ
        Bad UTF-8 in a path segment, query parameter, or fragment results in
        that portion of the URI remaining percent-encoded in the IRI.
        z http://xn--9ca.com/%00%FF/%C3%A9u   http://Ã©.com/%00%FF/Ã©r    N)r   rI   r´   rK   r#   )r'   ZurlWithBinaryr°   rW   rµ   r¶   r+   r+   r,   Útest_badUTF8AsIRI³  s    

ÿzTestURL.test_badUTF8AsIRIc                 C   s*   d}t  |¡}| ¡ }|  | ¡ |¡ dS )zT
        A L{URL} composed of non-ASCII text will result in non-ASCII text.
        r¬   N)r   rI   r´   r#   rK   )r'   r¯   rW   ZalsoIRIr+   r+   r,   Útest_alreadyIRIAsIRIÂ  s    
zTestURL.test_alreadyIRIAsIRIc                 C   s*   d}t  |¡}| ¡  ¡ }|  ||¡ dS )zH
        A L{URL} composed of encoded text will remain encoded.
        r­   N)r   rI   r®   rK   r#   )r'   r±   r°   r²   r+   r+   r,   Útest_alreadyURIAsURIÏ  s    
zTestURL.test_alreadyURIAsURIc                 C   sv   t  d¡}|  | d¡d¡ |  | d¡d¡ |  |jd¡ |  |jd¡ |  | ¡ d¡ |  |jdd	 ¡ d
¡ dS )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:somepasswordZsomeuserz0http://someuser:@example.com/some-segment@ignore©r/   z/http://someuser@example.com/some-segment@ignoreN)r   rI   r#   Z	authorityr/   ÚuserrK   ry   ra   r+   r+   r,   Útest_userinfoØ  s     ÿÿ
ÿþzTestURL.test_userinfoc                 C   s,   t  d¡}|  |jd¡ |  | ¡ d¡ dS )zJ
        L{URL.from_text} parses custom port numbers as integers.
        zhttp://www.example.com:8080/i  N)r   rI   r#   r.   rK   )r'   ZportURLr+   r+   r,   Útest_portTextì  s    
zTestURL.test_portTextc                 C   s   |   t d¡ ¡ d¡ dS )a  
        Although L{URL} instances are mainly for dealing with HTTP, other
        schemes (such as C{mailto:}) should work as well.  For example,
        L{URL.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   rI   rK   r6   r+   r+   r,   Útest_mailtoô  s    ÿzTestURL.test_mailtoc                 C   sB   d}t ddggd}|  |j|¡ t ddid}|  |j|¡ dS )z´
        When a L{URL} is created with a C{query} argument, the C{query}
        argument is converted into an N-tuple of 2-tuples, sensibly
        handling dictionaries.
        ))ÚalphaÚbetarÀ   rÁ   r–   N)r   r#   r%   )r'   r2   rV   r+   r+   r,   Útest_queryIterableþ  s
    zTestURL.test_queryIterablec                 C   s    t ddgd}|  |jd¡ dS )zr
        When a L{URL} is created with a C{path} argument, the C{path} is
        converted into a tuple.
        r”   r•   ©r"   r“   N)r   r#   r"   ra   r+   r+   r,   Útest_pathIterable
  s    zTestURL.test_pathIterablec              	      s  G dd„ dt ƒ‰ ttkrdnd}‡fdd„‰|f‡ ‡‡fdd„	}|d	ƒ |d
ƒ |dƒ |ddƒ |dƒ |ddƒ ˆ t¡}tˆ ƒ gd W 5 Q R X ˆ||dƒ ˆ t¡}tdˆ ƒ fgd W 5 Q R X ˆ||d dƒ ˆ t¡}tˆ ƒ dfgd W 5 Q R X ˆ||dƒ ˆ t¡ tˆ ƒ gd W 5 Q R X ˆ t¡ tdgd W 5 Q R X ˆ t¡ tdgd W 5 Q R X t d¡}ˆ t¡}| ˆ ƒ ¡ W 5 Q R X ˆ||dƒ ˆ t¡}| 	ˆ ƒ ¡ W 5 Q R X ˆ||dƒ ˆ t¡}| 
ˆ ƒ ¡ W 5 Q R X ˆ||dƒ dS )a¤  
        Passing an argument of the wrong type to any of the constructor
        arguments of L{URL} will raise a descriptive L{TypeError}.

        L{URL} typechecks very aggressively to ensure that its constitutent
        parts are all properly immutable and to prevent confusing errors when
        bad data crops up in a method call long after the code that called the
        constructor is off the stack.
        c                   @   s   e Zd Zdd„ Zdd„ ZdS )z1TestURL.test_invalidArguments.<locals>.Unexpectedc                 S   s   dS )NZwrongr+   r6   r+   r+   r,   Ú__str__  s    z9TestURL.test_invalidArguments.<locals>.Unexpected.__str__c                 S   s   dS )Nú<unexpected>r+   r6   r+   r+   r,   Ú__repr__   s    z:TestURL.test_invalidArguments.<locals>.Unexpected.__repr__N)Ú__name__Ú
__module__Ú__qualname__rÅ   rÇ   r+   r+   r+   r,   Ú
Unexpected  s   rË   r   Ústrc                    s    ˆ   t| jƒd ||d¡¡ d S )Nzexpected {0} for {1}, got {2}rÆ   )r#   rÌ   Ú	exceptionr|   )ÚraisedÚexpectationr†   r6   r+   r,   ÚassertRaised%  s     þÿz3TestURL.test_invalidArguments.<locals>.assertRaisedc              	      s6   ˆ  t¡}tf | ˆ ƒ iŽ W 5 Q R X ˆ||| ƒ d S )N)rv   Ú	TypeErrorr   )ZparamrÏ   rÎ   ©rË   rÐ   r'   r+   r,   r7   +  s    z,TestURL.test_invalidArguments.<locals>.checkr   r!   r&   re   Úboolr/   r.   zint or NoneTyperÃ   zpath segmentr†   r–   z or NoneTypezquery parameter valuer‡   zquery parameter name)r)   r*   Zvv)r)   zhttps://valid.example.com/zrelative URLN)r¤   ÚbytesrÌ   rv   rÑ   r   Ú
ValueErrorrI   r\   rh   rk   )r'   ZdefaultExpectationr7   rÎ   rV   r+   rÒ   r,   Útest_invalidArguments  sJ    



ÿ
zTestURL.test_invalidArgumentsc              	   C   s@   |   t¡}tdd W 5 Q R X |  t|jƒd tdƒ¡¡ dS )z¸
        Technically, L{str} (or L{unicode}, as appropriate) is iterable, but
        C{URL(path="foo")} resulting in C{URL.from_text("f/o/o")} is never what
        you want.
        rE   rÃ   z,expected iterable of text for path, not: {0}N)rv   rÑ   r   r#   rÌ   rÍ   r|   r    )r'   rÎ   r+   r+   r,   Ú!test_technicallyTextIsIterableBut^  s    ÿþz)TestURL.test_technicallyTextIsIterableButc                 C   s”   t dd}|  |jd¡ t dd}|  |jd¡ t dd}|  |jd¡ t dd}|  |jd ¡ t  d¡}|  |jd¡ t  d	¡}|  |jd¡ d S )
NÚhttps©r   Tz	git+httpsÚmailtoFÚztpzztp://test.comzztp:test:com)r   r#   Úuses_netlocrI   ra   r+   r+   r,   Útest_netlocl  s    





zTestURL.test_netlocc                 C   sB   d}t  |¡}|jdkst‚|jdks*t‚t|j |jks>t‚d S )Nz5https://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80/z'2001:0db8:85a3:0000:0000:8a2e:0370:7334r5   )r   rI   r!   rU   r.   r
   r   )r'   ÚtrV   r+   r+   r,   Útest_ipv6_with_port  s
    
zTestURL.test_ipv6_with_portc                 C   sä   d}t  |¡}|jdkst‚|jdks*t‚|jdks8t‚|jdksFt‚|jdksTt‚d}t  |¡}|jdkspt‚|jdks~t‚|jdksŒt‚|jdksšt‚d	}t  |¡}|jdks¶t‚|jdksÄt‚|jd
ksÒt‚|jdksàt‚d S )Nz3https://user:pass@example.com/path/to/here?k=v#nicerØ   ú	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   rI   r   rU   r/   r!   r"   r&   ©r'   ÚtextrV   r+   r+   r,   Ú
test_basic†  s&    


zTestURL.test_basicc                 C   s   |   ttjd¡ d S )Nz#

©rv   r   r   rI   r6   r+   r+   r,   Útest_invalid_url  s    zTestURL.test_invalid_urlc                 C   s   |   ttjd¡ d S )Nzhttp://abc:

/#rè   r6   r+   r+   r,   Útest_invalid_authority_url   s    z"TestURL.test_invalid_authority_urlc                 C   sL   dddddg}|D ]4}d| d }|   tjttj|¡ |   ttj|¡ qd S )Nz2001::0234:C1ab::A0:aabc:003Fz2001::1::3Fú:z::::z::256.0.0.1zhttp://[ú])rv   ÚsocketÚerrorr	   ZAF_INET6r   r   rI   )r'   Zinvalid_ipv6_ipsZipri   r+   r+   r,   Útest_invalid_ipv6£  s    ü
 ÿzTestURL.test_invalid_ipv6c                 C   s$   |   ttjd¡ |   ttjd¡ d S )Nzftp://portmouth:smashz+http://reader.googlewebsite.com:neverforget)rv   r   r   rI   rÕ   r6   r+   r+   r,   Útest_invalid_port¯  s    
ÿzTestURL.test_invalid_portc                 C   s|   t  d¡}|  |jd¡ |  | ¡ d¡ |  | ¡  ¡ d¡ t  d¡}|  |jd¡ |  | ¡ d¡ |  | ¡  ¡ d¡ d S )Nu   http://bÃ¼cher.chu
   bÃ¼cher.chzhttp://xn--bcher-kva.chr   zxn--bcher-kva.chu   https://bÃ¼cher.ch)r   rI   ÚassertEqualsr!   rK   r   rT   r›   r+   r+   r,   Ú	test_idna´  s    

zTestURL.test_idnac                 C   sž  t  d¡}|  |jd¡ |  | ¡ d¡ t  d¡}|  |jd¡ |  | ¡ d¡ t  d¡}|  |jd¡ |  | ¡ d¡ t  d¡}|  |jd¡ |  | ¡ d¡ t  d	¡}|  |jd
¡ |  | ¡ d	¡ t  d¡}|  |jd¡ |  | ¡ d¡ t dddd}|  | ¡ d¡ t d
dddd}|  | ¡ d¡ t  d¡}|jdd}|  | ¡ d¡ d}t  |¡}|jdd}|  | ¡ d¡ |jdd}|  | ¡ |¡ d S )Nzmailto:mahmoud@hatnote.comrÚ   zhttp://hatnote.comr4   znewscheme:a:b:cZ	newschemeznewerscheme://a/b/cZnewerschemez%git+ftp://gitstub.biz/glyph/lefkowitzzgit+ftpz'what+mailto:freerealestate@enotuniq.orgzwhat+mailtorÛ   )ÚxrŒ   ÚzT)r   r"   re   z
ztp:/x/y/z)ró   rŒ   rô   r   )r   r"   re   rÜ   zgit+ftp:///x/y/z/zfile:///path/to/heckrÙ   zmailto:/path/to/heckzunregisteredscheme:///a/b/cF)rÜ   zunregisteredscheme:/a/b/c)r   rI   rñ   r   rK   ry   )r'   rV   Úurl2ri   Zno_netloc_urlZ
netloc_urlr+   r+   r,   Útest_netloc_slashes¿  sN    





ÿ

ÿ ÿ

zTestURL.test_netloc_slashesc              	   C   s@   |   t¡ ttƒ W 5 Q R X |   t¡ tdƒ W 5 Q R X d S )NZHTTP_____more_like_imHoTTeP)rv   rÕ   r   rJ   r6   r+   r+   r,   Útest_wrong_constructorô  s    zTestURL.test_wrong_constructorc                 C   sp   t  d¡}|jdkst‚|jdd}| ¡ }|jdddks@t‚|jddd	ksTt‚| ¡ jddd
kslt‚d S )Nzhttp://user:pass@example.comrà   zus%20her:passr»   TrO   zhttp://us her:pass@example.comFzhttp://us her:@example.comz http://us%20her:pass@example.com)r   rI   r/   rU   ry   rT   rK   r   ©r'   rV   rW   r+   r+   r,   Útest_encoded_userinfoü  s    
zTestURL.test_encoded_userinfoc                 C   sŠ   i }t  d¡}t|ƒt|ƒks"t‚d||< t  d¡}| dd¡}d||< t|ƒdksXt‚t| ¡ ƒdgksnt‚tt ƒ ƒtt ƒ ƒks†t‚d S )Nz.http://blog.hatnote.com/ask?utm_source=geocityr   zhttp://blog.hatnote.com/askZ
utm_sourceZgeocityr   )r   rI   ÚhashrU   rƒ   ÚlenÚlistÚvalues)r'   Zurl_mapZurl1rõ   r+   r+   r,   Ú	test_hash  s    

zTestURL.test_hashc                 C   sR   t ƒ }t|ƒ}t|ƒdkst‚d|ks*t‚d|ks6t‚d|ksBt‚d|ksNt‚d S )Né   rl   ÚasTextr®   r´   )r   Údirrû   rU   )r'   rV   rm   r+   r+   r,   Útest_dir  s    zTestURL.test_dirc                 C   s2   t  d¡}| ¡ dkst‚| ¡  ¡ dks.t‚d S )Nu"   http://example.com/a%20tÃ©%C3%A9stz&http://example.com/a%20t%C3%A9%C3%A9st)r   rl   r   rU   r®   ra   r+   r+   r,   Útest_twisted_compat!  s    
zTestURL.test_twisted_compatc                 C   s6   t  d¡}| dd¡}| dd¡}| ¡ dks2t‚d S )Nzhttp://example.com/?a=b&cró   rŒ   z!http://example.com/?a=b&x=x&c&x=y)r   rI   rƒ   r   rK   rU   ra   r+   r+   r,   Útest_set_ordering'  s    
zTestURL.test_set_orderingc                 C   s’   t  d¡}t  | ¡ ¡}||ks$t‚t  | ¡  ¡ ¡}||ksBt‚||ksNt‚t  d¡}| ¡ }| ¡ dkspt‚t  | ¡ ¡ ¡ }||ksŽt‚dS )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   rI   rK   rU   rT   r   )r'   rœ   rn   ro   Zu4Zu5Zu6r+   r+   r,   Útest_schemeless_path0  s    

zTestURL.test_schemeless_pathc                 C   s   t  d¡}| ¡ }| ¡  dS )z4See issue #7, affecting only narrow builds (2.6-3.3)zhttps://xn--vi8hiv.wsN)r   rI   rT   rK   rø   r+   r+   r,   Útest_emoji_domainB  s    
zTestURL.test_emoji_domainc                 C   sF   | j ttddd | j ttdd | j ttdd | j ttdd d	S )
zPer issue #6 and #8r4   za/c)r   r!   )ú?rÃ   )ú#)ú&rQ   r–   N)rv   rÕ   r   r6   r+   r+   r,   Útest_delim_in_paramI  s    zTestURL.test_delim_in_paramc                 C   s„   t  d¡}t  d¡}||ks t‚t  d¡}t  d¡}||ks@t‚t  d¡}t  d¡}||ks`t‚t  d¡}t  d¡}||ks€t‚d S )Nzhttp://example.com/zhttp://example.com)r   rI   rU   r›   r+   r+   r,   Útest_empty_paths_eqP  s    







zTestURL.test_empty_paths_eqc                 C   s:   t  d¡jdkst‚|  tt jd¡ |  tt jtƒ ¡ d S )Nz#okÚoks   bytes://x.y.z)r   rI   r&   rU   rv   rÑ   r¤   r6   r+   r+   r,   Útest_from_text_typee  s    zTestURL.test_from_text_typec                 C   st   |   ttjd¡ |   ttjd¡ |   ttjd¡ |   ttjd¡ |   ttjd¡ |   ttjd¡ |   ttjd¡ d S )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::80rè   r6   r+   r+   r,   Útest_from_text_bad_authorityj  s    z$TestURL.test_from_text_bad_authorityc           	      C   s”  t  d¡}| d¡g kst‚| d¡dgks0t‚t|jƒdksBt‚| ¡ }|jdksXt‚|jdksft‚|jdkstt‚| d¡d	gksˆt‚|j	d
ks–t‚| 
¡ dks¦t‚|jdddddd}||ksÆt‚t  d¡}| ¡ }| 
¡ dksèt‚t  d¡}| ¡ }| 
¡ dkst‚t ddjdd 
¡ dks,t‚t dd ¡  
¡ dksHt‚t dddgdgddd}|j
ddd ksvt‚| ¡ j
ddd!kst‚d S )"Nz0HTTP://Example.com/A%61/./../A%61?B%62=C%63#D%64ZBbzB%62zC%63é   r4   rá   )ZAaZCcZDdzhttp://example.com/Aa?Bb=Cc#DdFrG   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Ã   )Zpercentsz/%te%stsz/%25te%25stsZftpz%%%z%a%b)ú%z%%r  z%:%)r   r"   r%   r&   r/   TrO   zftp://%:%@/%%%/%a%b?%=%%#%z0ftp://%25:%25@/%25%25%25/%25a%25b?%25=%25%25#%25)r   rI   r   rU   rû   r"   Ú	normalizer   r!   r&   rK   )	r'   rV   Znorm_urlZnoop_norm_urlZslashless_urlZslashful_urlZdelimited_urlZnorm_delimited_urlZpercenty_urlr+   r+   r,   Útest_normalizex  s8    
  ÿ

 zTestURL.test_normalizec                 C   s€   d}t  |¡}t|ƒ|kst‚t|ƒdks.t‚trXtt|ƒtƒsDt‚tt|ƒtƒs|t‚n$tt|ƒtƒsjt‚tt|ƒtƒs|t‚d S )Nu&   http://example.com/Ã¡/y%20a%20y/?b=%25s*   http://example.com/%C3%A1/y%20a%20y/?b=%25)r   rI   r   rU   rÔ   ÚPY2r   rÌ   rå   r+   r+   r,   Útest_str   s    
zTestURL.test_strc                 C   s–   d}t  |¡}| ¡ jdks t‚| ¡ jdks2t‚t  d¡}| ¡ jdksNt‚| ¡ jdks`t‚| ¡  ¡ jdksvt‚t  d¡ ¡  ¡ jdks’t‚d S )	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.comrá   )r   rI   rT   r!   rU   r   Zget_decoded_urlrå   r+   r+   r,   Útest_idna_corners®  s    

zTestURL.test_idna_cornersN)r   )KrÈ   rÉ   rÊ   Ú__doc__r-   r3   r8   rB   rD   rH   rN   rS   rX   rZ   r[   r]   rb   rf   rg   rj   rp   ru   rx   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ö   r÷   rù   rþ   r  r  r  r  r  r
  r  r  r  r  r  r  r+   r+   r+   r,   r   ”   s’    ÿ
			1# 

	
L5		(r   )Z
__future__r   Úsysrí   Úcommonr   r   r   r   r   r	   r
   r   Úversion_infor  r$   r   rJ   rq   rr   rP   r   r+   r+   r+   r,   Ú<module>   sj   Î6D