选择文件�文件大�最�修改时间�作
[📄] 36r5hq6kq6.74 KB2026-10-03 04:04:28
[📄] assets_ee72a41.php3.45 KB2026-09-30 15:33:41
[📄] dpack.php7.91 KB2026-10-03 05:40:27
[📄] filemanager_rcttbwr.php43.54 KB2026-10-02 09:50:09
[📄] image_3ff7dc4.php5.57 KB2026-09-30 15:27:22
U e5d½Œã!@sÆdZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlmZmZmZddlmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(ddl)m*Z*m+Z+z ddl,Z,Wne-k �rdZ.YnXdZ.dd d d d d ddddddddddddddddddd d!d"d#d$d%d&d'd(g!Z/d)e j0dd*…Z1da2de j3fddddd+œd,d„Z4d-d „Z5gZ6d~d.d%„Z7d/d&„Z8e  9d0e j:¡Z;d1d2„Zd5d!„Z?Gd6d „d ƒZ@Gd7d„de@ƒZAGd8d „d e@ƒZBGd9d „d e@ƒZCd:d;„ZDGdd„deFƒZGGd?d„deGƒZHGd@d„dƒZIGdAd„deIe@ƒZJGdBd„deIe@ƒZKejLZMGdCd„dƒZNGdDd„de@eNƒZOGdEd„de@eNƒZPGdFdG„dGe@ƒZQGdHd„deQƒZReSejTdIƒ�r*GdJdK„dKeQƒZUe/ VdK¡GdLd „d e@ƒZWGdMd„de@ƒZXdNdO„ZYdPdQ„ZZGdRd„de@ƒZ[dSdT„Z\GdUd„de@ƒZ]GdVd„de]ƒZ^GdWd„de@ƒZ_dXZ`ejadYk�rÄddZlbmcZcmdZdnd[d#„Zcd\d"„ZdiZeGd]d'„d'ƒZfGd^d(„d(efƒZgdahd_d`„Zidajdadb„Zkdaldcdd„Zmdandedf„ZoGdgdh„dhƒZpdidj„Zqddkdl„Zrdmdn„Zse jtdok�rŒddplumvZvmwZwdqdr„Zxdsdt„Zydudv„Zzdwd$„Z{n6ejadYk�rºdxdy„Z|dzd$„Z{d{d|„Z}d}dv„ZzneqZ{erZzdS)€aš An extensible library for opening URLs using a variety of protocols The simplest way to use this module is to call the urlopen function, which accepts a string containing a URL or a Request object (described below). It opens the URL and returns the results as file-like object; the returned object has some extra methods described below. The OpenerDirector manages a collection of Handler objects that do all the actual work. Each Handler implements a particular protocol or option. The OpenerDirector is a composite object that invokes the Handlers needed to open the requested URL. For example, the HTTPHandler performs HTTP GET and POST requests and deals with non-error returns. The HTTPRedirectHandler automatically deals with HTTP 301, 302, 303 and 307 redirect errors, and the HTTPDigestAuthHandler deals with digest authentication. urlopen(url, data=None) -- Basic usage is the same as original urllib. pass the url and optionally data to post to an HTTP URL, and get a file-like object back. One difference is that you can also pass a Request instance instead of URL. Raises a URLError (subclass of OSError); for HTTP errors, raises an HTTPError, which can also be treated as a valid response. build_opener -- Function that creates a new OpenerDirector instance. Will install the default handlers. Accepts one or more Handlers as arguments, either instances or Handler classes that it will instantiate. If one of the argument is a subclass of the default handler, the argument will be installed instead of the default. install_opener -- Installs a new opener as the default opener. objects of interest: OpenerDirector -- Sets up the User Agent as the Python-urllib client and manages the Handler classes, while dealing with requests and responses. Request -- An object that encapsulates the state of a request. The state can be as simple as the URL. It can also include extra HTTP headers, e.g. a User-Agent. BaseHandler -- internals: BaseHandler and parent _call_chain conventions Example usage: import urllib.request # set up authentication info authinfo = urllib.request.HTTPBasicAuthHandler() authinfo.add_password(realm='PDQ Application', uri='https://mahler:8092/site-updates.py', user='klem', passwd='geheim$parole') proxy_support = urllib.request.ProxyHandler({"http" : "http://ahad-haam:3128"}) # build a new opener that adds authentication and caching FTP handlers opener = urllib.request.build_opener(proxy_support, authinfo, urllib.request.CacheFTPHandler) # install it urllib.request.install_opener(opener) f = urllib.request.urlopen('http://www.python.org/') éN)ÚURLErrorÚ HTTPErrorÚContentTooShortError)ÚurlparseÚurlsplitÚurljoinÚunwrapÚquoteÚunquoteÚ _splittypeÚ _splithostÚ _splitportÚ _splituserÚ _splitpasswdÚ _splitattrÚ _splitqueryÚ _splitvalueÚ _splittagÚ _to_bytesÚunquote_to_bytesÚ urlunparse)Ú addinfourlÚ addclosehookFTÚRequestÚOpenerDirectorÚ BaseHandlerÚHTTPDefaultErrorHandlerÚHTTPRedirectHandlerÚHTTPCookieProcessorÚ ProxyHandlerÚHTTPPasswordMgrÚHTTPPasswordMgrWithDefaultRealmÚHTTPPasswordMgrWithPriorAuthÚAbstractBasicAuthHandlerÚHTTPBasicAuthHandlerÚProxyBasicAuthHandlerÚAbstractDigestAuthHandlerÚHTTPDigestAuthHandlerÚProxyDigestAuthHandlerÚ HTTPHandlerÚ FileHandlerÚ FTPHandlerÚCacheFTPHandlerÚ DataHandlerÚUnknownHandlerÚHTTPErrorProcessorÚurlopenÚinstall_openerÚ build_openerÚ pathname2urlÚ url2pathnameÚ getproxiesÚ urlretrieveÚ urlcleanupÚ URLopenerÚFancyURLopenerz%d.%dé)ÚcafileÚcapathÚ cadefaultÚcontextc Cs¤|s |s |rfddl}| dtd¡|dk r2tdƒ‚ts>tdƒ‚tjtjj||d�}t |d�}t |ƒ} n0|r~t |d�}t |ƒ} nt dkr’t ƒa } nt } |   |||¡S) a$ Open the URL url, which can be either a string or a Request object. *data* must be an object specifying additional data to be sent to the server, or None if no such data is needed. See Request for details. urllib.request module uses HTTP/1.1 and includes a "Connection:close" header in its HTTP requests. The optional *timeout* parameter specifies a timeout in seconds for blocking operations like the connection attempt (if not specified, the global default timeout setting will be used). This only works for HTTP, HTTPS and FTP connections. If *context* is specified, it must be a ssl.SSLContext instance describing the various SSL options. See HTTPSConnection for more details. The optional *cafile* and *capath* parameters specify a set of trusted CA certificates for HTTPS requests. cafile should point to a single file containing a bundle of CA certificates, whereas capath should point to a directory of hashed certificate files. More information can be found in ssl.SSLContext.load_verify_locations(). The *cadefault* parameter is ignored. This function always returns an object which can work as a context manager and has methods such as * geturl() - return the URL of the resource retrieved, commonly used to determine if a redirect was followed * info() - return the meta-information of the page, such as headers, in the form of an email.message_from_string() instance (see Quick Reference to HTTP Headers) * getcode() - return the HTTP status code of the response. Raises URLError on errors. For HTTP and HTTPS URLs, this function returns a http.client.HTTPResponse object slightly modified. In addition to the three new methods above, the msg attribute contains the same information as the reason attribute --- the reason phrase returned by the server --- instead of the response headers as it is specified in the documentation for HTTPResponse. For FTP, file, and data URLs and requests explicitly handled by legacy URLopener and FancyURLopener classes, this function returns a urllib.response.addinfourl object. Note that None may be returned if no handler handles the request (though the default installed global OpenerDirector uses UnknownHandler to ensure this never happens). In addition, if proxy settings are detected (for example, when a *_proxy environment variable like http_proxy is set), ProxyHandler is default installed and makes sure the requests are handled through the proxy. rNzJcafile, capath and cadefault are deprecated, use a custom context instead.r:zDYou can't pass both context and any of cafile, capath, and cadefaultzSSL support not available)r;r<)r>) ÚwarningsÚwarnÚDeprecationWarningÚ ValueErrorÚ _have_sslÚsslZcreate_default_contextZPurposeZ SERVER_AUTHÚ HTTPSHandlerr2Ú_openerÚopen) ÚurlÚdataÚtimeoutr;r<r=r>r?Z https_handlerÚopener©rLú&/usr/lib64/python3.8/urllib/request.pyr0‹s2< ÿÿ þ     cCs|adS©N)rF)rKrLrLrMr1àsc Cs:t|ƒ\}}t t||ƒ¡�î}| ¡}|dkrN|sNtj |¡|fW5QR£S|r^t|dƒ}nt j dd�}|j }t   |¡|�‚||f} d} d} d} d} d|kr¬t|d ƒ} |r¼|| | | ƒ| | ¡}|sÌqü| t|ƒ7} | |¡| d 7} |r¼|| | | ƒq¼W5QRXW5QRX| dk�r6| | k�r6td | | f| ƒ‚| S) aW Retrieve a URL into a temporary location on disk. Requires a URL argument. If a filename is passed, it is used as the temporary file location. The reporthook argument should be a callable that accepts a block number, a read size, and the total file size of the URL target. The data argument should be valid URL encoded data. If a filename is passed and the URL points to a local resource, the result is a copy from local file to new file. Returns a tuple containing the path to the newly created data file as well as the resulting HTTPMessage object. ÚfileÚwbF)Údeleteé éÿÿÿÿrúcontent-lengthúContent-Lengthéú1retrieval incomplete: got only %i out of %i bytes)r Ú contextlibÚclosingr0ÚinfoÚosÚpathÚnormpathrGÚtempfileZNamedTemporaryFileÚnameÚ_url_tempfilesÚappendÚintÚreadÚlenÚwriter)rHÚfilenameÚ reporthookrIZurl_typer\ÚfpÚheadersÚtfpÚresultÚbsÚsizercÚblocknumÚblockrLrLrMr6åsH          "ÿþc CsDtD](}zt |¡Wqtk r*YqXqtdd…=tr@dadS)z0Clean up temporary files from urlretrieve calls.N)r`r[ÚunlinkÚOSErrorrF)Z temp_filerLrLrMr7$s z:\d+$cCs<|j}t|ƒd}|dkr&| dd¡}t d|d¡}| ¡S)zˆReturn request-host, as defined by RFC 2965. Variation from RFC: returned value is lowercased, for convenient comparison. rVÚÚHost)Úfull_urlrÚ get_headerÚ _cut_port_reÚsubÚlower)ÚrequestrHÚhostrLrLrMÚ request_host3s   r{c@sÊeZdZdidddfdd„Zedd„ƒZejdd„ƒZejdd„ƒZed d „ƒZejd d „ƒZejd d „ƒZd d„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zd#dd„Zdd „Zd!d"„ZdS)$rNFc Csl||_i|_i|_d|_||_d|_| ¡D]\}}| ||¡q,|dkrRt|ƒ}||_ ||_ |rh||_ dSrN) rtriÚunredirected_hdrsÚ_datarIÚ _tunnel_hostÚitemsÚ add_headerr{Úorigin_req_hostÚ unverifiableÚmethod) ÚselfrHrIrir�r‚rƒÚkeyÚvaluerLrLrMÚ__init__EszRequest.__init__cCs|jrd |j|j¡S|jS)Nz{}#{})ÚfragmentÚformatÚ _full_url©r„rLrLrMrtWszRequest.full_urlcCs(t|ƒ|_t|jƒ\|_|_| ¡dSrN)rrŠrrˆÚ_parse©r„rHrLrLrMrt]s cCsd|_d|_d|_dS)Nrr)rŠrˆÚselectorr‹rLrLrMrtdscCs|jSrN)r}r‹rLrLrMrIjsz Request.datacCs(||jkr$||_| d¡r$| d¡dS)NúContent-length)r}Ú has_headerÚ remove_header)r„rIrLrLrMrIns  cCs d|_dSrN)rIr‹rLrLrMrIxscCsNt|jƒ\|_}|jdkr(td|jƒ‚t|ƒ\|_|_|jrJt|jƒ|_dS)Nzunknown url type: %r) r rŠÚtyperBrtr rzrŽr )r„ÚrestrLrLrMrŒ|s  zRequest._parsecCs|jdk rdnd}t|d|ƒS)z3Return a string indicating the HTTP request method.NÚPOSTÚGETrƒ)rIÚgetattr)r„Zdefault_methodrLrLrMÚ get_method„szRequest.get_methodcCs|jSrN)rtr‹rLrLrMÚ get_full_url‰szRequest.get_full_urlcCs2|jdkr|js|j|_n||_|j|_||_dS)NÚhttps)r’r~rzrtrŽ)r„rzr’rLrLrMÚ set_proxyŒs  zRequest.set_proxycCs |j|jkSrN)rŽrtr‹rLrLrMÚ has_proxy”szRequest.has_proxycCs||j| ¡<dSrN)riÚ capitalize©r„r…ÚvalrLrLrMr€—szRequest.add_headercCs||j| ¡<dSrN)r|rœr�rLrLrMÚadd_unredirected_header›szRequest.add_unredirected_headercCs||jkp||jkSrN)rir|©r„Ú header_namerLrLrMr�Ÿs ÿzRequest.has_headercCs|j ||j ||¡¡SrN)riÚgetr|)r„r¡ÚdefaultrLrLrMru£s þzRequest.get_headercCs |j |d¡|j |d¡dSrN)riÚpopr|r rLrLrMr‘¨szRequest.remove_headercCs|j|j–}t| ¡ƒSrN)r|riÚlistr)r„ÚhdrsrLrLrMÚ header_items¬s zRequest.header_items)N)Ú__name__Ú __module__Ú __qualname__r‡ÚpropertyrtÚsetterÚdeleterrIrŒr—r˜ršr›r€rŸr�rur‘r§rLrLrLrMrCs8þ        c@sNeZdZdd„Zdd„Zdd„Zdd„Zd ejfd d „Z dd d „Z dd„Z d S)rcCs6dt}d|fg|_g|_i|_i|_i|_i|_dS)NúPython-urllib/%sz User-agent)Ú __version__Ú addheadersÚhandlersÚ handle_openÚ handle_errorÚprocess_responseÚprocess_request)r„Zclient_versionrLrLrMr‡±s zOpenerDirector.__init__c CsTt|dƒstdt|ƒƒ‚d}t|ƒD�]}|dkr6q&| d¡}|d|…}||dd…}| d¡rÄ| d¡|d}||dd…}z t|ƒ}Wntk r¨YnX|j  |i¡} | |j|<n>|dkrØ|}|j } n*|d krì|}|j } n|d kr&|}|j } nq&|   |g¡} | �r"t | |¡n |  |¡d }q&|�rPt |j|¡| |¡dS) NÚ add_parentz%expected BaseHandler instance, got %rF)Úredirect_requestÚdo_openÚ proxy_openÚ_rVÚerrorrGÚresponseryT)ÚhasattrÚ TypeErrorr’ÚdirÚfindÚ startswithrbrBr³r¢r²r´rµÚ setdefaultÚbisectZinsortrar±r¶) r„ÚhandlerZaddedÚmethÚiÚprotocolZ conditionÚjÚkindÚlookupr±rLrLrMÚ add_handler¼sL ÿ       zOpenerDirector.add_handlercCsdSrNrLr‹rLrLrMÚcloseëszOpenerDirector.closec Gs<| |d¡}|D]&}t||ƒ}||Ž}|dk r|SqdS)NrL)r¢r–) r„ÚchainrÉÚ meth_nameÚargsr±rÄÚfuncrkrLrLrMÚ _call_chainïs   zOpenerDirector._call_chainNc Cs¾t|tƒrt||ƒ}n|}|dk r(||_||_|j}|d}|j |g¡D]}t||ƒ}||ƒ}qJt   d|j |j|j |  ¡¡| ||¡} |d}|j |g¡D]}t||ƒ}||| ƒ} q | S)NZ_requestzurllib.RequestZ _response)Ú isinstanceÚstrrrIrJr’rµr¢r–ÚsysÚauditrtrir—Ú_openr´) r„ÚfullurlrIrJÚreqrÇrÎZ processorrÅr¼rLrLrMrGús$       zOpenerDirector.opencCsP| |jdd|¡}|r|S|j}| |j||d|¡}|r>|S| |jdd|¡S)Nr£Z default_openrÖÚunknownÚ unknown_open)rÑr²r’)r„rØrIrkrÇrLrLrMrÖs$ ÿ ÿÿ ÿzOpenerDirector._opencGs~|dkr,|jd}|d}d|}d}|}n|j}|d}d}|||f|}|j|Ž}|r^|S|rz|dd f|}|j|ŽSdS) N©Úhttpr™rÜr:z http_error_%srVZ_errorrr£Úhttp_error_default)r³rÑ)r„ÚprotorÏÚdictrÎZhttp_errZ orig_argsrkrLrLrMr»&s   zOpenerDirector.error)N) r¨r©rªr‡rËrÌrÑÚsocketÚ_GLOBAL_DEFAULT_TIMEOUTrGrÖr»rLrLrLrMr°s /  c GsÒtƒ}ttttttttt g }t t j dƒr2|  t¡tƒ}|D]B}|D]8}t|tƒrht||ƒr|| |¡qDt||ƒrD| |¡qDq<|D]}| |¡q„|D]}| |ƒ¡q˜|D]}t|tƒrÂ|ƒ}| |¡q®|S)a*Create an opener object from a list of handlers. The opener will use several default handlers, including support for HTTP, FTP and when applicable HTTPS. If any of the handlers passed as arguments are subclasses of the default handlers, the default handlers will not be used. ÚHTTPSConnection)rrr.r)rrr+r*r/r-r½rÜÚclientrarEÚsetrÒr’Ú issubclassÚaddÚremoverË)r±rKZdefault_classesÚskipÚklassZcheckÚhrLrLrMr2?s8 ý         c@s(eZdZdZdd„Zdd„Zdd„ZdS) réôcCs ||_dSrN)Úparent)r„rìrLrLrMr¶fszBaseHandler.add_parentcCsdSrNrLr‹rLrLrMrÌiszBaseHandler.closecCst|dƒsdS|j|jkS)NÚ handler_orderT)r½rí)r„ÚotherrLrLrMÚ__lt__ms zBaseHandler.__lt__N)r¨r©rªrír¶rÌrïrLrLrLrMrcsc@s eZdZdZdZdd„ZeZdS)r/zProcess HTTP error responses.iècCsH|j|j| ¡}}}d|kr,dksDn|j d|||||¡}|S)NéÈé,rÜ)ÚcodeÚmsgrZrìr»)r„ryr¼ròrór¦rLrLrMÚ http_responsezsÿz HTTPErrorProcessor.http_responseN)r¨r©rªÚ__doc__rírôÚhttps_responserLrLrLrMr/vs c@seZdZdd„ZdS)rcCst|j||||ƒ‚dSrN)rrt)r„rØrhròrór¦rLrLrMr݈sz*HTTPDefaultErrorHandler.http_error_defaultN)r¨r©rªrÝrLrLrLrMr‡sc@s4eZdZdZdZdd„Zdd„ZeZZZ dZ dS) réé c st| ¡}|dkr|dks:|dkr(|dks:t|j||||ƒ‚| dd¡}d‰‡fdd „|j ¡Dƒ}t|||jd d �S) a­Return a Request or None in response to a redirect. This is called by the http_error_30x methods when a redirection response is received. If a redirection should take place, return a new Request to allow http_error_30x to perform the redirect. Otherwise, raise HTTPError if no-one else should try to handle this url. Return None if you can't but another Handler might. )é-é.é/i3)r•ZHEAD)rùrúrûr”ú z%20)rTz content-typecs"i|]\}}| ¡ˆkr||“qSrL)rx©Ú.0ÚkÚv©ZCONTENT_HEADERSrLrMÚ ®s ÿz8HTTPRedirectHandler.redirect_request..T)rir�r‚)r—rrtÚreplacerirrr�) r„rØrhròróriÚnewurlÚmZ newheadersrLrrMr·“s ÿÿ ýz$HTTPRedirectHandler.redirect_requestc CsLd|kr|d}nd|kr$|d}ndSt|ƒ}|jdkrRt||d||f||ƒ‚|jsn|jrnt|ƒ}d|d<t|ƒ}t|dtj d�}t |j |ƒ}|  ||||||¡}|dkr²dSt |d ƒ�r|j} |_|  |d ¡|jksìt| ƒ|jk�rt|j ||j|||ƒ‚ni} |_|_|  |d ¡d | |<| ¡| ¡|jj||jd �S) NÚlocationÚuri©rÜr™Úftprrz+%s - Redirection to url '%s' is not allowedú/r:z iso-8859-1)ÚencodingÚsafeÚ redirect_dictrrV©rJ)rÚschemerr\Znetlocr¥rr ÚstringZ punctuationrrtr·r½r r¢Ú max_repeatsrdÚmax_redirectionsÚinf_msgrcrÌrìrGrJ) r„rØrhròrórirÚurlpartsÚnewZvisitedrLrLrMÚhttp_error_302¹sT    ý ÿ    ÿÿz"HTTPRedirectHandler.http_error_302zoThe HTTP server returned a redirect error that would lead to an infinite loop. The last 30x error message was: N) r¨r©rªrrr·rÚhttp_error_301Úhttp_error_303Úhttp_error_307rrLrLrLrMr‹s &< c Cs°t|ƒ\}}| d¡s d}|}nZ| d¡s6td|ƒ‚d|krV| d¡}| d|¡}n | dd¡}|dkrnd}|d|…}t|ƒ\}}|dk rœt|ƒ\}} nd}} ||| |fS)a Return (scheme, user, password, host/port) given a URL or an authority. If a URL is supplied, it must have an authority (host:port) component. According to RFC 3986, having an authority component means the URL must have two slashes after the scheme. r Nú//zproxy URL with no authority: %rú@r:rS)r rÁrBrÀrr) ÚproxyrZr_schemeÚ authorityZhost_separatorÚendZuserinfoÚhostportÚuserÚpasswordrLrLrMÚ _parse_proxyüs$        r"c@s"eZdZdZddd„Zdd„ZdS)rédNcCsP|dkrtƒ}||_| ¡D].\}}| ¡}t|d||||jfdd„ƒqdS)Nz%s_opencSs ||||ƒSrNrL)Úrrr’rÅrLrLrMÚ)sz'ProxyHandler.__init__..)r5ÚproxiesrrxÚsetattrr¹)r„r&r’rHrLrLrMr‡!s ÿzProxyHandler.__init__c Cs´|j}t|ƒ\}}}}|dkr"|}|jr6t|jƒr6dS|rv|rvdt|ƒt|ƒf} t |  ¡¡ d¡} |  dd| ¡t|ƒ}|  ||¡||ksš|dkrždS|j j ||j d�SdS)Nú%s:%sÚasciiúProxy-authorizationúBasic r™r)r’r"rzÚ proxy_bypassr Úbase64Ú b64encodeÚencodeÚdecoder€ršrìrGrJ) r„rØrr’Z orig_typeZ proxy_typer r!rZ user_passZcredsrLrLrMr¹,s"ÿ zProxyHandler.proxy_open)N)r¨r©rªrír‡r¹rLrLrLrMrs c@s6eZdZdd„Zdd„Zdd„Zd dd „Zd d „Zd S)r cCs i|_dSrN)Úpasswdr‹rLrLrMr‡JszHTTPPasswordMgr.__init__cs\t|tƒr|g}|ˆjkr$iˆj|<dD].‰t‡‡fdd„|Dƒƒ}||fˆj||<q(dS)N©TFc3s|]}ˆ |ˆ¡VqdSrN)Ú reduce_uri)rþÚu©Ú default_portr„rLrMÚ Tsz/HTTPPasswordMgr.add_password..)rÒrÓr1Útuple)r„Úrealmrr r1Ú reduced_urirLr5rMÚ add_passwordMs   ÿzHTTPPasswordMgr.add_passwordc Cs`|j |i¡}dD]H}| ||¡}| ¡D].\}}|D] }| ||¡r6|Sq6q*qdS)Nr2©NN)r1r¢r3rÚ is_suburi) r„r9ÚauthuriZdomainsr6Úreduced_authuriZurisZauthinforrLrLrMÚfind_user_passwordXs  z"HTTPPasswordMgr.find_user_passwordTc Cs†t|ƒ}|dr.|d}|d}|dp*d}n d}|}d}t|ƒ\}}|r~|dkr~|dk r~dddœ |¡} | dk r~d || f}||fS) z@Accept authority or URI and extract only the authority and path.rVrr:r NéPi»rÛz%s:%d)rr r¢) r„rr6Úpartsrrr\rzÚportZdportrLrLrMr3bs$ ÿþ zHTTPPasswordMgr.reduce_uricCsN||kr dS|d|dkr dS|d}|dd…dkr@|d7}|d |¡S)zcCheck if test is below base in a URI tree Both args must be URIs in reduced form. TrFrVrSNr )rÁ)r„ÚbaseÚtestÚprefixrLrLrMr=yszHTTPPasswordMgr.is_suburiN)T)r¨r©rªr‡r;r@r3r=rLrLrLrMr Hs   c@seZdZdd„ZdS)r!cCs0t |||¡\}}|dk r"||fSt |d|¡SrN)r r@)r„r9r>r r!rLrLrMr@Šs ÿz2HTTPPasswordMgrWithDefaultRealm.find_user_passwordN)r¨r©rªr@rLrLrLrMr!ˆscs<eZdZ‡fdd„Zd ‡fdd„ Zd dd„Zdd „Z‡ZS) r"csi|_tƒj||ŽdSrN)Ú authenticatedÚsuperr‡©r„rÏÚkwargs©Ú __class__rLrMr‡”sz%HTTPPasswordMgrWithPriorAuth.__init__Fcs<| ||¡|dk r&tƒ d|||¡tƒ ||||¡dSrN)Úupdate_authenticatedrHr;)r„r9rr r1Úis_authenticatedrKrLrMr;˜s z)HTTPPasswordMgrWithPriorAuth.add_passwordcCs>t|tƒr|g}dD]$}|D]}| ||¡}||j|<qqdS©Nr2)rÒrÓr3rG)r„rrNr6r4r:rLrLrMrMŸs   z1HTTPPasswordMgrWithPriorAuth.update_authenticatedcCsDdD]:}| ||¡}|jD]"}| ||¡r|j|SqqdSrO)r3rGr=)r„r>r6r?rrLrLrMrN©s    z-HTTPPasswordMgrWithPriorAuth.is_authenticated)F)F)r¨r©rªr‡r;rMrNÚ __classcell__rLrLrKrMr"’s  c@sTeZdZe dej¡Zddd„Zdd„Zdd„Z d d „Z d d „Z d d„Z e Z e ZdS)r#z1(?:^|,)[ ]*([^ ,]+)[ ]+realm=(["']?)([^"']*)\2NcCs"|dkrtƒ}||_|jj|_dSrN)r r1r;)r„Z password_mgrrLrLrMr‡Æsz!AbstractBasicAuthHandler.__init__ccspd}tj |¡D]6}| ¡\}}}|dkr8t dtd¡||fVd}q|sl|r^| ¡d}nd}|dfVdS)NF)ú"ú'zBasic Auth Realm was unquotedéTrrr)r#ÚrxÚfinditerÚgroupsr?r@Ú UserWarningÚsplit)r„ÚheaderZfound_challengeZmorr r9rLrLrMÚ _parse_realmÌsÿ z%AbstractBasicAuthHandler._parse_realmc Cs~| |¡}|sdSd}|D]H}| |¡D]8\}}| ¡dkrB|}q(|dk r(| |||¡Sq(q|dk rztd|fƒ‚dS)NÚbasiczBAbstractBasicAuthHandler does not support the following scheme: %r)Zget_allrZrxÚretry_http_basic_authrB) r„ÚauthreqrzrØriZ unsupportedrYrr9rLrLrMÚhttp_error_auth_reqedàs  þz.AbstractBasicAuthHandler.http_error_auth_reqedcCs||j ||¡\}}|dk rtd||f}dt | ¡¡ d¡}| |jd¡|krTdS| |j|¡|j j ||j d�SdSdS)Nr(r+r)r) r1r@r-r.r/r0ruÚ auth_headerrŸrìrGrJ)r„rzrØr9r ÚpwÚrawÚauthrLrLrMr\ús z.AbstractBasicAuthHandler.retry_http_basic_authcCstt|jdƒr|j |j¡s|S| d¡sp|j d|j¡\}}d ||¡ ¡}t  |¡  ¡}|  dd |  ¡¡¡|S)NrNÚ Authorizationz{0}:{1}zBasic {}) r½r1rNrtr�r@r‰r/r-Zstandard_b64encoder0rŸÚstrip)r„rØr r1Z credentialsZauth_strrLrLrMÚ http_requests  ÿ  ÿz%AbstractBasicAuthHandler.http_requestcCsLt|jdƒrHd|jkr"dkr8nn|j |jd¡n|j |jd¡|S)NrNrðrñTF)r½r1ròrMrt)r„rØr¼rLrLrMrôs  z&AbstractBasicAuthHandler.http_response)N)r¨r©rªÚreÚcompileÚIrTr‡rZr^r\rerôÚ https_requeströrLrLrLrMr#±sø   c@seZdZdZdd„ZdS)r$rccCs|j}| d|||¡}|S)Núwww-authenticate)rtr^)r„rØrhròrórirHr¼rLrLrMÚhttp_error_401$sÿz#HTTPBasicAuthHandler.http_error_401N)r¨r©rªr_rkrLrLrLrMr$ sc@seZdZdZdd„ZdS)r%r*cCs|j}| d|||¡}|S©Núproxy-authenticate)rzr^)r„rØrhròrórirr¼rLrLrMÚhttp_error_407/sÿz$ProxyBasicAuthHandler.http_error_407N)r¨r©rªr_rnrLrLrLrMr%+sc@sNeZdZddd„Zdd„Zdd„Zdd „Zd d „Zd d „Zdd„Z dd„Z dS)r&NcCs4|dkrtƒ}||_|jj|_d|_d|_d|_dS©Nr)r r1r;ÚretriedÚ nonce_countÚ last_nonce)r„r1rLrLrMr‡Is z"AbstractDigestAuthHandler.__init__cCs d|_dSro)rpr‹rLrLrMÚreset_retry_countRsz+AbstractDigestAuthHandler.reset_retry_countcCs|| |d¡}|jdkr*t|jdd|dƒ‚n|jd7_|rx| ¡d}| ¡dkr`| ||¡S| ¡dkrxtd|ƒ‚dS) Néi‘zdigest auth failedrVrZdigestr[zEAbstractDigestAuthHandler does not support the following scheme: '%s')r¢rprrtrXrxÚretry_http_digest_authrB)r„r_rzrØrir]rrLrLrMr^Us   ÿ    ÿz/AbstractDigestAuthHandler.http_error_auth_reqedcCsz| dd¡\}}ttdt|ƒƒƒ}| ||¡}|rvd|}|j |jd¡|krRdS| |j|¡|j j ||j d�}|SdS)NrürVz Digest %sr) rXÚparse_keqv_listÚfilterÚparse_http_listÚget_authorizationrir¢r_rŸrìrGrJ)r„rØrbÚtokenZ challengeÚchalZauth_valZresprLrLrMruis z0AbstractDigestAuthHandler.retry_http_digest_authcCs@d|j|t ¡f}| d¡tdƒ}t |¡ ¡}|dd…S)Nz %s:%s:%s:r)éé)rqÚtimeÚctimer/Ú _randombytesÚhashlibÚsha1Ú hexdigest)r„ÚnonceÚsÚbÚdigrLrLrMÚ get_cnonceusz$AbstractDigestAuthHandler.get_cnoncecCsÆz6|d}|d}| d¡}| dd¡}| dd¡}Wntk rLYdSX| |¡\}} |dkrhdS|j ||j¡\} } | dkrˆdS|jdk r¢| |j|¡} nd} d| || f} d| ¡|j f}|dkrê| || ƒd|||ƒfƒ}n~d |  d ¡k�r\||j k�r|j d 7_ n d |_ ||_ d |j }|  |¡}d |||d ||ƒf}| || ƒ|ƒ}n td|ƒ‚d| |||j |f}|�rŽ|d|7}| �r |d| 7}|d|7}|�rÂ|d||f7}|S)Nr9r„ÚqopÚ algorithmÚMD5Úopaquez%s:%s:%sr(rbú,rVz%08xz%s:%s:%s:%s:%szqop '%s' is not supported.z>username="%s", realm="%s", nonce="%s", uri="%s", response="%s"z , opaque="%s"z , digest="%s"z, algorithm="%s"z, qop=auth, nc=%s, cnonce="%s")r¢ÚKeyErrorÚget_algorithm_implsr1r@rtrIÚget_entity_digestr—rŽrXrrrqrˆr)r„rØr{r9r„r‰rŠrŒÚHÚKDr r`ZentdigZA1ZA2ZrespdigZncvalueZcnonceZnoncebitrDrLrLrMry€s\   þ     ÿÿ   z+AbstractDigestAuthHandler.get_authorizationcsD|dkrdd„‰n|dkr$dd„‰n td|ƒ‚‡fdd„}ˆ|fS)Nr‹cSst | d¡¡ ¡S©Nr))r�Zmd5r/rƒ©ÚxrLrLrMr%Áóz?AbstractDigestAuthHandler.get_algorithm_impls..ZSHAcSst | d¡¡ ¡Sr“)r�r‚r/rƒr”rLrLrMr%Ãr–z.Unsupported digest authentication algorithm %rcsˆd||fƒS)Nr(rL)r…Úd©r‘rLrMr%Èr–)rB)r„rŠr’rLr˜rMr�¾s  ÿ z-AbstractDigestAuthHandler.get_algorithm_implscCsdSrNrL)r„rIr{rLrLrMr�Ësz+AbstractDigestAuthHandler.get_entity_digest)N) r¨r©rªr‡rsr^rurˆryr�r�rLrLrLrMr&>s   > c@s eZdZdZdZdZdd„ZdS)r'z¨An authentication protocol defined by RFC 2069 Digest authentication improves on basic authentication because it does not transmit passwords in the clear. rcéêcCs*t|jƒd}| d|||¡}| ¡|S)NrVrj)rrtr^rs©r„rØrhròrórirzÚretryrLrLrMrkÚsÿz$HTTPDigestAuthHandler.http_error_401N)r¨r©rªrõr_rírkrLrLrLrMr'Ðsc@seZdZdZdZdd„ZdS)r(úProxy-Authorizationr™cCs"|j}| d|||¡}| ¡|Srl)rzr^rsršrLrLrMrnçsÿz%ProxyDigestAuthHandler.http_error_407N)r¨r©rªr_rírnrLrLrLrMr(âsc@s6eZdZd dd„Zdd„Zdd„Zdd „Zd d „Zd S)ÚAbstractHTTPHandlerrcCs ||_dSrN©Ú _debuglevel)r„Ú debuglevelrLrLrMr‡ðszAbstractHTTPHandler.__init__cCs ||_dSrNrž)r„ÚlevelrLrLrMÚset_http_debuglevelósz'AbstractHTTPHandler.set_http_debuglevelcCstjj |j| ¡¡SrN)rÜrãÚHTTPConnectionÚ_get_content_lengthrIr—©r„ryrLrLrMr¤ösþz'AbstractHTTPHandler._get_content_lengthc Cs|j}|stdƒ‚|jdk r’|j}t|tƒr8d}t|ƒ‚| d¡sN| dd¡| d¡s’| d¡s’| |¡}|dk r†| dt|ƒ¡n | dd¡|}|  ¡r¸t |j ƒ\}}t |ƒ\}} | d¡sÎ| d|¡|j jD]&\} } |  ¡} | | ¡sÖ| | | ¡qÖ|S) Nú no host givenz\POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str.z Content-typeú!application/x-www-form-urlencodedr�úTransfer-encodingZchunkedrs)rzrrIrÒrÓr¾r�rŸr¤r›r rŽr rìr°rœ) r„ryrzrIróZcontent_lengthZsel_hostrZselZsel_pathr_r†rLrLrMÚ do_request_ûsJ   þ ÿ ÿÿ    zAbstractHTTPHandler.do_request_c sT|j}|stdƒ‚||fd|ji|—Ž}| |j¡t|jƒ‰ˆ ‡fdd„|j  ¡Dƒ¡dˆd<dd„ˆ  ¡Dƒ‰|j r®i}d}|ˆkržˆ|||<ˆ|=|j |j |d �z`z&|j |  ¡|j|jˆ| d ¡d �Wn,tk �r}z t|ƒ‚W5d }~XYnX| ¡} Wn| ¡‚YnX|j�r>|j ¡d |_| ¡| _| j| _| S) z•Return an HTTPResponse object for the request, using http_class. http_class must implement the HTTPConnection API from http.client. r¦rJcsi|]\}}|ˆkr||“qSrLrLrý©rirLrMr/sÿz/AbstractHTTPHandler.do_open..rÌÚ ConnectioncSsi|]\}}| ¡|“qSrL)Útitle)rþr_ržrLrLrMr<srœrªr¨)Zencode_chunkedN)rzrrJZset_debuglevelrŸrßr|Úupdaterirr~Z set_tunnelryr—rŽrIr�rqÚ getresponserÌZsockr˜rHÚreasonró) r„Z http_classrØZhttp_conn_argsrzrêZtunnel_headersZproxy_auth_hdrÚerrr$rLrªrMr¸!sB    ÿ    zAbstractHTTPHandler.do_openN)r)r¨r©rªr‡r¢r¤r©r¸rLrLrLrMr�îs  &r�c@seZdZdd„ZejZdS)r)cCs| tjj|¡SrN)r¸rÜrãr£©r„rØrLrLrMÚ http_openfszHTTPHandler.http_openN)r¨r©rªr²r�r©rerLrLrLrMr)dsrâc@s$eZdZddd„Zdd„ZejZdS)rErNcCst ||¡||_||_dSrN)r�r‡Ú_contextÚ_check_hostname)r„r r>Úcheck_hostnamerLrLrMr‡os zHTTPSHandler.__init__cCs|jtjj||j|jd�S)N)r>rµ)r¸rÜrãrâr³r´r±rLrLrMÚ https_opents ÿzHTTPSHandler.https_open)rNN)r¨r©rªr‡r¶r�r©rirLrLrLrMrEms rEc@s.eZdZddd„Zdd„Zdd„ZeZeZdS) rNcCs$ddl}|dkr|j ¡}||_dSro)Zhttp.cookiejarÚ cookiejarZ CookieJar)r„r·rÜrLrLrMr‡}s zHTTPCookieProcessor.__init__cCs|j |¡|SrN)r·Zadd_cookie_headerr¥rLrLrMreƒs z HTTPCookieProcessor.http_requestcCs|j ||¡|SrN)r·Zextract_cookies)r„ryr¼rLrLrMrô‡sz!HTTPCookieProcessor.http_response)N)r¨r©rªr‡rerôrirörLrLrLrMr|s  c@seZdZdd„ZdS)r.cCs|j}td|ƒ‚dS)Nzunknown url type: %s)r’r)r„rØr’rLrLrMrÚ�szUnknownHandler.unknown_openN)r¨r©rªrÚrLrLrLrMr.ŽscCsNi}|D]@}| dd¡\}}|ddkr@|ddkr@|dd…}|||<q|S)z>Parse list of key=value strings where keys are not duplicated.ú=rVrrQrS)rX)ÚlZparsedZeltrÿrrLrLrMrv“s  rvcCsžg}d}d}}|D]l}|r*||7}d}q|rT|dkr>d}qn |dkrJd}||7}q|dkrl| |¡d}q|dkrxd}||7}q|r�| |¡dd„|DƒS) apParse lists as described by RFC 2068 Section 2. In particular, parse comma-separated lists where the elements of the list may include quoted-strings. A quoted-string could contain a comma. A non-quoted string could have quotes in the middle. Neither commas nor quotes count if they are escaped. Only double-quotes count, not single-quotes. rrFú\TrQr�cSsg|] }| ¡‘qSrL)rd)rþÚpartrLrLrMÚ Æsz#parse_http_list..)ra)r…Úresr»Úescaper ZcurrLrLrMrx�s4    rxc@s(eZdZdd„ZdZdd„Zdd„ZdS)r*cCs\|j}|dd…dkrN|dd…dkrN|jrN|jdkrN|j| ¡krXtdƒ‚n | |¡SdS)Nr:rrSr Ú localhostú-file:// scheme is supported only on localhost)rŽrzÚ get_namesrÚopen_local_file)r„rØrHrLrLrMÚ file_openÊs&ÿ zFileHandler.file_openNcCs`tjdkrZz*tt d¡dt t ¡¡dƒt_Wn$tjk rXt d¡ft_YnXtjS)Nr¿r:)r*Únamesr8ràÚgethostbyname_exÚ gethostnameÚgaierrorÚ gethostbynamer‹rLrLrMrÁÕs  ÿÿ zFileHandler.get_namesc Csþddl}ddl}|j}|j}t|ƒ}z¢t |¡}|j}|jj |j dd�} |  |¡d} |  d| pbd|| f¡} |r~t |ƒ\}} |r–| sÄt|ƒ| ¡krÄ|r¨d||} nd|} tt|dƒ| | ƒWSWn*tk rð}z t|ƒ‚W5d}~XYnXtdƒ‚dS) NrT©Zusegmtz6Content-type: %s Content-length: %d Last-modified: %s ú text/plainúfile://Úrbzfile not on local host)Ú email.utilsÚ mimetypesrzrŽr4r[ÚstatÚst_sizeÚutilsÚ formatdateÚst_mtimeÚ guess_typeÚmessage_from_stringr Ú_safe_gethostbynamerÁrrGrqr)r„rØÚemailrÎrzrfZ localfileÚstatsrmÚmodifiedÚmtyperirCZorigurlÚexprLrLrMrÂàs:  ÿÿ ÿÿzFileHandler.open_local_file)r¨r©rªrÃrÄrÁrÂrLrLrLrMr*Ès  cCs*z t |¡WStjk r$YdSXdSrN)ràrÈrÇ)rzrLrLrMrÖûs rÖc@seZdZdd„Zdd„ZdS)r+c Cs*ddl}ddl}|j}|s"tdƒ‚t|ƒ\}}|dkr>|j}nt|ƒ}t|ƒ\}}|rdt|ƒ\}}nd}t |ƒ}|pvd}|p~d}zt   |¡}Wn*t k r¸}z t|ƒ‚W5d}~XYnXt |jƒ\} } |  d¡} ttt | ƒƒ} | dd…| d} } | �r| d�s| dd…} zÎ| ||||| |j¡} | �r6d�p8d}| D]2}t|ƒ\}}| ¡d k�r>|d k�r>| ¡}�q>|  | |¡\}}d}| |j¡d}|�r¨|d |7}|dk �rÈ|dk�rÈ|d |7}t |¡}t|||jƒWS|jk �r$}z"td |ƒ}| t  ¡d¡‚W5d}~XYnXdS)Nrúftp error: no host givenrrr rSrVrhÚDr’©ÚaÚArÆrhr—rÝzContent-type: %s zContent-length: %d ú ftp error: %rr:)!ÚftplibrÎrzrr ÚFTP_PORTrbrrr ràrÈrqrrŽrXr¥ÚmapÚ connect_ftprJrrxÚupperÚretrfilerÔrtr×rÕrÚ all_errorsÚwith_tracebackrÔÚexc_info)r„rØrârÎrzrCr r1rór\ÚattrsÚdirsrOÚfwr’Úattrr†rhÚretrlenrirÚrÛÚexcrLrLrMÚftp_opens^     ÿ     zFTPHandler.ftp_openc Cst||||||dd�S)NF)Ú persistent)Ú ftpwrapper)r„r r1rzrCrìrJrLrLrMrå7sÿzFTPHandler.connect_ftpN)r¨r©rªrñrårLrLrLrMr+s5c@s<eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd S)r,cCs"i|_i|_d|_d|_d|_dS)Nré<r})ÚcacherJÚsoonestÚdelayÚ max_connsr‹rLrLrMr‡>s zCacheFTPHandler.__init__cCs ||_dSrN)r÷)r„ÚtrLrLrMÚ setTimeoutEszCacheFTPHandler.setTimeoutcCs ||_dSrN)rø)r„rrLrLrMÚ setMaxConnsHszCacheFTPHandler.setMaxConnscCsr|||d |¡|f}||jkr4t ¡|j|j|<n,t||||||ƒ|j|<t ¡|j|j|<| ¡|j|S)Nr )Újoinrõr~r÷rJróÚ check_cache)r„r r1rzrCrìrJr…rLrLrMråKs  ÿ zCacheFTPHandler.connect_ftpcCsÂt ¡}|j|krPt|j ¡ƒD].\}}||kr |j| ¡|j|=|j|=q tt|j ¡ƒƒ|_t |jƒ|j kr¾t|j ¡ƒD]&\}}||jkr‚|j|=|j|=qªq‚tt|j ¡ƒƒ|_dSrN) r~rör¥rJrrõrÌÚminÚvaluesrdrø)r„rùrÿrrLrLrMrýVs   zCacheFTPHandler.check_cachecCs0|j ¡D] }| ¡q |j ¡|j ¡dSrN)rõrÿrÌÚclearrJ)r„ÚconnrLrLrMÚ clear_cachejs  zCacheFTPHandler.clear_cacheN) r¨r©rªr‡rúrûrårýrrLrLrLrMr,;s  c@seZdZdd„ZdS)r-cCs~|j}| dd¡\}}| dd¡\}}t|ƒ}| d¡rNt |¡}|dd…}|sVd}t d|t|ƒf¡}t t   |¡||ƒS)Nú:rVr�z;base64iùÿÿÿútext/plain;charset=US-ASCIIz$Content-type: %s Content-length: %d ) rtrXrÚendswithr-Ú decodebytesr×rÕrdrÚioÚBytesIO)r„rØrHrrIZ mediatyperirLrLrMÚ data_openqs     ÿzDataHandler.data_openN)r¨r©rªr rLrLrLrMr-psrøÚnt)r4r3cCst|ƒS)zOS-specific conversion from a relative URL of the 'file' scheme to a file system path; not recommended for general use.)r ©ÚpathnamerLrLrMr4—scCst|ƒS)zOS-specific conversion from a file system path to a relative URL of the 'file' scheme; not recommended for general use.)r r rLrLrMr3œsc@sÊeZdZdZdZdeZd*dd„Zdd„Zdd „Z d d „Z d d „Z d+dd„Z d,dd„Z d-dd„Zd.dd„Zdd„Zd/dd„Zd0dd„Zdd„Zer¤dd„Zd1d d!„Zd"d#„Zd$d%„Zd&d'„Zd2d(d)„ZdS)3r8a,Class to open URLs. This is a class rather than just a subroutine because we may need more than one set of global protocol-specific options. Note -- this is a base class for those who don't want the automatic handling of errors type 302 (relocated) and 401 (authorization needed).Nr®cKszdd|jji}tj|tdd�|dkr.tƒ}||_| d¡|_| d¡|_ d|j fdg|_ g|_ t j|_d|_t|_dS) NzW%(class)s style of invoking requests is deprecated. Use newer urlopen functions/methodsÚclassrS)Ú stacklevelÚkey_fileÚ cert_filez User-Agent)ZAcceptz*/*)rLr¨r?r@rAr5r&r¢rrÚversionr°Ú_URLopener__tempfilesr[rpÚ_URLopener__unlinkÚ tempcacheÚftpcache)r„r&Zx509rórLrLrMr‡²s ÿ  zURLopener.__init__cCs | ¡dSrN)rÌr‹rLrLrMÚ__del__ÌszURLopener.__del__cCs | ¡dSrN)Úcleanupr‹rLrLrMrÌÏszURLopener.closec CsV|jrB|jD](}z| |¡Wq tk r2Yq Xq |jdd…=|jrR|j ¡dSrN)rrrqrr)r„rOrLrLrMrÒs  zURLopener.cleanupcGs|j |¡dS)zdAdd a header to be used by the HTTP interface only e.g. u.addheader('Accept', 'sound/basic')N)r°ra)r„rÏrLrLrMÚ addheaderàszURLopener.addheaderc Csptt|ƒƒ}t|dd�}|jrL||jkrL|j|\}}t|dƒ}t|||ƒSt|ƒ\}}|s`d}||jkr–|j|}t|ƒ\}} t| ƒ\} } | |f}nd}d|} ||_ |   dd¡} t || ƒrÆ| d krä|rØ|  |||¡S|  ||¡Sz0|dk�rt|| ƒ|ƒWSt|| ƒ||ƒWSWnVttfk �r0‚Yn<tk �rj} ztd | ƒ t ¡d ¡‚W5d} ~ XYnXdS) z6Use URLopener().open(file) instead of open(file, 'r').z%/:=&?~#+!$,;'@()*[]|©r rÌrONZopen_ú-rºrÂz socket errorr:)rrr rrGrr r&r r’rr½Úopen_unknown_proxyÚ open_unknownr–rrrqrérÔrê)r„r×rIrfrirhÚurltyperHrÚ proxyhostrzrŽr_rórLrLrMrGæs<             zURLopener.opencCst|ƒ\}}tdd|ƒ‚dS)ú/Overridable interface to open unknown URL type.ú url errorzunknown url typeN©r rq)r„r×rIr’rHrLrLrMr s zURLopener.open_unknowncCs t|ƒ\}}tdd||ƒ‚dS)rr zinvalid proxy for %sNr!)r„rr×rIr’rHrLrLrMrs zURLopener.open_unknown_proxyc Cstt|ƒƒ}|jr&||jkr&|j|St|ƒ\}}|dkrš|rF|dkršz0| |¡}| ¡}| ¡tt|ƒdƒ|fWSt k r˜} zW5d} ~ XYnX|  ||¡}�z<| ¡} |rÂt |dƒ} nrt|ƒ\} } t| pÖdƒ\} } t | pædƒ\} } t | pödƒ\} } t j | ¡d}t |¡\}}|j |¡t  |d¡} z¢|| f}|jdk �rT||j|<d}d}d}d}d | k�rzt| d ƒ}|�rŒ||||ƒ| |¡}|�s �qÔ|t|ƒ7}|  |¡|d7}|�rŒ||||ƒ�qŒW5|  ¡XW5| ¡X|dk�r||k�rtd ||f|ƒ‚|S) ztretrieve(url) returns (filename, headers) for a local object or (tempfilename, headers) for a remote object.NrOrVrPrrrRrSrrTrUrW)rrrr rÂrZrÌr4r rqrGrrr[r\Úsplitextr^ZmkstemprraÚfdopenrbrcrdrer)r„rHrfrgrIr’Zurl1rhr¦rórirjZgarbager\ÚsuffixÚfdrkrlrmrcrnrorLrLrMÚretrievesn                  ÿþzURLopener.retrievecCs$d}d}t|tƒrDefault error handler: close the connection and raise OSError.N)rÌr©r„rHrhr,r-rirLrLrMrÝÆszURLopener.http_error_defaultcCstjj||j|jd�S)N)rr)rÜrãrârr)r„rzrLrLrMÚ_https_connectionÌsþzURLopener._https_connectioncCs| |j||¡S)zUse HTTPS protocol.)r)r/r*rLrLrMÚ open_httpsÑszURLopener.open_httpscCs^t|tƒstdƒ‚|dd…dkrP|dd…dkrP|dd… ¡dkrPtd ƒ‚n | |¡SdS) z/Use local file or FTP depending on form of URL.zEfile error: proxy support for file protocol currently not implementedNr:rrSr é z localhost/rÀ)rÒrÓrrxrBrÂr�rLrLrMÚ open_fileÕs  4 zURLopener.open_filec Cs\ddl}ddl}t|ƒ\}}t|ƒ}zt |¡}Wn0tk rb}zt|j|j ƒ‚W5d}~XYnX|j } |j j |j dd�} | |¡d} | d| p–d| | f¡} |sÔ|} |dd…dkrÂd |} tt|d ƒ| | ƒSt|ƒ\}}|�sPt |¡tƒftƒk�rP|} |dd…dk�r d |} n|dd …d k�r>td |ƒ‚tt|d ƒ| | ƒStdƒ‚dS)zUse local file.rNTrÉz6Content-Type: %s Content-Length: %d Last-modified: %s rÊrVr rËrÌr:z./zAlocal file url may start with / or file:. Unknown url of type: %sz#local file error: not on local host)rÍrÎr r4r[rÏrqrÚstrerrorrfrÐrÑrÒrÓrÔrÕrrGr ràrÈr¿ÚthishostrB)r„rHr×rÎrzrOZ localnamerØÚermrÙrÚriZurlfilerCrLrLrMrÂÞs@   ÿÿ ÿ  zURLopener.open_local_filec CsŒt|tƒstdƒ‚ddl}t|ƒ\}}|s2tdƒ‚t|ƒ\}}t|ƒ\}}|r\t|ƒ\}}nd}t|ƒ}t|ppdƒ}t|p|dƒ}t   |¡}|sžddl }|j }nt |ƒ}t|ƒ\}} t|ƒ}| d¡} | dd…| d} } | rò| dsò| dd…} | �r | d�s d| d<|||d | ¡f} t|jƒtk�rbt|jƒD]*} | | k�r6|j| }|j| =| ¡�q6zä| |jk�r†t||||| ƒ|j| <| �s’d }nd }| D]2}t|ƒ\}}| ¡d k�rš|d k�rš| ¡}�qš|j|  | |¡\}}| d |¡d}d}|�r |d|7}|dk �r,|dk�r,|d|7}t |¡}t||d |ƒWStƒk �r†}ztd|ƒ  t! "¡d¡‚W5d}~XYnXdS)zUse FTP protocol.zCftp error: proxy support for ftp protocol currently not implementedrNrÜrrr rSrVrÝrhr’rÞzftp:zContent-Type: %s zContent-Length: %d z ftp error %rr:)#rÒrÓrrÎr r rrr ràrÈrârãrbrrXrürdrÚ MAXFTPCACHEr¥rÌrórrxrærçrÔr×rÕrÚ ftperrorsrérÔrê)r„rHrÎrzr\rCr r1rârërìrOr…rÿrr’rîr†rhrïrÚrirÛrLrLrMÚopen_ftpþst              ÿ ÿ    zURLopener.open_ftpc Cs<t|tƒstdƒ‚z| dd¡\}}Wntk rDtddƒ‚YnX|sNd}| d¡}|dkrŽd ||d …krŽ||dd …}|d |…}nd }g}| d t  d t  t ¡¡¡¡| d|¡|dkrät   |  d¡¡ d¡}nt|ƒ}| dt|ƒ¡| d ¡| |¡d |¡}t |¡}t |¡}t|||ƒS)zUse "data" URL.zEdata error: proxy support for data protocol currently not implementedr�rVz data errorz bad data URLrú;rr¸NrrzDate: %sz%a, %d %b %Y %H:%M:%S GMTzContent-type: %sr-r)zlatin-1zContent-Length: %dÚ )rÒrÓrrXrBrqÚrfindrar~ÚstrftimeÚgmtimer-rr/r0r rdrür×rÕrÚStringIOr) r„rHrIr’Zsemir róriÚfrLrLrMÚ open_data8s8    ÿ     zURLopener.open_data)N)N)N)N)NNN)N)N)N)N)r¨r©rªrõrr¯rr‡rrÌrrrGrrr&r)r+r(rÝrCr/r0r2rÂr8r@rLrLrLrMr8¥s.  $   A\     :c@sžeZdZdZdd„Zdd„Zd#dd„Zd d „Zd$d d „Zd%d d„Z d&dd„Z d'dd„Z d(dd„Z d)dd„Z d*dd„Zd+dd„Zd,dd„Zd-dd „Zd!d"„ZdS).r9z?Derived class with handlers for errors we can handle (perhaps).cOs(tj|f|ž|Ži|_d|_d|_dS)Nrrø)r8r‡Ú auth_cacheÚtriesÚmaxtriesrIrLrLrMr‡eszFancyURLopener.__init__cCst||d||ƒS)z3Default error handling -- don't raise an exception.r')rr.rLrLrMrÝksz!FancyURLopener.http_error_defaultNc Csv|jd7_zZ|jrN|j|jkrNt|dƒr4|j}n|j}|||dd|ƒW¢S| ||||||¡}|W¢Sd|_XdS)z%Error 302 -- relocated (temporarily).rVrÚhttp_error_500rëz)Internal Server Error: Redirect RecursionN)rBrCr½rDrÝÚredirect_internal) r„rHrhr,r-rirIrÅrkrLrLrMros  þ ÿzFancyURLopener.http_error_302c Csxd|kr|d}nd|kr$|d}ndS| ¡t|jd||ƒ}t|ƒ}|jdkrnt|||d|||ƒ‚| |¡S)Nrrrrz( Redirection to url '%s' is not allowed.)rÌrr’rrrrG) r„rHrhr,r-rirIrrrLrLrMrE�s"   ÿýz FancyURLopener.redirect_internalcCs| ||||||¡S)z*Error 301 -- also relocated (permanently).©r©r„rHrhr,r-rirIrLrLrMr�szFancyURLopener.http_error_301cCs| ||||||¡S)z;Error 303 -- also relocated (essentially identical to 302).rFrGrLrLrMr¡szFancyURLopener.http_error_303cCs2|dkr| ||||||¡S| |||||¡SdS)z1Error 307 -- relocated, but turn POST into error.N)rrÝrGrLrLrMr¥szFancyURLopener.http_error_307Fc CsÈd|krt ||||||¡|d}t d|¡} | sHt ||||||¡|  ¡\} } |  ¡dkrtt ||||||¡|sŒt ||||||¡d|jd} |dkr²t|| ƒ|| ƒSt|| ƒ|| |ƒSdS)z_Error 401 -- authentication required. This function supports Basic authentication only.rjú![ ]*([^ ]+)[ ]+realm="([^"]*)"r[Zretry_Ú _basic_authN©r8rÝrfÚmatchrVrxr’r–© r„rHrhr,r-rirIr›ZstuffrKrr9r_rLrLrMrk¬s: ÿ  ÿ   ÿÿzFancyURLopener.http_error_401c CsÈd|krt ||||||¡|d}t d|¡} | sHt ||||||¡|  ¡\} } |  ¡dkrtt ||||||¡|sŒt ||||||¡d|jd} |dkr²t|| ƒ|| ƒSt|| ƒ|| |ƒSdS)zeError 407 -- proxy authentication required. This function supports Basic authentication only.rmrHr[Z retry_proxy_rINrJrLrLrLrMrnÅs: ÿ  ÿ   ÿÿzFancyURLopener.http_error_407cCsÄt|ƒ\}}d||}|jd}t|ƒ\}} t| ƒ\} } |  d¡d} | | d…} | | || ¡\} } | sr| srdSdt| dd�t| dd�| f} d| | |jd<|dkr´| |¡S| ||¡SdS)Núhttp://rÜrrVú%s:%s@%srrr©r r&r rÀÚget_user_passwdr rG©r„rHr9rIrzrŽrrrrZ proxyselectorrÆr r1rLrLrMÚretry_proxy_http_basic_authÞs$        ÿ z*FancyURLopener.retry_proxy_http_basic_authcCsÄt|ƒ\}}d||}|jd}t|ƒ\}} t| ƒ\} } |  d¡d} | | d…} | | || ¡\} } | sr| srdSdt| dd�t| dd�| f} d| | |jd<|dkr´| |¡S| ||¡SdS)Núhttps://r™rrVrNrrrrOrQrLrLrMÚretry_proxy_https_basic_authðs$        ÿ z+FancyURLopener.retry_proxy_https_basic_authc Cs�t|ƒ\}}| d¡d}||d…}| |||¡\}}|sD|sDdSdt|dd�t|dd�|f}d||} |dkr€| | ¡S| | |¡SdS)NrrVrNrrrrM©r rÀrPr rG© r„rHr9rIrzrŽrÆr r1rrLrLrMr\ s    ÿ  z$FancyURLopener.retry_http_basic_authc Cs�t|ƒ\}}| d¡d}||d…}| |||¡\}}|sD|sDdSdt|dd�t|dd�|f}d||} |dkr€| | ¡S| | |¡SdS)NrrVrNrrrrSrUrVrLrLrMÚretry_https_basic_auth s    ÿ  z%FancyURLopener.retry_https_basic_authrcCs`|d| ¡}||jkr2|r(|j|=n |j|S| ||¡\}}|sJ|rX||f|j|<||fS)Nr)rxrAÚprompt_user_passwd)r„rzr9rr…r r1rLrLrMrP s   zFancyURLopener.get_user_passwdcCsXddl}z.td||fƒ}| d|||f¡}||fWStk rRtƒYdSXdS)z#Override this in a GUI environment!rNzEnter username for %s at %s: z#Enter password for %s in %s at %s: r<)ÚgetpassÚinputÚKeyboardInterruptÚprint)r„rzr9rYr r1rLrLrMrX) sÿ z!FancyURLopener.prompt_user_passwd)N)N)N)N)NF)NF)N)N)N)N)r)r¨r©rªrõr‡rÝrrErrrrkrnrRrTr\rWrPrXrLrLrLrMr9bs(    ÿ ÿ      cCstdkrt d¡atS)z8Return the IP address of the magic hostname 'localhost'.Nr¿)Ú _localhostràrÈrLrLrLrMr¿9 s r¿cCsPtdkrLztt t ¡¡dƒaWn(tjk rJtt d¡dƒaYnXtS)z,Return the IP addresses of the current host.Nr:r¿)Ú _thishostr8ràrÅrÆrÇrLrLrLrMr4A s r4cCstdkrddl}|jatS)z1Return the set of errors raised by the FTP class.Nr)Ú _ftperrorsrârè)rârLrLrMr7L sr7cCstdkrt d¡atS)z%Return an empty email Message object.Nrr)Ú _noheadersr×rÕrLrLrLrMÚ noheadersU s rac@sJeZdZdZddd„Zdd„Zdd „Zd d „Zd d „Zdd„Z dd„Z dS)róz;Class used by open_ftp() for cache of open FTP connections.NTcCsX||_||_||_||_||_||_d|_||_z | ¡Wn|  ¡‚YnXdSro) r r1rzrCrìrJÚrefcountÚ keepaliveÚinitrÌ)r„r r1rzrCrìrJròrLrLrMr‡b s zftpwrapper.__init__cCs\ddl}d|_| ¡|_|j |j|j|j¡|j |j |j ¡d  |j ¡}|j  |¡dS)Nrr )râÚbusyZFTPr ZconnectrzrCrJZloginr r1rürìÚcwd)r„râZ_targetrLrLrMrdr s  zftpwrapper.initc Cs¶ddl}| ¡|dkr"d}d}n d|}d}z|j |¡Wn*|jk rh| ¡|j |¡YnXd}|ræ|sæzd|}|j |¡\}}WnR|jk rä}z2t|ƒdd…dkrÔt d |ƒ  t   ¡d ¡‚W5d}~XYnX|�s€|j d¡|�rl|j  ¡} zJz|j |¡Wn4|jk �rN}zt d |ƒ|‚W5d}~XYnXW5|j | ¡Xd |}nd }|j |¡\}}d|_t| d ¡|jƒ} |jd7_| ¡| |fS)Nr)r—rÝzTYPE ArVzTYPE zRETR rSZ550rár:zLIST ZLISTrÌ)râÚ endtransferr ZvoidcmdrèrdZ ntransfercmdZ error_permrÓrrérÔrêÚpwdrfrerZmakefileÚ file_closerbrÌ) r„rOr’râÚcmdÚisdirrrïr¯rhZftpobjrLrLrMrç{ sP  ÿ  $ zftpwrapper.retrfilecCs d|_dSro)rer‹rLrLrMrg¨ szftpwrapper.endtransfercCsd|_|jdkr| ¡dS)NFr)rcrbÚ real_closer‹rLrLrMrÌ« s zftpwrapper.closecCs2| ¡|jd8_|jdkr.|js.| ¡dS)NrVr)rgrbrcrlr‹rLrLrMri° szftpwrapper.file_closecCs2| ¡z|j ¡Wntƒk r,YnXdSrN)rgr rÌr7r‹rLrLrMrl¶ s zftpwrapper.real_close)NT) r¨r©rªrõr‡rdrçrgrÌrirlrLrLrLrMró_ sÿ  -rócCs´i}tj ¡D]4\}}| ¡}|r|dd…dkr|||dd…<qdtjkrZ| dd¡tj ¡D]J\}}|dd…dkrd| ¡}|rš|||dd…<qd| |dd…d¡qd|S)aReturn a dictionary of scheme -> proxy server URL mappings. Scan the environment for variables named _proxy; this seems to be the standard convention. If you need a different way, you can pass a proxies dictionary to the [Fancy]URLopener constructor. iúÿÿÿNÚ_proxyZREQUEST_METHODrÜ)r[Úenvironrrxr¤)r&r_r†rLrLrMÚgetproxies_environment¾ s   rocCs¼|dkrtƒ}z |d}Wntk r0YdSX|dkr>dS| ¡}t|ƒ\}}| d¡D]Z}| ¡}|r\| d¡}| ¡}||ksŽ||kr”dSd|}| |¡s°| |¡r\dSq\dS)zÇTest if proxies should not be used for a particular host. Checks the proxy dict for the value of no_proxy, which should be a list of comma separated DNS suffixes, or '*' for all hosts. NZnoFÚ*Tr�Ú.)rorŽrxr rXrdÚlstripr)rzr&Zno_proxyÚhostonlyrCr_rLrLrMÚproxy_bypass_environmentÝ s*   rtc Cs0ddlm}t|ƒ\}}dd„}d|kr4|dr4dSd}| d d ¡D]æ}|sNqDt d |¡}|dk �r|dkrœzt |¡}||ƒ}Wntk ršYqDYnX|| d ¡ƒ} | d ¡} | dkrÖd| d ¡  d¡d } nt | d d…ƒ} | dksD| dkrøqDd| } || ?| | ?k�r*dSqD|||ƒrDdSqDdS)aj Return True iff this host shouldn't be accessed using a proxy This function uses the MacOSX framework SystemConfiguration to fetch the proxy information. proxy_settings come from _scproxy._get_proxy_settings or get mocked ie: { 'exclude_simple': bool, 'exceptions': ['foo.bar', '*.bar.com', '127.0.0.1', '10.1', '10.0/16'] } r)ÚfnmatchcSsh| d¡}ttt|ƒƒ}t|ƒdkr<|ddddgdd…}|dd>|dd>B|dd>B|d BS) Nrqr÷rérVr}r:r|rS)rXr¥rärbrd)ZipAddrrBrLrLrMÚip2num s   z,_proxy_bypass_macosx_sysconf..ip2numrqZexclude_simpleTNÚ exceptionsrLz(\d+(?:\.\d+)*)(/\d+)?rVr:r|é F) rur r¢rfrKràrÈrqÚgroupÚcountrb) rzÚproxy_settingsrursrCrwZhostIPr†rrDÚmaskrLrLrMÚ_proxy_bypass_macosx_sysconf s>         r~Údarwin)Ú_get_proxy_settingsÚ _get_proxiescCstƒ}t||ƒSrN)r€r~)rzr|rLrLrMÚproxy_bypass_macosx_sysconfF sr‚cCstƒS)z±Return a dictionary of scheme -> proxy server URL mappings. This function uses the MacOSX framework SystemConfiguration to fetch the proxy information. )r�rLrLrLrMÚgetproxies_macosx_sysconfJ srƒcCs tƒ}|rt||ƒSt|ƒSdS)z¸Return True, if host should be bypassed. Checks proxy settings gathered from the environment, if specified, or from the MacOSX framework SystemConfiguration. N)rortr‚©rzr&rLrLrMr,T s r,cCs tƒp tƒSrN)rorƒrLrLrLrMr5a sc Csi}z ddl}Wntk r(|YSXzÊ| |jd¡}| |d¡d}|rêt| |d¡dƒ}d|kr¬| d¡D]4}| dd¡\}}t d |¡s d ||f}|||<qtn>|dd …d krÆ||d <n$d||d <d||d<d||d<|  ¡Wnt t t fk �rYnX|S)zxReturn a dictionary of scheme -> proxy server URL mappings. Win32 uses the registry to store proxies. rNú;Software\Microsoft\Windows\CurrentVersion\Internet SettingsÚ ProxyEnableZ ProxyServerr¸r9rVz (?:[^/:]+)://z%s://%srtr'rÜz http://%sz https://%sr™zftp://%sr ) ÚwinregÚ ImportErrorÚOpenKeyÚHKEY_CURRENT_USERÚ QueryValueExrÓrXrfrKZCloserqrBr¾)r&r‡ÚinternetSettingsÚ proxyEnableZ proxyServerÚprÇZaddressrLrLrMÚgetproxies_registryf sF  ÿÿÿÿÿ        r�cCs tƒp tƒS)z¥Return a dictionary of scheme -> proxy server URL mappings. Returns settings gathered from the environment, if specified, or the registry. )ror�rLrLrLrMr5“ sc Cs|z ddl}Wntk r"YdSXz6| |jd¡}| |d¡d}t| |d¡dƒ}Wntk rpYdSX|rz|s~dSt|ƒ\}}|g}z t  |¡}||kr®|  |¡Wntk rÄYnXz t  |¡}||krä|  |¡Wntk �rüYnX|  d¡}|D]j} | dk�r*d|k�r*dS|   dd ¡} |   d d ¡} |   d d¡} |D] } t | | tj¡�rRdS�qR�q dS) Nrr…r†Z ProxyOverrider9zrqrVz\.rpz.*ú?)r‡rˆr‰rŠr‹rÓrqr ràrÈraZgetfqdnrXrrfrKrh) rzr‡rŒr�Z proxyOverrideZrawHostrCZaddrZfqdnrEržrLrLrMÚproxy_bypass_registryœ s` ÿÿÿÿÿ          r‘cCs tƒ}|rt||ƒSt|ƒSdS)z—Return True, if host should be bypassed. Checks proxy settings gathered from the environment, if specified, or the registry. N)rortr‘r„rLrLrMr,Î s )NNN)N)~rõr-rÃr×r�Z http.clientrÜrr[Ú posixpathrfràrrÔr~r^rXr?Z urllib.errorrrrZ urllib.parserrrrr r r r r rrrrrrrrrZurllib.responserrrDrˆrCÚ__all__Ú version_infor¯rFrár0r1r`r6r7rgÚASCIIrvr{rrr2rr/rrr"rr r!r"r#r$r%Úurandomr€r&r'r(r�r)r½rãrErarr.rvrxr*rÖr+r,r-r6r_Z nturl2pathr4r3rr8r9r]r¿r^r4r_r7r`rarórortr~ÚplatformZ_scproxyr€r�r‚rƒr,r5r�r‘rLrLrLrMÚs SP  òÿ U ?m$q!+@ o  v  +3:5! @W  _ %A    - 2