
    <eYF                       d Z ddlZddlZddlZddlZddlZddlmZ ddlmZ ddl	Z	ddl
Z
ddlZddlZddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z% ej&        dk    Z' G d de
j(                  Z) G d	 d
e
j(                  Z* G d d          Z+d Z,d Z-d Z. G d de
j(                  Z/ G d de
j(                  Z0 G d de
j(                  Z1e2dk    r e
j3                     dS dS )zTests for http/cookiejar.py.    N)	os_helper)warnings_helper)	time2isoz	http2timeiso2timetime2netscapeparse_ns_headersjoin_header_wordssplit_header_wordsCookie	CookieJarDefaultCookiePolicyLWPCookieJarMozillaCookieJar	LoadErrorlwp_cookie_strDEFAULT_HTTP_PORTescape_pathreachis_HDNdomain_matchuser_domain_matchrequest_pathrequest_portrequest_hostwin32c                   J    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 ZdS )DateTimeTestsc           	         d}d}|                      t          |          d           |                      t          ||z             d           |                      t          |d|z  z             d           |                      t          |d|z  z             d           t                      }t          d	          }||fD ]}|                     |d
d|d|            d S )Nx+<Q z2002-04-19 14:36:40Zz2002-04-20 14:36:40Z   z2002-04-21 14:36:40Z   z2002-04-22 14:36:40Z  z!^\d{4}-\d\d-\d\d \d\d:\d\d:\d\dZ$zbad time2isoz format:  )assertEqualr   assertRegexselfbasedayazbztexts         //usr/lib/python3.11/test/test_http_cookiejar.pytest_time2isozzDateTimeTests.test_time2isoz   s   4*@AAA48,,.DEEE4#:..0FGGG4#:..0FGGG[[vH 	G 	GDT#G#G>@bb""EG G G G	G 	G    c           	         d}d}|                      t          |          d           |                      t          ||z             d           |                      t          |d|z  z             d           |                      t          |d|z  z             d           t                      }t          d	          }||fD ]}|                     |d
d|d|            d S )Nr    r!   zFri, 19-Apr-2002 14:36:40 GMTzSat, 20-Apr-2002 14:36:40 GMTr"   zSun, 21-Apr-2002 14:36:40 GMTr#   zMon, 22-Apr-2002 14:36:40 GMTr$   z;[a-zA-Z]{3}, \d{2}-[a-zA-Z]{3}-\d{4} \d{2}:\d{2}:\d{2} GMT$zbad time2netscape format: r%   )r&   r   r'   r(   s         r/   test_time2netscapez DateTimeTests.test_time2netscape(   s   t,,.MNNNtCx008	: 	: 	: 	tAcEz228	: 	: 	: 	tAcEz228	: 	: 	: __6""H 	> 	>DNN57RR<> > > >	> 	>r1   c                     d }|                       |d          d           |                       |d          d           |                       |d          d           d S )Nc                 T    t          j        t          |                     d d         S N   )timegmtimer   r.   s    r/   
parse_datez0DateTimeTests.test_http2time.<locals>.parse_date?   s!    ;y//33r1   z01 Jan 2001)i     r<   r   r           z	03-Feb-20)i  r"   r#   r   r   r=   z	03-Feb-98)i  r"   r#   r   r   r=   r&   r)   r;   s     r/   test_http2timezDateTimeTests.test_http2time>   s    	4 	4 	4 	M224KLLL 	K002IJJJ 	K002IJJJJJr1   c           
         g d}d}t          |          }d}|                     |||d|d|d           |D ]}|                     t          |          ||           |                     t          |                                          ||                                           |                     t          |                                          ||                                           d S )N)zThu, 03 Feb 1994 00:00:00 GMT Thursday, 03-Feb-94 00:00:00 GMTz"Thursday, 03-Feb-1994 00:00:00 GMTz03 Feb 1994 00:00:00 GMTz03-Feb-94 00:00:00 GMTz03-Feb-1994 00:00:00 GMTz03-Feb-1994 00:00 GMTz03-Feb-1994 00:00z02-Feb-1994 24:00z	03-Feb-94z03-Feb-1994z03 Feb 1994z  03   Feb   1994  0:00  z  03-Feb-1994  >P-z1994-02-03 00:00:00Zz  =>  'z' ())r   r&   r   lowerupper)r)   teststest_tresultexpectedss         r/   test_http2time_formatsz$DateTimeTests.test_http2time_formatsJ   s   
 
 
, 6"")06I	K 	K 	K  	F 	FAYq\\61555Yqwwyy11617799EEEYqwwyy11617799EEEE	F 	Fr1   c           
      |    dD ]8}|                      t          |          d|dt          |                     9d S )N) GarbagezMandag 16. September 1996z
01-00-1980z
01-13-1980z
00-01-1980z
32-01-1980z01-01-1980 25:00:00z01-01-1980 00:61:0001-01-1980 00:00:62z08-Oct-3697739z08-01-3697739z09 Feb 19942632 22:23:32 GMTz Wed, 09 Feb 1994834 22:23:32 GMTz
http2time(z) is not None
http2time(test) )assertIsNoner   r)   tests     r/   test_http2time_garbagez$DateTimeTests.test_http2time_garbagen   se     	N 	ND  iooo6:ddIdOOOMN N N N!	N 	Nr1   c                     t          d                    ddz                       t          d                    ddz                       d S )Nz01 Jan 1970{}00:00:00 GMT!r%   i z01 Jan 1970 00:00:00{}GMT!)r   formatr)   s    r/   2test_http2time_redos_regression_actually_completesz@DateTimeTests.test_http2time_redos_regression_actually_completes   sL     	.55cGmDDEEE.55cGmDDEEEEEr1   c                     d }|                       |d          d           |                       |d          d           |                       |d          d           d S )Nc                 T    t          j        t          |                     d d         S r6   )r8   r9   r   r:   s    r/   r;   z/DateTimeTests.test_iso2time.<locals>.parse_date   s!    ;x~~..rr22r1   19940203T141529Z)i  r"   r#            z1994-02-03 07:15:29 -0700z1994-02-03 19:45:29 +0530r>   r?   s     r/   test_iso2timezDateTimeTests.test_iso2time   s    	3 	3 	3 	$6771	3 	3 	3 	$?@@1	3 	3 	3 	$?@@1	3 	3 	3 	3 	3r1   c                    g d}d}|D ]}|                      t          |          ||           |                      t          |                                          ||                                           |                      t          |                                          ||                                           d S )N)
z1994-02-03 00:00:00 -0000z1994-02-03 00:00:00 +0000z1994-02-03 00:00:00z
1994-02-03z1994-02-03T00:00:0019940203z1994-02-02 24:00:0019940203T000000Zz  1994-02-03 z  1994-02-03T00:00:00  rC   )r&   r   rE   rF   )r)   rG   rH   rK   s       r/   test_iso2time_formatsz#DateTimeTests.test_iso2time_formats   s    
 
 
  	E 	EAXa[[&!444Xaggii00&!''))DDDXaggii00&!''))DDDD	E 	Er1   c                 \    dD ](}|                      t          |          d|z             )d S )N)rN   rO   rB   z
1980-00-01z
1980-13-01z
1980-01-00z
1980-01-32z1980-01-01 25:00:00z1980-01-01 00:61:00rP   z01-01-1980T00:00:6219800101T250000Zziso2time(%r))rQ   r   rR   s     r/   test_iso2time_garbagez#DateTimeTests.test_iso2time_garbage   sL     	5 	5D htnn,t35 5 5 5	5 	5r1   c                     t          d                    ddz                       t          d                    ddz                       d S )Nz1994-02-03{}14:15:29 -0100!r%   i@B z1994-02-03 14:15:29{}-0100!)r   rV   rW   s    r/   $test_iso2time_performance_regressionz2DateTimeTests.test_iso2time_performance_regression   sL     	.55c%i@@AAA.55c%i@@AAAAAr1   N)__name__
__module____qualname__r0   r3   r@   rL   rT   rX   r_   rc   rf   rh    r1   r/   r   r      s        G G G> > >,
K 
K 
K"F "F "FHN N N*F F F3 3 3 E E E.5 5 5$B B B B Br1   r   c                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )HeaderTestsc                 b    g dg}dD ]&}|                      t          |g          |           'd S )N)foobar)expiresl   d9W version0)z)foo=bar; expires=01 Jan 2040 22:23:32 GMTz+foo=bar; expires="01 Jan 2040 22:23:32 GMT"r&   r	   r)   rJ   hdrs      r/   test_parse_ns_headersz!HeaderTests.test_parse_ns_headers   sU    OOOP 	@ 	@C -se44h????		@ 	@r1   c                 b    ddgg}dD ]&}|                      t          |g          |           'd S )Nrp   )ru   1)zfoo=bar; version="1"foo=bar; Version="1"rw   rx   s      r/   test_parse_ns_headers_versionz)HeaderTests.test_parse_ns_headers_version   sW     $%567 	@ 	@C -se44h????		@ 	@r1   c                 \    d}ddgg}|                      t          |g          |           d S )Nz expires=01 Jan 2040 22:23:32 GMT)rs   z01 Jan 2040 22:23:32 GMTrt   rw   )r)   ry   rJ   s      r/   #test_parse_ns_headers_special_namesz/HeaderTests.test_parse_ns_headers_special_names   s>     1<>NOP)3%00(;;;;;r1   c                     t          ddgg          }|                     |d           |                     t          g g          d           d S )Nrq   Nrr   bazzfoo; bar=bazrN   )r
   r&   )r)   joineds     r/   test_join_header_wordsz"HeaderTests.test_join_header_words   sT    "]N$C#DEE000*B400"55555r1   c                    ddggfddggfddggfddggfddggfd	dggfd
ddggfdddggfddggfdddggfdg dgfddgdgdggfdddgdgdgdggfg}|D ]\  }}	 t          |g          }nP#  dd l}dd l}|                                }|                    d |           d|                                z  }Y nxY w|                     ||d|d|d|d           d S ) Nrq   r   foo=barrp   	   foo   z
   foo=   )rq   rN   z   foo=z   foo=   ; z   foo=   ; bar= baz r   foo=bar bar=bazzfoo= bar=baz)rq   zbar=bazfoo=bar;bar=bazfoo bar baz)r   )rr   N)r   Nza, b, c)aN)bN)cNz(foo; bar=baz, spam=, foo="\,\;\"", bar= )spamrN   )rq   z,;")rr   rN   r   z (error -- traceback follows)

%s
When parsing: ''
Expected:     ''
Got:          ''
)r   	tracebackioStringIO	print_excgetvaluer&   )r)   rG   argexpectrI   r   r   fs           r/   test_split_header_wordsz#HeaderTests.test_split_header_words   s   m_%&.)*+M?+,[M?++({m_-$^'D&EF..!A BC1234..!A BCJJJKL+}EF8n-n~.?@& ! 	 	KCM+SE22M$$$$$$$$KKMM##D!,,,=

LVff ssFFFFFF	/    	 	s   A,,AB9c                     g d}|D ]H\  }}t          |g          }t          |          }|                     ||d|d|d|d|d	           Id S )N))rq   rq   )r   r   )r   rq   )zfoo=zfoo="")r   foo=bar; bar=baz)r   r   )r   zfoo; bar; baz)zfoo="\"" bar="\\"zfoo="\""; bar="\\")z	foo,,,barzfoo, bar)zfoo=bar,bar=bazzfoo=bar, bar=baz)ztext/html; charset=iso-8859-1ztext/html; charset="iso-8859-1")z)foo="bar"; port="80,81"; discard, bar=bazz'foo=bar; port="80,81"; discard, bar=baz)zBasic realm="\"foo\\\\bar\""zBasic; realm="\"foo\\\\bar\""r   r   r   z'
Input was:    'r   )r   r
   r&   )r)   rG   r   r   inputress         r/   test_roundtripzHeaderTests.test_roundtrip  s      , ! 	! 	!KC&u--E#E**CS&&
 ssFFFCCC+  ! ! ! !	! 	!r1   N)	ri   rj   rk   rz   r~   r   r   r   r   rl   r1   r/   rn   rn      su        @ @ @@ @ @< < <6 6 6     D! ! ! ! !r1   rn   c                        e Zd Zg dfdZd ZdS )FakeResponseNc                 v    ddl }|                    d                    |                    | _        || _        dS )zD
        headers: list of RFC822-style 'Key: value' strings
        r   N
)emailmessage_from_stringjoin_headers_url)r)   headersurlr   s       r/   __init__zFakeResponse.__init__2  s9     	11$))G2D2DEE			r1   c                     | j         S N)r   rW   s    r/   infozFakeResponse.info9  s	    4=(r1   )ri   rj   rk   r   r   rl   r1   r/   r   r   1  s4        !t     )((((r1   r   c                 &    t          | ||d          S )NzSet-Cookie2	_interact	cookiejarr   set_cookie_hdrss      r/   interact_2965r   ;  s    Y_mDDDr1   c                 &    t          | ||d          S )Nz
Set-Cookier   r   s      r/   interact_netscaper   >  s    Y_lCCCr1   c                 (   t           j                            |          }|                     |           |                    dd          }g }|D ]}|                    |d|           t          ||          }|                     ||           |S )zDPerform a single request / response cycle, returning Cookie: header.r   rN   z: )urllibrequestRequestadd_cookie_header
get_headerappendr   extract_cookies)	r   r   r   hdr_namereq
cookie_hdrr   ry   r   s	            r/   r   r   A  s    
.
 
 
%
%C$$$"--JG 3 3888SS12222
w
$
$Cc3'''r1   c                      e Zd Zd Zd Zd Zd Zd Z ej	        e
d          ej        d                         Z ej	        e
d          ej        d                         Z ej	        e
d          ej        d	                         Zd
 ZdS )FileCookieJarTestsc                 r    t           j        }t          |          }|                     |j        |           d S r   )r   TESTFNr   r&   filenamer)   r   r   s      r/   test_constructor_with_strz,FileCookieJarTests.test_constructor_with_strO  s5    #""X.....r1   c                     t          j        t          j                  }t	          |          }|                     |j        t          j        |                     d S r   )	pathlibPathr   r   r   r&   r   osfspathr   s      r/   test_constructor_with_path_likez2FileCookieJarTests.test_constructor_with_path_likeT  sI    <	 011""RYx%8%899999r1   c                 X    t          d           }|                     |j                   d S r   )r   rQ   r   r)   r   s     r/   test_constructor_with_nonez-FileCookieJarTests.test_constructor_with_noneY  s+    !*%%%%%r1   c                 8    G d d          }t           t          |fD ]|}|                     |          5  |                     t                    5   |            }t          |          }d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   }d S )Nc                       e Zd ZdS )?FileCookieJarTests.test_constructor_with_other_types.<locals>.AN)ri   rj   rk   rl   r1   r/   Ar   ^  s        Dr1   r   r   )intfloatsubTestassertRaises	TypeErrorr   )r)   r   type_instancer   s        r/   !test_constructor_with_other_typesz4FileCookieJarTests.test_constructor_with_other_types]  s9   	 	 	 	 	 	 	 	 5!_ 	8 	8Eu-- 8 8&&y11 8 8$uwwH$h777A8 8 8 8 8 8 8 8 8 8 8 8 8 8 88 8 8 8 8 8 8 8 8 8 8 8 8 8 8	8 	8s5   BA7+B7A;;B>A;?BB	B	c                    t           j        }t                      }t          |dd           |                     |j        d         d         d         j        d            	 |                    |d           t                      }|                    |d           t          j	        |           n# t          j	        |           w xY w|                     |j        d         d         d         j        d            d S )Nhttp://www.acme.com/boowww.acme.com/Tignore_discard)
r   r   r   r   r&   _cookiesvaluesaveloadunlinkr   s      r/   test_lwp_valueless_cookiez,FileCookieJarTests.test_lwp_valueless_cookieg  s    #NN!3U;;;N3C8?EtLLL	'FF8DF111AFF8DF111X&&&&IX&&&&N3C8?EtLLLLLs   <B0 0Cz9windows file permissions are incompatible with file modesc                 h   t           j        }t                      }t          |dd           	 |                    |d           t          j        |          }|                     t          j        |j	                  d           t          j
        |           d S # t          j
        |           w xY wNr   r   Tr   i  )r   r   r   r   r   r   statr&   S_IMODEst_moder   r)   r   r   sts       r/   test_lwp_filepermissionsz+FileCookieJarTests.test_lwp_filepermissionsu  s     #NN!3U;;;	'FF8DF111""BT\"*55u===X&&&&&IX&&&&   AB B1c                 h   t           j        }t                      }t          |dd           	 |                    |d           t          j        |          }|                     t          j        |j	                  d           t          j
        |           d S # t          j
        |           w xY wr   )r   r   r   r   r   r   r   r&   r   r   r   r   s       r/   test_mozilla_filepermissionsz/FileCookieJarTests.test_mozilla_filepermissions  s     #!3U;;;	'FF8DF111""BT\"*55u===X&&&&&IX&&&&r   c                 t   t           j        }t          t          fD ]} ||          }t          j                            d          }dg}t          |d          }|                    ||           | 	                    t          |          d           	 |                                 |                                 |                                 |                                 t          j        |           n# t          j        |           w xY w| 	                    t          |          d           d S )Nr   z1Set-Cookie: pll_lang=en; Max-Age=31536000; path=/r<   r   )r   r   r   r   r   r   r   r   r   r&   lenr   clearr   r   )r)   r   cookiejar_classr   r   r   r   s          r/   test_cookie_files_are_truncatedz2FileCookieJarTests.test_cookie_files_are_truncated  s    # ,.>? 	( 	(O))A.(()?@@CJKGw(>??Cc3'''SVVQ'''	+			 ****	 ****SVVQ'''')	( 	(s   AC::Dc                 j   t           j        }t          t          fD ]o} |            }	 |                    d           |                     d           9# t          $ r*}|                     |j        t                     Y d }~hd }~ww xY w	 t          |d          5 }|                    d           t          t          fD ]-} |            }|                     t          |j        |           .	 d d d            n# 1 swxY w Y   t          j        |           d S # t          j        |           w xY w)NzAfor this test to work, a file with this filename should not existr   z%expected OSError for invalid filenamewzoops
)r   r   r   r   r   failOSErrorassertIsNot	__class__r   openwriter   r   )r)   r   r   r   excr   s         r/   test_bad_magicz!FileCookieJarTests.test_bad_magic  s   #+-== 
	C 
	CO!!AC !< = = = 		ABBBB  ; ; ;   	::::::::;	'h$$ C!!!'35E'E C CO'))A%%iBBBBCC C C C C C C C C C C C C C C X&&&&&IX&&&&sH   A
B BBD AC;/D ;C??D C?D D2N)ri   rj   rk   r   r   r   r   r   unittestskipIf	mswindowsr   skip_unless_working_chmodr   r   r   r	  rl   r1   r/   r   r   N  s       / / /
: : :
& & &8 8 8M M M X_Y [\\(
' 
' )( ]\
' X_Y [\\(
' 
' )( ]\
' X_Y [\\(( ( )( ]\(0' ' ' ' 'r1   r   c                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&d% Z'd& Z(d' Z)d( Z*d)S )*CookieTestsc                     t                      }dD ]h\  }}}t          j                            |          }|                    ||          }|r|                     |           S|                     |           id S )N))http://foo.bar.com/zblah.comF)r  zrhubarb.blah.comF)r  zrhubarb.foo.bar.comF)r  .foo.bar.comT)r  foo.bar.comT)r  z.bar.comT)r  bar.comT)r  comT)http://foo.com/zrhubarb.foo.comF)r  .foo.comT)r  foo.comT)r  r  T)http://foo/zrhubarb.fooF)r  z.fooT)r  rq   T)r  z	foo.localT)r  .localT)http://barfoo.comr  F)r  r  F)r   r   r   r   domain_return_ok
assertTrueassertFalse)r)   polr   domainokr   rs          r/   test_domain_return_okz!CookieTests.test_domain_return_ok  s     "##  	& 	&OC* n,,S11G$$VW55A &4??1%%%%""1%%%%1	& 	&r1   c                    t           j        }t          |          }t          |dd           t          |dd           |j        d         d         d         }|                     |j                   |                     |j        d           |j        d         d         d         }|                     |j                   |                     |j        d           |                     t          |          d           t          |          }|                    d	d	
           	 t          |          }|                    d	d	
           t          j        |j                   n# t          j        |j                   w xY w|                     t          |          t          j        dd	z  ddz  |                     |                     t          |d          d           d S )Nr   eggsz"spam"; path=/foo/r   r   /foo/z"spam"zJ"spam"; path="/foo/"; domain="www.acme.com"; path_spec; discard; version=0T)ignore_expiresr   zpath_specified=%sFhttp://www.acme.com/foo/z"spam"; eggs)r   r   r   r   r   rQ   r   r&   namer   reprr   revertr   r   resub)r)   r   r   cookieold_strs        r/   test_missing_valuezCookieTests.test_missing_value  s    #X&&!3V<<<!35IJJJN+C08&,'''f---N+G4X>&,'''h/////,	. 	. 	. q''	d4888	) **AHHDH>>>QZ((((IQZ((((GGF&-/BU/J 	 	 	
 	*1.HII'	) 	) 	) 	) 	)s   $&E$ $E?c                    dD ]\  }}}t          ||          }t          |          }t          |dd           	 |j        d         d         d         }|                     |j        |           t          |dd           |r4|j        d         d         d	         }|                     |j        d
           # t          $ r |                     |           Y w xY wd S )N))NFr   )NTr<   )FFN)FTr<   )TFr   )TTr   )rfc2109_as_netscaperfc2965http://www.example.com/zni=ni; Version=1www.example.comr   nifoo=bar; Version=1rq   r<   )	r   r   r   r   r&   ru   r   KeyErrorrQ   )r)   r2  r3  ru   policyr   r.  
cookie2965s           r/   test_rfc2109_handlingz!CookieTests.test_rfc2109_handling4  s$   	6 	< 	<1' )$7! ! !F &!!Aa!:<NOOO<$56s;DA   999a!:24 4 4 <!",=!>s!CE!JJ$$Z%7;;;  + + +!!'*****+#	< 	<s   B77CCc                 P   t                      }t          |dd           t          |dd           t          |dd           t          |dd           t          |dd           t          |dd           t          |dd	           t          |dd
           |j        d         d         d         }|                     |j        d           |                     |j                   |                     |j        t                     | 	                    |j
                   |                     |                    d                     | 	                    |                    d                     |j        d         d         d         }|                     |j        d           | 	                    |j                   |                     |j        d           |                     |j
                   |j        d         d         d         }|                     |j                   | 	                    |j
                   |j        d         d         d         }|j        d         d         d         }|                     |j                   |                     |j                   |j        d         d         d         }|                     |j                   |                     |j        d           |j        d         d         d
         }|                     |j                   d S )Nr   z0spam=eggs; DoMain=.acme.com; port; blArgh="feep"zni=ni; port=80,8080http://www.acme.com:80/znini=nizfoo=bar; expires=z-spam=eggs; expires="Foo Bar 25 33:22:11 3022"z	fortytwo=z=unladenswallowholyhandgrenade	.acme.comr   r   blArghblarghr   r6  z80,8080ninirq   fortytworN   )r   r   r   r&   r   r  domain_specifiedportr   r  port_specifiedhas_nonstandard_attrrQ   rs   assertIsNotNoner   )r)   r   r.  rq   r   s        r/   test_ns_parserzCookieTests.test_ns_parserS  s   KK!3L	N 	N 	N!35JKKK!6	BBB!68KLLL!6 9? 	@ 	@ 	@!3[AAA!35FGGG!35FGGGK(-f5444/000&7888.///33H==>>>44X>>???N+C067770111i000-...N+C08&+&&&./// j(-e4z.)#.u5#+&&&$,'''N+C0<V\***r***
 N+C01BC&,'''''r1   c                     t                      }t          |dd           t          |dd           |j        d         d         }|                     d|           |                     d|           d S )Nr   zexpires=eggszversion=eggs; spam=eggsr   r   rs   ru   )r   r   r   assertIn)r)   r   cookiess      r/   test_ns_parser_special_namesz(CookieTests.test_ns_parser_special_names  ss     KK!3^DDD!35NOOO*^,S1i)))i)))))r1   c                 R   t                      }t          t          j                    dz             }t          j        |           5  d| g}t
          j                            d          }t          |d          }|	                    ||          }| 
                    t          |          d           | 
                    t          |d         j                  |           d d d            n# 1 swxY w Y   t          |dd|z             | 
                    t          |          d           t          t          j                    dz
            }t          |dd|z             t          |d          }| 
                    t          |          d           |                     d	|           |                     d
|           t          |dd|z             t          |dd|z             | 
                    t          |          d           t          |dd|z             t          |dd|z             t          |d          }| 
                    t          |          d           t          |dd           | 
                    t          |          d           |                                 | 
                    t          |          d           |                     d	|           t#          dddd dddddddddd d i           }	| 
                    |	j        d           d S )N  z%Set-Cookie: FOO=BAR; path=/; expires=http://www.coyote.com/r<   r   r   zspam="bar"; expires=%szfoo="eggs"; expires=%s
spam="bar"rq   zeggs="bar"; expires=%szbar="bar"; expires=%sr#   z!eggs="bar"; expires=%s; max-age=0z bar="bar"; max-age=0; expires=%szhttp://www.rhubarb.net/zwhum="fizz"r"   r)  r   Fzwww.python.orgTr   z1444312383.018307i?uV)r   r   r8   r   check_no_warningsr   r   r   r   make_cookiesr&   r   rs   r   rK  assertNotInclear_session_cookiesr   )
r)   r   futurer   r   r   rL  nowhr.  s
             r/   test_expireszCookieTests.test_expires  s   KKty{{4/00.t44 	H 	HGvGGHG.(()ABBCw(@AACnnS#..GS\\1---]71:+=>>GGG	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	!35M 6! 	" 	" 	"Q###DIKKM**!35M6 	 	 	a!788Q###lA&&&""" 	!35M 6! 	" 	" 	"!35L 6! 	" 	" 	"Q###!3 624:6; 	< 	< 	<!3 624:6; 	< 	< 	<a!788Q### 	!6FFFQ###	!!!Q###lA&&& FGu&6uc':d  	44444s   BC//C36C3c                 .   t          d          }t          |          }t          |dd           |                     d|j        d                    t          |          }t          |dd           |                     d|j        d                    t          |          }t          |d	d           |                     d
|j        d                    t          |          }t          |dd           |                     d|j        d                    t                      }t          |dd           |                     d|j        d                    t                      }t          |dd           |                     d|j        d                    t                      }t          |d	d           |                     d|j        d                    t                      }t          |dd           |                     d|j        d                    d S )NTr3  r   zspam="bar"; Version="1"r   r   zhttp://www.acme.com/blahzeggs="bar"; Version="1"z http://www.acme.com/blah/rhubarb/blah/z!http://www.acme.com/blah/rhubarb/z/blah/rhubarb/rQ  
eggs="bar"/blahz/blah/rhubarb)r   r   r   rK  r   r   r)   r  r   s      r/   test_default_pathzCookieTests.test_default_path  s   !$///cNNa/1JKKKc1:n5666cNNa35NOOOc1:n5666cNNa;/	1 	1 	1h
> :;;;cNNa</	1 	1 	1&
>(BCCC KK!3\BBBc1:n5666KK!7FFFc1:n5666KK!?NNNgqz.9:::KK!@,OOOoqz.'ABBBBBr1   c                     t                      }d}d}t          |||           |                     d|j        d                    |                     t          ||          |           d S )Nzhttp://example.com/?spam/eggsr]  r   zexample.com)r   r   rK  r   r&   )r)   cjurir   s       r/   test_default_path_with_queryz(CookieTests.test_default_path_with_query  si    [[-"c5)))c2;}5666*2s33U;;;;;r1   c                 d    g d}|D ](\  }}|                      t          |          |           )d S )N))z/foo%2f/bar/foo%2F/bar)rf  rf  )
/foo%%/barrg  )/fo%19o/barrh  )z/fo%7do/barz/fo%7Do/bar)	/foo/bar&ri  )	/foo//barrj  )	~/foo/barrk  )z	/foo/barz/foo%19/bar)z	/}foo/barz/%7Dfoo/bar)u
   /foo/barüz/foo/bar%C3%BC)u   /foo/barꯍz/foo/bar%EA%AF%8D)r&   r   )r)   casesr   rI   s       r/   test_escape_pathzCookieTests.test_escape_path  sS      * ! 	7 	7KC[--v6666	7 	7r1   c                    t           j                            d          }|                     t	          |          d           t           j                            d          }|                     t	          |          d           t           j                            d          }|                     t	          |          d           d S )NzThttp://www.example.com/rheum/rhaponticum;foo=bar;sing=song?apples=pears&spam=eggs#niz$/rheum/rhaponticum;foo=bar;sing=songzBhttp://www.example.com/rheum/rhaponticum?apples=pears&spam=eggs#niz/rheum/rhaponticumzhttp://www.example.comr   )r   r   r   r&   r   r)   r   s     r/   test_request_pathzCookieTests.test_request_path  s    n$$:; ; 	c**?	A 	A 	A n$$() ) 	c**,@AAAn$$%=>>c**C00000r1   c                 D   t                      }t          d          }t          |          }d}t          ||d           |j        d         d         d         }dD ]\  }}| | }t          j                            |          }	t          ||          }
|rD|                     d	|
d
|            |                     |	                    ||	                     | 
                    d	|
d|            |                     |	                    ||	                     d S )NT)strict_ns_set_pathzhttp://bar.comzspam=eggs; Path=/foor  /foor   ))rs  T)r&  T)/foo/barT)r   F)z/foobad/fooFz	spam=eggszcookie not set for zcookie set for )r   r   r   r   r   r   r   rK  r  set_ok_pathrT  r  )r)   r  strict_ns_path_polr   base_urlr.  pathr!  r   r   rX  s              r/   test_path_prefix_matchz"CookieTests.test_path_prefix_match"  sG   !##0DIIIcNN#!X'=>>>I&v.v61 	N 	NHD"
 %t%%C.((--C!!S))A Nk1.JD.J.JKKK 2 > >vs K KLLLL  a1I41I1IJJJ  !3!?!?!L!LMMMM	N 	Nr1   c                 (   t           j                            dddi          }|                     t	          |          d           t           j                            dddi          }|                     t	          |          t
                     d S )Nzhttp://www.acme.com:1234/Hostzwww.acme.com:4321r   1234r   )r   r   r   r&   r   r   ro  s     r/   test_request_portzCookieTests.test_request_port:  s    n$$%@.46I-J % L Lc**F333n$$%;.46I-J % L Lc**,=>>>>>r1   c                    t           j                            dddi          }|                     t	          |          d           t           j                            dddi          }|                     t	          |          d           t           j                            d	dd
i          }|                     t	          |          d           d S )Nzhttp://1.1.1.1/r{  www.acme.com:80r|  z1.1.1.1r   zirrelevant.comr   z&http://www.acme.com:2345/resource.htmlzwww.acme.com:5432)r   r   r   r&   r   ro  s     r/   test_request_hostzCookieTests.test_request_hostB  s    n$$%6.46G-H % J J
 	c**I666n$$%;.46F-G % I Ic**N;;;n$$%M.46I-J % L Lc**N;;;;;r1   c                 &   |                      t          d                     |                      t          d                     |                     t          d                     |                     t          d                     |                     t          d                     |                     t          d                     |                     t          d                     |                     t          d                     d S )	Nr  z1foo2.3bar4.5com192.168.1.1rN   .r  z..foozfoo.)r  r   r  rW   s    r/   test_is_HDNzCookieTests.test_is_HDNR  s    }--...122333..///$$$%%%//000)))(((((r1   c                 6   |                      t          d          d           |                      t          d          d           |                      t          d          d           |                      t          d          d           |                      t          d          d           |                      t          d          d           |                      t          d          d           |                      t          d	          d	           d S )
Nr   r?  acme.comz
acme.localr  .comr  rN   z192.168.0.1)r&   r   rW   s    r/   
test_reachzCookieTests.test_reach\  s    ~..<<<z**J777|,,h777x(333v///sS)))rB'''}--}=====r1   c                    |                      t          dd                     |                     t          dd                     |                      t          dd                     |                      t          dd                     |                     t          dd                     |                      t          dd                     |                     t          dd                     |                      t          d	d
                     |                     t          dd                     |                     t          dd                     |                      t          dd                     |                      t          dd                     |                     t          dd                     |                      t          dd                     |                      t          dd                     |                      t          dd                     |                      t          dd                     |                     t          dd                     |                      t          dd                     |                     t          dd                     |                      t          dd                     |                      t          dd                     |                     t          dd                     |                     t          dd                     |                     t          dd                     |                     t          dd                     |                     t          dd                     |                      t          dd                     |                     t          dd                     |                     t          dd                     |                     t          dd                     d S )Nr  z.168.1.1zx.y.comzx.Y.comz.Y.comzY.comz	a.b.c.comz.c.comzexample.localr  z	blah.blahrN   z.rhubarb.rhubarbr  r?  zrhubarb.acme.comzwww.rhubarb.acme.comzy.comz.y.comr  r  mz.mr  )r  r   r  r   rW   s    r/   test_domain_matchzCookieTests.test_domain_matchf  s   ]MBBCCCmZ@@AAAY	::;;;Y99:::i99:::[(;;<<<h<<===_h??@@@k266777b*<==>>>R,,---)*jAABBB*:{CCDDD)*<kJJKKK)*@+NNOOO))Y??@@@))X>>???*9g>>???)'7;;<<<*8W==>>>)(H==>>>))V<<===*9e<<===*9c::;;;*9d;;<<<*9b99:::*9c::;;;)-GGHHH*=*EEFFF*=#>>???*="==>>>>>r1   c                     t                      }t          |dd           |                     t          |          d           d S )Nzhttp://www.nasty.com/z)foo=bar; domain=friendly.org; Version="1"r   )r   r   r&   r   r   s     r/   test_wrong_domainzCookieTests.test_wrong_domain  sL    
 KKa0A	C 	C 	CQ#####r1   c                 H   t          d          }t          |          }t          |dd           t          |dd           |                     t	          |          d           dD ]9}t          |d	|z  d
           |                     t	          |          d           :d S )NT)strict_domainr9  zhttp://example.co.uk/zno=problemoz!okey=dokey; Domain=.example.co.ukr"   )z.co.ukz.org.zaz.tx.usz.name.uszhttp://example.%s/zspam=eggs; Domain=.co.uk)r   r   r   r&   r   )r)   cprb  
pseudo_tlds       r/   test_strict_domainzCookieTests.test_strict_domain  s     !t444b!!!"5}EEE"5=	? 	? 	?R!$$$E 	) 	)Jb"6"C8: : :SWWa((((	) 	)r1   c                    t                      }t          |dd           |                     t          |          d           |                     |j        d         d         d         j        d           |                     t          |d          d           |                     t          |d          d           t          t          j        	          }|                    |           |                     t          |d          d
           t          |dd           t          |dd           |                     t          |          d           |                     |j        d         d         d         j        d           |                     |j        d         d         d         j        d           |                     t          |d          d           t          |dd           |                     t          |          d           t          |dd           |                     t          |          d           d S )Nhttp://foo.net/zns=barr<   foo.netr   nsrr   http://www.foo.net/)strict_ns_domainrN   http://foo.net/foo/zspam1=eggs; domain=foo.netzhttp://foo.net/foo/bar/zspam2=eggs; domain=.foo.netr#   .foo.netrs  spam1r%  rt  spam2zspam2=eggs; spam1=eggs; ns=barznini="ni"; domain=.netzhttp://foo.co.ukznasty=trick; domain=.co.uk   )	r   r   r&   r   r   r   r   DomainStrictNonDomain
set_policy)r)   r   r  s      r/   test_two_component_domain_nsz(CookieTests.test_two_component_domain_ns  sO    KK 	!.999Q###I.s3D9?GGG*1.?@@(KKK*1.CDD!	# 	# 	# "0FH H H	S*1.CDDbIII 	!26	8 	8 	8 	!67	9 	9 	9Q###J/7@F	! 	! 	!J/
;GDJ	! 	! 	!*1.GHH9	; 	; 	; 	!.0HIIIQ### 	!/1MNNNQ#####r1   c                     t                      }t          |dd           |                     t          |          d           d S )Nhttp://localhostfoo=bar; domain=localhost;r<   r   r   r&   r   r   s     r/   test_localhost_domainz!CookieTests.test_localhost_domain  sA    KK!/1MNNNQ#####r1   c                     t                      }t          |dd           |                     |j        d         d         d         j        d           d S )Nr  r  z
.localhostr   rq   rr   r   r   r&   r   r   r   s     r/   test_localhost_domain_contentsz*CookieTests.test_localhost_domain_contents  sO    KK!/1MNNNL1#6u=CUKKKKKr1   c                     t                      }t          |dd           |                     |j        d         d         d         j        d           d S )Nr  zfoo=bar;zlocalhost.localr   rq   rr   r  r   s     r/    test_localhost_domain_contents_2z,CookieTests.test_localhost_domain_contents_2  sO    KK!/<<<$56s;EBH%PPPPPr1   c                     t                      }t          |dd           |                     t          |          d           d S )Nzhttp://evil.comzfoo=bar; domain=.localhostr   r  r   s     r/   test_evil_nonlocal_domainz%CookieTests.test_evil_nonlocal_domain  sA    KK!.0LMMMQ#####r1   c                     t                      }t          |dd           |                     t          |          d           d S )Nr  zfoo=bar; domain=.evil.comr   r  r   s     r/   test_evil_local_domainz"CookieTests.test_evil_local_domain  sA    KK!/1LMMMQ#####r1   c                     t                      }t          |dd           |                     t          |          d           d S )Nr  z foo=bar; domain=.someother.localr   r  r   s     r/   test_evil_local_domain_2z$CookieTests.test_evil_local_domain_2  sA    KK!/1STTTQ#####r1   c                 |   t          d          }t          |          }t          |dd           |                     t	          |          d           |                     |j        d         d         d         j        d	           |                     t          |d          d
           |                     t          |d          d           t          |dd           |                     t	          |          d           |                     t          |d          d
           t          |dd           |                     |j        d         d         d         j        d           |                     t	          |          d           |                     t          |d          d
           |                     t          |d          d           t          |dd           |                     t	          |          d           t          |dd           |                     t	          |          d           d S )NTr[  r  r}   r<   r  r   rq   rr   z$Version=1; foo=barr  rN   zhttp://foo.net/fooz1spam=eggs; domain=foo.net; path=/foo; Version="1"zhttp://www.foo.net/foo/z&spam=eggs; domain=foo.net; Version="1"r  r&  r   r%  r"   r  z($Version=1; spam=eggs; $Domain="foo.net"z#ni="ni"; domain=".net"; Version="1"zhttp://foo.co.uk/z'nasty=trick; domain=.co.uk; Version="1"r#   )r   r   r   r&   r   r   r   r_  s      r/   !test_two_component_domain_rfc2965z-CookieTests.test_two_component_domain_rfc2965  s_   !$///cNN 	a*,BCCCQ###I.s3E:@%HHHq*;<<.	0 	0 	0 	q*?@@"EEE
 	a-I	K 	K 	KQ###q*>??.	0 	0 	0
 	a2>	@ 	@ 	@J/8@F	! 	! 	!Q###q*?@@.	0 	0 	0q*CDDC	E 	E 	E 	a*;	= 	= 	=Q### 	a,?	A 	A 	AQ#####r1   c                 >   t          t          dgdg                    }t          j                            d          }dg}t          |d          }|                    ||           |                     t          |          d           t          j                            d          }t          |d          }|                    ||           |                     t          |          d	           t          j                            d
          }t          |d
          }|                    ||           |                     t          |          d	           t          j                            d
          }t          |d
          }|	                    ||          }|
                    |d                    |                     t          |          d           |                    |           |                     |                    d                     d S )Nr  r   )blocked_domainsallowed_domainsr  http://acme.com/*Set-Cookie: CUSTOMER=WILE_E_COYOTE; path=/r   r   r<   rP  r"   r   )r   r   r   r   r   r   r   r&   r   rS  
set_cookier   r  
has_header)r)   r   r   r   r   rL  s         r/   test_domain_allowzCookieTests.test_domain_allow(  s   0'L+,. . . / / / n$$%788?@7$677	#s###Q###n$$%;<<7$:;;	#s###Q###n$$%=>>7$<==	#s###Q### n$$%=>>7$<==..c**	WQZ   Q###	C   1122222r1   c                 
   t          ddg          }t          |          }dg}t          j                            d          }t          |d          }|                    ||           |                     t          |          d           |	                    dg          }|                    ||           |                     t          |          d	           |
                                 t          j                            d
          }t          |d
          }|                    ||           |                     t          |          d	           t          j                            d
          }|                    |           |                     |                    d                     |                     |                    d                     |
                                 |	                    dg           |                    ||           |                     t          |          d	           t          j                            d          }t          |d          }|                    ||          }|                    |d                    |                     t          |          d           |                    |           |                     |                    d                     |
                                 |	                    g            t          j                            d          }t          |d          }|                    ||          }|                    ||           |                     t          |          d	           t          j                            d          }|                    |           |                     |                    d                     t          j                            d          }|                    |           |                     |                    |d         |                     |                     |                    d                     |	                    dg          }t          j                            d          }|                    |           |                     |                    d                     t          j                            d          }|                    |           |                     |                    d                     d S )NTr?  )r3  r  r  r  r   r   r  r<   zhttp://www.roadrunner.net/r   Cookie2r"   r  zhttp://badacme.com/)r   r   r   r   r   r   r   r&   r   set_blocked_domainsr   r   r  r  rS  r  r  	return_ok)r)   r  r   r   r   r   prL  s           r/   test_domain_blockzCookieTests.test_domain_blockG  s   !;-9 9 9S!!!?@n$$%;<<7$:;;	#s###Q#####ZL11	#s###Q###				n$$%ABB7$@AA	#s###Q###n$$%ABB	C   x00111y11222				...	#s###Q### n$$%;<<7$:;;..c**	WQZ   Q###	C   11222				###n$$%7887$677..c**	#s###Q###n$$%788	C   x00111n$$%:;;	C   wqz37788811222##ZL11n$$%788	C   11222n$$%:;;	C   1122222r1   c           
         dD ]}dD ]}t                      }|rt          d          }t          }d}nt          d          }t          }d}|                    |           d} |||d	||            |||d
|d|           |                     |j        d         d         d         j        d           |                     |j        d         d         d         j        d           d S )N)TF)r%   rN   Fr[  rN   Tz; Version=1r   foo1=barfoo2=barz; securer   r   foo1z#non-secure cookie registered securefoo2z#secure cookie registered non-secure)	r   r   r   r   r  r  r   securer  )r)   r  
whitespacer   r  r   vsr   s           r/   test_securezCookieTests.test_secure  s6    	; 	;B% ; ;
KK '-e<<<C+CBB-d;;;C'C&BS!!!,Assbb**=>>>Assrrr::FGGG  J~.s3F;B9; ; ; J~.s3F;B9; ; ; ;#;	; 	;r1   c                    t                      }t          |          }dg}t          j                            d          }t          |d          }|                    ||           |                     t          |          d           t          j                            d          }|	                    |           | 
                    |                    d                     t          j                            d          }|	                    |           |                     |                    d                     t          j                            d          }|	                    |           | 
                    |                    d                     t          j                            d          }|	                    |           |                     |                    d                     d S )	Nr  (Set-Cookie: session=narf; secure; path=/https://www.acme.com/r<   r   r   zwss://www.acme.com/zws://www.acme.com/)r   r   r   r   r   r   r   r&   r   r   r  r  r  r)   r  r   r   r   r   s         r/   test_secure_blockzCookieTests.test_secure_block  s   !##S!!!=>n$$%<==7$;<<	#s###Q###n$$%<==	C   x00111n$$%;<<	C   11222 n$$%:;;	C   x00111 n$$%9::	C   1122222r1   c                    t          dg          }t          |          }dg}t          j                            d          }t          |d          }|                    ||           |                     t          |          d           t          j                            d          }|	                    |           | 
                    |                    d                     t          j                            d          }|	                    |           | 
                    |                    d                     t          j                            d	          }|	                    |           |                     |                    d                     t          j                            d
          }|	                    |           | 
                    |                    d                     d S )Nfoos)secure_protocolsr  r  r  r<   r   r   zfoos://www.acme.com/zfoo://www.acme.com/)r   r   r   r   r   r   r   r&   r   r   r  r  r  r  s         r/   test_custom_secure_protocolsz(CookieTests.test_custom_secure_protocols  s   !F8<<<S!!!=>n$$%<==7$;<<	#s###Q### n$$%<==	C   11222n$$%;<<	C   11222n$$%;<<	C   x00111n$$%:;;	C   1122222r1   c                     t          t          d                    }t          |dd           t          |d          }|                     |d           d S )NTr[  r  r   zfoo=\b"a"r; Version=1z$Version=1; foo=\\b\"a\"r)r   r   r   r&   )r)   r   rX  s      r/   test_quote_cookie_valuez#CookieTests.test_quote_cookie_value  s_    0>>>???a/1IJJJ!344899999r1   c                 d   d}t          t          d                    }t          ||d           t          j                            |          }|                     t          |          d           |                    |           | 	                    |
                    d                     d S )Nhttp://www.acme.comTr[  r7  r<   r   )r   r   r   r   r   r   r&   r   r   r  r  )r)   r   r   r   s       r/   test_missing_final_slashz$CookieTests.test_missing_final_slash  s    #)$77788a2333n$$S))Q###	C   x0011111r1   c                    t          d          }t          |          }d}t          ||d           t          ||          }|                     d|d           t          |          }d}t          ||d           t          ||          }|                     d|d	           t          |          }d}t          ||d
           t          ||          }|                     d|d	           d S )NTr[  r  spam=eggs; Version=1Domainz*absent domain returned with domain presentz%spam=eggs; Version=1; Domain=.bar.comz$Domain=".bar.com"zdomain not returnedz$spam=eggs; Version=1; Domain=bar.comz$Domain="bar.com"r   r   r   rT  rK  r)   r  r   r   rX  s        r/   test_domain_mirrorzCookieTests.test_domain_mirror  s   !$///cNN#a4555!S!!1A	C 	C 	C cNN#aEFFF!S!!*A/DEEEcNN#aDEEE!S!!)1.CDDDDDr1   c                 J   t          d          }t          |          }d}t          ||d           t          ||          }|                     d|d           t          |          }d}t          ||d           t          ||          }|                     d|d	           d S )
NTr[  r  r  r   z&absent path returned with path presentzspam=eggs; Version=1; Path=/z	$Path="/"zpath not returnedr  r  s        r/   test_path_mirrorzCookieTests.test_path_mirror  s    !$///cNN#a4555!S!!$LMMMcNN#a<===!S!!k1&9:::::r1   c                 n   t          d          }t          |          }d}t          ||d           t          ||          }|                     d|d           t          |          }d}t          ||d           t          ||          }|                     |dd	           t          |          }d}t          ||d
           t          ||          }|                     d|d           t          |          }d}t          ||d           t          ||          }|                     d|d           d S )NTr[  r  r  Portz&absent port returned with port presentzspam=eggs; Version=1; Portz\$Port([^=]|$)z-port with no value not returned with no valuezspam=eggs; Version=1; Port="80"z
$Port="80"z5port with single value not returned with single valuez$spam=eggs; Version=1; Port="80,8080"z$Port="80,8080"z;port with multiple values not returned with multiple values)r   r   r   rT  r'   rK  r  s        r/   test_port_mirrorzCookieTests.test_port_mirror  sd   !$///cNN#a4555!S!!$LMMMcNN#a:;;;!S!!-H	J 	J 	J cNN#a?@@@!S!!lAM	O 	O 	O cNN#aDEEE!S!!'	  	  	  	  	 r1   c                     t          t          d                    }d}t          ||d           t          ||          }|                     d|d           d S )NTr[  r  zfspam=eggs; Version=1; Comment="does anybody read these?"; CommentURL="http://foo.bar.net/comment.html"Commentz:Comment or CommentURL cookie-attributes returned to server)r   r   r   rT  )r)   r   r   rX  s       r/   test_no_return_commentz"CookieTests.test_no_return_comment-  s~    )$77788#a E 	F 	F 	F !S!!AH	J 	J 	J 	J 	Jr1   c                    t          t          d                    }t          |dd           t          |dd           t          |dd           t          |dd           t          |d	d
           g d}g d}g d}g d}t	          d          D ]}d}|D ]}|                     |t                     |                     |j        ||                    |                     |j	        ||                    |                     |j
        ||                    |                     |j        ||                    |dz   }d S )NTr[  zhttp://blah.spam.org/zefoo=eggs; Version=1; Comment="does anybody read these?"; CommentURL="http://foo.bar.net/comment.html"zhttp://www.acme.com/blah/zspam=bar; securezfoo=bar; secure; Version=1zfoo=bar; path=/; Version=1http://www.sol.nosbang=wallop; version=1; domain=".sol.no"; port="90,100, 80,8080"; max-age=100; Comment = "Just kidding! (\"|\\\\) ")r<   r   r<   r<   r<   )rq   r   rq   rq   bang)zblah.spam.orgr   r   r   z.sol.no)r   r^  r\  r   r   r  r   r<   )r   r   r   r   rangeassertIsInstancer   r&   ru   r)  r   rx  )r)   csversionsnamesdomainspathsir   s           r/   test_Cookie_iteratorz CookieTests.test_Cookie_iterator7  s   *488899b1 4E 	F 	F 	F 	"9;MNNNb52	4 	4 	4b52	4 	4 	4b-K	L 	L 	L
 #??555. . .222q 	 	AA  %%a000  HQK888  q222  71:666  q222E	 	r1   c                    |                      t          dg          g dg           |                      t          dg          g dg           |                      t          dg          ddgg           |                      t          dg          g dg           |                      t          d	g          d
dgg           |                      t          dg          g            d S )Nzfoo=bar; path=/; domain)rp   )rx  r   )r   Nrt   z)foo=bar; expires=Foo Bar 12 33:22:11 2000)rp   )rs   Nrt   rq   r   rt   zfoo=bar; expireszfoo=bar; versionrp   )ru   NrN   rw   rW   s    r/   rz   z!CookieTests.test_parse_ns_headersW  s?   7899A A A B	 	 	 	IJKKBBBC	 	 	
 	eW%%-./	 	 	
 	0122BBBC	E 	E 	E 	0122/01	3 	3 	3 	)2$//44444r1   c                 X   d }t          t          j                    dz             }dgdgdgdgdgd|z  gfD ]0} ||          }|                     t          |          d	           1d
g} ||          }|j        d         d         d         }|                     |j                   d S )Nc                     t                      }t          j                            d          }t	          | d          }|                    ||           |S )Nr4  )r   r   r   r   r   r   )r   r   r   r"  s       r/   cookiejar_from_cookie_headerszICookieTests.test_bad_cookie_header.<locals>.cookiejar_from_cookie_headerst  sL    A.(()BCCCW&?@@Aa%%%Hr1   rO  zSet-Cookie: zSet-Cookie2: z-Set-Cookie2: a=foo; path=/; Version=1; domainzSet-Cookie: b=foo; max-age=oopszSet-Cookie: b=foo; version=spamzSet-Cookie:; Expires=%sr   z3Set-Cookie: c=foo; expires=Foo Bar 12 33:22:11 2000r5  r   r   )r   r8   r&   r   r   rQ   rs   )r)   r  rV  r   r   r.  s         r/   test_bad_cookie_headerz"CookieTests.test_bad_cookie_headerr  s    	 	 	 ty{{4/00 <=././&/0
 	( 	(G .-g66ASVVQ'''' II))'22-.s3C8&.)))))r1   N)+ri   rj   rk   r#  r0  r;  rI  rM  rY  r`  rd  rm  rp  ry  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rz   r  rl   r1   r/   r  r    s       ^& & &B) ) )@< < <>.( .( .(`	* 	* 	*55 55 55r&C &C &CP< < <7 7 721 1 1 N N N0? ? ?< < < ) ) )> > >"? "? "?H$ $ $) ) ).$ .$ .$`$ $ $L L LQ Q Q$ $ $$ $ $$ $ $*$ *$ *$X3 3 3>A3 A3 A3F; ; ;.3 3 383 3 36: : :2 2 2E E E.; ; ;     >J J J  @5 5 56* * * * *r1   r  c                   V    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd ZdS )LWPCookieTestsc                 p   t          j                    d         dz   }g }t          t          d                    }t          j                            dddi          }|                    d	|z             t          |d
          }|	                    ||           t          j                            d
          }|
                    |           |                     |                    d          d           |                     |                    d          d           |                    d           t          |d
          }|	                    ||           t          j                            d          }|
                    |           |                    d          }|                     d|           |                     d|           |                    d           t          |d          }|	                    ||           t          j                            d
          }|
                    |           |                    d          }|                     d|           |                     d|           |                     d|           t          j                            d          }|
                    |           |                    d          }|                     d|           |                     d|           |                     |                    d                     d S )Nr   r<   Tr[  r=  r{  r  r|  zVSet-Cookie: CUSTOMER=WILE_E_COYOTE; path=/ ; expires=Wednesday, 09-Nov-%d 23:12:40 GMTr   r   zCUSTOMER=WILE_E_COYOTEr  $Version="1"4Set-Cookie: PART_NUMBER=ROCKET_LAUNCHER_0001; path=/zhttp://www.acme.com/foo/bar PART_NUMBER=ROCKET_LAUNCHER_0001z%Set-Cookie: SHIPPING=FEDEX; path=/foor  zSHIPPING=FEDEXr(  zSHIPPING=FEDEX;)r8   	localtimer   r   r   r   r   r   r   r   r   r&   r   rK  rT  r  
startswith)r)   year_plus_oner   r   r   r   rX  s          r/   test_netscape_example_1z&LWPCookieTests.test_netscape_example_1  s   J ((+a/)D999:: n$$%>%'89 % ; ; 	8:GH	I 	I 	I 7$:;;	#s###n$$%;<<	C   113KLLL	22NCCCMNNN7$:;;	#s###n$$%BCC	C   NN8$$8!<<<.222>???7$9::	#s###n$$%;<<	C   NN8$$8!<<<.222)1---n$$%?@@	C   NN8$$8!<<<.222%67788888r1   c                    t                      }g }t          j                            d          }|                    d           t          |d          }|                    ||           t          j                            d          }|                    |           |                     |	                    d          d           |                    d           t          |d          }|                    ||           t          j                            d          }|                    |           | 
                    |	                    d          d           d S )Nr   r  r   r  z6Set-Cookie: PART_NUMBER=RIDING_ROCKET_0023; path=/ammozhttp://www.acme.com/ammozBPART_NUMBER=RIDING_ROCKET_0023;\s*PART_NUMBER=ROCKET_LAUNCHER_0001)r   r   r   r   r   r   r   r   r&   r   r'   r)   r   r   r   r   s        r/   test_netscape_example_2z&LWPCookieTests.test_netscape_example_2  sW   0 KKn$$%;<<MNNN7$:;;	#s###n$$%;<<	C   11;	= 	= 	= 	D	F 	F 	F7$:;;	#s###n$$%?@@	C   11=	> 	> 	> 	> 	>r1   c                    t          t          d                    }t          |dd          }|                     |           t          |dd          }|                     |d           t          |dd	          }|                     |d
           |                     |d           |                     |d           t          |d          }|                     |d           |                     d|           d S )NTr[  zhttp://www.acme.com/acme/loginz3Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"z!http://www.acme.com/acme/pickitem=Part_Number="Rocket_Launcher_0001"; Version="1"; Path="/acme"z=^\$Version="?1"?; Customer="?WILE_E_COYOTE"?; \$Path="/acme"$z!http://www.acme.com/acme/shippingz+Shipping="FedEx"; Version="1"; Path="/acme"z^\$Version="?1"?;z7Part_Number="?Rocket_Launcher_0001"?;\s*\$Path="\/acme"z-Customer="?WILE_E_COYOTE"?;\s*\$Path="\/acme"z http://www.acme.com/acme/processz%Shipping="?FedEx"?;\s*\$Path="\/acme"WILE_E_COYOTE)r   r   r   r  r'   rK  r)   r   r.  s      r/   test_ietf_example_1z"LWPCookieTests.test_ietf_example_1%  sA    )$77788, /AC C 	   & q"E ;< < 	L	N 	N 	N* q"ELN N 	!5666 "7 	8 	8 	8 "7 	8 	8 	8* q"DEE!IJJJov.....r1   c                 (   t          t          d                    }t          |ddd           t          |d          }|                     |d           t          |d          }|                     d	|           |                     d
|           d S )NTr[  z&http://www.acme.com/acme/ammo/specificr  z@Part_Number="Riding_Rocket_0023"; Version="1"; Path="/acme/ammo"z!http://www.acme.com/acme/ammo/...z(Riding_Rocket_0023.*Rocket_Launcher_0001zhttp://www.acme.com/acme/parts/Rocket_Launcher_0001Riding_Rocket_0023)r   r   r   r'   rK  rT  r
  s      r/   test_ietf_example_2z"LWPCookieTests.test_ietf_example_2  s     )$77788 	7KN	P 	P 	P" q"EFF!LMMM q"CDD,f555-v66666r1   c                    t          d          }t          |          }d}t          |dd          }|                     |           t          |dd          }|                     t          |          d           t          |d	d
          }|                     t          |          d           t          |d	d          }|                     t          |          d           t          |dd          }|                     t          |          d           t          |dd          }|                     t          |          d           t          |dd          }|                     t          |          d           t          |dd          }|                     t          |          d           t          |dd          }|                     t          |          d           t          |dd          }|                     t          |          d           t          |dd          }|                     t          |          d           t          j        }	 |                    |d           t          |          }t          |          }|
                    |d           t          j        |           n# t          j        |           w xY w|                     |t          |                     d S )NTr[  r  zmax-age=3600r  z!foo=bar; domain=".com"; version=1z'ping=pong; domain="acme.com"; version=1r<   zhttp://www.a.acme.comz'whiz=bang; domain="acme.com"; version=1z,wow=flutter; domain=".a.acme.com"; version=1r"   zhttp://125.125.125.125z*zzzz=ping; domain="125.125.125"; version=1r  z6blah=rhubarb; domain=".sol.no"; path="/foo"; version=1zhttp://www.sol.no/foo/barz3bing=bong; domain=".sol.no"; path="/foo"; version=1r#   z5whiz=ffft; domain=".sol.no"; port="90,100"; version=1r  r  z9foo9=bar; version=1; domain=".sol.no"; port; max-age=100;   zhttp://www.sol.no/<oo/z"foo8=bar; version=1; path="/%3coo"r7   r   )r   r   r   r  r&   r   r   r   r   r*  r   r   )r)   r  r   max_ager.  r   olds          r/   test_rejectionzLWPCookieTests.test_rejection  s-   !$///$$$  q"7BD D q"7HJ JQ### q"9HJ JQ### q"9MO OQ### q":KM MQ### q"5 +, , 	Q### q"= +, , 	Q### q"5 +, , 	Q### "AB B
 	Q### q"5 ./ / 	Q### q":DF FQ### #	'FF8DF111q''CC(((AFF8DF111X&&&&IX&&&&d1gg&&&&&s   AK   Kc                    t          t          d                    }t          |dd           t          |dd          }t          j        dt          j                  }|                     d|           |                     ||           t          |d	          }|                     |           t          |d
          }d S )NTr[  z7http://www.acme.com/foo%2f%25/%3c%3c%0Anew%C3%A5/%C3%A5zfoo  =   bar; version    =   1u/   http://www.acme.com/foo%2f%25/<<%0anewå/æøåz bar=baz; path="/foo/"; version=1z^\$version=\"?1\"?r   u-   http://www.acme.com/foo/%25/<<%0anewå/æøåu   http://www.acme.com/ü)	r   r   r   r,  compileIrK  r'   r  )r)   r   r.  
version_res       r/   test_url_encodingz LWPCookieTests.test_url_encoding$  s     )$77788a 56	8 	8 	8 H.0 0 Z 5rt<<
i(((,,,FH H    q"<==r1   c                 d   t          j                    d         dz   }t          j        t	          t          d                    }t          |dd           t          |dd           t          |dd	           d
|fz  }t          |dd|z             t          |dd|z             t          |dd|z             |D ]#}|j        dk    r|	                    dd           $fd} ||d          }| 
                    t          |          d           |                     dt          |                     |                     dt          |                      ||d          }| 
                    t          |          d           |                     dt          |                     d S )Nr   r<   Tr[  r  r   z foo1=bar; max-age=100; Version=1z4foo2=bar; port="80"; max-age=100; Discard; Version=1zfoo3=bar; secure; Version=1zexpires=09-Nov-%d 23:12:40 GMTzhttp://www.foo.com/zfooa=bar; %szfoob=bar; Domain=.foo.com; %sz fooc=bar; Domain=www.foo.com; %sr  HTTPOnlyrN   c                     	 |                      |           t          t          d                    }|                    |           t	          j                   n# t	          j                   w xY w|S )Nr   Tr[  )r   r   r   r   r   r   )rb  r   new_cr   s      r/   save_and_restorez5LWPCookieTests.test_mozilla.<locals>.save_and_restoreT  s    +~666()<T)J)J)JL L

.
999 ****	 ****Ls   A
A" "A8r7   zname='foo1', value='bar'zrest={'HTTPOnly': ''}Fr  )r8   r   r   r   r   r   r   r   r)  set_nonstandard_attrr&   r   rK  r*  )r)   r  r   rs   r.  r  r  r   s          @r/   test_mozillazLWPCookieTests.test_mozilla:  s   ((+a/#X$7$E$E$EG G Ga/8	: 	: 	:a/L	N 	N 	Na/1NOOO2m5EE!2(72	4 	4 	4!29GC	E 	E 	E!2<wF	H 	H 	H  	< 	<F{f$$++J;;;	 	 	 	 	 ! D))UQ'''0$u++>>>-tE{{;;;  E**UQ'''0$u++>>>>>r1   c                 \   t                      }g }t          j                            d          }|                    d           t          |d          }|                    ||           |                    d           t          |d          }|                    ||           t          j                            d          }|                    |           |                     d|	                    d                     |                     d|	                    d                     d S )Nzhttp://foo.bar.acme.com/fooz4Set-Cookie: Customer=WILE_E_COYOTE; domain=.acme.comzhttp://www.acme.com/fooz4Set-Cookie: PART_NUMBER=3,4; domain=foo.bar.acme.comzPART_NUMBER=3,4r   zCustomer=WILE_E_COYOTE)
r   r   r   r   r   r   r   r   rK  r   r  s        r/   test_netscape_miscz!LWPCookieTests.test_netscape_miscg  s   KKn$$%BCC 	MNNN7$=>>	#s###
 	MNNN7$=>>	#s###n$$%BCC	C   ')A)ABBB.s~~h/G/GHHHHHr1   c                 d   t          t          d                    }t          |dd           t          |dd          }|                     d|           t          |dd           t          |d          }|                     d|           |                     t          |          d	           d S )
NTr[  http://example/z#foo1=bar; PORT; Discard; Version=1;z$foo2=bar; domain=".local"; Version=1r  zfoo3=bar; Version=1r  r#   )r   r   r   rK  r&   r   r
  s      r/   test_intranet_domains_2965z)LWPCookieTests.test_intranet_domains_2965~  s    )$77788a*;	= 	= 	=q"3EG Gj&)))a*,ABBBq"344j&)))Q#####r1   c                    t          t          d                    }t          |dd           t          |dd          }|                     t	          |          d           |                     d|           t          |d          }|                     d|           |                     t	          |          d           d S )NFr[  r$  r  zfoo2=bar; domain=.localr"   r  )r   r   r   r&   r   rK  r
  s      r/   test_intranet_domains_nsz'LWPCookieTests.test_intranet_domains_ns  s    )E:::;;!.
;;;"1&7#<> >Q###j&)))"1&788j&)))Q#####r1   c                    t          t          d                    }g }t          j                            d          }|                    d           t          |d          }|                    ||           t          j                            d          }|                    |           | 	                    |
                    d          d           | 	                    |
                    d          d           t          j                            d	          }|                    |           | 	                    |
                    d          d           | 	                    |
                    d          d           d S )
NTr[  zhttp://www.ants.com/z,Set-Cookie: JSESSIONID=ABCDERANDOM123; Path=r   zJSESSIONID=ABCDERANDOM123r  r  zhttp://www.ants.com:8080)r   r   r   r   r   r   r   r   r   r&   r   r  s        r/   test_empty_pathzLWPCookieTests.test_empty_path  sc    )D999::n$$%;<<EFFF7$:;;	#s###n$$%;<<	C   114	6 	6 	6	22NCCC n$$%?@@	C   114	6 	6 	6	22NCCCCCr1   c                 $   t          j                    d         dz   }t          j                            d          }g }|                    d           |                    d|z             |                    d|z             |                    d           |                    d           t          |d          }t                      }|                    ||           ddddd	}|D ]}d
|j	        z  }||         dz   ||<   |
                                 |D ]}d|j	        z  }||         dz   ||<   |                     |d         |d                    |                     |d         d           |                     |d         d           d S )Nr   r<   z"http://www.perlmeister.com/scriptsz$Set-Cookie: s1=session;Path=/scriptszWSet-Cookie: p1=perm; Domain=.perlmeister.com;Path=/;expires=Fri, 02-Feb-%d 23:24:20 GMTz>Set-Cookie: p2=perm;Path=/;expires=Fri, 02-Feb-%d 23:24:20 GMTz<Set-Cookie: s2=session;Path=/scripts;Domain=.perlmeister.comz2Set-Cookie2: s3=session;Version=1;Discard;Path="/")session_after
perm_aftersession_beforeperm_beforez	%s_beforez%s_afterr,  r.  r+  r-  )r8   r   r   r   r   r   r   r   r   r   rU  r&   assertNotEqual)	r)   r  r   r   r   r   counterr.  keys	            r/   test_session_cookiesz#LWPCookieTests.test_session_cookies  s   ((+a/
 n$$%IJJ=>>> D$% 	& 	& 	& 	 02?@ 	A 	A 	A 1 	2 	2 	2KLLL7$HIIKK	#s###$%!"%&"#% %  	, 	,F,C"3<!+GCLL	!!! 	, 	,Fv|+C"3<!+GCLL 	.0FGGG11555G$45q99999r1   N)ri   rj   rk   r  r  r  r  r  r  r   r"  r%  r'  r)  r2  rl   r1   r/   r  r    s        Y9 Y9 Y9v1> 1> 1>fg/ g/ g/`37 37 37jX' X' X't> > >,+? +? +?ZI I I.$ $ $
$ 
$ 
$D D D>(: (: (: (: (:r1   r  __main__)4__doc__r   r   sysr,  test.supportrS   r   r   r8   r
  urllib.requestr   r   http.cookiejarr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   platformr  TestCaser   rn   r   r   r   r   r   r  r  ri   mainrl   r1   r/   <module>r<     s%   " " 				  



 				     " " " " " " ( ( ( ( ( (       ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! \W$	oB oB oB oB oBH% oB oB oBdd! d! d! d! d!(# d! d! d!N) ) ) ) ) ) ) )E E ED D D
 
 
t' t' t' t' t'* t' t' t'lM* M* M* M* M*(# M* M* M*`K	: K	: K	: K	: K	:X& K	: K	: K	:\ zHMOOOOO r1   