
    daf[f                     P   d dl Z d dlZd dlZd dl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mZ d dlmZ 	 d dlZ ej&                  d       ej(                  j+                  e      Zej(                  j1                  edd	      Zej(                  j1                  edd
      Z G d dej6                  j8                        Z G d dej<                        Z G d d      Z  G d dej6                  jB                        Z" G d dej6                  jB                        Z# G d de	jH                        Z% ejL                  dd       G d de	jH                               Z'd Z( G d de	jH                        Z)d Z*e+dk(  r e	jX                          yy# e$ r dZY bw xY w)     N)support)hashlib_helper)threading_helper)warnings_helperT)modulecertdatazkeycert.pemzkeycert2.pemc                       e Zd ZdZd Zd Zy)LoopbackHttpServerz^HTTP server w/ a few modifications that make it useful for
    loopback testing purposes.
    c                     t         j                  j                  j                  | ||       | j                  j                  d       y )Ng?)httpserver
HTTPServer__init__socket
settimeout)selfserver_addressRequestHandlerClasss      5/root/Python-3.12.4/Lib/test/test_urllib2_localnet.pyr   zLoopbackHttpServer.__init__%   s6    ''(6(;	= 	s#    c                 f    | j                   j                         \  }}|j                  d       ||fS )zHTTPServer method, overridden.g      $@)r   acceptr   )r   requestclient_addresss      r   get_requestzLoopbackHttpServer.get_request.   s6     #'++"4"4"6
 	4 ((r   N)__name__
__module____qualname____doc__r   r    r   r   r
   r
       s    $
)r   r
   c                   "    e Zd ZdZd Zd Zd Zy)LoopbackHttpServerThreadz2Stoppable thread that runs a loopback http server.c                     t         j                  j                  |        d| _        t        j                         | _        d|_        t        d|      | _        | j                  j                  | _
        y )NFzHTTP/1.0)z	127.0.0.1r   )	threadingThreadr   _stop_serverEventreadyprotocol_versionr
   httpdserver_portportr   request_handlers     r   r   z!LoopbackHttpServerThread.__init__=   sW    !!$'!__&
+5('(8(79
JJ**	r   c                 f    d| _         | j                          | j                  j                          y)z.Stops the webserver if it's currently running.TN)r&   joinr*   server_closer   s    r   stopzLoopbackHttpServerThread.stopF   s%     !		

!r   c                     | j                   j                          | j                  s(| j                  j	                          | j                  s'y y N)r(   setr&   r*   handle_requestr2   s    r   runzLoopbackHttpServerThread.runN   s4    

##JJ%%' ##r   N)r   r   r   r   r   r3   r8   r    r   r   r"   r"   :   s    <+"(r   r"   c                   F    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)DigestAuthHandlerz-Handler for performing digest authentication.c                 J    d| _         g | _        i | _        d| _        d| _        y )Nr   z
Test Realmauth)_request_num_nonces_users_realm_name_qopr2   s    r   r   zDigestAuthHandler.__init__X   s'    '	r   c                     || _         y r5   )rA   )r   qops     r   set_qopzDigestAuthHandler.set_qop_   s	    	r   c                 6    t        |t              sJ || _        y r5   )
isinstancedictr?   )r   userss     r   	set_userszDigestAuthHandler.set_usersb   s    %&&&r   c                     || _         y r5   )r@   )r   realms     r   	set_realmzDigestAuthHandler.set_realmf   s
     r   c                     | xj                   dz  c_         t        j                  t        | j                         j	                  d            j                         }| j                  j                  |       |S )N   ascii)r=   hashlibmd5strencode	hexdigestr>   append)r   nonces     r   _generate_noncez!DigestAuthHandler._generate_noncei   sW    QC 1 1299'BCMMOE"r   c                 
   |j                  d      }||dz   d  }|j                  d      }i }|D ]Q  }|j                  d      \  }}|j                         }|d   dk(  r|d   dk(  r|dd }n|j                         }|||<   S |S )N rN   ,=r   ")findsplitstrip)r   auth_strfirst_space_indexparts	auth_dictpartnamevalues           r   _create_auth_dictz#DigestAuthHandler._create_auth_dicto   s    $MM#.-a/01s#	 	$D**S/KD%::<DQx359#3a#IdO	$ r   c                    i }|j                  |       ||d<   ||d<   ||d<   d|z  }t        j                  |j                  d            j	                         }d|z  }t        j                  |j                  d            j	                         }	||d<   |	|d<   d	|z  }
t        j                  |
j                  d            j	                         }||d
   k(  S )Npasswordmethoduriz#%(username)s:%(realm)s:%(password)srO   z%(method)s:%(uri)sHA1HA2z3%(HA1)s:%(nonce)s:%(nc)s:%(cnonce)s:%(qop)s:%(HA2)sresponse)updaterP   rQ   rS   rT   )r   rd   rj   rk   rl   
final_dictHA1_strrm   HA2_strrn   response_strro   s               r   _validate_authz DigestAuthHandler._validate_auth   s    
)$!)
:%
8
57*Dkk'..12<<>&3kk'..12<<>
5
546@A;;|227;<FFH9Z000r   c           
         |j                  dd       |j                  dd       |j                  dd| j                  d| j                  d| j	                         d	       |j                          |j                  j                  d
       y)Ni  zProxy Authentication RequiredContent-Type	text/htmlzProxy-AuthenticatezDigest realm="z", qop="z	",nonce="z", s   Proxy Authentication Required.F)send_responsesend_headerr@   rA   rW   end_headerswfilewriter-   s     r   _return_auth_challengez(DigestAuthHandler._return_auth_challenge   s}    %%c+JK##NK@##  tyy$*>*>*@#B	C 	##%##$EFr   c                 X   t        | j                        dk(  ryd|j                  vr| j                  |      S | j	                  |j                  d         }|d   | j                  v r| j                  |d      }n| j                  |      S |j                  d      | j                  vr| j                  |      S | j                  j                  |d          d}|j                  |j                  fD ]#  }| j                  |||j                  |      s"d}% |s| j                  |      S y)a  Performs digest authentication on the given HTTP request
        handler.  Returns True if authentication was successful, False
        otherwise.

        If no users have been set, then digest auth is effectively
        disabled and this method will always return True.
        r   TzProxy-AuthorizationusernamerV   F)lenr?   headersr~   rh   getr>   removepath
short_pathru   command)r   r.   rd   rj   auth_validatedr   s         r   r7   z DigestAuthHandler.handle_request   s0    t{{q  (?(??..??..''(=>I $3;;	*(=?22?CC==)T\\922?CC##Ig$67"N )--/I/IJ *&&y'/'6'>'>'+- &*N* "22?CCr   N)r   r   r   r   r   rD   rI   rL   rW   rh   ru   r~   r7   r    r   r   r:   r:   U   s2    7!"1$*r   r:   c                       e Zd ZdZdZdZdZedeZ ej                  ej                  d            j                  d      Zd Zd Zd	 Zd
 Zd Zy)BasicAuthHandlerz,Handler for performing basic authentication.testUsertestPassTest:rO   c                 ^    t        j                  j                  j                  | g|i | y r5   )r   r   BaseHTTPRequestHandlerr   )r   argskwargss      r   r   zBasicAuthHandler.__init__   s$    **33DJ4J6Jr   c                      y r5   r    r   formatr   s      r   log_messagezBasicAuthHandler.log_message   s    r   c                 j    | j                  d       | j                  dd       | j                          y )N   Content-typerx   )ry   rz   r{   r2   s    r   do_HEADzBasicAuthHandler.do_HEAD   s,    35r   c                     | j                  d       | j                  dd| j                  z         | j                  dd       | j                          y )Ni  zWWW-AuthenticatezBasic realm="%s"r   rx   )ry   rz   REALMr{   r2   s    r   do_AUTHHEADzBasicAuthHandler.do_AUTHHEAD   sG    3+-ADJJ-NO5r   c                    | j                   j                  dd      s,| j                          | j                  j	                  d       y | j                   j                  dd      d| j
                  z   k(  r=| j                  d       | j                          | j                  j	                  d       y | j                          y )NAuthorization s   No Auth header receivedzBasic r   s   It works)r   r   r   r|   r}   ENCODED_AUTHry   r{   r2   s    r   do_GETzBasicAuthHandler.do_GET   s    ||4JJ78\\%(043D3D(DEs#JJ[) r   N)r   r   r   r   USERPASSWDr   USER_PASSWDbase64	b64encoderS   decoder   r   r   r   r   r   r    r   r   r   r      s`    6DFE!6*K#6##K$6$6w$?@GGPLK
r   r   c                   "    e Zd ZdZd Zd Zd Zy)FakeProxyHandlerzThis is a 'fake proxy' that makes it look like the entire
    internet has gone down due to a sudden zombie invasion.  It main
    utility is in providing us with authentication support for
    testing.
    c                 l    || _         t        j                  j                  j                  | g|i | y r5   )digest_auth_handlerr   r   r   r   )r   r   r   r   s       r   r   zFakeProxyHandler.__init__  s.     $7 **33DJ4J6Jr   c                      y r5   r    r   s      r   r   zFakeProxyHandler.log_message  s     	r   c                    t         j                  j                  | j                  d      \  }}}}}}|| _        | j
                  j                  |       r| j                  dd       | j                  dd       | j                          | j                  j                  t        d| j                  z  d             | j                  j                  d       y y )	Nr   r   OKrw   rx   zYou've reached %s!<BR>rO   sF   Our apologies, but our server is down due to a sudden zombie invasion.)urllibparseurlparser   r   r   r7   ry   rz   r{   r|   r}   bytes)r   scmnetlocr   paramsqueryfragments          r   r   zFakeProxyHandler.do_GET  s    7=||7L7LIIv84fdFE8##2248sD)^[9JJU#;dii#G#*, -JJ : ; 9r   N)r   r   r   r   r   r   r   r    r   r   r   r      s    K
;r   r   c                   J     e Zd ZdZdZdZdZ fdZd Z fdZ	d Z
d	 Z xZS )
BasicAuthTestsr   r   	Incorrectr   c                 >   t         t        |           d }t        |      | _        | j                  | j                         d| j                  j                  z  | _        | j                  j                          | j                  j                  j                          y )Nc                      t        | i |S r5   )r   )r   r   s     r   #http_server_with_basic_auth_handlerzABasicAuthTests.setUp.<locals>.http_server_with_basic_auth_handler$  s    #T4V44r   zhttp://127.0.0.1:%s)superr   setUpr"   r   
addCleanupstop_serverr,   
server_urlstartr(   wait)r   r   	__class__s     r   r   zBasicAuthTests.setUp!  sp    nd)+	5./RS(()/$++2B2BB r   c                 F    | j                   j                          d | _         y r5   r   r3   r2   s    r   r   zBasicAuthTests.stop_server,      r   c                 *    t         t        |           y r5   )r   r   tearDown)r   r   s    r   r   zBasicAuthTests.tearDown0  s    nd,.r   c                 $   t         j                  j                         }|j                  | j                  | j
                  | j                  | j                         t         j                  j                  t         j                  j                  |             	 | j                  t         j                  j                  | j
                               y # t         j                  j                  $ r! | j                  d| j
                  z         Y y w xY w)Nz!Basic auth failed for the url: %s)r   r   HTTPBasicAuthHandleradd_passwordr   r   r   r   install_openerbuild_opener
assertTrueurlopenerror	HTTPErrorfailr   ahs     r   test_basic_auth_successz&BasicAuthTests.test_basic_auth_success3  s    ^^002


DOOTYYL%%fnn&A&A"&EF	MOOFNN224??CD||%% 	MII9DOOKL	Ms   8C ;DDc                    t         j                  j                         }|j                  | j                  | j
                  | j                  | j                         t         j                  j                  t         j                  j                  |             | j                  t         j                  j                  t         j                  j                  | j
                         y r5   )r   r   r   r   r   r   r   INCORRECT_PASSWDr   r   assertRaisesr   r   r   r   s     r   test_basic_auth_httperrorz(BasicAuthTests.test_basic_auth_httperror<  s    ^^002


DOOTYY@U@UV%%fnn&A&A"&EF&,,00&..2H2H$//Zr   )r   r   r   r   r   r   r   r   r   r   r   r   __classcell__r   s   @r   r   r     s3    DF"E	!/M[r   r   rQ   )opensslc                   L     e Zd ZdZdZdZdZ fdZd Zd Z	d Z
d	 Zd
 Z xZS )ProxyAuthTestszhttp://localhosttestertest123	TestRealmc                     t         t                   d } j                  |t        j
                  j                                dt        j
                  d<   dt        j
                  d<   t                _         j                  j                   j                   j                  i        j                  j                   j                          fd}t        |       _         j                   j                           j                  j#                           j                  j$                  j'                          d j                  j(                  z  }t*        j,                  j/                  d|i      }t*        j,                  j1                          _        t*        j,                  j5                  | j2                         _        y )Nc                 ~    t         j                  j                          t         j                  j                  |        y r5   osenvironclearrp   old_environs    r   restore_environz-ProxyAuthTests.setUp.<locals>.restore_environN  $    JJJJk*r   r   NO_PROXYno_proxyc                  6    t        j                  g| i |S r5   )r   r   )r   r   r   s     r   create_fake_proxy_handlerz7ProxyAuthTests.setUp.<locals>.create_fake_proxy_handlerY  s    #D$<$<NtNvNNr   zhttp://127.0.0.1:%dr   )r   r   r   r   r   r   copyr:   r   rI   r   r   rL   r   r"   r   r   r   r(   r   r,   r   r   ProxyHandlerProxyDigestAuthHandlerproxy_digest_handlerr   opener)r   r   r   	proxy_urlhandlerr   s   `    r   r   zProxyAuthTests.setUpK  s@   nd)+	+ 	):;!#

:!#

:#4#6   **DIIt{{+CD  **4::6	O //HI(() )DKK,<,<<	..--v	.BC$*NN$I$I$K!nn11T..0r   c                 F    | j                   j                          d | _         y r5   r   r2   s    r   r   zProxyAuthTests.stop_serverf  r   r   c                 ^   | j                   j                  | j                  | j                  | j                  | j
                  dz          | j                  j                  d       | j                  t        j                  j                  | j                  j                  | j                         y )Nbadr<   )r   r   r   URLr   r   r   rD   r   r   r   r   r   openr2   s    r   -test_proxy_with_bad_password_raises_httperrorz<ProxyAuthTests.test_proxy_with_bad_password_raises_httperrorj  sw    !!..tzz488/3yy$++e:K	M  ((0&,,00++**((	$r   c                     | j                   j                  d       | j                  t        j                  j
                  | j                  j                  | j                         y Nr<   )	r   rD   r   r   r   r   r   r   r   r2   s    r   ,test_proxy_with_no_password_raises_httperrorz;ProxyAuthTests.test_proxy_with_no_password_raises_httperrorr  sD      ((0&,,00++**((	$r   c                 ~   | j                   j                  | j                  | j                  | j                  | j
                         | j                  j                  d       | j                  j                  | j                        5 }|j                         r	 |j                         rd d d        y # 1 sw Y   y xY wr  )r   r   r   r   r   r   r   rD   r   r   readr   results     r   test_proxy_qop_auth_worksz(ProxyAuthTests.test_proxy_qop_auth_worksx  s    !!..tzz488/3yy$++	G  ((0[[dhh' 	6++- ++-	 	 	s   "B33B<c                    | j                   j                  | j                  | j                  | j                  | j
                         | j                  j                  d       	 | j                  j                  | j                        }|5  |j                         r	 |j                         rd d d        y # 1 sw Y   y xY w# t        j                  j                  $ r Y y w xY w)Nzauth-int)r   r   r   r   r   r   r   rD   r   r   r  r   r   URLErrorr  s     r   0test_proxy_qop_auth_int_works_or_throws_urlerrorz?ProxyAuthTests.test_proxy_qop_auth_int_works_or_throws_urlerror  s    !!..tzz488/3yy$++	G  ((4
	[[%%dhh/F  kkm kkm   ||$$ 	 		s   #%C 
"B66B?C"!C")r   r   r   r   r   r   r   r   r   r   r  r  r
  r   r   s   @r   r   r   C  s5    
CDFE06$$r   r   c                 V      G  fddt         j                  j                        S )Nc                   <    e Zd ZdZg Zg ZdZd Zd Z fdZ	d Z
y)1GetRequestHandler.<locals>.FakeHTTPRequestHandlerz	TestHTTP/P   c                 p    | j                         }|r$| j                  j                  |      }||d  }|r#y y r5   )	send_headr|   r}   )r   bodydones      r   r   z8GetRequestHandler.<locals>.FakeHTTPRequestHandler.do_GET  s5    >>#Dzz''-DE{ r   c                     | j                   d   }| j                  j                  t        |            }| j	                          | j
                  j                  |       y )NzContent-Length)r   rfiler  intr   requestsrU   )r   content_length	post_datas      r   do_POSTz9GetRequestHandler.<locals>.FakeHTTPRequestHandler.do_POST  sC    !\\*:;N

N(;<IKKMMM  +r   c                    | j                   _        | j                  j                  | j                         j                  d      \  }}}| j                  |       |D ]&  \  }}| j                  ||d| j                  iz         ( |r$| j                  dd       | j                          |S | j                          y )Nr   r,   r   z
text/plain)
r   headers_receivedr  rU   r   popry   rz   r,   r{   )r   response_coder   r  headerrg   FakeHTTPRequestHandler	responsess         r   r  z;GetRequestHandler.<locals>.FakeHTTPRequestHandler.send_head  s    6:ll"3MM  ++4==+;(M7D}-#* E  &1C)CDE  >  "r   c                      y r5   r    )r   r   s     r   r   z=GetRequestHandler.<locals>.FakeHTTPRequestHandler.log_message  s    r   N)r   r   r   server_versionr  r  r,   r   r  r  r   )r  r   s   r   r  r    s,    $	#	,		r   r  )r   r   r   )r   r  s   `@r   GetRequestHandlerr#    s"    #!C!C #L "!r   c                        e Zd ZdZ fdZddZd ZddZd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 xZS )TestUrlopenaN  Tests urllib.request.urlopen using the network.

    These tests are not exhaustive.  Assuming that testing using files does a
    good job overall of some of the basic interface features.  There are no
    tests exercising the optional 'data' and 'proxies' arguments.  No tests
    for transparent redirection have been written.
    c                 *   t         t        |           | j                  t        j
                  j                         d }| j                  |t        j                  j                                dt        j                  d<   dt        j                  d<   y )Nc                 ~    t         j                  j                          t         j                  j                  |        y r5   r   r   s    r   r   z*TestUrlopen.setUp.<locals>.restore_environ  r   r   *r   r   )
r   r%  r   r   r   r   
urlcleanupr   r   r   )r   r   r   s     r   r   zTestUrlopen.setUp  sd    k4&( 	112	+ 	):;!$

:!$

:r   c                    g }t        j                  j                  ||fi |}	 |j                  |j	                  d             |j                  |j                                |j                  |j                  d             |j                  |j                                |j                          dj                  |      S # |j                          w xY w)Nr   i   r   )
r   r   r   extend	readlinesrU   readliner  closer0   )r   urldatar   lfs         r   r   zTestUrlopen.urlopen  s    NN""377	HHQ[[%&HHQZZ\"HHQVVD\"HHQVVXGGIxx{ GGIs   A>C Cc                 F    | j                   j                          d | _         y r5   r   r2   s    r   r   zTestUrlopen.stop_server  r   r   c                 8   |dg dfg}t        |      }t        |      | _        | j                  | j                         | j                  j                          | j                  j                  j                          | j                  j                  }||_        |S )Nr   s   we don't care)	r#  r"   r   r   r   r   r(   r   r,   )r   r   r   r,   s       r   start_serverzTestUrlopen.start_server  s    r#345I#I..w7(() {{r   c                     t        t        j                  d      s| j                  d       ddlm} |dg dfg}t        |      } || fd|i|}|j                  |_        |S )NHTTPSHandlerzssl support requiredr   )make_https_serverr      we care a bithandler_class)hasattrr   r   skipTesttest.ssl_serversr8  r#  r,   )r   r   r   r8  r   r   s         r   start_https_serverzTestUrlopen.start_https_server  sd    v~~~6MM016r#345I#I."4IwI&I{{r   c                     d}ddgdfdg |fg}| j                  |      }| j                  d|j                  z        }| j                  ||       | j                  |j                  ddg       y )	Ns   We got here...i.  )Locationz(http://localhost:%(port)s/somewhere_elser   r   http://localhost:%s//z/somewhere_elser5  r   r,   assertEqualr  )r   expected_responser   r   r0  s        r   test_redirectionzTestUrlopen.test_redirection  s    -KL"'(
	 ##I.||2W\\AB01))C1B+CDr   c                     d}d}ddg|fg}| j                  |      }| j                  d|j                  z        }| j                  ||       y )Ns   hello worlds   a
hello worl
1
d
0
r   )zTransfer-EncodingchunkedrA  )r5  r   r,   rD  )r   rE  chunked_startro   r   r0  s         r   test_chunkedzTestUrlopen.test_chunked	  s`    *! 	 ;<mLM##H-||2W\\AB01r   c                    d}| j                  dg |fg      }	 | j                  d|j                  z         | j                  d       | j                  |       | j                  |j                  dg       y # t        j
                  j                  $ r*}|j                         }|j                          Y d }~rd }~ww xY w)Ns   Bad bad bad...i  zhttp://localhost:%s/weeblez404 should raise URLErrorz/weeble)r5  r   r,   r   r   r   r	  r  r.  rD  r  )r   rE  r   r2  r0  s        r   test_404zTestUrlopen.test_404  s    -##c2/@%A$BC	3LL5DE
 II1201))I;7 ||$$ 	668DGGII	s   A8 8B? B::B?c                     d}| j                  dg |fg      }| j                  d|j                  z        }| j                  ||       | j                  |j                  dg       y )N   pycon 2008...r   http://localhost:%s/bizarre/bizarrerC  r   rE  r   r0  s       r   test_200zTestUrlopen.test_200&  sd    ,##c2/@%A$BC||9GLLHI01))J<8r   c                     d}| j                  dg |fg      }| j                  d|j                  z  d      }| j                  ||       | j                  |j                  ddg       y )NrN  r   rO  s   get=with_feelingrP  rC  rQ  s       r   test_200_with_parametersz$TestUrlopen.test_200_with_parameters-  sm    ,##c2/@%A$BC||9GLLH0201))J8K+LMr   c                     | j                         }t        j                  t              }| j	                  d|j
                  z  |      }| j                  |d       y )Ncafilehttps://localhost:%s/bizarrecontextr9  )r>  sslcreate_default_contextCERT_localhostr   r,   rD  )r   r   rZ  r0  s       r   
test_httpszTestUrlopen.test_https5  sN    ))+,,NC||:W\\ISZ|[/0r   c                    | j                  t              }t        j                  dt        f      5  | j                  d|j                  z  t              }| j                  |d       | j                  t        j                  j                        5 }| j                  d|j                  z  t               d d d        | j                  t              }| j                  t        j                  j                        5 }| j                  d|j                  z  t               d d d        d d d        y # 1 sw Y   ~xY w# 1 sw Y   xY w# 1 sw Y   y xY w)Ncertfiler   rX  rV  r9  )r>  r]  r   check_warningsDeprecationWarningr   r,   rD  r   r   r   r	  CERT_fakehostname)r   r   r0  cms       r   test_https_with_cafilez"TestUrlopen.test_https_with_cafile;  s*   ))>)B++R1C,DE 	7<< > M'5   7DT#34""6<<#8#89 7R;gllJ$5  77 --7H-IG""6<<#8#89 7R;gllJ$5  77	7 	77 7
7 7	7 	7s=   A E%D47AE>%E #E4D=	9E E		EEc                 L   | j                  t              }t        j                  dt        f      5  | j                  t        j                  j                        5 }| j                  d|j                  z  d       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr`  r   rX  T)	cadefault)r>  r]  r   rb  rc  r   r   r   r	  r   r,   )r   r   re  s      r   test_https_with_cadefaultz%TestUrlopen.test_https_with_cadefaultL  s    ))>)B++R1C,DE 	-""6<<#8#89 -R;gllJ'+  --	- 	-- -	- 	-s#   *B!B=BB	BB#c                    t         | j                  d       t         j                  s| j                  d       d fd}t        j                  t         j                        }|j                  |       | j                  |t              }t        j                  t              }| j                  d|j                  z  |       | j                  d       y )	Nzssl module requiredzSNI support required in OpenSSLc                 
    |y r5   r    )ssl_sockserver_nameinitial_contextsni_names      r   cb_sniz*TestUrlopen.test_https_sni.<locals>.cb_sniZ  s    "Hr   )rZ  ra  rV  zhttps://localhost:%srY  	localhost)r[  r<  HAS_SNI
SSLContextPROTOCOL_TLS_SERVERset_servername_callbackr>  r]  r\  r   r,   rD  )r   rp  rZ  r   ro  s       @r   test_https_snizTestUrlopen.test_https_sniT  s    ;MM/0{{MM;<	# ..!8!89''/))'N)S,,NC+gll:GL;/r   c                 ,   | j                         }t        j                  j                  d|j                  z  ddi      }t        j                  j                  |      5  	 d d d        | j                  |j                  d   d       y # 1 sw Y   )xY w)NrA  Rangezbytes=20-39r   )r5  r   r   Requestr,   r   rD  r  r   r   reqs      r   test_sending_headersz TestUrlopen.test_sending_headersd  s    ##%nn$$%;gll%J.5}-E % G^^##C( 		11':MJ	 	s    B

Bc                    | j                         }t        j                  j                  d|j                  z  ddi      }t        j                  j                  |      5  	 d d d        | j                  d|j                  j                                | j                  d|j                  j                                y # 1 sw Y   ^xY w)NrA  zX-SoMe-hEaderfoobarry  zX-Some-Header)
r5  r   r   rz  r,   r   assertInr  keysassertNotInr{  s      r   test_sending_headers_camelz&TestUrlopen.test_sending_headers_camell  s    ##%nn$$%;gll%J.=x-H % J^^##C( 		ow'?'?'D'D'FG'*B*B*G*G*IJ	 	s    B??Cc                 2   | j                         }t        j                  j                  d|j                  z        5 }dD ]!  }| j                  t        ||      d|z         # | j                  |j                         d       d d d        y # 1 sw Y   y xY w)Nhttp://localhost:%s)r  r.  infogeturlz3object returned from urlopen lacks the %s attributezcalling 'read' failed)r5  r   r   r   r,   r   r;  r  )r   r   open_urlattrs       r   
test_basiczTestUrlopen.test_basicu  s    ##%^^##$9GLL$HI 	FX; F$ 7 :>@D:E FF OOHMMO-DE		F 	F 	Fs   ABBc                 `   | j                         }t        j                  j                  d|j                  z        }|5  |j                         }d d d        | j                  t        j                  j                  d       | j                  |j                         d       y # 1 sw Y   UxY w)Nr  zEobject returned by 'info' is not an instance of email.message.Messageplain)r5  r   r   r   r,   r  assertIsInstanceemailmessageMessagerD  get_content_subtype)r   r   r  info_objs       r   	test_infozTestUrlopen.test_info}  s    ##%>>))!GLL02 	'}}H	'h(=(=B	C 	557A	' 	's   B$$B-c                    | j                         }t        j                  j                  d|j                  z        }|5  |j                         }d d d        | j                  d|j                  z         y # 1 sw Y   )xY w)Nr  )r5  r   r   r   r,   r  rD  )r   r   r  r/  s       r   test_geturlzTestUrlopen.test_geturl  sl    ##%>>))*?',,*NO 	$//#C	$3gllBC	$ 	$s   A88Bc                     d}| j                  dg |fg      }t        j                  j                  d|j                  z        }|D ]  }| j                  ||        y )NrN  r   r  )r5  r   r   r   r,   rD  )r   rE  r   r0  lines        r   test_iterationzTestUrlopen.test_iteration  sa    ,##c2/@%A$BC~~%%&;gll&JK 	6DT#45	6r   c                    dddddz  dz   g}dj                  |      }| j                  dg |fg      }t        j                  j	                  d	|j
                  z        }t        |      D ]9  \  }}| j                  |||   d
|dt        ||         dt        |             ; | j                  dz   t        |             y )Ns   We
s   got
s   here
s	   verylong i       
r   r   r  zFetched line number z1 doesn't match expected:
    Expected length was z, got rN   )	r0   r5  r   r   r   r,   	enumeraterD  r   )r   linesrE  r   r0  indexr  s          r   test_line_iterationzTestUrlopen.test_line_iteration  s    (I|d/BU/JKHHUO##c2/@%A$BC~~%%&;gll&JK$T? 	DKE4T5< $Su%6D	CD	D
 	CJ/r   c                 z   | j                  dg dfdg dfg      }t        j                  j                         }t        j                  j	                  d|j
                  z        }| j                  d |j                         |j                  |dj                  d             | j                  d|j                         | j                  d|j                  d             |j                  |dj                  d             | j                  d	|j                         | j                  d
|j                  d             y )Nr   s   anyr  1zus-ascii   1zContent-length
1234567890s
   123456789010)r5  r   r   r   rz  r,   rD  r0  r   rS   
get_header)r   r   r   r   s       r   test_issue16464zTestUrlopen.test_issue16464  s    ##"f"f%
  ,,...(()>)MNw||,GSZZ
34w||,g001ABCG\00<=5w112BCDr   r5   )r   r   r   r   r   r   r   r5  r>  rF  rJ  rL  rR  rT  r^  rf  ri  rv  r}  r  r  r  r  r  r  r  r   r   s   @r   r%  r%    s~    %	E289N17"-0 KKF	BD6
0Er   r%  c                  t    t        j                         } t        j                  t         j                  g|   y r5   )r   threading_setupunittestaddModuleCleanupthreading_cleanup)thread_infos    r   setUpModuler    s*    "224K.@@O;Or   __main__)-r   r   r  urllib.parser   urllib.requesthttp.serverr   r$   r  rP   testr   test.supportr   r   r   r[  ImportErrorrequires_working_socketr   dirname__file__herer0   r]  rd  r   r   r
   r%   r"   r:   r   r   r   TestCaser   requires_hashdigestr   r#  r%  r  r   mainr    r   r   <module>r     s    	         ' ) (    t ,	wwx dJ>GGLLz>B 
)// )4(y// (6v vr&t{{99 &X;t{{99 ;B%[X&& %[P $##E48JX&& J 9JZ("VxE(## xEtP
 zHMMO S  
Cs   F F%$F%