HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.7/test/__pycache__/test_http_cookies.cpython-37.opt-1.pyc
B

��g�H�@srddlZddlmZmZddlZddlmZddlZGdd�dej�Z	Gdd�dej�Z
dd	�Zed
krne�dS)�N)�run_unittest�run_doctest)�cookiesc@s|eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)�CookieTestsc
Cs�dddd�ddd�dd	d
iddd�d
d	diddd�dddiddd�dddddd�dd�d�d�g}x~|D]v}t��}|�|d�|�t|�|d �|�|jdd!�|d"�x.t|d#���D]\}}|�||j	|�q�WqhWdS)$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=\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�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�assertEqualrr	�sorted�items�value)�self�casesZcase�C�k�v�r �2/usr/local/lib/python3.7/test/test_http_cookies.py�
test_basics8
zCookieTests.test_basiccCs�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�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>
        )rrrrrr	�	js_output)rrr r r!�	test_load=s

zCookieTests.test_loadcCs(t��}d|d<|�|�dg�d�dS)Nzsome,funky;stuff�valz(Set-Cookie: val="some\054funky\073stuff")rrrr	)rrr r r!�test_extended_encodeVsz CookieTests.test_extended_encodecCs�t�d�}d|dd<|�|���d��t��}|�d�|�|ddd�t��}|�d�|�|ddd	�t�d�}d
|dd<|�|��d�dS)
NzCustomer="WILE_E_COYOTE"rr#�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	�endswithrr)rrr r r!�test_special_attrs^s




zCookieTests.test_special_attrscCs6t�d�}d|dd<d|dd<|�|��d�dS)NzCustomer="WILE_E_COYOTE"Tr#�secure�httponlyz6Set-Cookie: Customer="WILE_E_COYOTE"; HttpOnly; Secure)rrrr	)rrr r r!�test_set_secure_httponly_attrsus


z*CookieTests.test_set_secure_httponly_attrscCs:t��}|�d�|�|dd�|�|dd�dS)Nzeggs=scrambled; Path=/bacon�eggsr2r1)rrr�assertFalse)rrr r r!�)test_secure_httponly_false_if_not_present|s
z5CookieTests.test_secure_httponly_false_if_not_presentcCs:t��}|�d�|�|dd�|�|dd�dS)Nz-eggs=scrambled; httponly; secure; Path=/baconr4r2r1)rrrr.)rrr 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=/baconr4r2r1�foo�bar)rrrr.r)rrr 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	)rrr r r!�test_extra_spaces�s

zCookieTests.test_extra_spacescCs�t��}|�d�|�|djd�|�|ddd�|�|ddd�|�|�dg�d�|�|��d	�|�|�dg�d
�dS)Nz3Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"r#r$r%r&r'z/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>
        )rrrrrr	r()rrr r r!�test_quoted_meta�s

zCookieTests.test_quoted_metacCsDt��}x6dD].}|�|�|�t|�i�|�|��d�qWdS)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��}|�|�|�|��|�xRttjd�D]@}|j|d��*t�	tj
||d��}|�|��|�WdQRXq>WdS)Nz/Customer="WILE_E_COYOTE"; Path=/acme; Version=1zSet-Cookie: %s�)�proto)Zprotocol)rrrrr	�range�pickle�HIGHEST_PROTOCOL�subTest�loads�dumps)r�rawdataZexpected_outputrrAZC1r r r!�test_pickle�s
zCookieTests.test_picklec	Cs2d}t��}|�tj��|�|�WdQRXdS)Nz
a=b; c,d=e)rr�assertRaises�CookieErrorr)rrHrr r r!�test_illegal_chars�szCookieTests.test_illegal_charscCsHt��}d|d<|�t|d�d�d|dd<|�t|d�d�dS)N�©r8zSet-Cookie: foo="\251"u
comment ©�commentz.Set-Cookie: foo="\251"; Comment="comment \251")rrr�str)rrr r r!�test_comment_quoting�s
z CookieTests.test_comment_quotingN)�__name__�
__module__�__qualname__r"r)r+r0r3r6r7r:r;r<r?rIrLrPr r r r!r
s1
rc@sheZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�MorselTestszTests for the Morsel object.cCslt��}|�|j�|�|j�|�|j�|�|��tjj���x"|�	�D]\}}|�|d|�qNWdS)Nr=)
r�MorselZassertIsNone�keyr�coded_valuer�keys�	_reservedr)r�morselrVr*r r r!�
test_defaults�szMorselTests.test_defaultscCs�t��}x*|jD] }|�|�|��d|||<qWx"|jD]}|�||d|�q<Wx(d��D]}|�tj|j	|d|�qbWdS)Nz%s_valuezthe holy hand grenade)
rrUrYr.Z
isReservedKeyr�splitrJrK�__setitem__)r�M�ir r r!�test_reserved_keys�szMorselTests.test_reserved_keysc	Cst��}x,|jD]"}|�tj|j|d|d|�qWx�d��D]�}d|d<|�|d|d|�|�|j|�|�|j	d|�|�|j
d|�|�|��d|d|f�d|d|f}|�|��|�q@Wx*d	D]"}|�tj|j|d|d|�q�WdS)
Nz%s_valuez(thou cast _the- !holy! ^hand| +*grenade~z/foor'z%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)
rrUrYrJrK�setr\rrVrrWr	r()rr^r_Zexpected_js_outputr r r!�test_setter�s$
zMorselTests.test_setterc	Cs`t��}|�t��d|_WdQRX|�t��d|_WdQRX|�t��d|_WdQRXdS)Nr=)rrUrJ�AttributeErrorrVrrW)rrZr r r!�test_set_propertiesszMorselTests.test_set_propertiesc	
Cs�d}ddddd�}t��}|�|�|j|�t��}|�|�|j|�|�||k�|�||k�d}xZ|D]R}|�|��>t��}|�|�|j|�|�||k�|�||k�WdQRXqpWt��}|�|�|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)rVrz"value"�/r8zexample.com�)r'rN�domainr%))rVr�mismatch)rVrhz"value")rhrz"value"r9rNr@r=)
rrU�updaterar.r5rE�listrr)	rZ	base_case�attribs�morsel_a�morsel_brZcase_brrZr r r!�test_eq sN










zMorselTests.test_eqcCs�t��}|�ddd�|�ddd��|��}|�|tj�|�||�|�||�t�|�}|�|tj�|�||�|�||�dS)Nr8r9�bazrf)r%rN)rrUrari�copy�assertIsInstanceZassertIsNotr)rrlrmr r r!�	test_copyTs

zMorselTests.test_copyc	Cs�t��}d|d<|�|dd�d|d<|�|dd�d|d<|�|dd�|�tj��d	|d
<WdQRX|�d
|�dS)Nrr,rf�Versionr%zexample.com�DOMAINrgr�invalid)rrUrrJrK�assertNotIn)rrZr r r!�test_setitemeszMorselTests.test_setitemc	Cs�t��}|�ddd��|�|�dd�d�|�|dd�|�|�dd�d�|�|d	d�|�|�d
d�d�|�|dd�|�tj��|�dd�WdQRX|�d|�dS)
Nzexample.comrf)rgr%r,rr=rsr@r%rtrgru)rrUrir�
setdefaultrJrKrv)rrZr r r!�test_setdefaultrs
zMorselTests.test_setdefaultc	Cs<dddd�}t��}|�|�|�|dd�|�|dd�|�|dd�t��}|�t|����|�|dd�|�|dd�|�|dd�t��}|�dd	�|��D��|�|dd�|�|dd�|�|dd�|�tj��|�d
di�WdQRX|�d
|�|�t	|j�|�t	|jd�dS)
Nr@rfzexample.com)r,rsrtr,r%rgcss|]\}}||fVqdS)Nr )�.0rrr r r!�	<genexpr>�sz*MorselTests.test_update.<locals>.<genexpr>rurr)
rrUrirrjrrJrKrv�	TypeError)rrkrZr r r!�test_update�s*
zMorselTests.test_updatec
Cs�t��}|�ddd�|�ddd��xnttjd�D]\}|j|d��Ft�t�	||��}|�
|tj�|�||�|�t|�t|��WdQRXq6WdS)Nr8r9rorf)r%rNr@)rA)
rrUrarirBrCrDrErFrGrqrrO)rrlrArmr r r!rI�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=NonerVr*Z	coded_valz<Morsel: key=coded_val>zSet-Cookie: key=coded_valrer8zexample.comrr@)r'rNrgzmax-ager1r%zV<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=1Tr1r2zh<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+)rrUrrrOrariZassertRegex)rrZr r r!�	test_repr�s<






zMorselTests.test_reprN)rQrRrS�__doc__r[r`rbrdrnrrrwryr}rIr~r r r r!rT�s		4
rTcCsttt�tt�dS)N)rrrTrrr r r r!�	test_main�s
r��__main__)
rpZtest.supportrrZunittestZhttprrCZTestCaserrTr�rQr r r r!�<module>sTy