Your IP : 216.73.216.213


Current Path : /opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/test/__pycache__/test_http_cookies.cpython-34.pyc

�
f f�)�@s�ddlmZmZmZddlZddlmZddlZddlZGdd�dej	�Z
Gdd�dej	�Zdd	�Ze
d
kr�e�ndS)�)�run_unittest�run_doctest�check_warningsN)�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�;/opt/alt/python34/lib64/python3.4/test/test_http_cookies.py�setUps
zCookieTests.setUpcCs|jjddd�dS)N)r�__exit__)r
rrr�tearDownszCookieTests.tearDownc
Cs�idd6idd6dd6d6dd	6d
d6idd6id
d6d6dd	6dd6idd6idd6d6dd	6dd6idd6idd6d6dd	6dd6idd6idd6dd6dd 6d!d"6d6d#d	6d$jd*�d6g}x�|D]�}tj�}|j|d�|jt|�|d	�|j|jd)d$�|d�x;t|dj��D]#\}}|j||j	|�qdWq�WdS)+Nzchips=ahoy; vienna=finger�dataZahoyZchipsZfingerZvienna�dictz,<SimpleCookie: chips='ahoy' vienna='finger'>�reprz0Set-Cookie: chips=ahoy
Set-Cookie: vienna=finger�outputz)keebler="E=mc2; L=\"Loves\"; fudge=\012;"zE=mc2; L="Loves"; fudge=
;Zkeeblerz5<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:termz
value:termzkey:termz%<SimpleCookie: key:term='value:term'>zSet-Cookie: key:term=value:termza=b; c=[; d=r; f=h�b�a�[�c�r�d�h�fz'<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
ZcasesZcase�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_loadEs
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"rr0ZexpiresZGMTz3Customer="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_attrsfs

zCookieTests.test_special_attrscCsEtjd�}d|dd<d|dd<|j|j�d�dS)NzCustomer="WILE_E_COYOTE"Tr0�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'ZassertFalse)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=/baconr@r>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=/baconr@r>r=ZfooZbar)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-cookie=with; invalid; version; second=cookie;z2Set-Cookie: cookie=with
Set-Cookie: second=cookie)rr&r'r(r)r
r,rrr�test_bad_attrs�s
zCookieTests.test_bad_attrscCs3tj�}|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"r0r1r2r3r4z/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+rr5)r
r,rrr�test_quoted_meta�s
zCookieTests.test_quoted_metacCsZtj�}xGdD]?}|j|�|jt|�i�|j|j�d�qWdS)N�]foo=x�[foo=x�
blah]foo=x�
blah[foo=x�)rGrHrIrJ)rr&r'r(rr)r
r,�srrr�test_invalid_cookies�s


z CookieTests.test_invalid_cookiesc
Cs�d}d|}tj�}|j|�|j|j�|�xhttjd�D]S}|jd|��9tj	tj
|d|��}|j|j�|�WdQXqSWdS)Nz/Customer="WILE_E_COYOTE"; Path=/acme; Version=1zSet-Cookie: %s��protoZprotocol)rr&r'r(r�range�pickleZHIGHEST_PROTOCOLZsubTest�loads�dumps)r
ZrawdataZexpected_outputr,rOZC1rrr�test_pickle�s

zCookieTests.test_pickleN)�__name__�
__module__�__qualname__rrr/r6r8r<r?rArBrCrDrErFrMrTrrrrr	s1rc@s.eZdZdZdd�Zdd�ZdS)�MorselTestszTests for the Morsel object.cCs�tj�}x5|jD]*}|j|j|��d|||<qWx)|jD]}|j||d|�qNWx4dj�D]&}|jtj|j	|d|�q}WdS)Nz%s_valuezthe holy hand grenade)
r�Morsel�	_reservedr:Z
isReservedKeyr(�split�assertRaises�CookieError�__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/foor4z%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)
rrYrZr\r]�setr[r(rr5)r
r_r`Zexpected_js_outputrrr�test_setter�s
	zMorselTests.test_setterN)rUrVrW�__doc__rarcrrrrrX�srXcCsttt�tt�dS)N)rrrXrrrrrr�	test_mains
re�__main__)Ztest.supportrrrZunittestZhttprrQr
ZTestCaserrXrerUrrrr�<module>s�/