a 5êdg¬ã@s:dZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl mZddlZz ddlZWney~dZYn0ddlZddlZddlmZmZddlmZddlZdd„Zdad5d d „Zd d „Zd6dd„ZGdd„deƒZ Gdd„deƒZ!Gdd„de j"ƒZ#Gdd„de j"ƒZ$Gdd„de j"ƒZ%Gdd„de j"e e!ƒZ&Gdd„de j"ƒZ'Gdd„de j"ƒZ(Gd d!„d!e j"e ƒZ)Gd"d#„d#e j"ƒZ*Gd$d%„d%e j"ƒZ+Gd&d'„d'e j"ƒZ,Gd(d)„d)e j"ƒZ-Gd*d+„d+e j"ƒZ.Gd,d-„d-e e j"ƒZ/Gd.d/„d/e j"ƒZ0Gd0d1„d1e j"ƒZ1Gd2d3„d3e j"ƒZ2e3d4kr6e  4¡dS)7z;Regression tests for what was in Python 2's "urllib" moduleéN)Úpatch)Úsupport)Ú url2pathnameÚ pathname2url)Ú b64encodecCs4tt|ƒƒdd… ¡}t|ƒdkr,d|}d|S)z!Escape char as RFC 2396 specifieséNéz0%sú%)ÚhexÚordÚupperÚlen)ÚcharZhex_repr©rú,/usr/local/lib/python3.9/test/test_urllib.pyÚ hexescapes rcCsN|durtjj|d}nts(tƒ}|ant}|dur>| |¡S| ||¡SdS)z.urlopen(url [, data]) -> open file-like objectN)Úproxies)ÚurllibÚrequestÚFancyURLopenerÚ _urlopenerÚopen)ÚurlÚdatarÚopenerrrrÚurlopen$s rcCs<t dtf¡tj ¡WdƒS1s.0YdS)Nz8FancyURLopener style of invoking requests is deprecated.)rÚcheck_warningsÚDeprecationWarningrrrrrrrr4s ÿÿrFcs:G‡fdd„dtjƒ‰G‡‡fdd„dtjjƒ‰|ˆ_ˆS)Ncs@eZdZdZ‡fdd„Zdd„Zd dd„Zdd d „Zd d „ZdS)zfakehttp..FakeSocketrcs |ˆ_dS©N)Úbuf©Úselfr©ÚFakeHTTPConnectionrrÚsendall?sz$fakehttp..FakeSocket.sendallc_s|jd7_|S)Nr)Úio_refs)r!ÚargsÚkwdsrrrÚmakefileBsz%fakehttp..FakeSocket.makefileNcSs|jr dStj ||¡S©Nó)ÚclosedÚioÚBytesIOÚread)r!Zamtrrrr.Fsz!fakehttp..FakeSocket.readcSs|jr dStj ||¡Sr))r+r,r-Úreadline)r!Úlengthrrrr/Ksz%fakehttp..FakeSocket.readlinecSs(|jd8_|jdkr$tj |¡dS)Nrr)r%r,r-Úclose©r!rrrr1Ps z"fakehttp..FakeSocket.close)N)N) Ú__name__Ú __module__Ú __qualname__r%r$r(r.r/r1rr"rrÚ FakeSocket<s    r6cs(eZdZdZ‡fdd„Z”r$dd„ZdS)z$fakehttp..FakeHTTPConnectionNcsˆ|jƒ|_|jt|ƒ_dSr)ÚfakedataÚsockÚtypeZfakesockr2)r6rrÚconnectZs z,fakehttp..FakeHTTPConnection.connectcSsdSrrr2rrrr1csz*fakehttp..FakeHTTPConnection.close)r3r4r5rr:r1r)r6Ú mock_closerrr#Us r#)r,r-ÚhttpÚclientÚHTTPConnectionr7)r7r;r)r#r6r;rÚfakehttp;sr?c@seZdZddd„Zdd„ZdS)Ú FakeHTTPMixinFcCs"t||d}tjj|_|tj_dS)N©r;)r?r<r=r>Ú_connection_class)r!r7r;Zfake_http_classrrrr?ks  zFakeHTTPMixin.fakehttpcCs|jtj_dSr)rBr<r=r>r2rrrÚ unfakehttppszFakeHTTPMixin.unfakehttpN)F)r3r4r5r?rCrrrrr@js r@c@seZdZdd„Zdd„ZdS)Ú FakeFTPMixincCs&Gdd„dtƒ}tjj|_|tj_dS)Nc@s&eZdZd dd„Zdd„Zdd„ZdS) z,FakeFTPMixin.fakeftp..FakeFtpWrapperNTcSsdSrr)r!ÚuserÚpasswdÚhostÚportÚdirsÚtimeoutZ persistentrrrÚ__init__wsz5FakeFTPMixin.fakeftp..FakeFtpWrapper.__init__cSs t ¡dfS)Nr)r,r-)r!Úfiler9rrrÚretrfile{sz5FakeFTPMixin.fakeftp..FakeFtpWrapper.retrfilecSsdSrrr2rrrr1~sz2FakeFTPMixin.fakeftp..FakeFtpWrapper.close)NT)r3r4r5rKrMr1rrrrÚFakeFtpWrappervs ÿ rN)ÚobjectrrÚ ftpwrapperÚ_ftpwrapper_class)r!rNrrrÚfakeftpus zFakeFTPMixin.fakeftpcCs|jtj_dSr)rQrrrPr2rrrÚ unfakeftp„szFakeFTPMixin.unfakeftpN)r3r4r5rRrSrrrrrDtsrDc@seZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd"S)#Úurlopen_FileTestsz©Test urlopen() opening a temporary file. Try to test as much functionality as possible so as to cut down on reliance on connecting to the Net for testing. cCsptd|jjdƒ|_ttjdƒ}z| |j¡W| ¡n | ¡0tj|_ t j   |j ¡|_ td|j ƒ|_dS)Nztest_urllib: %s ÚasciiÚwbúfile:%s)ÚbytesÚ __class__r3ÚtextrrÚTESTFNÚwriter1ÚpathnamerÚparseÚquoteÚquoted_pathnamerÚ returned_obj)r!ÚfrrrÚsetUps ÿ zurlopen_FileTests.setUpcCs|j ¡t tj¡dS)zShut down the open objectN)rar1ÚosÚremoverr[r2rrrÚtearDowns zurlopen_FileTests.tearDowncCs&dD]}| t|j|ƒd|¡qdS)N) r.r/Ú readlinesÚfilenor1ÚinfoÚgeturlÚgetcodeÚ__iter__ú/object returned by urlopen() lacks %s attribute)Ú assertTrueÚhasattrra©r!ÚattrrrrÚtest_interface¢s ÿÿz urlopen_FileTests.test_interfacecCs| |j|j ¡¡dSr)Ú assertEqualrZrar.r2rrrÚ test_readªszurlopen_FileTests.test_readcCs,| |j|j ¡¡| d|j ¡d¡dS)Nr*zKcalling readline() after exhausting the file did not return an empty string)rsrZrar/r2rrrÚ test_readline­sÿzurlopen_FileTests.test_readlinecCs4|j ¡}| t|ƒdd¡| |d|jd¡dS)Nrz.readlines() returned the wrong number of linesrz"readlines() returned improper text)rargrsr rZ)r!Z lines_listrrrÚtest_readlines³s  ÿÿz urlopen_FileTests.test_readlinescCs:|j ¡}| |td¡| t |t|jƒ¡|jd¡dS)Nzfileno() did not return an intzTReading on the file descriptor returned by fileno() did not return the expected text) rarhÚassertIsInstanceÚintrsrdr.r rZ)r!Zfile_numrrrÚ test_filenoºs  ÿzurlopen_FileTests.test_filenocCs|j ¡dSr)rar1r2rrrÚ test_closeÁszurlopen_FileTests.test_closecCs| |jjtjj¡dSr)rwraZheadersÚemailÚmessageÚMessager2rrrÚ test_headersÆszurlopen_FileTests.test_headerscCs| |jj|j¡dSr)rsrarr`r2rrrÚtest_urlÉszurlopen_FileTests.test_urlcCs| |jj¡dSr)Ú assertIsNoneraÚstatusr2rrrÚ test_statusÌszurlopen_FileTests.test_statuscCs| |j ¡tjj¡dSr)rwrarir{r|r}r2rrrÚ test_infoÏszurlopen_FileTests.test_infocCs| |j ¡|j¡dSr)rsrarjr`r2rrrÚ test_geturlÒszurlopen_FileTests.test_geturlcCs| |j ¡¡dSr)r€rarkr2rrrÚ test_getcodeÕszurlopen_FileTests.test_getcodecCs|jD]}| ||j¡qdSr)rarsrZ)r!ÚlinerrrÚ test_iterØs zurlopen_FileTests.test_itercCs| ttjjd|j¡dS)Nz./)Ú assertRaisesÚ ValueErrorrrrr]r2rrrÚtest_relativelocalfileász(urlopen_FileTests.test_relativelocalfileN)r3r4r5Ú__doc__rcrfrrrtrurvryrzr~rr‚rƒr„r…r‡rŠrrrrrTˆs"  rTc@sDeZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dS)Ú ProxyTestscCs6t ¡|_ttjƒD]}d| ¡vr|j |¡qdS)NÚproxy)rZEnvironmentVarGuardÚenvÚlistrdÚenvironÚlowerÚunset)r!Úkrrrrcçs  zProxyTests.setUpcCs|j ¡|`dSr)rŽÚ__exit__r2rrrrfïs zProxyTests.tearDowncCsp|j dd¡tj ¡}| d|d¡|j dd¡| tj d¡¡| tj d¡¡| tj d¡¡dS)NÚNO_PROXYÚ localhostÚnoú0localhost, anotherdomain.com, newdomain.com:1234úanotherdomain.comúanotherdomain.com:8888únewdomain.com:1234)rŽÚsetrrÚgetproxies_environmentrsrnÚproxy_bypass_environment©r!rrrrÚ+test_getproxies_environment_keep_no_proxiesôs z6ProxyTests.test_getproxies_environment_keep_no_proxiesc Csˆzh|j dd¡tj ¡}| d|d¡|j dd¡tj ¡}| d|¡W|j d¡|j d¡n|j d¡|j d¡0dS)NÚ HTTP_PROXYúhttp://somewhere:3128r<ZREQUEST_METHODÚGET)rŽrœrrrrsÚ assertNotInr’rŸrrrÚtest_proxy_cgi_ignoreÿs   ÿ z ProxyTests.test_proxy_cgi_ignorecCsÞtjj}|j dd¡| |dƒ¡| |dƒ¡| |dƒ¡| |dƒ¡| |dƒ¡| |dƒ¡| |d ƒ¡| |d ƒ¡| |d ƒ¡| |d ƒ¡| |d ƒ¡| |dƒ¡| |dƒ¡| |dƒ¡dS)Nr•z8localhost, anotherdomain.com, newdomain.com:1234, .d.o.tr–Z LocalHostZ LOCALHOSTz .localhostr›z.newdomain.com:1234z foo.d.o.tzd.o.tršz.anotherdomain.com:8888zwww.newdomain.com:1234Z prelocalhostú newdomain.comznewdomain.com:1235©rrržrŽrœrnÚ assertFalse©r!ZbypassrrrÚ(test_proxy_bypass_environment_host_match s$ÿz3ProxyTests.test_proxy_bypass_environment_host_matchcCsntjj}|j dd¡| |dƒ¡| |dƒ¡|j dd¡| |dƒ¡| |dƒ¡| |dƒ¡dS)Nr•Ú*r¦r›z*, anotherdomain.comr™r§r©rrrÚ*test_proxy_bypass_environment_always_matchsz5ProxyTests.test_proxy_bypass_environment_always_matchcCsDtjj}|j dd¡| |dƒ¡| |dƒ¡| |dƒ¡dS)Nr•r˜z localhost zanotherdomain.com:8888 znewdomain.com:1234 )rrržrŽrœr¨r©rrrÚ%test_proxy_bypass_environment_newline(sÿz0ProxyTests.test_proxy_bypass_environment_newlineN) r3r4r5rcrfr r¥rªr¬r­rrrrrŒås   rŒc@s$eZdZdd„Zdd„Zdd„ZdS)ÚProxyTests_withOrderedEnvcCstj|_t ¡t_dSr)rdrÚ _saved_envÚ collectionsÚ OrderedDictr2rrrrc3szProxyTests_withOrderedEnv.setUpcCs |jt_dSr)r¯rdrr2rrrrf9sz"ProxyTests_withOrderedEnv.tearDowncCsdtjd<dtjd<| tj d¡¡| tj d¡¡dtjd<dtjd<tj ¡}| i|¡d tjd<d tjd<| tj d¡¡| tj d ¡¡| tj d ¡¡| tj d ¡¡| tj d¡¡dtjd<dtjd<tj ¡}| d|d¡dS)NÚZno_proxyr–ZNo_ProxyZ arbitraryZ http_proxyr¢r¡z%localhost, noproxy.com, my.proxy:1234zxyz.comznoproxy.com:5678z my.proxy:1234zmy.proxyzhttp://somewhereelse:3128Z Http_Proxyr<) rdrr¨rrržrrsrnrŸrrrÚ,test_getproxies_environment_prefer_lowercase<s&           zFProxyTests_withOrderedEnv.test_getproxies_environment_prefer_lowercaseN)r3r4r5rcrfr³rrrrr®1sr®c@seZdZdZdd„Zdd„Zdd„Ze e d¡d d „ƒZ e e d¡d d „ƒZ e e d¡d d„ƒZ e e d¡dd„ƒZ dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Ze ejd'd(¡d)d*„ƒZd+d,„Zd-d.„Zd/d0„Z e e d¡d1d2„ƒZ!d3S)4Úurlopen_HttpTestsz.Test urlopen() opening a fake http connection.cCsv| d|d¡zTtdƒ}| | ¡d¡| | ¡d¡| | ¡d¡| | ¡d¡W| ¡n | ¡0dS)NsHTTP/s 200 OK Hello!úhttp://python.org/óHello!r*éÈ©r?rrsr/rjrkrC)r!ÚverÚfprrrÚ check_readXszurlopen_HttpTests.check_readcCsFd}| d¡z(tj |¡}| | ¡|¡W| ¡n | ¡0dS)Nz-http://docs.python.org/library/urllib.html#OKóHTTP/1.1 200 OK Hello!)r?rrrrsrjrC)r!rrºrrrÚtest_url_fragmentcs   z#urlopen_HttpTests.test_url_fragmentcCs<| d¡z"tdƒ}| |jj¡W| ¡n | ¡0dS)Nr¼úhttp://www.python.org)r?rrnrºZ will_closerC)r!ÚresprrrÚtest_willclosems  z urlopen_HttpTests.test_willclosezssl module requiredc CsttddƒƒdgD]ø}t|ƒ}d|›d}| d¡zÊt|ƒ dd¡}tjj}|  |d |›¡"t j   d |›¡Wdƒn1sŠ0Y|  |d |›¡"t j   d |›¡Wdƒn1sÎ0Yt d |›ƒ}|  || ¡¡W| ¡q| ¡0qdS) Nré!éz//localhost:7777/testú/óHTTP/1.1 200 OK Hello.ú\ú\\úcontain control.*úhttp:úhttps:)rÚrangeÚchrr?ÚreprÚreplacer<r=Ú InvalidURLÚassertRaisesRegexrrrr¤rjrC)r!Úchar_norÚschemeless_urlÚescaped_char_reprrÎr¿rrrÚ(test_url_path_with_control_char_rejectedus$   ÿ0 ÿ0z:urlopen_HttpTests.test_url_path_with_control_char_rejectedcCsø| d¡d}d|d}zÎtjj}| |d¡"tj d|›¡Wdƒn1sX0Y| |d¡"tj d|›¡Wdƒn1s–0Ytd|›ƒ}| d |  ¡¡| d |  ¡¡| d |  ¡¡W|  ¡n |  ¡0dS) NrÄz:localhost:7777?a=1 HTTP/1.1 X-injected: header TEST: 123ú//ú:8080/test/?test=az*contain control.*\\r.*(found at least . .)rÈúcontain control.*\\nrÉú ú Ú ) r?r<r=rÎrÏrrrr¤rjrC)r!rGrÑrÎr¿rrrÚ4test_url_path_with_newline_header_injection_rejecteds   ÿ00zFurlopen_HttpTests.test_url_path_with_newline_header_injection_rejectedc CsìttddƒƒdgD]Ò}t|ƒ}d|›d}| d¡z¤t|ƒ dd¡}tjj}|  |d |›¡t d |›ƒWdƒn1s†0Y|  |d |›¡t d |›ƒWdƒn1sÆ0YW|  ¡q|  ¡0qdS) NrrÁrÂz //localhostz/test/rÄrÅrÆrÇrÈrÉ) rrÊrËr?rÌrÍr<r=rÎrÏrrC)r!rÐrrÑrÒrÎrrrÚ(test_url_host_with_control_char_rejectedªs   ÿ,.z:urlopen_HttpTests.test_url_host_with_control_char_rejectedcCs²| d¡d}d|d}zˆtjj}| |d¡td|›ƒWdƒn1sT0Y| |d¡td|›ƒWdƒn1sŽ0YW| ¡n | ¡0dS) NrÄzlocalhost X-injected: header rÔrÕzcontain control.*\\rrÈrÖrÉ)r?r<r=rÎrÏrrC)r!rGrÑrÎrrrÚ4test_url_host_with_newline_header_injection_rejected»s  ÿ,.zFurlopen_HttpTests.test_url_host_with_newline_header_injection_rejectedcCs| d¡dS)Ns0.9©r»r2rrrÚ test_read_0_9Êszurlopen_HttpTests.test_read_0_9cCs| d¡dS)Ns1.0rÝr2rrrÚ test_read_1_0Ïszurlopen_HttpTests.test_read_1_0cCs| d¡dS)Ns1.1rÝr2rrrÚ test_read_1_1Òszurlopen_HttpTests.test_read_1_1cCs8|jdddz| ttd¡W| ¡n | ¡0dS)NsÎHTTP/1.1 401 Authentication Required Date: Wed, 02 Jan 2008 03:03:54 GMT Server: Apache/1.3.33 (Debian GNU/Linux) mod_ssl/2.8.22 OpenSSL/0.9.7e Connection: close Content-Type: text/html; charset=iso-8859-1 TrArµ©r?rˆÚOSErrorrrCr2rrrÚtest_read_bogusÕs ûz!urlopen_HttpTests.test_read_boguscCsf|jdddzHd}| tjj|¡tdƒWdƒn1sB0YW| ¡n | ¡0dS)NsöHTTP/1.1 302 Found Date: Wed, 02 Jan 2008 03:03:54 GMT Server: Apache/1.3.33 (Debian GNU/Linux) mod_ssl/2.8.22 OpenSSL/0.9.7e Location: file://guidocomputer.athome.com:/python/license Connection: close Content-Type: text/html; charset=iso-8859-1 TrAzRedirection to url 'file:rµ)r?rÏrÚerrorÚ HTTPErrorrrC)r!ÚmsgrrrÚtest_invalid_redirectâsú(z'urlopen_HttpTests.test_invalid_redirectc CsNttƒjƒD]<}|jdddz| tjjtd¡W|  ¡q |  ¡0q dS)Ns_HTTP/1.1 302 Found Location: file://guidocomputer.athome.com:/python/license Connection: close TrAúhttp://something) rÊrZmaxtriesr?rˆrrärårrC)r!ÚirrrÚtest_redirect_limit_independentòsý ÿz1urlopen_HttpTests.test_redirect_limit_independentcCs4| d¡z| ttd¡W| ¡n | ¡0dS)Nr*rèrár2rrrÚtest_empty_sockets z#urlopen_HttpTests.test_empty_socketcCsV| tjj¡}tdƒWdƒn1s,0Y| |jj¡| |jj¡dS)Nz/file://localhost/a/file/which/doesnot/exists.py) rˆrräÚURLErrorrrnÚ exceptionÚfilenameÚreason©r!ÚerrrÚtest_missing_localfile s&z(urlopen_HttpTests.test_missing_localfilec Csàt ¡\}}d| tjjd¡}z\| tj |¡¡t|ƒ}| |¡Wdƒn1s\0YWt  |¡t  |¡nt  |¡t  |¡0|  tj |¡¡|  t jj¡t|ƒWdƒn1sÒ0YdS)Nzfile://localhost/rÃ)ÚtempfileÚmkstemprÍrdÚpathÚseprnÚexistsrr1Úunlinkr¨rˆrrärì)r!ÚfdZtmp_fileZ tmp_fileurlZfobjrrrÚtest_file_notexistss  *  ÿ  z%urlopen_HttpTests.test_file_notexistscCsZd}| tjj¡}t|ƒWdƒn1s00Y| |jj¡| |jj ¡dS)Nz ftp:///path© rˆrrärìrr¨rírîrnrï)r!Z test_ftp_urlrñrrrÚtest_ftp_nohosts &z!urlopen_HttpTests.test_ftp_nohostcCsV| tjj¡}tdƒWdƒn1s,0Y| |jj¡| |jj ¡dS)Nz.ftp://localhost/a/file/which/doesnot/exists.pyrûrðrrrÚtest_ftp_nonexisting%s&z&urlopen_HttpTests.test_ftp_nonexistingZ MAXFTPCACHErcCsH| ¡z0tj ddddg¡tjjd<tdƒW| ¡n | ¡0dS)NrEÚpassr–éÚtestzftp://localhost)rRrrrPZftpcacherrSr2rrrÚtest_ftp_cache_pruning+s  z(urlopen_HttpTests.test_ftp_cache_pruningcCsn| d¡zTtdƒ}| | ¡d¡| | ¡d¡| | ¡d¡| | ¡d¡W| ¡n | ¡0dS)NóHTTP/1.0 200 OK Hello!zhttp://user:pass@python.org/r¶r*r·r¸)r!rºrrrÚtest_userpass_inurl4s z%urlopen_HttpTests.test_userpass_inurlcCs°| d¡z–d}d |¡}tjj}dt| d¡ƒ d¡}t|ƒ}|  ||j  d¡¡|  |  ¡d¡|  |  ¡d¡|  | ¡|¡|  | ¡d ¡W| ¡n | ¡0dS) Nrza b:c dzhttp://{}@python.org/zAuthorization: Basic %s ÚASCIIzUTF-8r¶r*r·)r?Úformatr<r=r>rÚencodeÚdecoderÚassertInrrsr/ZassertNotEqualrjrkrC)r!ZuserpassrZfakehttp_wrapperZ authorizationrºrrrÚtest_userpass_inurl_w_spaces?s  ÿz.urlopen_HttpTests.test_userpass_inurl_w_spacescCs<t dtf¡tj ¡Wdƒn1s.0YdS©Nr²)rrrrrÚ URLopenerr2rrrÚtest_URLopener_deprecationRsz,urlopen_HttpTests.test_URLopener_deprecationc Csvt ¡}t dtf¡L| t¡"tjj dd|dWdƒn1sJ0YWdƒn1sh0YdS)Nr²zhttps://localhostz/nonexistent/path)ZcafileÚcontext) ÚsslZcreate_default_contextrrrrˆr‰rrr)r!r rrrÚtest_cafile_and_contextVs  ÿz)urlopen_HttpTests.test_cafile_and_contextN)"r3r4r5r‹r»r½rÀÚunittestÚ skipUnlessrrÓrÚrÛrÜrÞrßràrãrçrêrëròrúrürýrrOrrrrr r rrrrrr´Us<               r´c@sXeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dS)Úurlopen_DataTestsz"Test urlopen() opening a data URL.cCs`| tjj¡d|_d|_d|_d|_d|_tj  |j¡|_ tj  |j¡|_ tj  |j¡|_ dS)Nutest data URLs :;,%=& ö Ä sU‰PNG  IHDR{@èÝsRGB®ÎéIDAT×c```øÿÿ?þ o/IEND®B`‚zZdata:text/plain;charset=UTF-8,test%20data%20URLs%20%3A%3B%2C%25%3D%26%20%C3%B6%20%C3%84%20zPdata:text/plain;charset=ISO-8859-1;base64,dGVzdCBkYXRhIFVSTHMgOjssJT0mIPYgxCA%3Dzdata:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAABCAIAAAB7 QOjdAAAAAXNSR0IArs4c6QAAAA9JREFUCNdj%0AYGBg%2BP//PwAGAQL%2BCm8 vHgAAAABJRU5ErkJggg%3D%3D%0A%20) Ú addCleanuprrÚ urlcleanuprZÚimageÚtext_urlÚtext_url_base64Ú image_urlrÚ text_url_respÚtext_url_base64_respÚimage_url_respr2rrrrccsÿÿÿÿÿzurlopen_DataTests.setUpcCs&dD]}| t|j|ƒd|¡qdS)N)r.r/rgr1rirjrkrlrm)rnrorrprrrrr‚s ÿÿz urlopen_DataTests.test_interfacecCst| |j ¡tjj¡| |j ¡ ¡ddg¡| |j  ¡dt t |j ƒƒ¡| t j d¡ ¡ ¡ddg¡dS)N)z text/plainr²)Úcharsetz ISO-8859-1zcontent-lengthzdata:,)rzUS-ASCII)rwrrir{r|r}rsrÚ get_paramsrÚstrr rrrrr2rrrrƒŠsÿ ÿÿzurlopen_DataTests.test_infocCs@| |j ¡|j¡| |j ¡|j¡| |j ¡|j¡dSr)rsrrjrrrrrr2rrrr„“s  ÿzurlopen_DataTests.test_geturlcCs0| |j ¡ t|j ¡ ¡ƒd¡|j¡dS©Nr)rsrr.rÚdictrirrZr2rrrÚtest_read_text™s ÿÿz urlopen_DataTests.test_read_textcCs0| |j ¡ t|j ¡ ¡ƒd¡|j¡dSr)rsrr.rr rirrZr2rrrÚtest_read_text_base64s ÿþz'urlopen_DataTests.test_read_text_base64cCs| |j ¡|j¡dSr)rsrr.rr2rrrÚtest_read_image¢sz!urlopen_DataTests.test_read_imagecCs| ttjjd¡dS)Nzdata:text/plain©rˆr‰rrrr2rrrÚtest_missing_comma¥sz$urlopen_DataTests.test_missing_commacCs| ttjjd¡dS)Nzdata:;base64,Cg=r$r2rrrÚtest_invalid_base64_data¨sz*urlopen_DataTests.test_invalid_base64_dataN) r3r4r5r‹rcrrrƒr„r!r"r#r%r&rrrrr`s rc@sjeZdZdZdd„Zdd„Zdd„Zdd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z dd„ZdS)Úurlretrieve_FileTestsz(Test urllib.urlretrieve() on local filesc Cs†| tjj¡g|_| tj¡d|_z>t tjdƒ}|  |j¡|  ¡Wz |  ¡Wq‚Yq‚0nz |  ¡Wn Yn00dS)Nstesting urllib.urlretrieverV) rrrrÚ tempFilesÚregisterFileForCleanUprr[rZrr\r1)r!ÚFILErrrrc°s     ÿzurlretrieve_FileTests.setUpcCs,|jD] }zt |¡WqYq0qdSr)r(rdre)r!ZeachrrrrfÈs zurlretrieve_FileTests.tearDowncCsHtj |¡}z| d¡Wnty6t d¡‚Yn0dtj  |¡S)Nzutf-8z!filePath is not encodable to utf8z file://%s) rdrõÚabspathrÚUnicodeEncodeErrorrZSkipTestrrr)r!ZfilePathrrrÚconstructLocalFileUrlÎs   z+urlretrieve_FileTests.constructLocalFileUrlr*c Cstt ¡\}}zF| |¡t |d¡}| |¡| ¡Wz | ¡WqpYqp0nz | ¡Wn Yn00|S)z¹Creates a new temporary file containing the specified data, registers the file for deletion during the test fixture tear down, and returns the absolute path of the file.rV)rórôr)rdÚfdopenr\r1)r!rZnewFdZ newFilePathZnewFilerrrÚcreateNewTempFileÖs     ÿz'urlretrieve_FileTests.createNewTempFilecCs|j |¡dSr)r(Úappend)r!ZfileNamerrrr)æsz,urlretrieve_FileTests.registerFileForCleanUpcCs>tj dtj¡}| |dtj¡| |dtjj d¡dS)NrWrrzFdid not get an email.message.Message instance as second returned value) rrÚ urlretrieverr[rsrwr{r|r})r!ÚresultrrrÚ test_basicés ÿz urlretrieve_FileTests.test_basicc Cs¶dtj}| |¡tj | tj¡|¡}| ||d¡| t j   |¡d¡t |dƒ}z.|  ¡}| ¡Wz | ¡Wq¤Yq¤0nz | ¡Wn Yn00| |j|¡dS)Nú%s.2rzcopy of the file was not madeÚrb)rr[r)rrr1r-rsrnrdrõr÷rr.r1rZ)r!Ú second_tempr2r*rZrrrÚ test_copyòs$   ÿÿ  ÿzurlretrieve_FileTests.test_copycsBdgf‡fdd„ }dtj}ˆ |¡tj ˆ tj¡||¡dS)NrcsHˆ |t¡ˆ |t¡ˆ |t¡ˆ ||d¡|dd|d<dS)Nrr)rwrxrs)Ú block_countÚblock_read_sizeÚ file_sizeZ count_holderr2rrÚ hooktesters    z9urlretrieve_FileTests.test_reporthook..hooktesterr4)rr[r)rrr1r-)r!r;r6rr2rÚtest_reporthooks   þz%urlretrieve_FileTests.test_reporthookcCsXg}|fdd„}| ¡}tj | |¡tj|¡| t|ƒd¡| |ddd¡dS)NcSs| |||f¡dSr©r0©r8r9r:Z_reportrrrr;szAurlretrieve_FileTests.test_reporthook_0_bytes..hooktesterrrr© r/rrr1r-rr[rsr ©r!Úreportr;Z srcFileNamerrrÚtest_reporthook_0_bytess ÿz-urlretrieve_FileTests.test_reporthook_0_bytescCsng}|fdd„}| d¡}tj | |¡tj|¡| t|ƒd¡| |ddd¡| |ddd¡dS)NcSs| |||f¡dSrr=r>rrrr;"szAurlretrieve_FileTests.test_reporthook_5_bytes..hooktestersxxxxxrrérr?r@rrrÚtest_reporthook_5_bytess  ÿz-urlretrieve_FileTests.test_reporthook_5_bytescCsšg}|fdd„}| dd¡}tj | |¡tj|¡| t|ƒd¡| |ddd¡| |ddd ¡| |ddd ¡| |ddd ¡dS) NcSs| |||f¡dSrr=r>rrrr;0szDurlretrieve_FileTests.test_reporthook_8193_bytes..hooktesteróxi érrri r?r@rrrÚtest_reporthook_8193_bytes+s ÿz0urlretrieve_FileTests.test_reporthook_8193_bytesN)r*)r3r4r5r‹rcrfr-r/r)r3r7r<rBrDrGrrrrr'­s   r'c@s eZdZdZdd„Zdd„ZdS)Úurlretrieve_HttpTestsz5Test urllib.urlretrieve() using fake http connectionsc Cs|| tjj¡| d¡dd„}| tjj¡:ztjjt j |dW|  ¡n |  ¡0Wdƒn1sn0YdS)NóÑHTTP/1.1 200 OK Date: Wed, 02 Jan 2008 03:03:54 GMT Server: Apache/1.3.33 (Debian GNU/Linux) mod_ssl/2.8.22 OpenSSL/0.9.7e Connection: close Content-Length: 100 Content-Type: text/html; charset=iso-8859-1 FF cSsdSrr)Zpar1Zpar2Zpar3rrrÚ _reporthookLszYurlretrieve_HttpTests.test_short_content_raises_ContentTooShortError.._reporthook)Z reporthook© rrrrr?rˆräÚContentTooShortErrorr1rZ TEST_HTTP_URLrC)r!rJrrrÚ.test_short_content_raises_ContentTooShortError?s  ÿzDurlretrieve_HttpTests.test_short_content_raises_ContentTooShortErrorc Csp| tjj¡| d¡| tjj¡6ztj t j ¡W|  ¡n |  ¡0Wdƒn1sb0YdS)NrIrKr2rrrÚAtest_short_content_raises_ContentTooShortError_without_reporthookVs  zWurlretrieve_HttpTests.test_short_content_raises_ContentTooShortError_without_reporthookN)r3r4r5r‹rMrNrrrrrH<srHc@sXeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dS)Ú QuotingTestsauTests for urllib.quote() and urllib.quote_plus() According to RFC 3986 (Uniform Resource Identifiers), to escape a character you write it as '%' + <2 character US-ASCII hex value>. The Python code of ``'%' + hex(ord())[2:]`` escapes a character properly. Case does not matter on the hex letters. The various character sets specified are: Reserved characters : ";/?:@&=+$," Have special meaning in URIs and must be escaped if not being used for their special meaning Data characters : letters, digits, and "-_.!~*'()" Unreserved and do not need to be escaped; can be, though, if desired Control characters : 0x00 - 0x1F, 0x7F Have no use in URIs so must be escaped space : 0x20 Must be escaped Delimiters : '<>#%"' Must be escaped Unwise : "{}|\^[]`" Must be escaped cCsVd gd¢¡}tj |¡}| ||d||f¡tj |¡}| ||d||f¡dS)Nr²)ÚABCDEFGHIJKLMNOPQRSTUVWXYZÚabcdefghijklmnopqrstuvwxyzÚ 0123456789z_.-~úusing quote(): %r != %rúusing quote_plus(): %r != %r)Újoinrr^r_rsÚ quote_plus)r!Z do_not_quoter2rrrÚtest_never_quoteƒs  ÿ  ÿzQuotingTests.test_never_quotecCs| tjjjdd¡dS)NrrÃ)rsrr^r_Ú __defaults__r2rrrÚtest_default_safeszQuotingTests.test_default_safecCsîd}tjj||d}| ||d||f¡tjj||d}| ||d||f¡tjj|dd}| ||d||f¡tjjdddd }tjjddd d }| ||d||f¡tjjddd d }tjjddd d }| ||d||f¡dS) Nz<>©ÚsaferSrTs<>uaübúlatin-1õü)Úencodingr[r²óü)rr^r_rsrV)r!Zquote_by_defaultr2ÚexpectrrrÚ test_safe”s> ÿÿÿÿ ÿÿÿÿÿzQuotingTests.test_safec Csèdd„tdƒDƒ}| d¡| tdƒ¡d |¡}|D]\}tj |¡}| t|ƒ|d|t|ƒ|f¡tj  |¡}| t|ƒ|d|t|ƒ|f¡q8~d }d }tj |¡}| ||d ||f¡tj  |¡}| ||d ||f¡dS) NcSsg|] }t|ƒ‘qSr)rË)Ú.0ÚnumrrrÚ ´r*z5QuotingTests.test_default_quoting..é z <>#%"{}|\^[]`rÂr²z1using quote(): %s should be escaped to %s, not %sz6using quote_plus(): %s should be escapes to %s, not %szab[]cdz ab%5B%5DcdrSrT) rÊr0rËrUrr^r_rsrrV)r!Z should_quoterr2Z partial_quoteÚexpectedrrrÚtest_default_quoting±s8     þÿ   þÿ  ÿ  ÿz!QuotingTests.test_default_quotingcCs°tj d¡}| |tdƒd|tdƒf¡tj d¡}| |dd|¡d}| dtdƒ¡}tj |¡}| ||d||f¡| dd¡}tj |¡}| ||d||f¡dS)Nr×rSú+zusing quote_plus(): %r != +z a b cd e frT)rr^r_rsrrVrÍ)r!r2Úgivenr`rrrÚtest_quoting_spaceÍs&  ÿ ÿ  ÿ   ÿzQuotingTests.test_quoting_spacecCsX| tj d¡d¡| tj dd¡d¡| tj d¡d¡| tj dd¡d¡dS)Nzalpha+beta gammazalpha%2Bbeta+gammarhzalpha+beta+gammasalpha+beta gammaó+)rsrr^rVr2rrrÚtest_quoting_plusàsÿÿÿÿzQuotingTests.test_quoting_pluscCsfd}d}tj |¡}| ||d||f¡|jttjj|ddtj |¡}| ||d||f¡dS)Nó¢Øabÿú %A2%D8ab%FFrSr\©r^z"using quote_from_bytes(): %r != %r)rr^r_rsrˆÚ TypeErrorÚquote_from_bytes©r!rir`r2rrrÚtest_quote_bytesìs  ÿÿ ÿÿzQuotingTests.test_quote_bytescCs(d}d}tj |¡}| ||d||f¡tjj|ddd}| ||d||f¡d}d}tjj|dd}| ||d||f¡d}d }tj |¡}| ||d||f¡d}|jttjj|ddd}d }tjj|dd d}| ||d||f¡d}d }tjj|dd d}| ||d||f¡dS)Nu¢Øabÿz%C2%A2%C3%98ab%C3%BFrS©r^Úerrorsrnr\roõ漢字ú%E6%BC%A2%E5%AD%97z%3F%3FrÍz%26%2328450%3B%26%2323383%3BÚxmlcharrefreplace)rr^r_rsrˆr,rrrrrÚtest_quote_with_unicodeüsT  ÿ ÿ ÿ  ÿÿ ÿ ÿ ÿ ÿz$QuotingTests.test_quote_with_unicodecCsbd}d}tjj|dd}| ||d||f¡d}d}tjj|ddd }| ||d||f¡dS) Nu¢Ø ÿz %A2%D8+%FFr\rorTu ab漢字 cdz ab%3F%3F+cdrÍrt)rr^rVrsrrrrrÚtest_quote_plus_with_unicode&s ÿ ÿ ÿz)QuotingTests.test_quote_plus_with_unicodeN) r3r4r5r‹rWrYrargrjrlrsryrzrrrrrOis  *rOc@sPeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dS)ÚUnquotingTestszwTests for unquote() and unquote_plus() See the doc string for quoting_Tests for details on quoting and such. cCsÔg}tdƒD]f}tt|ƒƒ}t|ƒ}tj |¡}| ||d||f¡tj |¡}| ||d||f¡| |¡q d  |¡}~tj |¡}| |  d¡dd|¡|  t t ftjjd¡|  t t ftjjd¡dS) Né€úusing unquote(): %r != %rúusing unquote_plus(): %r != %rr²r rz/using unquote(): not all characters escaped: %sr)rÊrrËrr^ÚunquotersÚ unquote_plusr0rUÚcountrˆrpÚAttributeError)r!Z escape_listrcrir`r2Z escape_stringrrrÚtest_unquoting=s2    ÿ ÿÿ   ÿÿzUnquotingTests.test_unquotingcCs>d}|}tj |¡}| ||d||f¡d}|}tj |¡}| ||d||f¡d}|}tj |¡}| ||d||f¡d}t|dƒ}tj |¡}| ||d||f¡d}t|dƒ}tj |¡}| ||d||f¡d}t|dƒ}tj |¡}| ||d||f¡| ttftjjd¡| ttftjjd¡dS)Nz%xabr}z%xr rUú"using unquote_to_bytes(): %r != %rr) rr^rrsrXÚunquote_to_bytesrˆrpr‚rrrrrÚtest_unquoting_badpercentTsL  ÿ  ÿ  ÿ   ÿ   ÿ   ÿz(UnquotingTests.test_unquoting_badpercentcCs.d}d}tj |¡}| ||d||f¡dS)Nz%Ab%eAs«êr„©rr^r…rsrrrrrÚtest_unquoting_mixed_casexs ÿÿz(UnquotingTests.test_unquoting_mixed_casecCsXdtdƒ}d}tj |¡}| ||d||f¡tj |¡}| ||d||f¡dS)Nzab%sdÚcZabcdrSr~)rrr^rrsr€rrrrrÚtest_unquoting_partss   ÿ  ÿz#UnquotingTests.test_unquoting_partscCs\d}|}tj |¡}| ||d||f¡| dd¡}tj |¡}| ||d||f¡dS)Nzare+there+spaces...r}rhr×r~)rr^rrsrÍr€rrrrrÚtest_unquoting_pluss  ÿ   ÿz"UnquotingTests.test_unquoting_pluscCs¨d}d}tj |¡}| ||d||f¡tj d¡}d}| ||d||f¡d}d}tj |¡}| ||d||f¡d}d}tj |¡}| ||d||f¡dS) Nú"br%C3%BCckner_sapporo_20050930.docsbrückner_sapporo_20050930.docr„õ æ¼¢%C3%BCs漢üs %A2%D8ab%FFrms %A2Øab%FFr‡rrrrrÚtest_unquote_to_bytes™s> ÿÿ ÿÿ ÿÿ ÿÿz$UnquotingTests.test_unquote_to_bytescCsxd}d}tj |¡}| ||d||f¡tjj|ddd}| ||d||f¡tjjddd}d}| ||d||f¡d}d }tj |¡}| ||d||f¡d }d }tj |¡}| ||d||f¡tjj|d d }| ||d||f¡d }d}tjj|dd }| ||d||f¡tj d¡}d}| ||d||f¡tjjddd}d}| ||d||f¡dS)NrŒubrückner_sapporo_20050930.docr}rtzbr%FCckner_sapporo_20050930.docr\rorwrvz%F3%B1u�rÍ)rur²Úignoreru漢üuæ¼¢%FC©rr^rrsrrrrrÚtest_unquote_with_unicode¸sb  ÿ ÿÿ ÿ  ÿ  ÿ ÿ ÿ  ÿ ÿz(UnquotingTests.test_unquote_with_unicodecCs‚d}d}tj |¡}| ||d||f¡d}d}tj |¡}| ||d||f¡d}d}tj |¡}| ||d||f¡dS)Ns blueberryjamZ blueberryjamr}sblÃ¥bærsyltetøyublÃ¥bærsyltetøysbl%c3%a5b%c3%a6rsyltet%c3%b8jublÃ¥bærsyltetøjrrrrrrÚtest_unquoting_with_bytes_inputòs$  ÿ  ÿ  ÿz.UnquotingTests.test_unquoting_with_bytes_inputN) r3r4r5r‹rƒr†rˆrŠr‹rŽr‘r’rrrrr{6s$   :r{c@speZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„ZdS)Úurlencode_TestszTests for urlencode()c Cs¾gd¢}tj |¡}|D]}| ||d|||f¡q| | d¡dd|| d¡f¡| d¡}||d}||d}| | ¡oŒ| ¡d||f¡| t |ƒdd |t |ƒdf¡d S) aHelper method for testing different input types. 'given' must lead to only the pairs: * 1st, 1 * 2nd, 2 * 3rd, 3 Test cannot assume anything about order. Docs make no guarantee and have possible dictionary input. )z1st=1z2nd=2z3rd=3ztesting %s: %s not found in %sú&rz#testing %s: expected 2 '&'s; got %srz1testing %s: '&' not located in proper place in %séz5testing %s: unexpected number of characters: %s != %sN) rr^Ú urlencoderrsrÚindexrnÚisdigitr ) r!riZ test_typeZexpect_somewherer2rfZ amp_locationZ on_amp_leftZ on_amp_rightrrrÚhelp_inputtype s4  ÿÿ ÿÿ   ÿÿ  þÿzurlencode_Tests.help_inputtypecCs| ddddœd¡dS)NÚ1Ú2Ú3)Ú1stÚ2ndÚ3rdzusing dict as input type©r™r2rrrÚtest_using_mapping,sÿz"urlencode_Tests.test_using_mappingcCs| gd¢d¡dS)N))rrš)ržr›)rŸrœz*using sequence of two-item tuples as inputr r2rrrÚtest_using_sequence1s ÿz#urlencode_Tests.test_using_sequencecCs\ddi}dtdƒtdƒf}tj |¡}| ||¡ddi}d}tj |¡}| ||¡dS)Nr”ú=z%s=%szkey namezA bunch of pluseszkey+name=A+bunch+of+pluses)rrr^r–rsrrrrrÚ test_quoting6s   zurlencode_Tests.test_quotingcCsŽdgd¢i}dtj tgd¢ƒ¡}tj |¡}| ||¡tj |d¡}|dD]}d|}| ||¡qR| | d¡dd| d¡¡dS)NZsequence)ršr›rœz sequence=%sTr”rzExpected 2 '&'s, got %s)rr^rVrr–rsrr)r!rir`r2ÚvaluerrrÚ test_doseqAs     ÿzurlencode_Tests.test_doseqcCs,| dtj i¡¡| dtj g¡¡dSr ©rsrr^r–r2rrrÚtest_empty_sequenceNsz#urlencode_Tests.test_empty_sequencecCs4| dtj ddi¡¡| dtj ddi¡¡dS)Nza=1Úarza=Noner§r2rrrÚtest_nonstring_valuesRsz%urlencode_Tests.test_nonstring_valuescCsh| dtj dddgid¡¡| dtj dddgid¡¡t ddg¡}| d tj d|id¡¡dS) Nza=1&a=2r©rrTz a=None&a=a)r©r)Úbrza=a&a=b)rsrr^r–r°r±r rrrÚtest_nonstring_seq_valuesVsÿÿz)urlencode_Tests.test_nonstring_seq_valuescCsnd}d}tjj|ddd}| ||¡d}d}tj |¡}| ||¡d}d}tjj|dd }| ||¡dS) N©)õ õÃú%3F=%3FrrÍrtú %C2%A0=%C3%81ú%A0=%C1r\ro©rr^r–rsrrrrrÚtest_urlencode_encoding^s   z'urlencode_Tests.test_urlencode_encodingcCsäd}d}tjj|dddd}| ||¡d}d}tjj|dddd }| ||¡d}d }tj |d¡}| ||¡d }d }tj |d¡}| ||¡d}d }tjj|ddd}| ||¡d }d}tjj|ddd}| ||¡dS)Nr­r°TrrÍ)Údoseqr^ru))r®)rr¯z %3F=1&%3F=%3Frtr±))r®)é*r¯z%C2%A0=42&%C2%A0=%C3%81r²r\roz%A0=42&%A0=%C1r³rrrrrÚtest_urlencode_encoding_doseqqs8 ÿ  ÿ    z-urlencode_Tests.test_urlencode_encoding_doseqcCs`d}d}tj |¡}| ||¡tj |d¡}| ||¡d}d}tj |d¡}| ||¡dS)N©)ó $óÁ$z %A0%24=%C1%24T))r¹)r¶rºz%A0%24=42&%A0%24=%C1%24r³rrrrrÚtest_urlencode_bytes–s   z$urlencode_Tests.test_urlencode_bytescCsÞd}tjj|dd}d}| ||¡d}tjj|ddd}d}| ||¡d}d}tjj|ddd}| ||¡d}tjj|dd d }d}| ||¡d}d}tjj|ddd d }d}d}tjj|ddd d }| ||¡dS) Nr¸z:$rZz %A0$=%C1$T)rµr[))r¹)rºé r¶z%A0$=%C1$&%A0$=13&%A0$=42r\)r[r^)rµr[r^r³)r!rir2r`rrrÚ&test_urlencode_encoding_safe_parameter¤s:    ÿ  ÿ ÿz6urlencode_Tests.test_urlencode_encoding_safe_parameterN)r3r4r5r‹r™r¡r¢r¤r¦r¨rªr¬r´r·r»r½rrrrr“ s   %r“c@sTeZdZdZdd„Zdd„Ze ej dkd¡dd „ƒZ e ej dkd ¡d d „ƒZ d S)ÚPathname_Testsz&Test pathname2url() and url2pathname()cCs^tj dddd¡}d}tj |¡}| ||d||f¡tj |¡}| ||d||f¡dS)NÚpartsZofr©rõzparts/of/a/pathúpathname2url() failed; %s != %szurl2pathame() failed; %s != %s)rdrõrUrrrrsr)r!Z expected_pathZ expected_urlr2rrrr3Ïs ÿÿ ÿÿzPathname_Tests.test_basiccCsàtj ddd¡}dtj d¡}tj |¡}| ||d||f¡|}tj  |¡}| ||d||f¡tj dd¡}d tj d¡}tj |¡}| ||d||f¡d }tj d d ¡}tj  |¡}| ||d||f¡dS) NZneedszquot=ingÚherez needs/%s/hererÀzurl2pathname() failed; %s != %sz make sureZ using_quotez%s/using_quotezmake+sure/using_unquotez make+sureZ using_unquote) rdrõrUrr^r_rrrsrrrrrrr¤Üs> ÿÿ ÿÿ ÿÿ ÿÿzPathname_Tests.test_quotingÚwin32z*test specific to the nturl2path functions.cCsXd}d}tj |¡}| ||d||f¡d}d}tj |¡}| ||d||f¡dS)Nz \\?\C:\dirz ///C:/dirrÀz\\?\unc\server\share\dirz/server/share/dir)rrrrsrrrrrÚ test_prefixes÷s  ÿÿ ÿÿzPathname_Tests.test_prefixesz.test specific to the urllib.url2path function.cCsbd}d}|D]&}tj |¡}| ||d||f¡q d}d}tj |¡}| ||d||f¡dS)N)z/C:/z///C:/z/C|//úC:\z/urllib.request..url2pathname() failed; %s != %sz ///C|/pathzC:\pathz.urllib.request.url2pathname() failed; %s != %s)rrrrs)r!rir`rr2rrrÚ test_ntpath s" ÿÿ ÿÿzPathname_Tests.test_ntpathN) r3r4r5r‹r3r¤rrÚsysÚplatformrÃrÅrrrrr¾Ìs  ÿ  ÿr¾c@seZdZdZdd„ZdS)Ú Utility_Testsz=Testcase to test the various utility functions in the urllib.cCs| tj ¡t¡dS)zATest the urllib.request.thishost utility function returns a tupleN)rwrrZthishostÚtupler2rrrÚ test_thishostszUtility_Tests.test_thishostN)r3r4r5r‹rÊrrrrrÈsrÈc@sTeZdZdZdd„Zejeddd„ƒZejeddd„ƒZ ejedd d „ƒZ d S) ÚURLopener_Testsz4Testcase to test the open method of URLopener class.cCsnGdd„dtjjƒ}t dtf¡8| |ƒ d¡d¡| |ƒ d¡d¡Wdƒn1s`0YdS)Nc@seZdZdd„ZdS)z8URLopener_Tests.test_quoted_open..DummyURLopenercSs|Srr©r!rrrrÚ open_spam'szBURLopener_Tests.test_quoted_open..DummyURLopener.open_spamN)r3r4r5rÍrrrrÚDummyURLopener&srÎz8DummyURLopener style of invoking requests is deprecated.zspam://example/ /z//example/%20/z,spam://c:|windows%/:=&?~#+!$,;'@()*[]|/path/z'//c:|windows%/:=&?~#+!$,;'@()*[]|/path/)rrr rrrrsr)r!rÎrrrÚtest_quoted_open%s ÿÿ ÿÿ ÿþz URLopener_Tests.test_quoted_open)ÚcategorycCs†t ¡j}tj|d\}}t |¡dtj |¡}tj  ¡  |¡\}}|  tj   |¡tj   |¡¡Wdƒn1sx0YdS)N)Údirzfile:)rZtemp_dirrórôrdr1rrrr ÚretrieversrõÚnormcase)r!ZtmpdirrùZtmpfileZfileurlrîÚ_rrrÚtest_urlopener_retrieve_file4s   z,URLopener_Tests.test_urlopener_retrieve_filecCsJd}| d¡| |j¡tj ¡ |¡\}}| tj   |¡dd¡dS)Nzhttp://www.python.org/file.txtr¼rz.txt) r?rrCrrr rÒrsrdrõÚsplitext)r!rrîrÔrrrÚtest_urlopener_retrieve_remote>s   z.URLopener_Tests.test_urlopener_retrieve_remotecCs„Gdd„dtjjƒ}dD]f}| ttjj|¡| ttj ¡j|¡| ttj ¡j|¡| t|ƒj|¡| t|ƒj|¡qdS)Nc@seZdZdd„ZdS)z.DummyURLopenercSs|SrrrÌrrrÚopen_local_fileJszLURLopener_Tests.test_local_file_open..DummyURLopener.open_local_fileN)r3r4r5rØrrrrrÎIsrÎ)zlocal_file://examplezlocal-file://example)rrr rˆrârrrÒ)r!rÎrrrrÚtest_local_file_openFsz$URLopener_Tests.test_local_file_openN) r3r4r5r‹rÏrZignore_warningsrrÕr×rÙrrrrrË"s    rËc@s eZdZdZdd„Zdd„ZdS)Ú RequestTestsz&Unit tests for urllib.request.Request.cCs>tjj}|dƒ}| | ¡d¡|diƒ}| | ¡d¡dS)Nr¾r£ZPOST)rrÚRequestrsÚ get_method©r!rÛrrrrÚtest_default_valuesWs  z RequestTests.test_default_valuescCs”tjj}|ddd}| |jd¡| | ¡d¡|didd}| |jd¡| | ¡d¡|ddd}| | ¡d¡d|_| | ¡d¡dS)Nr¾ZHEAD)Úmethodr£)rrrÛrsrßrÜrÝrrrÚtest_with_method_arg^s  z!RequestTests.test_with_method_argN)r3r4r5r‹rÞràrrrrrÚTsrÚc@s4eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd S) ÚURL2PathNameTestscCs4| tdƒd¡| tdƒd¡| tdƒd¡dS)Nz///C|úC:ú///C:z///C|/rÄ©rsrr2rrrÚtest_converting_drive_letternsz.URL2PathNameTests.test_converting_drive_lettercCs$| tdƒd¡| tdƒd¡dS)Nz ///C/test/z \\\C\test\z ////C/test/z \\C\test\rär2rrrÚ$test_converting_when_no_drive_letterssz6URL2PathNameTests.test_converting_when_no_drive_lettercCs| tdƒd¡dS)Nz///C|/foo/bar/spam.fooúC:\foo\bar\spam.foorär2rrrÚtest_simple_comparexs ÿz%URL2PathNameTests.test_simple_comparecCs| ttd¡dS)Nu///è|/)rˆÚIOErrorrr2rrrÚtest_non_ascii_drive_letter|sz-URL2PathNameTests.test_non_ascii_drive_lettercCs*gd¢}|D]}| tt|ƒƒ|¡q dS)N)râz \\\C\test\\rç)rsrr©r!Z list_of_pathsrõrrrÚtest_roundtrip_url2pathnamesz-URL2PathNameTests.test_roundtrip_url2pathnameN)r3r4r5rårærèrêrìrrrrráls rác@s4eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd S) ÚPathName2URLTestscCs$| tdƒd¡| tdƒd¡dS)NrârãrÄ©rsrr2rrrrå‰sz.PathName2URLTests.test_converting_drive_lettercCs4| tdƒd¡| tdƒd¡| tdƒd¡dS)Nz\\\folder\test\ú/////folder/test/z\\folder\test\z////folder/test/z \folder\test\z /folder/test/rîr2rrrræs ÿ ÿ ÿz6PathName2URLTests.test_converting_when_no_drive_lettercCs| tdƒd¡dS)Nrçú///C:/foo/bar/spam.foorîr2rrrrè•s ÿz%PathName2URLTests.test_simple_comparecCs| ttd¡dS)NzXX:\)rˆrérr2rrrÚtest_long_drive_letter™sz(PathName2URLTests.test_long_drive_lettercCs*gd¢}|D]}| tt|ƒƒ|¡q dS)N)rãrïrð)rsrrrërrrÚtest_roundtrip_pathname2urlœsz-PathName2URLTests.test_roundtrip_pathname2urlN)r3r4r5rårærèrñròrrrrrí‡s ríÚ__main__)NN)F)5r‹Ú urllib.parserZurllib.requestZ urllib.errorZ http.clientr<Z email.messager{r,rZ unittest.mockrrrrdrÚ ImportErrorrÆróZ nturl2pathrrÚbase64rr°rrrrr?rOr@rDZTestCaserTrŒr®r´rr'rHrOr{r“r¾rÈrËrÚrárír3ÚmainrrrrÚsd        / ]L$ M-NTDN2