a 5êdgÎ2ã@sîddlZddlmZddlmZddlmZddlZddlZddl Z ddl Z ddl Z e  d¡dd„Zdd „Ze d ejvd ¡Zee jje jjƒZGd d „d ejƒZGdd„dejƒZGdd„dejƒZGdd„dejƒZedkrêe ¡dS)éN)Úsupport)Ú socket_helper)Úsanepathname2urlZnetworkc Os`tdƒD]N}z||i|¤ŽWS|yT}z|}WYd}~qWYd}~qd}~00q|‚dS)Né)Úrange)ÚfuncÚexcÚargsÚkwargsÚiÚeÚlast_exc©rú0/usr/local/lib/python3.9/test/test_urllib2net.pyÚ _retry_thrices $rcs‡‡fdd„}|S)Ncstˆˆg|¢Ri|¤ŽS©N)r)r r ©rrrrÚwrappedsz(_wrap_with_retry_thrice..wrappedr)rrrrrrÚ_wrap_with_retry_thricesrZTRAVISz%bpo-35411: skip FTP test on Travis CIc@s eZdZdS)Ú AuthTestsN)Ú__name__Ú __module__Ú __qualname__rrrrr*src@seZdZdd„ZdS)ÚCloseSocketTestcCsp| tjj¡tj}t |¡>t|ƒ}|j }|  |j ¡|  ¡|  |j ¡Wdƒn1sb0YdSr)Ú addCleanupÚurllibÚrequestÚ urlcleanuprÚ TEST_HTTP_URLrÚtransient_internetÚ_urlopen_with_retryÚfpÚ assertFalseÚclosedÚcloseÚ assertTrue)ÚselfÚurlÚresponseÚsockrrrÚ test_closeSs  zCloseSocketTest.test_closeN)rrrr*rrrrrQsrc@sdeZdZdd„Zedd„ƒZdd„Zdd„Zd d „Zd d „Z e   d ¡dd„ƒZ ddd„Z dd„ZdS)ÚOtherNetworkTestscCsdSrr©r&rrrÚsetUpbszOtherNetworkTests.setUpcCs&dddtjjfg}| || ¡¡dS)Nzftp://www.pythontest.net/READMEz*ftp://www.pythontest.net/non-existent-file)rÚerrorÚURLErrorÚ _test_urlsÚ_extra_handlers)r&ÚurlsrrrÚtest_ftpks ÿþzOtherNetworkTests.test_ftpc CsŠtj}t|dƒ}zV| d¡| ¡dttj |¡ƒddt j j fg}|j ||  ¡ddWt |¡n t |¡0| tt jjd¡dS)NÚwz hi there zfile:zfile:///nonsensename/etc/passwdT)Úretryz./relative_path/to/file)rÚTESTFNÚopenÚwriter$rÚosÚpathÚabspathrr.r/r0r1ÚremoveZ assertRaisesÚ ValueErrorrÚurlopen)r&r6Úfr2rrrÚ test_filets  ÿþzOtherNetworkTests.test_filecCsZd}t |¡8tj |¡}tj |¡}| | ¡d¡Wdƒn1sL0YdS)Nz)http://www.pythontest.net/index.html#frag©rrrrÚRequestr>Ú assertEqualÚgeturl)r&Z urlwith_fragÚreqÚresrrrÚtest_urlwithfrag¡s    ÿz"OtherNetworkTests.test_urlwithfragcCsZd}t |¡8tj |¡}tj |¡}| | ¡d¡Wdƒn1sL0YdS)Nz*http://www.pythontest.net/redir/with_frag/z)http://www.pythontest.net/elsewhere/#fragrA)r&Zredirect_url_with_fragrErFrrrÚtest_redirect_url_withfrag©s    ÿz,OtherNetworkTests.test_redirect_url_withfragcCs¨tj}t |¡„tj ¡}tj |¡}| |  ¡¡|  |¡|  |  ¡¡|  |  d¡¡|  dd¡|  |¡| | d¡d¡Wdƒn1sš0YdS)Nz User-agentz User-Agentz Test-Agent)rrrrrrÚ build_openerrBr"Z header_itemsr7r%Z has_headerZ add_headerrCZ get_header)r&r'ÚopenerrrrrÚtest_custom_headers±s      z%OtherNetworkTests.test_custom_headersz XXX: http://www.imdb.com is gonec Cs¨d}t |¡†z0tj |¡}Wdƒn1s40YWnty\| d¡Yn 0| |¡tj |¡}| ¡}| |¡Wdƒn1sš0YdS)Nzhttp://www.imdb.comzOurlopen failed for site not sending Connection:close) rrrrr>r=Zfailr%Úread)r&ZURLrFrErrrÚtest_sites_no_connection_close¾s "   z0OtherNetworkTests.test_sites_no_connection_closeTc Csüddl}ddl}| d¡j}tjj|Žj}|r)Úfilegš™™™™™¹?)!ÚtimeÚloggingÚ getLoggerÚdebugrrrIr7rr.r/ZsubTestÚ isinstanceÚtuplerrrZINTERNET_TIMEOUTÚOSErrorÚtypeZassertIsInstanceZtime_outZsocket_peer_resetZioerror_peer_resetrLÚlenÚsocketÚtimeoutÚprintÚsysÚstderrr$Úsleep)r&r2Úhandlersr5rOrPrRr>r'rEZ expected_errr?ÚerrÚmsgÚbufrrrr0ÓsB    ÿÿþt(zOtherNetworkTests._test_urlscCs2g}tj ¡}| |j¡| d¡| |¡|S)Né)rrZCacheFTPHandlerrÚ clear_cacheZ setTimeoutÚappend)r&r^Zcfhrrrr1ús     z!OtherNetworkTests._extra_handlersN)T)rrrr-Úskip_ftp_test_on_travisr3r@rGrHrKÚunittestÚskiprMr0r1rrrrr+as  -   'r+c@sheZdZdd„Zdd„Zdd„Zdd„Zd d „Zd Ze d d „ƒZ e dd„ƒZ e dd„ƒZ e dd„ƒZ dS)Ú TimeoutTestcCs| tjj¡dSr)rrrrr,rrrr-szTimeoutTest.setUpcCsn| t ¡¡tj}tj|dd8t|ƒ}| |j ¡| |j j j   ¡¡Wdƒn1s`0YdS©N©rY)Ú assertIsNonerXÚgetdefaulttimeoutrrrrr rr$r!ÚrawÚ_sockÚ gettimeout©r&r'ÚurrrÚtest_http_basic s  zTimeoutTest.test_http_basicc Cs’| t ¡¡tj}t |¡`t d¡z"t|ƒ}|  |j ¡Wt d¡n t d¡0|  |j j j ¡d¡Wdƒn1s„0YdS©Né<)rkrXrlrrrrÚsetdefaulttimeoutr rr$rCr!rmrnrorprrrÚtest_http_default_timeouts  z%TimeoutTest.test_http_default_timeoutc Cs”| t ¡¡tj}t |¡bt d¡z&t|dd}|  |j ¡Wt d¡n t d¡0| |j j j  ¡¡Wdƒn1s†0YdS©Nrtrj)rkrXrlrrrrrur rr$r!rmrnrorprrrÚtest_http_no_timeouts   z TimeoutTest.test_http_no_timeoutcCsbtj}t |¡>t|dd}| |j¡| |jj j   ¡d¡Wdƒn1sT0YdS)Néxrj) rrrrr rr$rCr!rmrnrorprrrÚtest_http_timeout*s    zTimeoutTest.test_http_timeoutzftp://www.pythontest.net/cCsn| t ¡¡tj|jdd<t|jƒ}| |j¡| |j j j j   ¡¡Wdƒn1s`0YdSri) rkrXrlrrÚFTP_HOSTr rr$r!rmrnro©r&rqrrrÚtest_ftp_basic3s   zTimeoutTest.test_ftp_basicc Cs’| t ¡¡t |j¡dt d¡z$t|jƒ}| |j ¡Wt d¡n t d¡0|  |j j j j  ¡d¡Wdƒn1s„0YdSrs)rkrXrlrrr{rur rr$rCr!rmrnror|rrrÚtest_ftp_default_timeout;s  z$TimeoutTest.test_ftp_default_timeoutc Cs”| t ¡¡t |j¡ft d¡z(t|jdd}| |j ¡Wt d¡n t d¡0| |j j j j   ¡¡Wdƒn1s†0YdSrw)rkrXrlrrr{rur rr$r!rmrnror|rrrÚtest_ftp_no_timeoutGs zTimeoutTest.test_ftp_no_timeoutcCsbt |j¡Bt|jdd}| |j¡| |jjjj   ¡d¡Wdƒn1sT0YdSrw) rrr{r rr$rCr!rmrnror|rrrÚtest_ftp_timeoutSs zTimeoutTest.test_ftp_timeoutN)rrrr-rrrvrxrzr{rer}r~rr€rrrrrhs     rhÚ__main__)rfÚtestrZ test.supportrZtest.test_urllib2rr9rXZ urllib.errorrZurllib.requestr[ZrequiresrrZskipIfÚenvironrerr>r.r/r ZTestCaserrr+rhrÚmainrrrrÚs0      ÿÿ'%V