Your IP : 216.73.216.196


Current Path : /opt/alt/python310/lib64/python3.10/test/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/test/__pycache__/test_http_cookies.cpython-310.opt-2.pyc

o

0�iW�@s�ddlZddlmZmZddlZddlmZddlZddlm	Z	Gdd�dej
�ZGdd�dej
�Zd	d
�Z
edkr?e
�dSdS)�N)�run_unittest�run_doctest)�cookies)�supportc@s�eZdZdd�Zdd�Ze�d�dd��Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$S)%�CookieTestsc
Cs�dddd�ddd�dd	d
iddd�d
d	diddd�dddiddd�dddddd�dd�d�d�g}|D]9}t��}|�|d�|�t|�|d �|�|jdd!�|d"�t|d#���D]
\}}|�||j	|�q^q3dS)$Nzchips=ahoy; vienna=fingerZahoyZfinger)ZchipsZviennaz,<SimpleCookie: chips='ahoy' vienna='finger'>z0Set-Cookie: chips=ahoy
Set-Cookie: vienna=finger)�data�dict�repr�outputz%keebler="E=mc2; L=\"Loves\"; fudge=;"ZkeeblerzE=mc2; L="Loves"; fudge=;z3<SimpleCookie: keebler='E=mc2; L="Loves"; fudge=;'>z1Set-Cookie: keebler="E=mc2; L=\"Loves\"; fudge=;"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�b�[�r�h)�a�c�d�fz'<SimpleCookie: a='b' c='[' d='r' f='h'>�
)zSet-Cookie: a=bzSet-Cookie: c=[zSet-Cookie: d=rzSet-Cookie: f=hrr	)�sepr
r)
�joinr�SimpleCookie�load�assertEqualr	r
�sorted�items�value)�self�cases�case�C�k�v�r"�=/opt/alt/python310/lib64/python3.10/test/test_http_cookies.py�
test_basic
sF������(��zCookieTests.test_basicc	Cshgd�}|D]+\}}|�|��t��}|�|�|�|dj|�Wd�n1s,wYqdS)N))za="b=\""�b=")za="b=\\"�b=\)za="b=\="zb==)za="b=\n"zb=n)z
a="b=\042"r%)z
a="b=\134"r&)z
a="b=\377"ub=ÿ)z
a="b=\400"zb=400)z	a="b=\42"zb=42)za="b=\\042"zb=\042)za="b=\\134"zb=\134)z
a="b=\\\""�b=\")za="b=\\\042"r')za="b=\134\""r')za="b=\134\042"r'r)�subTestrrrrr)rr�encodedZdecodedrr"r"r#�test_unquote>s
���zCookieTests.test_unquoteZcpuc	Cs�d}dD]K}|�|��<d||d}t��}|�|�|dj}|�|dd�d�|�|dd�d	�|�t|�|d�Wd�n1sJwYqdS)
Ni@B)z\\z\134za="b=z;"r�r&���z\;)r(rrrrr�len)r�nr)rrrr"r"r#�test_unquote_largeVs

���zCookieTests.test_unquote_largecC�t��}|�d�|�|djd�|�|ddd�|�|ddd�|�|�dg�d�|�|��d	�|�|�dg�d
�dS)Nz/Customer="WILE_E_COYOTE"; Version=1; Path=/acme�Customer�
WILE_E_COYOTE�version�1�path�/acme�0Set-Cookie: Customer="WILE_E_COYOTE"; Path=/acme��
        <script type="text/javascript">
        <!-- begin hiding
        document.cookie = "Customer=\"WILE_E_COYOTE\"; Path=/acme; Version=1";
        // end hiding -->
        </script>
        ��
        <script type="text/javascript">
        <!-- begin hiding
        document.cookie = "Customer=\"WILE_E_COYOTE\"; Path=/acme";
        // end hiding -->
        </script>
        �rrrrrr
�	js_output�rrr"r"r#�	test_loadcs
�zCookieTests.test_loadcCs(t��}d|d<|�|�dg�d�dS)Nzsome,funky;stuff�valz(Set-Cookie: val="some\054funky\073stuff"�rrrr
r<r"r"r#�test_extended_encode|s
�z CookieTests.test_extended_encodecCs�t�d�}d|dd<|�|���d��t��}|�d�|�|ddd�t��}|�d�|�|ddd	�t�d�}d
|dd<|�|��d�dS)
N�Customer="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�
�max-agez0Set-Cookie: Customer="WILE_E_COYOTE"; Max-Age=10)rr�
assertTruer
�endswithrrr<r"r"r#�test_special_attrs�s$

�
�

�zCookieTests.test_special_attrscCs6t�d�}d|dd<d|dd<|�|��d�dS)NrATr1�secure�httponlyz6Set-Cookie: Customer="WILE_E_COYOTE"; HttpOnly; Securer?r<r"r"r#�test_set_secure_httponly_attrs�s

�z*CookieTests.test_set_secure_httponly_attrsc	Cs�gd�}|D]B}|j|d��2t�d�}||dd<|�|��d|�t��}|�d|�|�|dd|�Wd�n1sCwYqdS)N)ZStrictZLax�strictZlax)r>rAr1Zsamesitez1Set-Cookie: Customer="WILE_E_COYOTE"; SameSite=%sz%Customer="WILL_E_COYOTE"; SameSite=%s)r(rrrr
r)rZsamesite_valuesr>rr"r"r#�test_samesite_attrs�s

����zCookieTests.test_samesite_attrscC�:t��}|�d�|�|dd�|�|dd�dS)Nzeggs=scrambled; Path=/bacon�eggsrIrH)rrr�assertFalser<r"r"r#�)test_secure_httponly_false_if_not_present�s
z5CookieTests.test_secure_httponly_false_if_not_presentcCrM)Nz-eggs=scrambled; httponly; secure; Path=/baconrNrIrH)rrrrEr<r"r"r#�$test_secure_httponly_true_if_present�s
z0CookieTests.test_secure_httponly_true_if_presentcCsbt��}|�d�|�|dd�|�|dd�|�|ddd�|�|ddd�dS)Nz5eggs=scrambled; httponly=foo; secure=bar; Path=/baconrNrIrH�foo�bar)rrrrErr<r"r"r#�'test_secure_httponly_true_if_have_value�s
z3CookieTests.test_secure_httponly_true_if_have_valuecCs&t��}|�d�|�|��d�dS)Nz=eggs  =  scrambled  ;  secure  ;  path  =  bar   ; foo=foo   zASet-Cookie: eggs=scrambled; Path=bar; Secure
Set-Cookie: foo=foo)rrrrr
r<r"r"r#�test_extra_spaces�s


�zCookieTests.test_extra_spacescCr0)Nz3Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"r1r2r3r4r5r6r7r8r9r:r<r"r"r#�test_quoted_meta�s
�zCookieTests.test_quoted_metacCs@t��}dD]}|�|�|�t|�i�|�|��d�qdS)N)
z]foo=xz[foo=xz
blah]foo=xz
blah[foo=xzSet-Cookie: foo=barzSet-Cookie: foozfoo=bar; bazzbaz; foo=barzsecure;foo=barzVersion=1;foo=bar�)rrrrrr
)rr�sr"r"r#�test_invalid_cookies�s
�z CookieTests.test_invalid_cookiesc	Cs�d}d|}t��}|�|�|�|��|�ttjd�D]*}|j|d��t�	tj
||d��}|�|��|�Wd�n1sCwYqdS)Nz/Customer="WILE_E_COYOTE"; Path=/acme; Version=1zSet-Cookie: %s���proto)Zprotocol)rrrrr
�range�pickle�HIGHEST_PROTOCOLr(�loads�dumps)r�rawdataZexpected_outputrr\ZC1r"r"r#�test_pickle�s
���zCookieTests.test_picklecCsHd}t��}|�tj��|�|�Wd�dS1swYdS)Nz
a=b; c,d=e)rr�assertRaises�CookieErrorr)rrbrr"r"r#�test_illegal_chars�s
"�zCookieTests.test_illegal_charscCsHt��}d|d<|�t|d�d�d|dd<|�t|d�d�dS)N�©rRzSet-Cookie: foo="\251"u
comment ©�commentz.Set-Cookie: foo="\251"; Comment="comment \251")rrr�str)rrr"r"r#�test_comment_quotings
�z CookieTests.test_comment_quotingN)�__name__�
__module__�__qualname__r$r*rZrequires_resourcer/r=r@rGrJrLrPrQrTrUrVrYrcrfrjr"r"r"r#rs&1


rc@sveZdZ	dd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�MorselTestscCsht��}|�|j�|�|j�|�|j�|�|��tjj���|�	�D]\}}|�|d|�q&dS�NrW)
r�MorselZassertIsNone�keyr�coded_valuer�keys�	_reservedr)r�morselrqr>r"r"r#�
test_defaultss�zMorselTests.test_defaultscCszt��}|jD]}|�|�|��d|||<q|jD]}|�||d|�qd��D]}|�tj|j	|d|�q,dS)N�%s_valuezthe holy hand grenade)
rrprtrEZ
isReservedKeyr�splitrdre�__setitem__)r�M�ir"r"r#�test_reserved_keyss

��zMorselTests.test_reserved_keysc	Cs�t��}|jD]}|�tj|j|d|d|�qd��D]H}d|d<|�|d|d|�|�|j|�|�|j	d|�|�|j
d|�|�|��d|d|f�d|d|f}|�|��|�qd	D]}|�tj|j|d|d|�qhdS)
Nrwz(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)
rrprtrdre�setrxrrqrrrr
r;)rrzr{Zexpected_js_outputr"r"r#�test_setter+s0
��
���zMorselTests.test_settercCs�t��}|�t��d|_Wd�n1swY|�t��d|_Wd�n1s/wY|�t��d|_Wd�dS1sHwYdSro)rrprd�AttributeErrorrqrrr�rrur"r"r#�test_set_propertiesJs��"�zMorselTests.test_set_propertiesc		Cs�d}ddddd�}t��}|�|�|j|�t��}|�|�|j|�|�||k�|�||k�d}|D]3}|�|��$t��}|�|�|j|�|�||k�|�||k�Wd�n1sewYq7t��}|�|�|j|�d|d	<|�||k�|�||k�|�t��d
k�|�t��d
k�|�t��dk�|�t��dk�tt�����}|�t��|k�|�t��|k�t��}|j|�|�|�|�|t	|�k�|�|t	|�k�dS)N)rqr�"value"�/rR�example.com�)r5rh�domainr3))rqr�mismatch)rqr�r�)r�rr�rSrhrZrW)
rrp�updater}rErOr(�listrr)	rZ	base_case�attribs�morsel_a�morsel_brZcase_brrur"r"r#�test_eqSsT�





��



zMorselTests.test_eqcCs�t��}|�ddd�|�ddd��|��}|�|tj�|�||�|�||�t�|�}|�|tj�|�||�|�||�dS)NrRrS�bazr��r3rh)rrpr}r��copy�assertIsInstanceZassertIsNotr)rr�r�r"r"r#�	test_copy�s�
zMorselTests.test_copycCs�t��}d|d<|�|dd�d|d<|�|dd�d|d<|�|dd�|�tj��d	|d
<Wd�n1s=wY|�d
|�dS)NrrBr��Versionr3r��DOMAINr�r�invalid)rrprrdre�assertNotInr�r"r"r#�test_setitem�s
�zMorselTests.test_setitemcCs�t��}|�ddd��|�|�dd�d�|�|dd�|�|�dd�d�|�|d	d�|�|�d
d�d�|�|dd�|�tj��|�dd�Wd�n1sYwY|�d|�dS)
Nr�r�)r�r3rBrrWr�rZr3r�r�r�)rrpr�r�
setdefaultrdrer�r�r"r"r#�test_setdefault�s��zMorselTests.test_setdefaultcCsPdddd�}t��}|�|�|�|dd�|�|dd�|�|dd�t��}|�t|����|�|dd�|�|dd�|�|dd�t��}|�dd	�|��D��|�|dd�|�|dd�|�|dd�|�tj��|�d
di�Wd�n1s�wY|�d
|�|�t	|j�|�t	|jd�dS)
NrZr�r�)rBr�r�rBr3r�css�|]	\}}||fVqdS�Nr")�.0r r!r"r"r#�	<genexpr>�s�z*MorselTests.test_update.<locals>.<genexpr>r�rr)
rrpr�rr�rrdrer��	TypeError)rr�rur"r"r#�test_update�s,
�zMorselTests.test_updatec	Cs�t��}|�ddd�|�ddd��ttjd�D]8}|j|d��(t�t�	||��}|�
|tj�|�||�|�t|�t|��Wd�n1sMwYqdS)NrRrSr�r�r�rZr[)
rrpr}r�r]r^r_r(r`rar�rri)rr�r\r�r"r"r#rc�s����zMorselTests.test_picklec	Cst��}|�t|�d�|�t|�d�|�ddd�|�t|�d�|�t|�d�|�dd	d
dddd
��|�t|�d�|�t|�d�d|d<d|d<|�t|�d�|�t|�d�t��}|�ddd�d|d<|�t|�d�|�t|�d�dS)Nz<Morsel: None=None>zSet-Cookie: None=Nonerqr>Z	coded_valz<Morsel: key=coded_val>zSet-Cookie: key=coded_valr�rRr�rrZ)r5rhr�rDrHr3zV<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=1TrHrIzh<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=1rBzA<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+)rrprr	rir}r�ZassertRegexr�r"r"r#�	test_repr�sJ�
�
�
�
�
�
�zMorselTests.test_reprc	Cs�t��D]�}t��}|�tj��d||<Wd�n1swY|�tj��||d<Wd�n1s9wY|�tj��|�d|�Wd�n1sUwY|�tj��|�|d�Wd�n1sqwY|�tj��|�|dd�Wd�n1s�wY|�tj��|�d|d�Wd�n1s�wY|�tj��|�dd|�Wd�n1s�wYqdS)Nr>r5�coded-value)r�control_characters_c0rrprdrer�r})r�c0rur"r"r#�test_control_characterss2
�
��������z#MorselTests.test_control_charactersc	Cs�t��D]b}t��}|�ddd�||_t��}||d<|�tj��|�	�Wd�n1s1wYt��}|�ddd�||_
t��}||d<|�tj��|�	�Wd�n1sawYqdS)Nrqrr��cookie)rr�rrpr}Z_keyrrdrer
Z_coded_value)rr�rur�r"r"r#�test_control_characters_output s&
�
���z*MorselTests.test_control_characters_outputN)rkrlrmrvr|r~r�r�r�r�r�r�rcr�r�r�r"r"r"r#rns		4
(rncCsttt�tt�dSr�)rrrnrrr"r"r"r#�	test_main4s
r��__main__)r�Ztest.supportrrZunittestZhttprr^�testrZTestCaserrnr�rkr"r"r"r#�<module>s &
�