Current File : //usr/local/apps/python3/lib/python3.11/test/__pycache__/test_http_cookies.cpython-311.pyc
�

�Ke�J���ddlZddlZddlZddlmZddlZGd�dej��ZGd�dej��Zd�Z	e
dkrej��dSdS)	�N)�cookiesc�h�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�ZdS)�CookieTestsc
�<�dddd�ddd�dd	d
iddd�d
d	diddd�dddiddd�dddddd�dd�d��d�g}|D]�}tj��}|�|d��|�t|��|d ��|�|�d�!��|d"��t|d#�����D]&\}}|�||j	|���'��dS)$Nzchips=ahoy; vienna=finger�ahoy�finger)�chips�viennaz,<SimpleCookie: chips='ahoy' vienna='finger'>z0Set-Cookie: chips=ahoy
Set-Cookie: vienna=finger)�data�dict�repr�outputz)keebler="E=mc2; L=\"Loves\"; fudge=\012;"�keeblerzE=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
)�seprr)
�joinr�SimpleCookie�load�assertEqualr
r�sorted�items�value)�self�cases�case�C�k�vs      �@/usr/local/apps/python3/lib/python3.11/test/test_http_cookies.py�
test_basiczCookieTests.test_basics���0�$�x�8�8�C�J�
L�
L�
D��"A�B�Q�Q�
S�
S�%��'�*�6�2�
4�
4�,� �<�0�<�8�:�:�-� �c�s��<�<�A��)�)�%���	

�

�7&
��P�	0�	0�D��$�&�&�A�
�F�F�4��<� � � ����T�!�W�W�d�6�l�3�3�3����Q�X�X�$�X�/�/��h��@�@�@��t�F�|�1�1�3�3�4�4�
0�
0���1�� � ��1���Q�/�/�/�/�
0�	0�	0�c��tj��}|�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>
        �rrrrr r�	js_output�r!r$s  r'�	test_loadzCookieTests.test_load=s��� �"�"��	���@�A�A�A�����:��,�o�>�>�>�����:��y�1�3�7�7�7�����:��v�.��8�8�8�������6�(�+�+�>�	@�	@�	@���������)�	
�	
�	
�	
������f�X�.�.�1�	
�	
�	
�	
�	
r)c��tj��}d|d<|�|�dg��d��dS)Nzsome,funky;stuff�valz(Set-Cookie: val="some\054funky\073stuff"�rrrrr6s  r'�test_extended_encodez CookieTests.test_extended_encodeVsP��
� �"�"��%��%��������5�'�*�*�8�	:�	:�	:�	:�	:r)c�n�tjd��}d|dd<|�|����d����tj��}|�d��|�|ddd��tj��}|�d��|�|ddd	��tjd��}d
|dd<|�|���d��dS)
N�Customer="WILE_E_COYOTE"rr+�expires�GMTz3Customer="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�endswithrrr6s  r'�test_special_attrszCookieTests.test_special_attrs^s.��� �!;�<�<��#$��*�
�i� �������
�
�+�+�E�2�2�3�3�3�
� �"�"��	���D�E�E�E�����:��y�1�8�	:�	:�	:�� �"�"��	���B�C�C�C�����:��y�1�6�	8�	8�	8�
� �!;�<�<��#%��*�
�i� ���������K�	M�	M�	M�	M�	Mr)c��tjd��}d|dd<d|dd<|�|���d��dS)Nr=Tr+�secure�httponlyz6Set-Cookie: Customer="WILE_E_COYOTE"; HttpOnly; Securer:r6s  r'�test_set_secure_httponly_attrsz*CookieTests.test_set_secure_httponly_attrsusc��� �!;�<�<��"&��*�
�h��$(��*�
�j�!���������D�	F�	F�	F�	F�	Fr)c��gd�}|D]�}|�|���5tjd��}||dd<|�|���d|z��tj��}|�d|z��|�|dd|��ddd��n#1swxYwY��dS)N)�Strict�Lax�strict�lax)r9r=r+�samesitez1Set-Cookie: Customer="WILE_E_COYOTE"; SameSite=%sz%Customer="WILL_E_COYOTE"; SameSite=%s)�subTestrrrrr)r!�samesite_valuesr9r$s    r'�test_samesite_attrszCookieTests.test_samesite_attrs|s8��<�<�<��"�		A�		A�C����#��&�&�
A�
A��(�)C�D�D��,/��*�
�j�)�� � ������G�#�M�O�O�O��(�*�*�����>��D�E�E�E�� � ��:��z�!:�C�@�@�@�
A�
A�
A�
A�
A�
A�
A�
A�
A�
A�
A����
A�
A�
A�
A��		A�		As�BC�C	�
C	c���tj��}|�d��|�|dd��|�|dd��dS)Nzeggs=scrambled; Path=/bacon�eggsrGrF)rrr�assertFalser6s  r'�)test_secure_httponly_false_if_not_presentz5CookieTests.test_secure_httponly_false_if_not_present�sc��� �"�"��	���,�-�-�-�����6��:�.�/�/�/�����6��8�,�-�-�-�-�-r)c���tj��}|�d��|�|dd��|�|dd��dS)Nz-eggs=scrambled; httponly; secure; Path=/baconrSrGrF)rrrrBr6s  r'�$test_secure_httponly_true_if_presentz0CookieTests.test_secure_httponly_true_if_present�s_��� �"�"��	���>�?�?�?�����&�	�*�-�.�.�.�����&�	�(�+�,�,�,�,�,r)c�b�tj��}|�d��|�|dd��|�|dd��|�|ddd��|�|ddd��dS)Nz5eggs=scrambled; httponly=foo; secure=bar; Path=/baconrSrGrF�foo�bar)rrrrBrr6s  r'�'test_secure_httponly_true_if_have_valuez3CookieTests.test_secure_httponly_true_if_have_value�s���
� �"�"��	���F�G�G�G�����&�	�*�-�.�.�.�����&�	�(�+�,�,�,�	
����6��:�.��6�6�6�����6��8�,�e�4�4�4�4�4r)c��tj��}|�d��|�|���d��dS)Nz=eggs  =  scrambled  ;  secure  ;  path  =  bar   ; foo=foo   zASet-Cookie: eggs=scrambled; Path=bar; Secure
Set-Cookie: foo=foo)rrrrrr6s  r'�test_extra_spaceszCookieTests.test_extra_spaces�sW��� �"�"��	���N�O�O�O���������Q�	S�	S�	S�	S�	Sr)c��tj��}|�d��|�|djd��|�|ddd��|�|ddd��|�|�dg��d��|�|���d	��|�|�dg��d
��dS)Nz3Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"r+r,r-r.r/r0r1r2r3r4r6s  r'�test_quoted_metazCookieTests.test_quoted_meta�s��� �"�"��	���D�E�E�E�����:��,�o�>�>�>�����:��y�1�3�7�7�7�����:��v�.��8�8�8�������6�(�+�+�K�	M�	M�	M���������)�	
�	
�	
�	
������f�X�.�.�1�	
�	
�	
�	
�	
r)c��tj��}dD]b}|�|��|�t	|��i��|�|���d���cdS)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�)rrrrrr)r!r$�ss   r'�test_invalid_cookiesz CookieTests.test_invalid_cookies�sy��� �"�"��9�	-�	-�A�
�F�F�1�I�I�I����T�!�W�W�b�)�)�)����Q�X�X�Z�Z��,�,�,�,�
	-�	-r)c���d}d|z}tj��}|�|��|�|���|��ttjdz��D]�}|�|���5t
j	t
j
||�����}|�|���|��ddd��n#1swxYwY��dS)Nz/Customer="WILE_E_COYOTE"; Path=/acme; Version=1zSet-Cookie: %s���proto)�protocol)rrrrr�range�pickle�HIGHEST_PROTOCOLrO�loads�dumps)r!�rawdata�expected_outputr$rg�C1s      r'�test_picklezCookieTests.test_pickle�s��C��*�W�4��� �"�"��	���w������������_�5�5�5��6�2�Q�6�7�7�	?�	?�E����E��*�*�
?�
?��\�&�,�q�5�"A�"A�"A�B�B��� � ������o�>�>�>�
?�
?�
?�
?�
?�
?�
?�
?�
?�
?�
?����
?�
?�
?�
?��	?�	?s�AC)�)C-	�0C-	c���d}tj��}|�tj��5|�|��ddd��dS#1swxYwYdS)Nz
a=b; c,d=e)rr�assertRaises�CookieErrorr)r!rnr$s   r'�test_illegal_charszCookieTests.test_illegal_chars�s������ �"�"��
�
�
�w�2�
3�
3�	�	�
�F�F�7�O�O�O�	�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	�	s�A�A�Ac���tj��}d|d<|�t|d��d��d|dd<|�t|d��d��dS)N�©rYzSet-Cookie: foo="\251"u
comment ©�commentz.Set-Cookie: foo="\251"; Comment="comment \251")rrr�str)r!rs  r'�test_comment_quotingz CookieTests.test_comment_quoting�sz��� �"�"��'��%������Q�u�X���(A�B�B�B�:��%���������%��M�M�>�	
�	
�	
�	
�	
r)N)�__name__�
__module__�__qualname__r(r7r;rDrHrQrUrWr[r]r_rcrqrurz�r)r'rr
s������/0�/0�/0�b
�
�
�2:�:�:�M�M�M�.F�F�F�A�A�A�.�.�.�-�-�-�
5�
5�
5�S�S�S�
�
�
�2	-�	-�	-�?�?�?����
�
�
�
�
r)rc�T�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
S)�MorselTestszTests for the Morsel object.c��tj��}|�|j��|�|j��|�|j��|�|���tjj�����|�	��D]\}}|�|d|���dS�Nra)
r�Morsel�assertIsNone�keyr �coded_valuer�keys�	_reservedr)r!�morselr�r9s    r'�
test_defaultszMorselTests.test_defaults�s�����!�!�����&�*�%�%�%����&�,�'�'�'����&�,�-�-�-�����������(@�(E�(E�(G�(G�H�H�H������	+�	+�H�C�����S�"�c�*�*�*�*�	+�	+r)c�t�tj��}|jD]2}|�|�|����d|z||<�3|jD]!}|�||d|z���"d���D],}|�tj|j	|d|z���-dS)N�%s_valuezthe holy hand grenade)
rr�r�rB�
isReservedKeyr�splitrsrt�__setitem__)r!�M�is   r'�test_reserved_keyszMorselTests.test_reserved_keys�s����N������	"�	"�A��O�O�A�O�O�A�.�.�/�/�/���>�A�a�D�D���	3�	3�A����Q�q�T�:��>�2�2�2�2�(�.�.�0�0�	@�	@�A����g�1��m�Q�
�Q��
@�
@�
@�
@�	@�	@r)c	���tj��}|jD]0}|�tj|j|d|zd|z���1d���D]�}d|d<|�|d|zd|z��|�|j|��|�|j	d|z��|�|j
d|z��|�|���d|�dd|z�d	���d
|�dd|z�d�}|�|���|����dD]0}|�tj|j|d|zd|z���1dS)
Nr�z(thou cast _the- !holy! ^hand| +*grenade~z/foor/z%s_valz%s_coded_valzSet-Cookie: �=z; Path=/fooz^
        <script type="text/javascript">
        <!-- begin hiding
        document.cookie = "zB; Path=/foo";
        // end hiding -->
        </script>
        )zfoo barzfoo@bar)
rr�r�rsrt�setr�rr�r r�rr5)r!r�r��expected_js_outputs    r'�test_setterzMorselTests.test_setters����N������	H�	H�A����g�1��e�Q�
�Q��
�Q��
H�
H�
H�
H�;�A�A�C�C�	@�	@�A��A�f�I�
�E�E�!�X��\�>�A�#5�6�6�6����Q�U�A�&�&�&����Q�W�h��l�3�3�3����Q�]�N�Q�,>�?�?�?�������
�
�
�23�!�!�^�a�5G�5G�5G�H�
J�
J�
J�
J��q�q�.�1�$�$�$�
"&��
���Q�[�[�]�]�,>�?�?�?�?�'�	H�	H�A����g�1��e�Q�
�Q��
�Q��
H�
H�
H�
H�	H�	Hr)c��tj��}|�t��5d|_ddd��n#1swxYwY|�t��5d|_ddd��n#1swxYwY|�t��5d|_ddd��dS#1swxYwYdSr�)rr�rs�AttributeErrorr�r r��r!r�s  r'�test_set_propertieszMorselTests.test_set_properties$so����!�!��
�
�
�~�
.�
.�	�	��F�J�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�
�
�
�~�
.�
.�	�	��F�L�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�
�
�
�~�
.�
.�	$�	$�!#�F��	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$����	$�	$�	$�	$�	$�	$s5�A�A�	A�'A;�;A?�A?� B5�5B9�<B9c��d}ddddd�}tj��}|�|��|j|�tj��}|�|��|j|�|�||k��|�||k��d}|D]�}|�|��5tj��}|�|��|j|�|�||k��|�||k��ddd��n#1swxYwY��tj��}|�|��|j|�d|d	<|�||k��|�||k��|�tj��d
k��|�tj��d
k��|�tj��dk��|�tj��dk��ttj�������}|�tj��|k��|�tj��|k��tj��}|j|�|�|��|�|t|��k��|�|t|��k��dS)N)r�r �"value"�/rY�example.com�)r/rx�domainr-))r�r �mismatch)r�r�r�)r�r r�rZrxrera)
rr��updater�rBrTrO�listrr)	r!�	base_case�attribs�morsel_a�morsel_br"�case_brr�s	         r'�test_eqzMorselTests.test_eq-sJ��/�	���#��	
�
���>�#�#������ � � ����i� � ��>�#�#������ � � ����i� � �����H�,�-�-�-�����X�-�.�.�.�
��
�	6�	6�F����f�%�%�
6�
6�"�>�+�+������(�(�(����f�%�%�� � ��X�!5�6�6�6�����H� 4�5�5�5�
6�
6�
6�
6�
6�
6�
6�
6�
6�
6�
6����
6�
6�
6�
6���>�#�#������ � � ����i� � �#��������X�-�.�.�.�����H�,�-�-�-�	
�����)�)�Q�.�/�/�/������(�(�A�-�.�.�.������)�)�R�/�0�0�0������(�(�B�.�/�/�/��W�^�%�%�+�+�-�-�.�.�������)�)�U�2�3�3�3������(�(�E�1�2�2�2���!�!����
�I����
�
�g��������$�v�,�,�.�/�/�/�����4��<�<�/�0�0�0�0�0s�;A%D,�,D0	�3D0	c�
�tj��}|�ddd��|�ddd���|���}|�|tj��|�||��|�||��t	j|��}|�|tj��|�||��|�||��dS)NrYrZ�bazr��r-rx)rr�r�r��copy�assertIsInstance�assertIsNotr)r!r�r�s   r'�	test_copyzMorselTests.test_copyas����>�#�#�����U�E�5�)�)�)������
�
�	�	�	��=�=�?�?�����h���7�7�7�����8�,�,�,�����8�,�,�,��9�X�&�&�����h���7�7�7�����8�,�,�,�����8�,�,�,�,�,r)c��tj��}d|d<|�|dd��d|d<|�|dd��d|d<|�|dd��|�tj��5d	|d
<ddd��n#1swxYwY|�d
|��dS)Nrr>r��Versionr-r��DOMAINr�r �invalid)rr�rrsrt�assertNotInr�s  r'�test_setitemzMorselTests.test_setitemrs����!�!����y������	�*�A�.�.�.���y������	�*�A�.�.�.�(��x�������)�=�9�9�9�
�
�
�w�2�
3�
3�	(�	(� '�F�9��	(�	(�	(�	(�	(�	(�	(�	(�	(�	(�	(����	(�	(�	(�	(�����F�+�+�+�+�+s�B(�(B,�/B,c���tj��}|�ddd���|�|�dd��d��|�|dd��|�|�dd��d��|�|d	d��|�|�d
d��d��|�|dd��|�tj��5|�dd��ddd��n#1swxYwY|�d|��dS)
Nr�r�)r�r-r>r rar�rer-r�r�r�)rr�r�r�
setdefaultrsrtr�r�s  r'�test_setdefaultzMorselTests.test_setdefaults�����!�!���
�
�#��
�
�	�	�	�
	
����*�*�9�g�>�>��C�C�C�����	�*�B�/�/�/�����*�*�9�a�8�8�!�<�<�<�����	�*�A�.�.�.�����*�*�8�W�=�=�}�M�M�M������)�=�9�9�9�
�
�
�w�2�
3�
3�	2�	2����i��1�1�1�	2�	2�	2�	2�	2�	2�	2�	2�	2�	2�	2����	2�	2�	2�	2�����F�+�+�+�+�+s�E�E�Ec��dddd�}tj��}|�|��|�|dd��|�|dd��|�|dd��tj��}|�t	|�������|�|dd��|�|dd��|�|dd��tj��}|�d�|���D����|�|dd��|�|dd��|�|dd��|�tj��5|�d	d
i��ddd��n#1swxYwY|�d	|��|�t|j��|�t|jd��dS)Nrer�r�)r>r�r�r>r-r�c3�$K�|]\}}||fV��dS�Nr~)�.0r%r&s   r'�	<genexpr>z*MorselTests.test_update.<locals>.<genexpr>�s*����9�9���A�q�!�f�9�9�9�9�9�9r)r�r r)
rr�r�rr�rrsrtr��	TypeError)r!r�r�s   r'�test_updatezMorselTests.test_update�sY���A��G�G����!�!���
�
�g��������	�*�A�.�.�.�����	�*�A�.�.�.������)�=�9�9�9���!�!���
�
�d�7�=�=�?�?�+�+�,�,�,�����	�*�A�.�.�.�����	�*�A�.�.�.������)�=�9�9�9���!�!���
�
�9�9������9�9�9�9�9�9�����	�*�A�.�.�.�����	�*�A�.�.�.������)�=�9�9�9�
�
�
�w�2�
3�
3�	0�	0��M�M�9�g�.�/�/�/�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0����	0�	0�	0�	0�����F�+�+�+����)�V�]�3�3�3����)�V�]�A�6�6�6�6�6s�G9�9G=�G=c�>�tj��}|�ddd��|�ddd���t	t
jdz��D]�}|�|���5tjtj	||����}|�
|tj��|�||��|�t|��t|����ddd��n#1swxYwY��dS)NrYrZr�r�r�rerf)
rr�r�r�rirjrkrOrlrmr�rry)r!r�rgr�s    r'rqzMorselTests.test_pickle�sK���>�#�#�����U�E�5�)�)�)������
�
�	�	�	��6�2�Q�6�7�7�	?�	?�E����E��*�*�
?�
?�!�<���X�u�(E�(E�F�F���%�%�h���?�?�?�� � ��8�4�4�4�� � ��X����H�
�
�>�>�>�	
?�
?�
?�
?�
?�
?�
?�
?�
?�
?�
?����
?�
?�
?�
?��	?�	?s�7BD�D	�D	c	��tj��}|�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��tj��}|�ddd��d|d<|�t|��d��|�t	|��d��dS)Nz<Morsel: None=None>zSet-Cookie: None=Noner�r9�	coded_valz<Morsel: key=coded_val>zSet-Cookie: key=coded_valr�rYr�rre)r/rxr�rArFr-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=1TrFrGzh<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+)rr�rr
ryr�r��assertRegexr�s  r'�	test_reprzMorselTests.test_repr�s����!�!������f���'<�=�=�=�����V���&=�>�>�>��
�
�5�%��-�-�-�����f���'@�A�A�A�����V���&A�B�B�B��
�
���#����

�
�	�	�	�	
����f���0�	1�	1�	1�	
����V���/�	0�	0�	0� ��x����z������f���B�	C�	C�	C�	
����V���A�	B�	B�	B���!�!���
�
�5�%��-�-�-���y������f���=�	>�	>�	>�	
����V���<�	=�	=�	=�	=�	=r)N)r{r|r}�__doc__r�r�r�r�r�r�r�r�r�rqr�r~r)r'r�r��s�������&�&�+�+�+�
@�
@�
@�H�H�H�>$�$�$�21�21�21�h-�-�-�",�,�,�,�,�,�$7�7�7�6?�?�?�&=�&=�&=�&=�&=r)r�c�^�|�tjt����|Sr�)�addTest�doctest�DocTestSuiter)�loader�tests�patterns   r'�
load_testsr��s$��	�M�M�'�&�w�/�/�0�0�0��Lr)�__main__)r��unittestr��httprrj�TestCaserr�r�r{�mainr~r)r'�<module>r�s���������������������
�
�
�
�]
�]
�]
�]
�]
�(�#�]
�]
�]
�@v=�v=�v=�v=�v=�(�#�v=�v=�v=�r���
�z����H�M�O�O�O�O�O��r)