Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/test/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/__pycache__/test_http_cookies.cpython-35.opt-2.pyc



���]�H�@s�ddlZddlmZmZmZddlZddlmZddlZddl	Z	Gdd�dej
�ZGdd�dej
�Zdd	�Z
ed
kr�e
�dS)�N)�run_unittest�run_doctest�check_warnings)�cookiesc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS) �CookieTestscCs0t�|_|jj�tjddt�dS)N�ignorez.* class is insecure.*)r�_warnings_manager�	__enter__�warnings�filterwarnings�DeprecationWarning)�self�r�6/opt/alt/python35/lib64/python3.5/test_http_cookies.py�setUps
zCookieTests.setUpcCs|jjddd�dS)N)r�__exit__)r
rrr�tearDownszCookieTests.tearDowncCsvdddddddidd	d
didddd
diddd
didddd
diddd
didddddiddd
diddddddddd d!d"idd#d
d$jd*�ig}x�|D]�}tj�}|j|d�|jt|�|d�|j|jd)d$�|d
�x;t|dj��D]#\}}|j||j	|�qGWq�WdS)+N�datazchips=ahoy; vienna=finger�dictZchipsZahoyZviennaZfinger�reprz,<SimpleCookie: chips='ahoy' vienna='finger'>�outputz0Set-Cookie: chips=ahoy
Set-Cookie: vienna=fingerz)keebler="E=mc2; L=\"Loves\"; fudge=\012;"ZkeeblerzE=mc2; L="Loves"; fudge=
;z5<SimpleCookie: keebler='E=mc2; L="Loves"; fudge=\n;'>z5Set-Cookie: keebler="E=mc2; L=\"Loves\"; fudge=\012;"z
keebler=E=mc2zE=mc2z<SimpleCookie: keebler='E=mc2'>zSet-Cookie: keebler=E=mc2zkey:term=value:termzkey:termz
value:termz%<SimpleCookie: key:term='value:term'>zSet-Cookie: key:term=value:termza=b; c=[; d=r; f=h�a�b�c�[�d�r�f�hz'<SimpleCookie: a='b' c='[' d='r' f='h'>�
�Set-Cookie: a=b�Set-Cookie: c=[�Set-Cookie: d=r�Set-Cookie: f=h�sep)r r!r"r#)
�joinr�SimpleCookie�load�assertEqualrr�sorted�items�value)r
�casesZcase�C�k�vrrr�
test_basics>					
 #zCookieTests.test_basiccCs�tj�}|jd�|j|djd�|j|ddd�|j|ddd�|j|jdg�d�|j|j�d	�|j|jdg�d
�dS)Nz/Customer="WILE_E_COYOTE"; Version=1; Path=/acme�Customer�
WILE_E_COYOTE�version�1�pathz/acmez0Set-Cookie: Customer="WILE_E_COYOTE"; Path=/acmez�
        <script type="text/javascript">
        <!-- begin hiding
        document.cookie = "Customer=\"WILE_E_COYOTE\"; Path=/acme; Version=1";
        // end hiding -->
        </script>
        z�
        <script type="text/javascript">
        <!-- begin hiding
        document.cookie = "Customer=\"WILE_E_COYOTE\"; Path=/acme";
        // end hiding -->
        </script>
        )rr&r'r(r+r�	js_output)r
r-rrr�	test_loadFs
zCookieTests.test_loadcCs6tj�}d|d<|j|jdg�d�dS)Nzsome,funky;stuff�valz(Set-Cookie: val="some\054funky\073stuff")rr&r(r)r
r-rrr�test_extended_encode_s
z CookieTests.test_extended_encodecCs�tjd�}d|dd<|j|j�jd��tj�}|jd�|j|ddd�tj�}|jd�|j|ddd	�tjd�}d
|dd<|j|j�d�dS)
NzCustomer="WILE_E_COYOTE"rr1�expiresZGMTz3Customer="W"; expires=Wed, 01 Jan 2010 00:00:00 GMTzWed, 01 Jan 2010 00:00:00 GMTz1Customer="W"; expires=Wed, 01 Jan 98 00:00:00 GMTzWed, 01 Jan 98 00:00:00 GMT�
zmax-agez0Set-Cookie: Customer="WILE_E_COYOTE"; Max-Age=10)rr&�
assertTruer�endswithr'r()r
r-rrr�test_special_attrsgs

zCookieTests.test_special_attrscCsEtjd�}d|dd<d|dd<|j|j�d�dS)NzCustomer="WILE_E_COYOTE"Tr1�secure�httponlyz6Set-Cookie: Customer="WILE_E_COYOTE"; HttpOnly; Secure)rr&r(r)r
r-rrr�test_set_secure_httponly_attrs~s
z*CookieTests.test_set_secure_httponly_attrscCsGtj�}|jd�|j|dd�|j|dd�dS)Nzeggs=scrambled; Path=/bacon�eggsr@r?)rr&r'�assertFalse)r
r-rrr�)test_secure_httponly_false_if_not_present�s
z5CookieTests.test_secure_httponly_false_if_not_presentcCsGtj�}|jd�|j|dd�|j|dd�dS)Nz-eggs=scrambled; httponly; secure; Path=/baconrBr@r?)rr&r'r<)r
r-rrr�$test_secure_httponly_true_if_present�s
z0CookieTests.test_secure_httponly_true_if_presentcCswtj�}|jd�|j|dd�|j|dd�|j|ddd�|j|ddd�dS)Nz5eggs=scrambled; httponly=foo; secure=bar; Path=/baconrBr@r?�foo�bar)rr&r'r<r()r
r-rrr�'test_secure_httponly_true_if_have_value�s
z3CookieTests.test_secure_httponly_true_if_have_valuecCs3tj�}|jd�|j|j�d�dS)Nz=eggs  =  scrambled  ;  secure  ;  path  =  bar   ; foo=foo   zASet-Cookie: eggs=scrambled; Path=bar; Secure
Set-Cookie: foo=foo)rr&r'r(r)r
r-rrr�test_extra_spaces�s
zCookieTests.test_extra_spacescCs�tj�}|jd�|j|djd�|j|ddd�|j|ddd�|j|jdg�d�|j|j�d	�|j|jdg�d
�dS)Nz3Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"r1r2r3r4r5z/acmez0Set-Cookie: Customer="WILE_E_COYOTE"; Path=/acmez�
        <script type="text/javascript">
        <!-- begin hiding
        document.cookie = "Customer=\"WILE_E_COYOTE\"; Path=/acme; Version=1";
        // end hiding -->
        </script>
        z�
        <script type="text/javascript">
        <!-- begin hiding
        document.cookie = "Customer=\"WILE_E_COYOTE\"; Path=/acme";
        // end hiding -->
        </script>
        )rr&r'r(r+rr6)r
r-rrr�test_quoted_meta�s
zCookieTests.test_quoted_metac
CsZtj�}xGdD]?}|j|�|jt|�i�|j|j�d�qWdS)
N�]foo=x�[foo=x�
blah]foo=x�
blah[foo=x�Set-Cookie: foo=bar�Set-Cookie: foo�foo=bar; baz�baz; foo=bar�secure;foo=bar�Version=1;foo=bar�)
rKrLrMrNrOrPrQrRrSrT)rr&r'r(rr)r
r-�srrr�test_invalid_cookies�s

z CookieTests.test_invalid_cookiesc
Cs�d}d|}tj�}|j|�|j|j�|�xittjd�D]T}|jd|��9tj	tj
|d|��}|j|j�|�WdQRXqSWdS)Nz/Customer="WILE_E_COYOTE"; Path=/acme; Version=1zSet-Cookie: %s��proto�protocol)rr&r'r(r�range�pickle�HIGHEST_PROTOCOL�subTest�loads�dumps)r
�rawdataZexpected_outputr-rYZC1rrr�test_pickle�s

zCookieTests.test_picklec	Cs=d}tj�}|jtj��|j|�WdQRXdS)Nz
a=b; c,d=e)rr&�assertRaises�CookieErrorr')r
rar-rrr�test_illegal_chars�szCookieTests.test_illegal_charsN)�__name__�
__module__�__qualname__rrr0r7r9r>rArDrErHrIrJrWrbrerrrrr
s1
rc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�MorselTestscCs�tj�}|j|j�|j|j�|j|j�|j|j�tjjj��x-|j	�D]\}}|j|d|�qkWdS)NrU)
r�MorselZassertIsNone�keyr+�coded_valuer(�keys�	_reservedr*)r
�morselrkr8rrr�
test_defaults�s"zMorselTests.test_defaultscCs�tj�}x5|jD]*}|j|j|��d|||<qWx)|jD]}|j||d|�qNWx4dj�D]&}|jtj|j	|d|�q}WdS)Nz%s_valuezthe holy hand grenade)
rrjrnr<Z
isReservedKeyr(�splitrcrd�__setitem__)r
�M�irrr�test_reserved_keys�szMorselTests.test_reserved_keyscCstj�}x8|jD]-}|jtj|j|d|d|�qWx�dj�D]y}d|d<|j|d|d|�|j|j�d|d|f�d|d|f}|j|j	�|�qTWx;d	d
gD]-}|jtj|j|d|d|�q�WdS)Nz%s_valuez(thou cast _the- !holy! ^hand| +*grenade~z/foor5z%s_valz%s_coded_valzSet-Cookie: %s=%s; Path=/fooz�
        <script type="text/javascript">
        <!-- begin hiding
        document.cookie = "%s=%s; Path=/foo";
        // end hiding -->
        </script>
        zfoo barzfoo@bar)
rrjrnrcrd�setrqr(rr6)r
rsrtZexpected_js_outputrrr�test_setter�s
	zMorselTests.test_setterc"Cs�tj�}|jtd��d|_WdQRX|jtd��d|_WdQRX|jtd��d|_WdQRX|jtd��|jdddd	d
�WdQRXdS)Nz\bkey\brUz	\bvalue\bz\bcoded_value\bz\bLegalChars\brkr+rlZ
LegalCharsz.*)rrjZassertWarnsRegexrrkr+rlrv)r
rorrr�test_deprecationszMorselTests.test_deprecationc	Cspd}dddddd	d
di}tj�}|j|�|j|�tj�}|j|�|j|�|j||k�|j||k�d}xq|D]i}|j|��Qtj�}|j|�|j|�|j||k�|j||k�WdQRXq�Wtj�}|j|�|j|�d
|d<|j||k�|j||k�|jtj�dk�|jtj�dk�|jtj�dk�|jtj�dk�ttj�j��}|jtj�|k�|jtj�|k�tj�}|j|�|j|�|j|t	|�k�|j|t	|�k�dS)Nrkr+�"value"r5�/�commentrF�domainzexample.comr3��mismatchrGrXrU)rkr+ry�rkr+r~�rkr~ry�r~r+ry)rr�r�)
rrj�updatervr<rCr^�listr*r)	r
Z	base_case�attribs�morsel_a�morsel_br,Zcase_br*rorrr�test_eqsR











zMorselTests.test_eqcCs�tj�}|jddd�|jddddi�|j�}|j|tj�|j||�|j||�tj|�}|j|tj�|j||�|j||�dS)NrFrG�bazr3r}r{)rrjrvr��copy�assertIsInstanceZassertIsNotr()r
r�r�rrr�	test_copyRs
zMorselTests.test_copyc
Cs�tj�}d|d<|j|dd�d|d<|j|dd�d|d<|j|dd�|jtj��d	|d
<WdQRX|jd
|�dS)Nrr:r}�Versionr3zexample.com�DOMAINr|r+�invalid)rrjr(rcrd�assertNotIn)r
rorrr�test_setitemcs


zMorselTests.test_setitemc
Cs�tj�}|jddddi�|j|jdd�d�|j|dd�|j|jdd	�d�|j|dd�|j|jd
d�d�|j|dd�|jtj��|jdd�WdQRX|jd|�dS)Nr|zexample.comr3r}r:r+rUr�rXr�r�)rrjr�r(�
setdefaultrcrdr�)r
rorrr�test_setdefaultps
zMorselTests.test_setdefaultcCs�ddddddi}tj�}|j|�|j|dd�|j|dd�|j|dd�tj�}|jt|j���|j|dd�|j|dd�|j|dd�tj�}|jd	d
�|j�D��|j|dd�|j|dd�|j|dd�|jtj��|jddi�WdQRX|jd|�|jt	|j�|jt	|jd
�dS)Nr:rXr�r}r�zexample.comr3r|css!|]\}}||fVqdS)Nr)�.0r.r/rrr�	<genexpr>�sz*MorselTests.test_update.<locals>.<genexpr>r�r+r)
rrjr�r(r�r*rcrdr��	TypeError)r
r�rorrr�test_update�s*
 zMorselTests.test_updatecCs�tj�}|jddd�|jddddi�x�ttjd�D]z}|jd|��_tjtj	||��}|j
|tj�|j||�|jt|�t|��WdQRXqLWdS)	NrFrGr�r3r}r{rXrY)
rrjrvr�r[r\r]r^r_r`r�r(�str)r
r�rYr�rrrrb�s
zMorselTests.test_picklec
Csmtj�}|jt|�d�|jt|�d�|jddd�|jt|�d�|jt|�d�|jdd	d
ddd
ddddddi�|jt|�d�|jt|�d�d|d<d|d<|jt|�d�|jt|�d�tj�}|jddd�d|d<|jt|�d�|jt|�d�dS)Nz<Morsel: None=None>zSet-Cookie: None=Nonerkr8Z	coded_valz<Morsel: key=coded_val>zSet-Cookie: key=coded_valr5rzr{rFr|zexample.comzmax-agerr?r3rXzV<Morsel: key=coded_val; Comment=foo; Domain=example.com; Max-Age=0; Path=/; Version=1>zXSet-Cookie: key=coded_val; Comment=foo; Domain=example.com; Max-Age=0; Path=/; Version=1Tr@zh<Morsel: key=coded_val; Comment=foo; Domain=example.com; HttpOnly; Max-Age=0; Path=/; Secure; Version=1>zjSet-Cookie: key=coded_val; Comment=foo; Domain=example.com; HttpOnly; Max-Age=0; Path=/; Secure; Version=1r:zA<Morsel: key=coded_val; expires=\w+, \d+ \w+ \d+ \d+:\d+:\d+ \w+>zCSet-Cookie: key=coded_val; expires=\w+, \d+ \w+ \d+ \d+:\d+:\d+ \w+)rrjr(rr�rvr�ZassertRegex)r
rorrr�	test_repr�s<



zMorselTests.test_reprN)rfrgrhrprurwrxr�r�r�r�r�rbr�rrrrri�s	4
ricCsttt�tt�dS)N)rrrirrrrrr�	test_main�s
r��__main__)r�Ztest.supportrrrZunittestZhttprr\r
ZTestCaserrir�rfrrrr�<module>s��