Your IP : 216.73.216.213


Current Path : /opt/alt/python36/lib64/python3.6/test/__pycache__/
Upload File :
Current File : //opt/alt/python36/lib64/python3.6/test/__pycache__/test_urlparse.cpython-36.opt-1.pyc

3

� f��@s6ddlZddlZddlZddlZdZdZdZdZdgfdgfdgfdd2gfd	d3gfd
d4gfdd5gfdd6gfdd7d8gfdd9d:gfdgfdgfdgfdd;gfdd<gfdd=gfdd>gfdd?gfdd@dAgfd dBdCgfd#dDgfd%dEgfd'dFgfd)dGgfgZ	difdifdifdddgifd	dd
gifd
d
dgifdd
dgifdd
d
gifddgdgd+�fdd
ddgifdifdifdifdddgifdddgifdddgifdddgifdddgifddgdgd,�fd dd!d"gifd#d$d
gifd%d
d&gifd'd(dgifd)dd*gifgZ
Gd-d.�d.ej�ZGd/d0�d0ej�Z
ed1k�r2ej�dS)H�Nzhttp://a/b/c/d;p?q#fzhttp://a/b/c/d;p?qzhttp://a/b/c/d��&z&&�=z=a�aza=z&a=b�bza=a+b&b=b+c�a b�b cza=1&a=2�1�2��&s&&�=s=a�asa=s&a=b�bsa=a+b&b=b+c�a b�b csa=1&a=2�1�2z;a=b�;aza=a+b;b=b+c�	a b;b=b cs;a=b�;asa=a+b;b=b+c�	a b;b=b c)rr)rrc@sleZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;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.dYS)Z�UrlParseTestCasecCs`tjj|�}|j||�|j|j|j|j|j|j	f}|j||�tjj
|�}|j||�|j||j��tjj|j��}|j|j�|j��|j||�|j|j|j�|j|j|j�|j|j|j�|j|j|j�|j|j|j�|j|j	|j	�|j|j|j�|j|j
|j
�|j|j|j�|j|j|j�tjj|�}|j||�|j|j|j|j|j	f}|j||�tjj|�}|j||�|j||j��tjj|j��}|j|j�|j��|j||�|j|j|j�|j|j|j�|j|j|j�|j|j|j�|j|j	|j	�|j|j|j�|j|j
|j
�|j|j|j�|j|j|j�dS)N)�urllib�parse�urlparse�assertEqual�scheme�netloc�path�params�query�fragment�
urlunparse�geturl�username�password�hostname�port�urlsplit�
urlunsplit)�self�url�parsed�split�result�tZresult2Zresult3�r1�7/opt/alt/python36/lib64/python3.6/test/test_urlparse.py�checkRoundtripsIsRz UrlParseTestCase.checkRoundtripscCshxbtD]Z\}}tjj|dd�}|j||d|�dd�|D�}tjj|dd�}|j||d|�qWdS)NT)�keep_blank_valueszError parsing %rcSsg|]}t|d�r|�qS)�)�len)�.0�vr1r1r2�
<listcomp>�sz-UrlParseTestCase.test_qsl.<locals>.<listcomp>F)�parse_qsl_test_casesrr�	parse_qslr)r+�orig�expectr/�expect_without_blanksr1r1r2�test_qsl|szUrlParseTestCase.test_qslcslxftD]^\}�tjj|dd�}|j|�d|��fdd��D�}tjj|dd�}|j||d|�qWdS)NT)r4zError parsing %rcs&i|]}t�|d�r�||�qS)r)r6)r7r8)r=r1r2�
<dictcomp>�sz,UrlParseTestCase.test_qs.<locals>.<dictcomp>F)�parse_qs_test_casesrr�parse_qsr)r+r<r/r>r1)r=r2�test_qs�s
zUrlParseTestCase.test_qscsTdd"d%d(d+d.g}dd���fdd�|D�}x$||D]\}}}|j|||�q4WdS)/N�file:///tmp/junk.txt�filer�
/tmp/junk.txt�imap://mail.python.org/mbox1�imap�mail.python.org�/mbox1�1mms://wms.sys.hinet.net/cts/Drama/09006251100.asf�mms�wms.sys.hinet.net�/cts/Drama/09006251100.asf�nfs://server/path/to/file.txt�nfs�server�/path/to/file.txt�0svn+ssh://svn.zope.org/repos/main/ZConfig/trunk/�svn+ssh�svn.zope.org�/repos/main/ZConfig/trunk/�)git+ssh://git@github.com/user/project.git�git+ssh�git@github.com�/user/project.gitcSs8|djd�tdd�|dD��tdd�|dD��fS)Nr�asciicss|]}|jd�VqdS)r[N)�encode)r7�xr1r1r2�	<genexpr>�szDUrlParseTestCase.test_roundtrips.<locals>._encode.<locals>.<genexpr>r5css|]}|jd�VqdS)r[N)r\)r7r]r1r1r2r^�s�)r\�tuple)r0r1r1r2�_encode�sz1UrlParseTestCase.test_roundtrips.<locals>._encodecsg|]}�|��qSr1r1)r7r])rar1r2r9�sz4UrlParseTestCase.test_roundtrips.<locals>.<listcomp>�rErrFrrr�rErrFrr)rDrbrc�rHrIrJrrr�rHrIrJrr)rGrdre�rLrMrNrrr�rLrMrNrr)rKrfrg�rPrQrRrrr�rPrQrRrr)rOrhri�rTrUrVrrr�rTrUrVrr)rSrjrk�rXrYrZrrr�rXrYrZrr)rWrlrm)r3)r+�	str_cases�bytes_casesr,r-r.r1)rar2�test_roundtrips�s8z UrlParseTestCase.test_roundtripsc

s�ddd!d$d'g}dd���fdd�|D�}d(}d)}||f}||f}x`||fD]T\}}xJ|D]B}	x<|D]4\}
}}|	|
}
|	f|}|	f|}|j|
||�qbWqXWqJWdS)*N�://www.python.org�www.python.orgr�://www.python.org#abc�abc�://www.python.org?q=abc�q=abc�://www.python.org/#abc�/�://a/b/c/d;p?q#fr�/b/c/d�p�q�f�/b/c/d;pcSs8|djd�tdd�|dD��tdd�|dD��fS)Nrr[css|]}|jd�VqdS)r[N)r\)r7r]r1r1r2r^�szIUrlParseTestCase.test_http_roundtrips.<locals>._encode.<locals>.<genexpr>r5css|]}|jd�VqdS)r[N)r\)r7r]r1r1r2r^�sr_)r\r`)r0r1r1r2ra�sz6UrlParseTestCase.test_http_roundtrips.<locals>._encodecsg|]}�|��qSr1r1)r7r])rar1r2r9�sz9UrlParseTestCase.test_http_roundtrips.<locals>.<listcomp>�http�https�http�https�rrrrrr�rrrrr)rqr�r��rrrrrrt�rrrrrt)rsr�r��rrrrrvr�rrrrvr)rur�r��rrrxrrrt�rrrxrrt)rwr�r��rrzr{r|r}�rr~r|r})ryr�r�)rr�)r�r�)r3)
r+rnroZstr_schemesZ
bytes_schemesZ	str_testsZbytes_testsZschemesZ
test_casesrr,r-r.r1)rar2�test_http_roundtrips�s8


z%UrlParseTestCase.test_http_roundtripsc	CsR|||f}|jtjj||�|�dd�|D�}\}}}|jtjj||�|�dS)NcSsg|]}|jd��qS)r[)r\)r7r]r1r1r2r9�sz.UrlParseTestCase.checkJoin.<locals>.<listcomp>)rrr�urljoin)	r+�baseZrelurl�expectedZstr_componentsZbytes_componentsZbasebZrelurlbZ	expectedbr1r1r2�	checkJoin�s
zUrlParseTestCase.checkJoincCsndddddddg}dd	�|D�}xH||D]<}|jtjjtjj|��|�|jtjjtjj|��|�q*WdS)
N�Pythonz./Pythonzx-newscheme://foo.com/stuffzx://yzx:/yzx:/rxcSsg|]}|jd��qS)r[)r\)r7r]r1r1r2r9�sz7UrlParseTestCase.test_unparse_parse.<locals>.<listcomp>)rrrr*r)r#r)r+rnro�ur1r1r2�test_unparse_parse�s
z#UrlParseTestCase.test_unparse_parsecCs�|jtdd�|jtdd�|jtdd�|jtdd�|jtdd�|jtd	d
�|jtdd�|jtd
d�|jtdd�|jtdd�|jtdd�|jtdd�|jtdd�|jtdd�|jtdd�|jtdd�|jtdd�|jtd d�|jtd!d"�|jtd#d$�|jtd%d$�|jtd&d�|jtd'd(�|jtd)d*�|jtd+d,�|jtd-d.�|jtd/d0�|jtd1d"�|jtd2d�|jtd3d4�|jtd5d6�dS)7Nzg:h�gzhttp://a/b/c/gz./gzg/zhttp://a/b/c/g/z/gz
http://a/gz//gzhttp://gzg?yzhttp://a/b/c/g?yzg?y/./xzhttp://a/b/c/g?y/./xz#szhttp://a/b/c/d;p?q#szg#szhttp://a/b/c/g#szg#s/./xzhttp://a/b/c/g#s/./xzg?y#szhttp://a/b/c/g?y#szg;xzhttp://a/b/c/g;xzg;x?y#szhttp://a/b/c/g;x?y#s�.z
http://a/b/c/z./z..zhttp://a/b/z../z../gzhttp://a/b/gz../..z	http://a/z../../z../../grzhttp://a/b/c/d;p?q#fzg.zhttp://a/b/c/g.z.gzhttp://a/b/c/.gzg..zhttp://a/b/c/g..z..gzhttp://a/b/c/..gz./../gz./g/.zg/./hzhttp://a/b/c/g/hzg/../hzhttp://a/b/c/h)r��RFC1808_BASE)r+r1r1r2�test_RFC1808�s>zUrlParseTestCase.test_RFC1808cCs|jtjjd�d�dS)Nzmailto:1337@example.org�mailtor�1337@example.org)r�rr�rrr)rrrr)r+r1r1r2�test_RFC2368szUrlParseTestCase.test_RFC2368cCs�|jtdd�|jtdd�|jtdd�|jtdd�|jtdd�|jtd	d
�|jtdd�|jtd
d�|jtdd�|jtdd�|jtdd�|jtdd�|jtdd�|jtdd�|jtdd�|jtdd�|jtdd�|jtdd �|jtd!d �|jtd"d�|jtd#t�|jtd$d%�|jtd&d'�|jtd(d)�|jtd*d+�|jtd,d�|jtd-d�|jtd.d/�|jtd0d1�|jtd2d3�|jtd4d5�|jtd6d7�|jtd8d9�|jtd:d;�|jtd<d=�dS)>Nzg:hr�zhttp://a/b/c/gz./gzg/zhttp://a/b/c/g/z/gz
http://a/gz//gzhttp://gzg?yzhttp://a/b/c/g?yz#szhttp://a/b/c/d;p?q#szg#szhttp://a/b/c/g#szg?y#szhttp://a/b/c/g?y#szg;xzhttp://a/b/c/g;xzg;x?y#szhttp://a/b/c/g;x?y#sr�z
http://a/b/c/z./z..zhttp://a/b/z../z../gzhttp://a/b/gz../..z	http://a/z../../z../../grzg.zhttp://a/b/c/g.z.gzhttp://a/b/c/.gzg..zhttp://a/b/c/g..z..gzhttp://a/b/c/..gz./../gz./g/.zg/./hzhttp://a/b/c/g/hzg/../hzhttp://a/b/c/hz	g;x=1/./yzhttp://a/b/c/g;x=1/yz
g;x=1/../yzhttp://a/b/c/yzg?y/./xzhttp://a/b/c/g?y/./xzg?y/../xzhttp://a/b/c/g?y/../xzg#s/./xzhttp://a/b/c/g#s/./xzg#s/../xzhttp://a/b/c/g#s/../x)r��RFC2396_BASE)r+r1r1r2�test_RFC2396sFzUrlParseTestCase.test_RFC2396cCs�|jtdd�|jtdd�|jtdd�|jtdd�|jtdd�|jtd	d
�|jtdd�|jtd
d�|jtdd�|jtdd�|jtdd�|jtdd�|jtdd�|jtdd�|jtdd�|jtdd�|jtdd�|jtdd�|jtdd�|jtd d!�|jtd"d!�|jtd#d$�|jtd%d&�|jtd'd&�|jtd(d�|jtd)d�|jtd)d�|jtd*d�|jtd+d�|jtd,d�|jtd-d.�|jtd/d0�|jtd1d2�|jtd3d4�|jtd5d$�|jtd6d
�|jtd7d8�|jtd9d:�|jtd;d<�|jtd=d>�|jtd?d@�|jtdAdB�|jtdCdD�|jtdEdF�|jtdGd�|jdHdd�dS)INz?yzhttp://a/b/c/d;p?yz;xzhttp://a/b/c/;xzg:hr�zhttp://a/b/c/gz./gzg/zhttp://a/b/c/g/z/gz
http://a/gz//gzhttp://gzg?yzhttp://a/b/c/g?yz#szhttp://a/b/c/d;p?q#szg#szhttp://a/b/c/g#szg?y#szhttp://a/b/c/g?y#szg;xzhttp://a/b/c/g;xzg;x?y#szhttp://a/b/c/g;x?y#srzhttp://a/b/c/d;p?qr�z
http://a/b/c/z./z..zhttp://a/b/z../z../gzhttp://a/b/gz../..z	http://a/z../../z../../gz
../../../gz
../../../../gz/./gz/../gzg.zhttp://a/b/c/g.z.gzhttp://a/b/c/.gzg..zhttp://a/b/c/g..z..gzhttp://a/b/c/..gz./../gz./g/.zg/./hzhttp://a/b/c/g/hzg/../hzhttp://a/b/c/hz	g;x=1/./yzhttp://a/b/c/g;x=1/yz
g;x=1/../yzhttp://a/b/c/yzg?y/./xzhttp://a/b/c/g?y/./xzg?y/../xzhttp://a/b/c/g?y/../xzg#s/./xzhttp://a/b/c/g#s/./xzg#s/../xzhttp://a/b/c/g#s/../xzhttp:gzhttp://a/b/c/de)r��RFC3986_BASE)r+r1r1r2�test_RFC3986Hs\zUrlParseTestCase.test_RFC3986cCsX|jtdd�|jtdd�|jtdd�|jtdd�|jtdd�|jtdd	�|jtd
d�|jtdd
�|jtdd�|jtdd�|jtdd�|jtdd�|jtdd�|jtdd�|jtdd�|jtdd�|jtdd�|jtdd�|jtdd�|jtd d	�|jtd!d"�|jtd#d$�|jtdd�|jtdd�|jtd%d�|jtd&d�|jtd'd�|jd(dd(�|jd)dd�|jd)d*d*�|jd+d,d-�|jd.d,d/�|jd0dd1�|jd2dd3�|jtd4d5td6�|jd7d8d9�|jd:d8d;�|jd7d<d=�|jd:d<d=�|jd7d>d?�|jdd8d=�|jd@dAdA�dS)BNzg:hzhttp:gzhttp://a/b/c/gzhttp:zhttp://a/b/c/dr�z./gzg/zhttp://a/b/c/g/z/gz
http://a/gz//gzhttp://gz?yzhttp://a/b/c/d?yzg?yzhttp://a/b/c/g?yzg?y/./xzhttp://a/b/c/g?y/./xr�z
http://a/b/c/z./z..zhttp://a/b/z../z../gzhttp://a/b/gz../..z	http://a/z../../gz./../gz./g/.zg/./hzhttp://a/b/c/g/hzg/../hzhttp://a/b/c/hzhttp:?yzhttp:g?yzhttp:g?y/./xzhttp:///rzhttp://a/./gzsvn://pathtorepo/dir1Zdir2zsvn://pathtorepo/dir2zsvn+ssh://pathtorepo/dir1zsvn+ssh://pathtorepo/dir2zws://a/bzws://a/gz	wss://a/bz	wss://a/grx�fooz/foozhttp://a/b/c/d/e/z
../../f/g/zhttp://a/b/c/f/g/zhttp://a/b/c/d/ezhttp://a/b/f/g/z/../../f/g/z
http://a/f/g/z	../../f/gzhttp://a/b/c/f/grr)r��SIMPLE_BASE)r+r1r1r2�
test_urljoins�sTzUrlParseTestCase.test_urljoinscs�d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCg}d"d#���fd$d%�|D�}x:||D].\}}}tjj|�}|j|j|jf||f�qXWd&d'd(d)d*g}d+d%�|D�}x$||D]}|jttjj|��q�WdS)DN� http://Test.python.org:5432/foo/�test.python.org�8�http://12.34.56.78:5432/foo/�12.34.56.78�http://[::1]:5432/foo/�::1�http://[dead:beef::1]:5432/foo/�dead:beef::1�http://[dead:beef::]:5432/foo/�dead:beef::�:http://[dead:beef:cafe:5417:affe:8FA3:deaf:feed]:5432/foo/�'dead:beef:cafe:5417:affe:8fa3:deaf:feed� http://[::12.34.56.78]:5432/foo/�
::12.34.56.78�%http://[::ffff:12.34.56.78]:5432/foo/�::ffff:12.34.56.78�http://Test.python.org/foo/�http://12.34.56.78/foo/�http://[::1]/foo/�http://[dead:beef::1]/foo/�http://[dead:beef::]/foo/�5http://[dead:beef:cafe:5417:affe:8FA3:deaf:feed]/foo/�http://[::12.34.56.78]/foo/� http://[::ffff:12.34.56.78]/foo/�http://Test.python.org:/foo/�http://12.34.56.78:/foo/�http://[::1]:/foo/�http://[dead:beef::1]:/foo/�http://[dead:beef::]:/foo/�6http://[dead:beef:cafe:5417:affe:8FA3:deaf:feed]:/foo/�http://[::12.34.56.78]:/foo/�!http://[::ffff:12.34.56.78]:/foo/cSs"|djd�|djd�|dfS)Nrr[r5r_)r\)r0r1r1r2ra�sz.UrlParseTestCase.test_RFC2732.<locals>._encodecsg|]}�|��qSr1r1)r7r])rar1r2r9�sz1UrlParseTestCase.test_RFC2732.<locals>.<listcomp>zhttp://::12.34.56.78]/zhttp://[::1/foo/zftp://[::1/foo/bad]/badzhttp://[::1/foo/bad]/badzhttp://[::ffff:12.34.56.78cSsg|]}|jd��qS)r[)r\)r7r]r1r1r2r9�s)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�N)r�r�N)r�r�N)r�r�N)r�r�N)r�r�N)r�r�N)r�r�N)r�r�N)r�r�N)r�r�N)r�r�N)r�r�N)r�r�N)r�r�N)r�r�N)rrrrr'r(�assertRaises�
ValueError)r+rnror,r'r(Z	urlparsedZinvalid_urlr1)rar2�test_RFC2732�sVzUrlParseTestCase.test_RFC2732cs�ddddddddtdd
ftddfg
}dd���fdd�|D�}x^||D]R\}}}tjj|�}|j|j�|�|j|||f�|j|j|�|j|j|�qHWdS)N�http://python.org#frag�http://python.org�fragr�http://python.org/#frag�http://python.org/�http://python.org/?q#frag�http://python.org/?q�http://python.org/p#frag�http://python.org/p�http://python.org/p?qzhttp://a/b/c/d;p?qr}cSst|�dd�|D��S)Ncss|]}|jd�VqdS)r[N)r\)r7r]r1r1r2r^�szCUrlParseTestCase.test_urldefrag.<locals>._encode.<locals>.<genexpr>)�type)r0r1r1r2ra�sz0UrlParseTestCase.test_urldefrag.<locals>._encodecsg|]}�|��qSr1r1)r7r])rar1r2r9�sz3UrlParseTestCase.test_urldefrag.<locals>.<listcomp>)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�rrZ	urldefragrr$r,r")r+rnror,Zdefragr�r/r1)rar2�test_urldefrag�s$zUrlParseTestCase.test_urldefragcCsTtjjd�}|j|jd�|j|jd�tjjd�}|j|jd�|j|jd�dS)Nz,http://[FE80::822a:a8ff:fe49:470c%tESt]:1234zfe80::822a:a8ff:fe49:470c%tEStz%[FE80::822a:a8ff:fe49:470c%tESt]:1234s,http://[FE80::822a:a8ff:fe49:470c%tESt]:1234sfe80::822a:a8ff:fe49:470c%tESts%[FE80::822a:a8ff:fe49:470c%tESt]:1234)rrr)rr'r)r+r{r1r1r2�test_urlsplit_scoped_IPv6sz*UrlParseTestCase.test_urlsplit_scoped_IPv6c	Csd}tjj|�}|j|jd�|j|jd�|j|jd�|j|jd�|j|jd�|j|j	d�|j|j
d�|j|jd�|j|jd�|j|j
�dd�|dd��d	}tjj|�}|j|jd�|j|jd
�|j|jd�|j|jd�|j|jd�|j|j	d�|j|j
d
�|j|jd�|j|jd�|j|j
�|�d}tjj|�}|j|jd�|j|jd�|j|jd�|j|jd�|j|jd�|j|j	d�|j|j
d
�|j|jd�|j|jd�|j|j
�|�d}tjj|�}|j|jd�|j|jd�|j|jd�|j|jd�|j|jd�|j|j	d�|j|j
d�|j|jd�|j|jd�|j|j
�dd�|dd��d}tjj|�}|j|jd�|j|jd�|j|jd�|j|jd�|j|jd�|j|j	d�|j|j
d�|j|jd�|j|jd�|j|j
�|�d}tjj|�}|j|jd�|j|jd�|j|jd�|j|jd�|j|jd�|j|j	d �|j|j
d�|j|jd�|j|jd�|j|j
�|�d!}tjj|�}|jtd"��|jWdQRXdS)#NzHTTP://WWW.PYTHON.ORG/doc/#fragrzWWW.PYTHON.ORGz/doc/rr�zwww.python.org�z7http://User:Pass@www.python.org:080/doc/?query=yes#fragzUser:Pass@www.python.org:080z	query=yesZUserZPass�PzChttp://User@example.com:Pass@www.python.org:080/doc/?query=yes#fragz(User@example.com:Pass@www.python.org:080zUser@example.comsHTTP://WWW.PYTHON.ORG/doc/#fragshttpsWWW.PYTHON.ORGs/doc/rsfragswww.python.orgs7http://User:Pass@www.python.org:080/doc/?query=yes#fragsUser:Pass@www.python.org:080s	query=yessUsersPasssChttp://User@example.com:Pass@www.python.org:080/doc/?query=yes#frags(User@example.com:Pass@www.python.org:080sUser@example.coms%HTTP://WWW.PYTHON.ORG:65536/doc/#fragzout of range)rrr)rrrrr!r"r%r&r'r(r$�assertRaisesRegexr�)r+r,r{r1r1r2�test_urlsplit_attributes
s�  z)UrlParseTestCase.test_urlsplit_attributescCs�d}tjj|�}|j|jd�|j|jd�|j|jd�|j|jd�|j|jd�|j|j	d�|j|j
d�|j|jd�|j|jd�|j|j
�d�d}tjj|�}|j|jd	�|j|jd
�|j|jd�|j|jd�|j|jd
�|j|j	d�|j|j
d�|j|jd
�|j|jd�|j|j
�d�d}tjj|�}|j|j
�d�d}tjj|�}|j|j
�d�d}d}x@td�D]4}tjj||d�}|j|jd�|j|j
�d��q�WdS)NzQh
ttp://www.python
.org	/java
script:	alert('msg
')/?query
=	something#frag
mentrzwww.python.orgz/javascript:alert('msg')/zquery=somethingr"zGhttp://www.python.org/javascript:alert('msg')/?query=something#fragmentsQh
ttp://www.python
.org	/java
script:	alert('msg
')/?query
=	something#frag
mentshttpswww.python.orgs/javascript:alert('msg')/squery=somethingsfragmentsGhttp://www.python.org/javascript:alert('msg')/?query=something#fragmentzYx-new-scheme	://www.python
.org	/java
script:	alert('msg
')/?query
=	something#frag
mentzOx-new-scheme://www.python.org/javascript:alert('msg')/?query=something#fragmentsYx-new-scheme	://www.python
.org	/java
script:	alert('msg
')/?query
=	something#frag
mentsOx-new-scheme://www.python.org/javascript:alert('msg')/?query=something#fragmentzQhttps://www.python
.org	/java
script:	alert('msg
')/?query
=	something#frag
mentzhtt
psr_)rr�zHhttps://www.python.org/javascript:alert('msg')/?query=something#fragment)rrr)rrrrr!r"r%r&r'r(r$�range)r+r,r{r�_r1r1r2�!test_urlsplit_remove_unsafe_bytesgsHz2UrlParseTestCase.test_urlsplit_remove_unsafe_bytescCs�x�dD]�}x�tjjtjjfD]�}x�d
D]z}|j|||d��`d|}d	|}|rd|jd
�}|jd
�}||�}|j|j|�|jt	��|j
WdQRXWdQRXq&WqWqWdS)z Check handling of invalid ports.FTr��1.5�-1�0x10)�bytesrr(zwww.example.net:zhttp://r[N)FT)r�r�r�r�)rrr)r�subTestr\rrr�r�r()r+r�rr(rr,r{r1r1r2�test_attributes_bad_port�s



z)UrlParseTestCase.test_attributes_bad_portcCs�d}tjj|�}|j|jd�|j|jd�|j|jd�|j|jd�|j|jd�|j|j	�|�tjj
|�}|j|jd�|j|jd�|j|jd�|j|jd�|j|jd�|j|j	�|�d}tjj|�}|j|jd�|j|jd�|j|jd�|j|jd�|j|jd�|j|j	�|�tjj
|�}|j|jd�|j|jd�|j|jd�|j|jd�|j|jd�|j|j	�|�dS)Nz0sip:alice@atlanta.com;maddr=239.255.255.1;ttl=15rs0sip:alice@atlanta.com;maddr=239.255.255.1;ttl=15r)rrr)rrr%r&r'r(r$r)r+Zurir{r1r1r2�test_attributes_without_netloc�s<z/UrlParseTestCase.test_attributes_without_netloccCs,|jtjjd�d�|jtjjd�d�dS)
Nz http://example.com?blahblah=/foor�example.comr�
blahblah=/foos http://example.com?blahblah=/foo�http�example.comr�
blahblah=/foo)rr�rrr�r)r�r�rrr�r)rrrr)r+r1r1r2�test_noslash�szUrlParseTestCase.test_noslashcCs||jtjjd�d
�|jtjjd�d�|jtjjd�d�|jtjjd�d�|jtjjd	�d�|jtjjd�d�dS)Nrrz//www.python.org:80�www.python.org:80zhttp://www.python.org:80r�pathrs//www.python.org:80�www.python.org:80shttp://www.python.org:80�http)rrrrrr)rr�rrrr)rr�rrrr)rrr�rrr)rr�rrrr)r�r�rrrr)rrrr)r+r1r1r2�test_withoutscheme�sz#UrlParseTestCase.test_withoutschemecCs�|jtjjd�d�|jtjjd�d�|jtjjd�d�|jtjjd�d�|jtjjd	�d�|jtjjd�d�|jtjjd
�d�|jtjjd�d�dS)N�path:80rzhttp:rzhttps:r�zhttp://www.python.org:80�www.python.org:80�path:80rshttp:�httpshttps:�httpsshttp://www.python.org:80�www.python.org:80)rrr�rrr)rrrrrr)r�rrrrr)rr�rrrr)rrr�rrr)r�rrrrr)r�rrrrr)r�r�rrrr)rrrr)r+r1r1r2�test_portseparator�sz#UrlParseTestCase.test_portseparatorcCs|jttjjd�dS)Nr�)r��	TypeErrorrr�	urlencode)r+r1r1r2�
test_usingsys�szUrlParseTestCase.test_usingsyscCs�|jtjjd�d�|jtjjd�d�|jtjjd�d�|jtjjd�d�|jtjjd�d�|jtjjd�d�|jtjjd�d�|jtjjd�d�dS)Nzs3://foo.com/stuff�s3�foo.com�/stuffrzx-newscheme://foo.com/stuff�x-newschemez*x-newscheme://foo.com/stuff?query#fragmentr!r"z!x-newscheme://foo.com/stuff?queryss3://foo.com/stuff�s3�foo.com�/stuffrsx-newscheme://foo.com/stuff�x-newschemes*x-newscheme://foo.com/stuff?query#fragment�query�fragments!x-newscheme://foo.com/stuff?query)r�r�r�rrr)r�r�r�rrr)r�r�r�rr!r")r�r�r�rr!r)r�r�r�rrr)r�r�r�rrr)r�r�r�rr�r)r�r�r�rr�r)rrrr)r+r1r1r2�test_anyscheme�s zUrlParseTestCase.test_anyschemec
Cs�x�tjjtjjfD]�}|j|d���|dd�}|j|jd�|dd�}|j|jd�|j|dd�jd�|j|ddd	�jd�|j|d
dd	�jd�|j|d�jd�|j|d
�jd�|j|d
d�jd�WdQRXqWdS)
N)�functionzhttp://example.net/�ftprshttp://example.net/sftpshttpr)rspathrr)rrrr)r�rr)r+�funcr/r1r1r2�test_default_schemes

z$UrlParseTestCase.test_default_schemecCsd!}�x|D]�\}}}x�tjjtjjfD]�}|dkrD|tjjkrDd}|j||d���||dd�}|j|jd�|jt||�j	d|��|j||dd�jd�||dd�}|j|j|�|j
t||�j	|��|j||dd�j|�|j||�j|�WdQRXq(WqWdS)"N�
http:#fragrr��//example.net#frag�index.html#frag�	;a=b#fragr �	?a=b#fragr!�#frag�	abc#@frag�@frag�//abc#@frag�//abc:80#@frag�//abc#@frag:80�@frag:80)r,rF)Zallow_fragmentsr�#T�rrr��rrr��rrr��r	r r��r
r!r��rrr��rrr
�rrr
�rrr
�rrr)
rrrrrrrrrr)rrrr)r�rr"Z
assertTrue�getattr�endswithZassertFalse)r+Ztestsr,�attrZ
expected_fragrr/r1r1r2�test_parse_fragments"s6z%UrlParseTestCase.test_parse_fragmentscICsx|jtd��tjjdd�WdQRX|jtd��tjjdd�WdQRX|jtd��tjjdd�WdQRX|jtd��tjjdd�WdQRX|jtd��tjjd	�WdQRX|jtd��tjjd
�WdQRX|jtd��tjjd�WdQRX|jtd��tjjd�WdQRX|jtd��tjjdd�WdQRX|jtd��tjjdd�WdQRXdS)
NzCannot mix str�www.python.org�http�www.python.orgrrzhttp://python.orgshttp://python.org)r"r!rrrr)rr#rrrr)r"r!rrr)rr#rrr)	r�r�rrrr)r#r*r�)r+r1r1r2�test_mixed_types_rejectedCs(z*UrlParseTestCase.test_mixed_types_rejectedc
Cs:t|j�}|j}|j|j|�d|}d|}||�}||�}d}d}	|j||�|j|j�|�|j|j�|�|j|j|�|�|j|j|�|�|j|j||	�|�|j|j||	�|�|j||�|j|j�|�|j|j�|�|j|j|�|�|j|j|�|�|j|j||	�|�|j|j||	�|�dS)Nrrr[�strict)r)r)r6�_fieldsZ_encoded_counterpartZassertIsZ_decoded_counterpartr�decoder\)
r+Zstr_typeZnum_argsZ
bytes_typeZstr_argsZ
bytes_argsZ
str_resultZbytes_result�encoding�errorsr1r1r2�_check_result_type[s.
z#UrlParseTestCase._check_result_typecCs2tjjtjjtjjg}x|D]}|j|�qWdS)N)rrZDefragResultZSplitResultZParseResultr*)r+Zresult_typesZresult_typer1r1r2�test_result_pairsts


z"UrlParseTestCase.test_result_pairscCs�tjjddd�}|j|ddgi�tjjddd�}|j|ddgi�tjjddd�}|j|dd	gi�tjjd
dd�}|j|ddgi�tjjd
ddd
�}|j|ddgi�dS)Nu	key=Ł%E9zlatin-1)r(�keyuŁéukey=Ł%C3%A9zutf-8r[uŁ��u
key=Ł%E9-uŁ�-�ignore)r(r)uŁ-)rrrBr)r+r/r1r1r2�test_parse_qs_encoding~s
z'UrlParseTestCase.test_parse_qs_encodingcCs�tjjddd�}|j|dg�tjjddd�}|j|dg�tjjddd�}|j|dg�tjjd
dd�}|j|dg�tjjd
ddd
�}|j|dg�dS)Nu	key=Ł%E9zlatin-1)r(r,�Łéukey=Ł%C3%A9zutf-8r[�Ł��u
key=Ł%E9-�Ł�-r-)r(r)�Ł-)r,r/)r,r/)r,r0)r,r1)r,r2)rrr;r)r+r/r1r1r2�test_parse_qsl_encoding�s
z(UrlParseTestCase.test_parse_qsl_encodingcCsR|jt��"tjjdjdgd�dd�WdQRXtjjdjdgd�dd�dS)Nrza=a��
)Zmax_num_fields)r�r�rrrB�join)r+r1r1r2�test_parse_qsl_max_num_fields�s&z.UrlParseTestCase.test_parse_qsl_max_num_fieldsc
Cs�difdifdddgifddgdgd	�fd
dddgifd
ifdifdddgifddgdgd�fddddgifg
}xT|D]L\}}|jd|�d|����(tjj|dd�}|j||d|�WdQRXqvWdS)N�;z;;z;a=brrza=a+b;b=b+cza bzb c)rrza=1;a=2r	r
�;s;;s;a=brrsa=a+b;b=b+csa bsb c)rrsa=1;a=2rrz
Original: z, Expected: )�	separatorzError parsing %r)r�rrrBr)r+Zparse_qs_semicolon_casesr<r=r/r1r1r2�test_parse_qs_separator�sz(UrlParseTestCase.test_parse_qs_separatorc
Cs�dgfdgfddgfdddgfd	ddgfdgfd
gfdd gfdd!d"gfdd#d$gfg
}xT|D]L\}}|jd|�d|����(tjj|dd�}|j||d|�WdQRXqZWdS)%Nr8z;;z;a=brrza=a+b;b=b+c�a b�b cza=1;a=2r	r
r9s;;s;a=brrsa=a+b;b=b+c�a b�b csa=1;a=2rrz
Original: z, Expected: )r:zError parsing %r)rr)rr<)rr=)rr	)rr
)rr)rr>)rr?)rr)rr)r�rrr;r)r+Zparse_qsl_semicolon_casesr<r=r/r1r1r2�test_parse_qsl_separator�s


z)UrlParseTestCase.test_parse_qsl_separatorcCsJtjjddgdd�d�}Gdd	�d	�}tjjd
|�id�}|j|d�dS)
Nr5r_�r��)rrTc@seZdZdd�ZdS)z:UrlParseTestCase.test_urlencode_sequences.<locals>.TrivialcSsdS)NZtrivialr1)r+r1r1r2�__str__�szBUrlParseTestCase.test_urlencode_sequences.<locals>.Trivial.__str__N)�__name__�
__module__�__qualname__rCr1r1r1r2�Trivial�srGrz	a=trivial)rAr�rB)rrr�r)r+r/rGr1r1r2�test_urlencode_sequences�sz)UrlParseTestCase.test_urlencode_sequencescCsjtjjddi�}|j|d�tjjdditjjd�}|j|d�tjjddidtjjd�}|j|d	�dS)
Nrz
some valueza=some+valuezsome value/another)�	quote_viaza=some%20value%2Fanotherrx)ZsaferIza=some%20value/another)rrr�r�quote)r+r/r1r1r2�test_urlencode_quote_via�sz)UrlParseTestCase.test_urlencode_quote_viacCsF|jttjjd�tjjd�}|j|d�tjjd�}|j|d�dS)Nr�sarchaeological arcanazarchaeological%20arcanarr)r�r�rrZquote_from_bytesr)r+r/r1r1r2�test_quote_from_bytes�s
z&UrlParseTestCase.test_quote_from_bytescCs4tjjd�}|j|d�tjjd�}|j|d�dS)Nz	abc%20defsabc defrr)rrZunquote_to_bytesr)r+r/r1r1r2�test_unquote_to_bytes�sz&UrlParseTestCase.test_unquote_to_bytescCs0|jttjjddd�|jttjjddd�dS)Nsfoozutf-8)r(r%)r))r�r�rrrJ)r+r1r1r2�test_quote_errors�sz"UrlParseTestCase.test_quote_errorscCs�tjjd�}|j|jd�|j|jd�tjjd�}|j|jd�|j|jd�tjjd�}|j|jd�|j|jd�tjjd�}|j|jd�|j|jd�dS)Nztel:+31-641044153�telz
+31-641044153ztel:+31641044153z+31641044153)rrr)rrrr)r+�p1Zp2r1r1r2�test_issue14072�sz UrlParseTestCase.test_issue14072cCs�tjjd�}|j|jd�|j|jd�|j|jd�tjjd�}|j|jd�|j|jd�|j|jd�tjjd�}|j|jd�|j|jd	�|j|jd
�tjjd�}|j|jd�|j|jd�|j|jd
�dS)Nz"tel:123-4;phone-context=+1-650-516rOz123-4zphone-context=+1-650-516ztel:+1-201-555-0123z+1-201-555-0123rz"tel:7042;phone-context=example.comZ7042zphone-context=example.comz%tel:863-1234;phone-context=+1-914-555z863-1234zphone-context=+1-914-555)rrrrrrr )r+rPr1r1r2�test_telurl_params�s z#UrlParseTestCase.test_telurl_paramscCs$tjjtjj�}|jdt|��dS)N�Quoter)rrrSZ_ALWAYS_SAFE�assertIn�repr)r+Zquoterr1r1r2�test_Quoter_reprsz!UrlParseTestCase.test_Quoter_reprcCs�g}ddddddddd	d
ddd
ddh}xLttj�D]>}|jd�s2||krJq2ttj|�}t|dd�dkr2|j|�q2W|jtjj|�dS)N�	splitattr�	splithost�
splitnport�splitpasswd�	splitport�
splitquery�splittag�	splittype�	splituser�
splitvaluerSZ
ResultBaseZclear_cache�to_bytes�unwrapr�rEzurllib.parse)�dirrr�
startswithr�appendZassertCountEqual�__all__)r+r�Zundocumented�name�objectr1r1r2�test_alls
zUrlParseTestCase.test_allcsd�dd��D����fdd�tttdtj��D�}|jd|�|jd|�tjjd	�|j	t
��tjjd
�WdQRXx�dD]x}xrdD]j}xd|D]\}dj||j|��}|j|djt
|��d��(|j	t
��tjj|�WdQRXWdQRXq�Wq�Wq�WdS)Nz/:#?@cSsh|]}djt|���qS)z{:04X})�format�ord)r7�cr1r1r2�	<setcomp>*sz?UrlParseTestCase.test_urlsplit_normalization.<locals>.<setcomp>cs.g|]&}�ttj|�j��@r|�kr|�qSr1)�set�unicodedata�
decompositionr.)r7rl)�	hex_chars�
illegal_charsr1r2r9,sz@UrlParseTestCase.test_urlsplit_normalization.<locals>.<listcomp>�u℀u#uhttp://プ:80uhttp://プ︓80rr�r�netloc{}false.netloc�n{}user@netlocz{}://{}/pathz{:04X})r,�char)rr�r)rtru)�map�chrr��sys�
maxunicoderTrrr)r�r�rjr�rk)r+Zdenorm_charsrrrlr,r1)rqrrr2�test_urlsplit_normalization%s"


z,UrlParseTestCase.test_urlsplit_normalizationN)/rDrErFr3r?rCrpr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr r$r*r+r.r3r7r;r@rHrKrLrMrNrQrRrVrir{r1r1r1r2rGsX3	
#&0-972	]0)!



rc@speZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�
Utility_Testsz=Testcase to test the various utility functions in the urllib.cCs\tjj}|j|d�d	�|j|d�d
�|j|d�d�|j|d�d�|j|d�d
�dS)Nztype:opaquestringr��opaquestring�
:opaquestringztype:rztype:opaque:string�
opaque:string)r�r})Nr})Nr~)r�r)r�r)rrr^r)r+r^r1r1r2�test_splittypeFszUtility_Tests.test_splittypecCs�tjj}|j|d�d�|j|d�d�|j|d�d�|j|d�d�|j|d	�d�|j|d�d�|j|d
�d�|j|d�d�|j|d�d�|j|d�d�dS) Nz%//www.example.org:80/foo/bar/baz.html�www.example.org:80�/foo/bar/baz.htmlz//www.example.org:80rz//127.0.0.1#@host.com�	127.0.0.1�/#@host.comz//127.0.0.1#@host.com:80�/#@host.com:80z//127.0.0.1:80#@host.com�127.0.0.1:80z///file�/filez//example.net/file;�example.net�/file;z//example.net/file?�/file?z//example.net/file#�/file#)r�r�)r�r)Nr�)r�r�)r�r�)r�r�)rr�)r�r�)r�r�)r�r�)rrrXr)r+rXr1r1r2�test_splithostNs*









zUtility_Tests.test_splithostcCs\tjj}|j|d�d	�|j|d�d
�|j|d�d�|j|d�d�|j|d�d
�dS)NzUser:Pass@www.python.org:080�	User:Pass�www.python.org:080z@www.python.org:080rz
User:Pass@z(User@example.com:Pass@www.python.org:080�User@example.com:Pass)r�r�)rr�)Nr�)r�r)r�r�)rrr_r)r+r_r1r1r2�test_splituserks




zUtility_Tests.test_splitusercCs�tjj}|j|d�d�|j|d�d�|j|d�d�|j|d�d�|j|d
�d�|j|d�d�|j|d�d �|j|d�d!�|j|d�d"�|j|d�d#�|j|d�d$�|j|d�d%�|j|d�d&�dS)'Nzuser:ab�user�abzuser:a
b�a
bzuser:a	b�a	bzuser:a
b�a
bzuser:ab�abzuser:ab�abzuser:a:b�a:bzuser:a b�a bz	user 2:ab�user 2z
user+1:a+b�user+1�a+bzuser:rz:ab)r�r�)r�r�)r�r�)r�r�)r�r�)r�r�)r�r�)r�r�)r�r�)r�r�)r�r)r�N)rr�)rrrZr)r+rZr1r1r2�test_splitpasswdxszUtility_Tests.test_splitpasswdcCs�tjj}|j|d�d�|j|d�d�|j|d�d
�|j|d�d�|j|d�d�|j|d�d�|j|d�d�|j|d	�d�dS)Nz	parrot:88�parrot�88zparrot:�	127.0.0.1�
parrot:cheesez[::1]:88�[::1]z:88r)r�r�)r�N)r�N)r�N)r�N)r�r�)r�N)rr�)rrr[r)r+r[r1r1r2�test_splitport�szUtility_Tests.test_splitportcCs�tjj}|j|d�d	�|j|d�d�|j|dd�d�|j|d�d�|j|dd�d�|j|d�d�|j|dd�d�|j|d�d�|j|dd�d�dS)Nz	parrot:88r��Xr5�7zparrot:�	127.0.0.1z
parrot:cheese)r�r����)r�r�)r�r�r�)r�r�)r�r�r�)r�r�)r�r�)r�N)r�N)rrrYr)r+rYr1r1r2�test_splitnport�szUtility_Tests.test_splitnportcCsLtjj}|j|d�d�|j|d�d�|j|d�d	�|j|d�d
�dS)N�http://python.org/fake?foo=bar�http://python.org/fake�foo=barzhttp://python.org/fake?foo=bar?rz?foo=bar)r�r�)r�r)r�N)rr�)rrr\r)r+r\r1r1r2�test_splitquery�s


zUtility_Tests.test_splitquerycCs\tjj}|j|d�d	�|j|d�d
�|j|d�d�|j|d�d�|j|d�d
�dS)N�http://example.com?foo=bar#baz�http://example.com?foo=bar�bazzhttp://example.com?foo=bar#rz#bazz"http://example.com?foo=bar#baz#boo�boo)r�r�)r�r)rr�)r�N)r�r�)rrr]r)r+r]r1r1r2�
test_splittag�s



zUtility_Tests.test_splittagcCsftjj}|j|d�dddgf�|j|d�ddgf�|j|d�dddgf�|j|d�dgf�dS)Nz/path;attr1=value1;attr2=value2z/pathzattr1=value1zattr2=value2z/path;rz;attr1=value1;attr2=value2)rrrWr)r+rWr1r1r2�test_splitattr�s

zUtility_Tests.test_splitattrcCs\tjj}|j|d�d
�|j|d�d�|j|d�d�|j|d�d
�|j|d�d�dS)Nzfoo=barr��barzfoo=rz=bar�foobarzfoo=bar=baz�bar=baz)r�r�)r�r)rr�)r�N)r�r�)rrr`r)r+r`r1r1r2�test_splitvalue�szUtility_Tests.test_splitvaluecCs.tjjd�}|j|d�|jttjjd�dS)Nzhttp://www.python.orguhttp://www.python.org/mediæval)rrrarr��UnicodeError)r+r/r1r1r2�
test_to_bytes�szUtility_Tests.test_to_bytescCstjjd�}|j|d�dS)Nz<URL:type://host/path>ztype://host/path)rrrbr)r+r,r1r1r2�test_unwrap�szUtility_Tests.test_unwrapN)rDrErF�__doc__r�r�r�r�r�r�r�r�r�r�r�r�r1r1r1r2r|Bs
	
r|�__main__)rr)rr)rr)rr)rr)rr)rr)rr	)rr
)rr)rr)rr)rr)rr)rr)rr)rr)rr)rr)rr)rr)rr)ryroZunittestZurllib.parserr�r�r�r�r:rAZTestCaserr|rD�mainr1r1r1r2�<module>s�