a ze2@sddlZddlmZddlmZddlmZddlZddlZddl Z ddl Z ddl Z e dddZdd Zed ejvd Zee jje jjZGd d d ejZGdddejZGdddejZGdddejZedkredS)N)support) socket_helper)sanepathname2urlZnetworkc Os`tdD]N}z||i|WS|yT}z|}WYd}~qWYd}~qd}~00q|dS)N)range)funcexcargskwargsielast_excrH/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_urllib2net.py _retry_thrices $rcsfdd}|S)Ncstg|Ri|SN)r)r r rrrrwrappedsz(_wrap_with_retry_thrice..wrappedr)rrrrrr_wrap_with_retry_thricesrZTRAVISz%bpo-35411: skip FTP test on Travis CIc@seZdZdZdS) AuthTestsz&Tests urllib2 authentication features.N)__name__ __module__ __qualname____doc__rrrrr*src@seZdZddZdS)CloseSocketTestcCsp|tjjtj}t|>t|}|j }| |j | | |j Wdn1sb0YdSr) addCleanupurllibrequest urlcleanupr TEST_HTTP_URLrtransient_internet_urlopen_with_retryfp assertFalseclosedclose assertTrue)selfurlresponsesockrrr test_closeSs  zCloseSocketTest.test_closeN)rrrr+rrrrrQsrc@sdeZdZddZeddZddZddZd d Zd d Z e d ddZ dddZ ddZdS)OtherNetworkTestscCsdSrrr'rrrsetUpbszOtherNetworkTests.setUpcCs&dddtjjfg}|||dS)Nzftp://www.pythontest.net/READMEz*ftp://www.pythontest.net/non-existent-file)rerrorURLError _test_urls_extra_handlers)r'urlsrrrtest_ftpks zOtherNetworkTests.test_ftpc Cstj}t|d}zV|d|dttj|ddt j j fg}|j || ddWt|n t|0|tt jjddS)Nwz hi there zfile:zfile:///nonsensename/etc/passwdT)retryz./relative_path/to/file)rTESTFNopenwriter%rospathabspathrr/r0r1r2removeZ assertRaises ValueErrorrurlopen)r'r7fr3rrr test_filets  zOtherNetworkTests.test_filecCsZd}t|8tj|}tj|}||dWdn1sL0YdS)Nz)http://www.pythontest.net/index.html#fragrr rrRequestr? assertEqualgeturl)r'Z urlwith_fragreqresrrrtest_urlwithfrags    z"OtherNetworkTests.test_urlwithfragcCsZd}t|8tj|}tj|}||dWdn1sL0YdS)Nz*http://www.pythontest.net/redir/with_frag/z)http://www.pythontest.net/elsewhere/#fragrB)r'Zredirect_url_with_fragrFrGrrrtest_redirect_url_withfrags    z,OtherNetworkTests.test_redirect_url_withfragcCstj}t|tj}tj|}|| | || | | | d| dd| |||ddWdn1s0YdS)Nz User-agentz User-Agentz Test-Agent)rrrr rr build_openerrCr#Z header_itemsr8r&Z has_headerZ add_headerrDZ get_header)r'r(openerrrrrtest_custom_headerss      z%OtherNetworkTests.test_custom_headersz XXX: http://www.imdb.com is gonec Csd}t|z0tj|}Wdn1s40YWnty\|dYn 0||tj|}|}||Wdn1s0YdS)Nzhttp://www.imdb.comzOurlopen failed for site not sending Connection:close) rr rrr?r>Zfailr&read)r'ZURLrGrFrrrtest_sites_no_connection_closes "   z0OtherNetworkTests.test_sites_no_connection_closeTc Csddl}ddl}|dj}tjj|j}|r)fileg?)!timelogging getLoggerdebugrrrJr8rr/r0ZsubTest isinstancetuplerr rZINTERNET_TIMEOUTOSErrortypeZassertIsInstanceZtime_outZsocket_peer_resetZioerror_peer_resetrMlensockettimeoutprintsysstderrr%sleep)r'r3handlersr6rPrQrSr?r(rFZ expected_errr@errmsgbufrrrr1sB    t(zOtherNetworkTests._test_urlscCs2g}tj}||j|d|||S)N)rrZCacheFTPHandlerr clear_cacheZ setTimeoutappend)r'r_Zcfhrrrr2s     z!OtherNetworkTests._extra_handlersN)T)rrrr.skip_ftp_test_on_travisr4rArHrIrLunittestskiprNr1r2rrrrr,as  -   'r,c@sheZdZddZddZddZddZd d Zd Ze d d Z e ddZ e ddZ e ddZ dS) TimeoutTestcCs|tjjdSr)rrrrr-rrrr.szTimeoutTest.setUpcCsn|ttj}tj|dd8t|}||j ||j j j Wdn1s`0YdSNrZ) assertIsNonerYgetdefaulttimeoutrrrr r!rr%r"raw_sock gettimeoutr'r(urrrtest_http_basic s  zTimeoutTest.test_http_basicc Cs|ttj}t|`tdz"t|}| |j Wtdn td0| |j j jdWdn1s0YdSN<)rlrYrmrrrr setdefaulttimeoutr!rr%rDr"rnrorprqrrrtest_http_default_timeouts  z%TimeoutTest.test_http_default_timeoutc Cs|ttj}t|btdz&t|dd}| |j Wtdn td0||j j j Wdn1s0YdSNrurk)rlrYrmrrrr rvr!rr%r"rnrorprqrrrtest_http_no_timeouts   z TimeoutTest.test_http_no_timeoutcCsbtj}t|>t|dd}||j||jj j dWdn1sT0YdS)Nxrk) rrrr r!rr%rDr"rnrorprqrrrtest_http_timeout*s    zTimeoutTest.test_http_timeoutzftp://www.pythontest.net/cCsn|ttj|jdd<t|j}||j||j j j j Wdn1s`0YdSrj) rlrYrmrr FTP_HOSTr!rr%r"rnrorpr'rrrrrtest_ftp_basic3s   zTimeoutTest.test_ftp_basicc Cs|tt|jdtdz$t|j}||j Wtdn td0| |j j j j dWdn1s0YdSrt)rlrYrmrr r|rvr!rr%rDr"rnrorpr}rrrtest_ftp_default_timeout;s  z$TimeoutTest.test_ftp_default_timeoutc Cs|tt|jftdz(t|jdd}||j Wtdn td0||j j j j Wdn1s0YdSrx)rlrYrmrr r|rvr!rr%r"rnrorpr}rrrtest_ftp_no_timeoutGs zTimeoutTest.test_ftp_no_timeoutcCsbt|jBt|jdd}||j||jjjj dWdn1sT0YdSrx) rr r|r!rr%rDr"rnrorpr}rrrtest_ftp_timeoutSs zTimeoutTest.test_ftp_timeoutN)rrrr.rsrwryr{r|rfr~rrrrrrrris     ri__main__)rgtestrZ test.supportrZtest.test_urllib2rr:rYZ urllib.errorrZurllib.requestr\ZrequiresrrZskipIfenvironrfrr?r/r0r!ZTestCaserrr,rirmainrrrrs0      '%V