a ze"%@sddlZddlmZddlmZddlZddlZddlZddl Zddl Z ddl Z ddl Z edGdddejZGdddejZGd d d ejZed kredS) N)support) socket_helperZnetworkc@s$eZdZddZddZddZdS)URLTimeoutTestcCsttjdSN)socketsetdefaulttimeoutrZINTERNET_TIMEOUTselfr G/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_urllibnet.pysetUpszURLTimeoutTest.setUpcCstddSr)rrrr r r tearDownszURLTimeoutTest.tearDowncCsb|tjjtjtjj}t |&tj tj}| Wdn1sT0YdSr) addCleanupurllibrequest urlcleanupparseurlparserZ TEST_HTTP_URLnetlocrtransient_interneturlopenread)r domainfr r r testURLreads  zURLTimeoutTest.testURLreadN)__name__ __module__ __qualname__r r rr r r r rsrc@sZeZdZdZdZddZejddZddZ d d Z d d Z d dZ ddZ ddZdS)urlopenNetworkTestsaATests 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. setUp is not used for always constructing a connection to http://www.pythontest.net/ since there a few tests that don't use that address and making a connection is expensive enough to warrant minimizing unneeded connections. http://www.pythontest.net/cCs|tjjdSrrrrrrr r r r 5szurlopenNetworkTests.setUpc osf|d}t|@tjj|i|}z|VW|n |0Wdn1sX0YdSNr)rrrrrclose)r argskwargsresourcerr r r r9s  zurlopenNetworkTests.urlopencCs`||j@}dD]}|t||d|q||dWdn1sR0YdS)N)rreadline readlinesfilenor"infogeturlz3object returned from urlopen lacks the %s attributezcalling 'read' failed)rurl assertTruehasattrr)r open_urlattrr r r test_basicCs zurlopenNetworkTests.test_basiccCsT||j4}||td||tdWdn1sF0YdS)Nz readline did not return a stringzreadlines did not return a list)rr,assertIsInstancer'bytesr(list)r r/r r r test_readlinesLs  z"urlopenNetworkTests.test_readlinescCsZ||j:}|}||tjjd||dWdn1sL0YdS)NzEobject returned by 'info' is not an instance of email.message.MessageZhtml) rr,r*r2emailmessageMessage assertEqualZget_content_subtype)r r/Zinfo_objr r r test_infoTs  zurlopenNetworkTests.test_infocCsF||j&}|}|||jWdn1s80YdSr)rr,r+r9)r r/Z gotten_urlr r r test_geturl]szurlopenNetworkTests.test_geturlc Cs|jd}t|v|t tj|}Wdn1sF0Yz| }W| n | 0| |dWdn1s0YdS)NZ XXXinvalidXXXi) r,rrZ assertWarnsDeprecationWarningrrZFancyURLopeneropenZgetcoder"r9)r ZURLr/coder r r test_getcodecs   . z urlopenNetworkTests.test_getcodecCs|d}zt|Wnty$Yn0|d|d}|jt|d"tjd|Wdn1sn0YdS)Nzsadflkjsasf.i.nvali.d.z&%r should not resolve for test to workzuopening an invalid URL did not raise OSError; can be caused by a broken DNS server (e.g. returns 404 or hijacks page)msgz http://{}/) r gethostbynameOSErrorZskipTestZ assertRaisesrrrformat)r Z bogus_domainZfailure_explanationr r r test_bad_addressos z$urlopenNetworkTests.test_bad_addressN)rrr__doc__r,r contextlibcontextmanagerrr1r5r:r;r?rEr r r r r$s    rc@sReZdZdZddZejddZddZdd Z d d Z d Z d dZ ddZ dS)urlretrieveNetworkTestsz3Tests urllib.request.urlretrieve using the network.cCs|tjjdSrr rr r r r szurlretrieveNetworkTests.setUpc osr|d}t|Ltjj|i|\}}z||fVWt|n t|0Wdn1sd0YdSr!)rrrr urlretrieverunlink)r r#r$r% file_locationr*r r r rJs   z#urlretrieveNetworkTests.urlretrievec Cs||jb\}}|tj|dt|d }||dWdn1sV0YWdn1st0YdS)Nz9file location returned by urlretrieve is not a valid pathrbz=reading from the file location returned by urlretrieve failed)rJlogor-ospathexistsr=rr rLr*rr r r r1s z"urlretrieveNetworkTests.test_basicc Cs||jtjn\}}||tj|tj|t |d }|| dWdn1sf0YWdn1s0YdS)NrMz"reading from temporary file failed) rJrNrZTESTFNr9r-rOrPrQr=rrRr r r test_specified_paths z+urlretrieveNetworkTests.test_specified_pathcCsF||j&\}}||tjjdWdn1s80YdS)Nz0info is not an instance of email.message.Message)rJrNr2r6r7r8)r rLr*r r r test_headers z#urlretrieveNetworkTests.test_headerrc Cst||jT\}}|d}d}zt||Wn tyP|d|Yn0Wdn1sf0YdS)NZDatez%a, %d %b %Y %H:%M:%S GMTzDate value not in %r format)rJrNgettimestrptime ValueErrorZfail)r rL fileheadersZ datevalueZ dateformatr r r test_data_headers  z(urlretrieveNetworkTests.test_data_headercsgfdd}|j|j|d \}}t|d}Wdn1sF0Yt}|jtddd|ddd|jdddd |d|dd ||d d |d d D}|jddh|d|d|jd ddd|d|ddS)Ncs|||fdSr)append)Zblocks block_sizeZ total_sizerecordsr r recording_reporthookszEurlretrieveNetworkTests.test_reporthook..recording_reporthook)Z reporthookzContent-LengthzKThere should always be two calls; the first one before the transfer starts.r@rzblock size can't be 0 in %scSsh|]\}}}|qSr r ).0_r\r r r z:urlretrieveNetworkTests.test_reporthook..zblock sizes in %s must be equalz9number of blocks * block size must be >= total size in %s)rJrNintreprZ assertGreaterlenr9ZassertGreaterEqual)r r_rLrYZ expected_sizeZ records_reprZ block_sizesr r]r test_reporthooks, *z'urlretrieveNetworkTests.test_reporthookN)rrrrFr rGrHrJr1rSrTrNrZrjr r r r rIs    rI__main__)ZunittesttestrZ test.supportrrGr urllib.parserZurllib.requestrOZ email.messager6rVZrequiresZTestCaserrrIrmainr r r r s   rO