asda?‰PNG  IHDR ? f ??C1 sRGB ??é gAMA ±? üa pHYs ? ??o¨d GIDATx^íüL”÷e÷Y?a?("Bh?_ò???¢§?q5k?*:t0A-o??¥]VkJ¢M??f?±8\k2íll£1]q?ù???T a d@sdZddlZddlZddlZddlZddlZddlZddlZddl 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-ydZ.Yn0dZ.gdZ/d e j0dd Z1da2de j3fddddd d d Z4ddZ5gZ6dddZ7ddZ8e 9de j:Z;ddZddZ?GdddZ@Gdd d e@ZAGd!d"d"e@ZBGd#d$d$e@ZCd%d&ZDGd'd(d(e@ZEGd)d*d*ZFGd+d,d,eFZGGd-d.d.eGZHGd/d0d0ZIGd1d2d2eIe@ZJGd3d4d4eIe@ZKejLZMGd5d6d6ZNGd7d8d8e@eNZOGd9d:d:e@eNZPGd;d<dd>eQZReSejTd?rGd@dAdAeQZUe/VdAGdBdCdCe@ZWGdDdEdEe@ZXdFdGZYdHdIZZGdJdKdKe@Z[dLdMZ\GdNdOdOe@Z]GdPdQdQe]Z^GdRdSdSe@Z_dTZ`ejadUkrddVlbmcZcmdZdndWdXZcdYdZZdiZeGd[d\d\ZfGd]d^d^efZgdahd_d`ZidajdadbZkdaldcddZmdandedfZoGdgdhdhZpdidjZqddkdlZrdmdnZse jtdokrLddplumvZvmwZwdqdrZxdsdtZydudvZzdwdxZ{n6ejadUkrzdydzZ|d{dxZ{d|d}Z}d~dvZzneqZ{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('https://www.python.org/') N)URLError HTTPErrorContentTooShortError)urlparseurlspliturljoinunwrapquoteunquote _splittype _splithost _splitport _splituser _splitpasswd _splitattr _splitquery _splitvalue _splittag _to_bytesunquote_to_bytes urlunparse) addinfourl addclosehookFT)!RequestOpenerDirector BaseHandlerHTTPDefaultErrorHandlerHTTPRedirectHandlerHTTPCookieProcessor ProxyHandlerHTTPPasswordMgrHTTPPasswordMgrWithDefaultRealmHTTPPasswordMgrWithPriorAuthAbstractBasicAuthHandlerHTTPBasicAuthHandlerProxyBasicAuthHandlerAbstractDigestAuthHandlerHTTPDigestAuthHandlerProxyDigestAuthHandler HTTPHandler FileHandler FTPHandlerCacheFTPHandler DataHandlerUnknownHandlerHTTPErrorProcessorurlopeninstall_opener build_opener pathname2url url2pathname getproxies urlretrieve urlcleanup URLopenerFancyURLopenerz%d.%d)cafilecapath cadefaultcontextc Cs|s |s |rfddl}|dtd|dur2tdts>tdtjtjj||d}t |d}t |} n0|r~t |d}t |} nt durt a } nt } | |||S) aOpen 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 the properties url, headers, and status. See urllib.response.addinfourl for more detail on these properties. 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>) warningswarnDeprecationWarning ValueError _have_sslsslcreate_default_contextPurpose SERVER_AUTH HTTPSHandlerr2_openeropen) urldatatimeoutr;r<r=r>r?Z https_handleropenerrO,/usr/src/Python-3.9.18/Lib/urllib/request.pyr0s04       r0cCs|adSN)rI)rNrOrOrPr1sr1c Cslt|\}}tt||}|}|dkrR|sRtj||fWdS|rbt|d}nt j dd}|j }t ||||f} d} d} d} d} d |vrt|d } |r|| | | || }|sҐq| t|7} ||| d 7} |r|| | | qWdn1s0YWdn1s80Y| dkrh| | krhtd | | 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. fileNwbF)delete rcontent-lengthContent-Length1retrieval incomplete: got only %i out of %i bytes)r contextlibclosingr0infoospathnormpathrJtempfileNamedTemporaryFilename_url_tempfilesappendintreadlenwriter)rKfilename reporthookrLZurl_typer_fpheaderstfpresultbssizergblocknumblockrOrOrPr6sH          Nr6c CsBtD]&}zt|Wqty(Yq0qtdd=tr>dadS)z0Clean up temporary files from urlretrieve calls.N)rdr^unlinkOSErrorrI)Z temp_filerOrOrPr7s  r7z:\d+$cCs<|j}t|d}|dkr&|dd}td|d}|S)zReturn request-host, as defined by RFC 2965. Variation from RFC: returned value is lowercased, for convenient comparison. rYHost)full_urlr get_header _cut_port_resublower)requestrKhostrOrOrP request_host+s   rc@seZdZdidddfddZeddZejddZejddZed d Zejd d Zejd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZd#ddZdd Zd!d"ZdS)$rNFc Csl||_i|_i|_d|_||_d|_|D]\}}|||q,|durRt|}||_ ||_ |rh||_ dSrQ) rxrmunredirected_hdrs_datarL _tunnel_hostitems add_headerrorigin_req_host unverifiablemethod) selfrKrLrmrrrkeyvaluerOrOrP__init__=szRequest.__init__cCs|jrd|j|jS|jS)Nz{}#{})fragmentformat _full_urlrrOrOrPrxOszRequest.full_urlcCs(t||_t|j\|_|_|dSrQ)rrrr_parserrKrOrOrPrxUs cCsd|_d|_d|_dS)Nrv)rrselectorrrOrOrPrx\scCs|jSrQ)rrrOrOrPrLbsz Request.datacCs(||jkr$||_|dr$|ddS)NContent-length)r has_header remove_header)rrLrOrOrPrLfs  cCs d|_dSrQ)rLrrOrOrPrLpscCsNt|j\|_}|jdur(td|jt|\|_|_|jrJt|j|_dS)Nzunknown url type: %r) r rtyperBrxr r~rr )rrestrOrOrPrts  zRequest._parsecCs|jdurdnd}t|d|S)z3Return a string indicating the HTTP request method.NPOSTGETr)rLgetattr)rZdefault_methodrOrOrP get_method|szRequest.get_methodcCs|jSrQ)rxrrOrOrP get_full_urlszRequest.get_full_urlcCs2|jdkr|js|j|_n||_|j|_||_dS)Nhttps)rrr~rxr)rr~rrOrOrP set_proxys  zRequest.set_proxycCs |j|jkSrQ)rrxrrOrOrP has_proxyszRequest.has_proxycCs||j|<dSrQ)rm capitalizerrvalrOrOrPrszRequest.add_headercCs||j|<dSrQ)rrrrOrOrPadd_unredirected_headerszRequest.add_unredirected_headercCs||jvp||jvSrQ)rmrr header_namerOrOrPrs zRequest.has_headercCs|j||j||SrQ)rmgetr)rrdefaultrOrOrPrys zRequest.get_headercCs |j|d|j|ddSrQ)rmpoprrrOrOrPrszRequest.remove_headercCsi|j|j}t|SrQ)rrmlistr)rhdrsrOrOrP header_itemsszRequest.header_items)N)__name__ __module__ __qualname__rpropertyrxsetterdeleterrLrrrrrrrrryrrrOrOrOrPr;s6        rc@sNeZdZddZddZddZddZd ejfd d Z dd d Z ddZ d S)rcCs6dt}d|fg|_g|_i|_i|_i|_i|_dS)NPython-urllib/%sz User-agent) __version__ addheadershandlers handle_open handle_errorprocess_responseprocess_request)rZclient_versionrOrOrPrs zOpenerDirector.__init__c CsRt|dstdt|d}t|D]}|dvr6q&|d}|d|}||dd}|dr|d|d}||dd}z t|}WntyYn0|j |i} | |j|<n>|dkr|}|j } n*|d kr|}|j } n|d kr&|}|j } nq&| |g} | r t| |n | |d }q&|rNt|j|||dS) N add_parentz%expected BaseHandler instance, got %rF)redirect_requestdo_open proxy_open_rYerrorrJresponser}T)hasattr TypeErrorrdirfind startswithrfrBrrrrr setdefaultbisectinsortrerr) rhandlerZaddedmethiprotocol conditionjkindlookuprrOrOrP add_handlersL         zOpenerDirector.add_handlercCsdSrQrOrrOrOrPcloseszOpenerDirector.closec Gs<||d}|D]&}t||}||}|dur|SqdS)NrO)rr) rchainr meth_nameargsrrfuncrorOrOrP _call_chains   zOpenerDirector._call_chainNc Cst|trt||}n|}|dur(||_||_|j}|d}|j|gD]}t||}||}qJt d|j |j|j | |||} |d}|j|gD]}t||}||| } q| S)NZ_requestzurllib.RequestZ _response) isinstancestrrrLrMrrrrsysauditrxrmr_openr) rfullurlrLrMreqrr processorrrrOrOrPrJs$       zOpenerDirector.opencCsP||jdd|}|r|S|j}||j||d|}|r>|S||jdd|S)NrZ default_openrunknown unknown_open)rrr)rrrLrorrOrOrPrs    zOpenerDirector._opencGs~|dvr,|jd}|d}d|}d}|}n|j}|d}d}|||f|}|j|}|r^|S|rz|dd f|}|j|SdS) Nhttprrr:z http_error_%srY_errorrrhttp_error_default)rr)rprotordictrZhttp_errZ orig_argsrorOrOrPrs   zOpenerDirector.error)N) rrrrrrrsocket_GLOBAL_DEFAULT_TIMEOUTrJrrrOrOrOrPrs /  rc Gst}ttttttttt g }t t j dr2| tt}|D]B}|D]8}t|trht||r|||qDt||rD||qDq<|D]}||q|D]}||q|D]}t|tr|}||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-rrclientrerHsetrr issubclassaddremover)rrNZdefault_classesskipklasscheckhrOrOrPr27s2          r2c@s(eZdZdZddZddZddZdS) rcCs ||_dSrQ)parent)rrrOrOrPr^szBaseHandler.add_parentcCsdSrQrOrrOrOrPraszBaseHandler.closecCst|dsdS|j|jkS)N handler_orderT)rr)rotherrOrOrP__lt__es zBaseHandler.__lt__N)rrrrrrrrOrOrOrPr[src@s eZdZdZdZddZeZdS)r/zProcess HTTP error responses.icCsH|j|j|}}}d|kr,dksDn|jd|||||}|S)N,r)codemsgr]rr)rr}rrrrrOrOrP http_responsers  z HTTPErrorProcessor.http_responseN)rrr__doc__rrhttps_responserOrOrOrPr/ns r/c@seZdZddZdS)rcCst|j||||dSrQ)rrx)rrrlrrrrOrOrPrsz*HTTPDefaultErrorHandler.http_error_defaultN)rrrrrOrOrOrPrsrc@s4eZdZdZdZddZddZeZZZ dZ dS) r c st|}|dvr|dvs:|dvr(|dks:t|j|||||dd}dfdd |jD}t|||jd d S) aReturn 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)rHEAD)rrrr z%20)rWz content-typecs"i|]\}}|vr||qSrO)r|.0kvZCONTENT_HEADERSrOrP s  z8HTTPRedirectHandler.redirect_request..T)rmrr)rrrxreplacermrrr) rrrlrrrmnewurlm newheadersrOr rPrs  z$HTTPRedirectHandler.redirect_requestc CsLd|vr|d}nd|vr$|d}ndSt|}|jdvrRt||d||f|||jsn|jrnt|}d|d<t|}t|dtj d}t |j |}| ||||||}|durdSt |d r|j} |_| |d |jkst| |jkrt|j ||j|||ni} |_|_| |d d | |<|||jj||jd S) Nlocationurirrftprvz+%s - Redirection to url '%s' is not allowed/r:z iso-8859-1)encodingsafe redirect_dictrrYrM)rschemerr_netlocrrr string punctuationrrxrrrr max_repeatsrhmax_redirectionsinf_msgrgrrrJrM) rrrlrrrmrurlpartsnewZvisitedrOrOrPhttp_error_302sH          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) rrrrrrr#http_error_301http_error_303http_error_307r rOrOrOrPrs &< rc Cst|\}}|ds d}|}nZ|ds6td|d|vrV|d}|d|}n |dd}|dkrnd}|d|}t|\}}|durt|\}} 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. rN//zproxy URL with no authority: %r@r:rV)r rrBrrr) proxyrZr_scheme authorityZhost_separatorenduserinfohostportuserpasswordrOrOrP _parse_proxys$        r0c@s"eZdZdZdddZddZdS)rdNcCsb|durt}t|ds Jd||_|D].\}}|}t|d||||jfddq.dS)Nkeysproxies must be a mappingz%s_opencSs ||||SrQrO)rr)rrrOrOrP!sz'ProxyHandler.__init__..)r5rproxiesrr|setattrr)rr6rrKrOrOrPrs zProxyHandler.__init__c Cs|j}t|\}}}}|dur"|}|jr6t|jr6dS|rv|rvdt|t|f} t| d} | dd| t|}| ||||ks|dkrdS|j j ||j dSdS)N%s:%sasciiProxy-authorizationBasic rr)rr0r~ proxy_bypassr base64 b64encodeencodedecoderrrrJrM) rrr)rZ orig_typeZ proxy_typer.r/r-Z user_passZcredsrOrOrPr$s" zProxyHandler.proxy_open)N)rrrrrrrOrOrOrPrs rc@s6eZdZddZddZddZd dd Zd d Zd S)r cCs i|_dSrQ)passwdrrOrOrPrBszHTTPPasswordMgr.__init__cs\t|tr|g}|jvr$ij|<dD].tfdd|D}||fj||<q(dS)NTFc3s|]}|VqdSrQ) reduce_uri)ru default_portrrOrP Lsz/HTTPPasswordMgr.add_password..)rrrAtuple)rrealmrr.rA reduced_urirOrErP add_passwordEs   zHTTPPasswordMgr.add_passwordc Cs`|j|i}dD]H}|||}|D].\}}|D] }|||r6|Sq6q*qdS)NrBNN)rArrCr is_suburi) rrIauthuriZdomainsrFreduced_authuriZurisZauthinforrOrOrPfind_user_passwordPs  z"HTTPPasswordMgr.find_user_passwordTc Cst|}|dr.|d}|d}|dp*d}n d}|}d}t|\}}|r~|dur~|dur~ddd|} | dur~d || f}||fS) z@Accept authority or URI and extract only the authority and path.rYrr:rNPirz%s:%d)rr r) rrrFpartsrr*r_r~portZdportrOrOrPrCZs$  zHTTPPasswordMgr.reduce_uricCsN||kr dS|d|dkr dS|d}|dddkr@|d7}|d|S)zcCheck if test is below base in a URI tree Both args must be URIs in reduced form. TrFrYrVNr)r)rbasetestprefixrOrOrPrMqszHTTPPasswordMgr.is_suburiN)T)rrrrrKrPrCrMrOrOrOrPr @s   r c@seZdZddZdS)r!cCs0t|||\}}|dur"||fSt|d|SrQ)r rP)rrIrNr.r/rOrOrPrPs z2HTTPPasswordMgrWithDefaultRealm.find_user_passwordN)rrrrPrOrOrOrPr!sr!cs<eZdZfddZd fdd Zd ddZdd ZZS) r"csi|_tj|i|dSrQ) authenticatedsuperrrrkwargs __class__rOrPrsz%HTTPPasswordMgrWithPriorAuth.__init__Fcs<||||dur&td|||t||||dSrQ)update_authenticatedrXrK)rrIrr.rAis_authenticatedr[rOrPrKs z)HTTPPasswordMgrWithPriorAuth.add_passwordcCs>t|tr|g}dD]$}|D]}|||}||j|<qqdSNrB)rrrCrW)rrr^rFrDrJrOrOrPr]s   z1HTTPPasswordMgrWithPriorAuth.update_authenticatedcCsDdD]:}|||}|jD]"}|||r|j|SqqdSr_)rCrWrM)rrNrFrOrrOrOrPr^s    z-HTTPPasswordMgrWithPriorAuth.is_authenticated)F)F)rrrrrKr]r^ __classcell__rOrOr[rPr"s  r"c@sTeZdZedejZdddZddZddZ d d Z d d Z d dZ e Z e ZdS)r#z1(?:^|,)[ ]*([^ ,]+)[ ]+realm=(["']?)([^"']*)\2NcCs"|durt}||_|jj|_dSrQ)r rArK)rZ password_mgrrOrOrPrsz!AbstractBasicAuthHandler.__init__ccspd}tj|D]6}|\}}}|dvr8tdtd||fVd}q|sl|r^|d}nd}|dfVdS)NF)"'zBasic Auth Realm was unquotedTrrv)r#rxfinditergroupsr?r@ UserWarningsplit)rheaderZfound_challengemorr rIrOrOrP _parse_realms z%AbstractBasicAuthHandler._parse_realmc Cs~||}|sdSd}|D]H}||D]8\}}|dkrB|}q(|dur(||||Sq(q|durztd|fdS)NbasiczBAbstractBasicAuthHandler does not support the following scheme: %r)get_allrkr|retry_http_basic_authrB) rauthreqr~rrm unsupportedrirrIrOrOrPhttp_error_auth_reqeds  z.AbstractBasicAuthHandler.http_error_auth_reqedcCs||j||\}}|durtd||f}dt|d}||jd|krTdS||j||j j ||j dSdSdS)Nr8r;r9r) rArPr=r>r?r@ry auth_headerrrrJrM)rr~rrIr.pwrawauthrOrOrPrns z.AbstractBasicAuthHandler.retry_http_basic_authcCstt|jdr|j|js|S|dsp|jd|j\}}d||}t | }| dd| |S)Nr^ Authorizationz{0}:{1}zBasic {}) rrAr^rxrrPrr?r=standard_b64encoder@rstrip)rrr.rA credentialsZauth_strrOrOrP http_requests    z%AbstractBasicAuthHandler.http_requestcCsLt|jdrHd|jkr"dkr8nn|j|jdn|j|jd|S)Nr^rrTF)rrArr]rx)rrrrOrOrPr s  z&AbstractBasicAuthHandler.http_response)N)rrrrecompileIrdrrkrqrnrzr https_requestrrOrOrOrPr#s   r#c@seZdZdZddZdS)r$rvcCs|j}|d|||}|S)Nwww-authenticate)rxrq)rrrlrrrmrKrrOrOrPhttp_error_401s z#HTTPBasicAuthHandler.http_error_401N)rrrrrrrOrOrOrPr$sr$c@seZdZdZddZdS)r%r:cCs|j}|d|||}|SNproxy-authenticate)r~rq)rrrlrrrmr*rrOrOrPhttp_error_407's z$ProxyBasicAuthHandler.http_error_407N)rrrrrrrOrOrOrPr%#sr%c@sNeZdZdddZddZddZdd Zd d Zd d ZddZ ddZ dS)r&NcCs4|durt}||_|jj|_d|_d|_d|_dSNr)r rArKretried nonce_count last_nonce)rrArOrOrPrAs z"AbstractDigestAuthHandler.__init__cCs d|_dSr)rrrOrOrPreset_retry_countJsz+AbstractDigestAuthHandler.reset_retry_countcCs|||d}|jdkr*t|jdd|dn|jd7_|rx|d}|dkr`|||S|dkrxtd|dS) Nizdigest auth failedrYrdigestrlzEAbstractDigestAuthHandler does not support the following scheme: '%s')rrrrxrhr|retry_http_digest_authrB)rrrr~rrmrorrOrOrPrqMs       z/AbstractDigestAuthHandler.http_error_auth_reqedcCsz|dd\}}ttdt|}|||}|rvd|}|j|jd|krRdS||j||j j ||j d}|SdS)NrrYz Digest %sr) rhparse_keqv_listfilterparse_http_listget_authorizationrmrrrrrrJrM)rrrutokenZ challengechalZauth_valresprOrOrPras z0AbstractDigestAuthHandler.retry_http_digest_authcCs@d|j|tf}|dtd}t|}|ddS)Nz %s:%s:%s:r9)rtimectimer? _randombyteshashlibsha1 hexdigest)rnoncesbdigrOrOrP get_cnoncemsz$AbstractDigestAuthHandler.get_cnoncecCsz6|d}|d}|d}|dd}|dd}WntyJYdS0||\}} |durfdS|j||j\} } | durdS|jdur||j|} nd} d| || f} d||j f}|dur| || d|||f}n~d | d vrZ||j kr|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)NrIrqop algorithmMD5opaquez%s:%s:%sr8ru,rYz%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")rKeyErrorget_algorithm_implsrArPrxrLget_entity_digestrrrhrrrr)rrrrIrrrrHKDr.rsZentdigZA1ZA2ZrespdigZncvalueZcnonceZnoncebitrTrOrOrPrxs\            z+AbstractDigestAuthHandler.get_authorizationcsD|dkrddn|dkr$ddn td|fdd}|fS)NrcSst|dSNr9)rmd5r?rxrOrOrPr5z?AbstractDigestAuthHandler.get_algorithm_impls..ZSHAcSst|dSr)rrr?rrrOrOrPr5rz.Unsupported digest authentication algorithm %rcsd||fS)Nr8rO)rdrrOrPr5r)rB)rrrrOrrPrs   z-AbstractDigestAuthHandler.get_algorithm_implscCsdSrQrO)rrLrrOrOrPrsz+AbstractDigestAuthHandler.get_entity_digest)N) rrrrrrqrrrrrrOrOrOrPr&6s   > r&c@s eZdZdZdZdZddZdS)r'zAn authentication protocol defined by RFC 2069 Digest authentication improves on basic authentication because it does not transmit passwords in the clear. rvcCs*t|jd}|d|||}||S)NrYr)rrxrqrrrrlrrrmr~retryrOrOrPrs z$HTTPDigestAuthHandler.http_error_401N)rrrrrrrrrOrOrOrPr'sr'c@seZdZdZdZddZdS)r(Proxy-AuthorizationrcCs"|j}|d|||}||Sr)r~rqrrrOrOrPrs z%ProxyDigestAuthHandler.http_error_407N)rrrrrrrrOrOrOrPr(sr(c@s6eZdZd ddZddZddZdd Zd d Zd S)AbstractHTTPHandlerrcCs ||_dSrQ _debuglevel)r debuglevelrOrOrPrszAbstractHTTPHandler.__init__cCs ||_dSrQr)rlevelrOrOrPset_http_debuglevelsz'AbstractHTTPHandler.set_http_debuglevelcCstjj|j|SrQ)rrHTTPConnection_get_content_lengthrLrrr}rOrOrPrsz'AbstractHTTPHandler._get_content_lengthc Cs|j}|std|jdur|j}t|tr8d}t||dsN|dd|ds|ds||}|dur|dt|n |dd|}| rt |j \}}t |\}} |ds|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-urlencodedrTransfer-encodingchunkedrw)r~rrLrrrrrrrr rr rrr) rr}r~rLrcontent_lengthZsel_hostrZselZsel_pathrcrrOrOrP do_request_sF         zAbstractHTTPHandler.do_request_c sV|j}|std||fd|ji|}||jt|jfdd|j Ddd<dd D|j ri}d}|vr|||<|=|j |j |d zbz&|j | |j|j|d d Wn.ty}zt|WYd }~n d }~00|} Wn|Yn0|jr@|jd |_|| _| j| _| S) zReturn an HTTPResponse object for the request, using http_class. http_class must implement the HTTPConnection API from http.client. rrMcsi|]\}}|vr||qSrOrOrrmrOrPr 's z/AbstractHTTPHandler.do_open..r ConnectioncSsi|]\}}||qSrO)title)rrcrrOrOrPr 4rrrr)encode_chunkedN)r~rrMset_debuglevelrrrupdatermrr set_tunnelr}rrrLrru getresponsersockrrKreasonr) rZ http_classrZhttp_conn_argsr~rZtunnel_headersZproxy_auth_hdrerrr4rOrrPrsB        zAbstractHTTPHandler.do_openN)r)rrrrrrrrrOrOrOrPrs  &rc@seZdZddZejZdS)r)cCs|tjj|SrQ)rrrrrrrOrOrP http_open^szHTTPHandler.http_openN)rrrrrrrzrOrOrOrPr)\sr)rc@s$eZdZdddZddZejZdS)rHrNcCst||||_||_dSrQ)rr_context_check_hostname)rrr>check_hostnamerOrOrPrgs zHTTPSHandler.__init__cCs|jtjj||j|jdS)N)r>r)rrrrrrrrOrOrP https_openls zHTTPSHandler.https_open)rNN)rrrrrrrr~rOrOrOrPrHes rHc@s.eZdZdddZddZddZeZeZdS) rNcCs$ddl}|dur|j}||_dSr)Zhttp.cookiejar cookiejar CookieJar)rrrrOrOrPrus zHTTPCookieProcessor.__init__cCs|j||SrQ)radd_cookie_headerrrOrOrPrz{s z HTTPCookieProcessor.http_requestcCs|j|||SrQ)rextract_cookies)rr}rrOrOrPrsz!HTTPCookieProcessor.http_response)N)rrrrrzrr~rrOrOrOrPrts  rc@seZdZddZdS)r.cCs|j}td|dS)Nzunknown url type: %s)rr)rrrrOrOrPrszUnknownHandler.unknown_openN)rrrrrOrOrOrPr.sr.cCsNi}|D]@}|dd\}}|ddkr@|ddkr@|dd}|||<q|S)z>Parse list of key=value strings where keys are not duplicated.=rYrrarV)rh)lparsedeltr r rOrOrPrs  rcCsg}d}d}}|D]l}|r*||7}d}q|rT|dkr>d}qn |dkrJd}||7}q|dkrl||d}q|dkrxd}||7}q|r||dd|DS) 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. rvF\TrarcSsg|] }|qSrO)rx)rpartrOrOrP rz#parse_http_list..)re)rresrescaper currOrOrPrs4    rc@s(eZdZddZdZddZddZdS)r*cCs\|j}|dddkrN|dddkrN|jrN|jdkrN|j|vrXtdn ||SdS)Nr:r'rcr localhost-file:// scheme is supported only on localhost)rr~ get_namesropen_local_file)rrrKrOrOrP file_opens& zFileHandler.file_openNcCs^tjdurXz*ttddttdt_Wn"tjyVtdft_Yn0tjS)Nrr:)r*namesrHrgethostbyname_ex gethostnamegaierror gethostbynamerrOrOrPrs   zFileHandler.get_namesc Csddl}ddl}|j}|j}t|}zt|}|j}|jj |j dd} | |d} | d| pbd|| f} |r~t |\}} |r| st||vr|rd||} nd|} tt|d| | WSWn,ty}zt|WYd}~n d}~00tddS) NrTusegmtz6Content-type: %s Content-length: %d Last-modified: %s text/plainfile://rbzfile not on local host) email.utils mimetypesr~rr4r^statst_sizeutils formatdatest_mtime guess_typemessage_from_stringr _safe_gethostbynamerrrJrur)rremailrr~rjZ localfilestatsrqmodifiedmtypermrSZorigurlexprOrOrPrs:   zFileHandler.open_local_file)rrrrrrrrOrOrOrPr*s  r*cCs(z t|WStjy"YdS0dSrQ)rrr)r~rOrOrPrs rc@seZdZddZddZdS)r+c Cs.ddl}ddl}|j}|s"tdt|\}}|dur>|j}nt|}t|\}}|rdt|\}}nd}t |}|pvd}|p~d}zt |}Wn,t y}zt|WYd}~n d}~00t |j\} } | d} ttt | } | dd| d} } | r| ds| dd} z|||||| |j} | r8dp:d}| D]2}t|\}}|d kr@|d vr@|}q@| | |\}}d}||jd}|r|d |7}|dur|dkr|d |7}t|}t|||jWS|jy(}z*td |}|t dWYd}~n d}~00dS)Nrftp error: no host givenrvrrVrYr}DraArr}rrzContent-type: %s zContent-length: %d ftp error: %rr:)!ftplibrr~rr FTP_PORTrfrrr rrrurrrhrmap connect_ftprMrr|upperretrfilerrxrrr all_errorswith_tracebackrexc_info)rrrrr~rSr.rArr_attrsdirsrRfwrattrrrlretrlenrmrrexcrOrOrPftp_opens^          zFTPHandler.ftp_openc Cst||||||ddS)NF) persistent) ftpwrapper)rr.rAr~rSrrMrOrOrPr /szFTPHandler.connect_ftpN)rrrrr rOrOrOrPr+s5r+c@s<eZdZddZddZddZddZd d Zd d Zd S)r,cCs"i|_i|_d|_d|_d|_dS)Nr<r)cacherMsoonestdelay max_connsrrOrOrPr6s zCacheFTPHandler.__init__cCs ||_dSrQ)r)rtrOrOrP setTimeout=szCacheFTPHandler.setTimeoutcCs ||_dSrQ)r)rrrOrOrP setMaxConns@szCacheFTPHandler.setMaxConnscCsr|||d||f}||jvr4t|j|j|<n,t|||||||j|<t|j|j|<||j|S)Nr)joinrrrrMr check_cache)rr.rAr~rSrrMrrOrOrPr Cs   zCacheFTPHandler.connect_ftpcCst}|j|krPt|jD].\}}||kr |j||j|=|j|=q tt|j|_t |j|j krt|jD]&\}}||jkr|j|=|j|=qqtt|j|_dSrQ) rrrrMrrrminvaluesrhr)rrr r rOrOrPr"Ns   zCacheFTPHandler.check_cachecCs0|jD] }|q |j|jdSrQ)rr$rclearrM)rconnrOrOrP clear_cachebs  zCacheFTPHandler.clear_cacheN) rrrrrr r r"r'rOrOrOrPr,3s  r,c@seZdZddZdS)r-cCs~|j}|dd\}}|dd\}}t|}|drNt|}|dd}|sVd}td|t|f}t t |||S)N:rYrz;base64itext/plain;charset=US-ASCIIz$Content-type: %s Content-length: %d ) rxrhrendswithr= decodebytesrrrhrioBytesIO)rrrKrrLZ mediatypermrOrOrP data_openis     zDataHandler.data_openN)rrrr.rOrOrOrPr-hsr-rnt)r4r3cCst|S)zOS-specific conversion from a relative URL of the 'file' scheme to a file system path; not recommended for general use.)r pathnamerOrOrPr4sr4cCst|S)zOS-specific conversion from a file system path to a relative URL of the 'file' scheme; not recommended for general use.)r r0rOrOrPr3sr3c@seZdZdZdZdeZd*ddZddZdd Z d d Z d d Z d+ddZ d,ddZ d-ddZd.ddZddZd/ddZd0ddZddZerddZd1d 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).NrcKsdd|jji}tj|tdd|dur.t}t|ds@Jd||_|d|_ |d|_ d |j fd g|_ g|_ tj|_d|_t|_dS) NzW%(class)s style of invoking requests is deprecated. Use newer urlopen functions/methodsclassrc) stacklevelr2r3key_file cert_filez User-Agent)Acceptz*/*)r\rr?r@rAr5rr6rr4r5versionr_URLopener__tempfilesr^rt_URLopener__unlink tempcacheftpcache)rr6Zx509rrOrOrPrs   zURLopener.__init__cCs |dSrQ)rrrOrOrP__del__szURLopener.__del__cCs |dSrQ)cleanuprrOrOrPrszURLopener.closec CsT|jr@|jD]&}z||Wq ty0Yq 0q |jdd=|jrP|jdSrQ)r8r9rur:r%)rrRrOrOrPr=s   zURLopener.cleanupcGs|j|dS)zdAdd a header to be used by the HTTP interface only e.g. u.addheader('Accept', 'sound/basic')N)rre)rrrOrOrP addheaderszURLopener.addheaderc Csptt|}t|dd}|jrL||jvrL|j|\}}t|d}t|||St|\}}|s`d}||jvr|j|}t|\}} t| \} } | |f}nd}d|} ||_ | dd} t || r| d kr|r| |||S| ||Sz0|durt|| |WSt|| ||WSWnVttfy.Yn>tyj} z$td | td WYd} ~ n d} ~ 00dS) z6Use URLopener().open(file) instead of open(file, 'r').z%/:=&?~#+!$,;'@()*[]|rrrRNZopen_-rrz socket errorr:)rrr r:rJrr r6r rr ropen_unknown_proxy open_unknownrrrrurrr)rrrLrjrmrlurltyperKr) proxyhostr~rrcrrOrOrPrJs<             zURLopener.opencCst|\}}tdd|dS)/Overridable interface to open unknown URL type. url errorzunknown url typeNr ru)rrrLrrKrOrOrPrBs zURLopener.open_unknowncCs t|\}}tdd||dS)rErFzinvalid proxy for %sNrG)rr)rrLrrKrOrOrPrAs zURLopener.open_unknown_proxycCstt|}|jr&||jvr&|j|St|\}}|dur|rF|dkrz0||}|}|tt|d|fWSt yYn0| ||}zL|} |rt |d} nrt|\} } t| pd\} } t | pd\} } t | pd\} } t j| d} t| \}}|j|t |d} z|| f}|jdurD||j|<d}d}d}d}d | vrjt| d }|r|||||||}|sq|t|7}| ||d7}|r|||||q|W| n | 0W|n |0|dkr||krtd ||f||S) ztretrieve(url) returns (filename, headers) for a local object or (tempfilename, headers) for a remote object.NrRrYrSrvrUrVrrWrXrZ)rrr:r rr]rr4r rurJrrr^r_splitextramkstempr8refdopenrfrgrhrir)rrKrjrkrLrZurl1rlrrmrnZgarbager_suffixfdrorprqrgrrrsrOrOrPretrieve sn                  zURLopener.retrievecCs"d}d}t|trr?r@rr}rrr BadStatusLinerstatusrr http_errorrlr)rZconnection_factoryrKrLZ user_passwdZ proxy_passwdr~rZrealhostrCrZ proxy_authruZ http_connrmrirrrOrOrP_open_generic_httpNst              zURLopener._open_generic_httpcCs|tjj||S)zUse HTTP protocol.)rRrrrrrKrLrOrOrP open_httpszURLopener.open_httpc Csbd|}t||rPt||}|dur6||||||} n|||||||} | rP| S||||||S)zHandle http errors. Derived class can override this, or provide specific handlers named http_error_DDD where DDD is the 3-digit error code.z http_error_%dN)rrr) rrKrlerrcodeerrmsgrmrLrcrrorOrOrPrQs  zURLopener.http_errorcCs|t||||ddS)z>Default error handler: close the connection and raise OSError.N)rrrrKrlrUrVrmrOrOrPrszURLopener.http_error_defaultcCstjj||j|jdS)N)r4r5)rrrr4r5)rr~rOrOrP_https_connectionszURLopener._https_connectioncCs||j||S)zUse HTTPS protocol.)rRrXrSrOrOrP open_httpsszURLopener.open_httpscCs^t|tstd|dddkrP|dddkrP|dddkrPtd n ||SdS) z/Use local file or FTP depending on form of URL.zEfile error: proxy support for file protocol currently not implementedNr:r'rcr z localhost/r)rrrr|rBrrrOrOrP open_files  4 zURLopener.open_filec Cs^ddl}ddl}t|\}}t|}zt|}Wn2tyd}zt|j|j WYd}~n d}~00|j } |j j |j dd} ||d} |d| pd| | f} |s|} |dddkrd |} tt|d | | St|\}}|sRt|tftvrR|} |dddkr"d |} n|dd d kr@td |tt|d | | StddS)zUse local file.rNTrz6Content-Type: %s Content-Length: %d Last-modified: %s rrYrrrr:z./zAlocal file url may start with / or file:. Unknown url of type: %sz#local file error: not on local host)rrr r4r^rrurstrerrorrjrrrrrrrrJr rrrthishostrB)rrKrrr~rRZ localnamererqrrrmZurlfilerSrOrOrPrs@ $    zURLopener.open_local_filec Cst|tstdddl}t|\}}|s2tdt|\}}t|\}}|r\t|\}}nd}t|}t|ppd}t|p|d}t |}|sddl }|j }nt |}t|\}} t|}|d} | dd| d} } | r| ds| dd} | r | ds d| d<|||d| f} t|jtkrbt|jD]*} | | kr6|j| }|j| =|q6z| |jvrt||||| |j| <| sd }nd }| D]2}t|\}}|d kr|d vr|}q|j| | |\}}|d |d}d}|r |d|7}|dur,|dkr,|d|7}t|}t||d |WSty}z&td| t!"dWYd}~n d}~00dS)zUse FTP protocol.zCftp error: proxy support for ftp protocol currently not implementedrNrrvrrVrYrr}rrzftp:zContent-Type: %s zContent-Length: %d z ftp error %rr:)#rrrrr r rrr rrrrrfrrhr!rhr; MAXFTPCACHErrrrr|r r rrrr ftperrorsrrr)rrKrr~r_rSr.rArrrrRrr r rrrrlrrrmrrOrOrPopen_ftpsj                    zURLopener.open_ftpc Cs:t|tstdz|dd\}}WntyBtddYn0|sLd}|d}|dkrd ||d vr||dd }|d |}nd }g}|d t d t t|d||dkrt | dd}nt|}|dt||d ||d|}t|}t|}t|||S)zUse "data" URL.zEdata error: proxy support for data protocol currently not implementedrrYz data errorz bad data URLr);rrNrvzDate: %sz%a, %d %b %Y %H:%M:%S GMTzContent-type: %sr=r9zlatin-1zContent-Length: %d )rrrrhrBrurfindrerstrftimegmtimer=r+r?r@r rhr!rrr,StringIOr) rrKrLrsemirrrmfrOrOrP open_data0s8          zURLopener.open_data)N)N)N)N)NNN)N)N)N)N)rrrrr8rr7rr<rr=r>rJrBrArMrRrTrQrrCrXrYr[rrarjrOrOrOrPr8s.  $   A\     :r8c@seZdZdZddZddZd#ddZd d Zd$d d Zd%d dZ d&ddZ d'ddZ d(ddZ d)ddZ d*ddZd+ddZd,ddZd-dd Zd!d"ZdS).r9z?Derived class with handlers for errors we can handle (perhaps).cOs.tj|g|Ri|i|_d|_d|_dS)Nrr)r8r auth_cachetriesmaxtriesrYrOrOrPr]szFancyURLopener.__init__cCst||d||S)z3Default error handling -- don't raise an exception.rN)rrWrOrOrPrcsz!FancyURLopener.http_error_defaultNc Cs~|jd7_zb|jrR|j|jkrRt|dr4|j}n|j}|||dd|Wd|_S|||||||}|Wd|_Sd|_0dS)z%Error 302 -- relocated (temporarily).rYhttp_error_500rz)Internal Server Error: Redirect RecursionrN)rlrmrrnrredirect_internal) rrKrlrUrVrmrLrrorOrOrPr#gs&  zFancyURLopener.http_error_302c Csxd|vr|d}nd|vr$|d}ndS|t|jd||}t|}|jdvrnt|||d|||||S)Nrrr(rz( Redirection to url '%s' is not allowed.)rrrrrrrJ) rrKrlrUrVrmrLrr!rOrOrProys    z FancyURLopener.redirect_internalcCs|||||||S)z*Error 301 -- also relocated (permanently).r#rrKrlrUrVrmrLrOrOrPr$szFancyURLopener.http_error_301cCs|||||||S)z;Error 303 -- also relocated (essentially identical to 302).rprqrOrOrPr%szFancyURLopener.http_error_303cCs2|dur|||||||S||||||SdS)z1Error 307 -- relocated, but turn POST into error.N)r#rrqrOrOrPr&szFancyURLopener.http_error_307Fc Csd|vrt|||||||d}td|} | sHt||||||| \} } | dkrtt|||||||st||||||d|jd} |durt|| || St|| || |SdS)z_Error 401 -- authentication required. This function supports Basic authentication only.r![ ]*([^ ]+)[ ]+realm="([^"]*)"rlZretry_ _basic_authNr8rr{matchrfr|rr rrKrlrUrVrmrLrstuffrurrIrcrOrOrPrs.      zFancyURLopener.http_error_401c Csd|vrt|||||||d}td|} | sHt||||||| \} } | dkrtt|||||||st||||||d|jd} |durt|| || St|| || |SdS)zeError 407 -- proxy authentication required. This function supports Basic authentication only.rrrrlZ retry_proxy_rsNrtrvrOrOrPrs.      zFancyURLopener.http_error_407cCst|\}}d||}|jd}t|\}} t| \} } | dd} | | d} || || \} } | sr| srdSdt| ddt| dd| f} d| | |jd<|dur||S|||SdS)Nhttp://rr(rY%s:%s@%srvr?r r6r rget_user_passwdr rJrrKrIrLr~rrr)rCrDZ proxyselectorrr.rArOrOrPretry_proxy_http_basic_auths           z*FancyURLopener.retry_proxy_http_basic_authcCst|\}}d||}|jd}t|\}} t| \} } | dd} | | d} || || \} } | sr| srdSdt| ddt| dd| f} d| | |jd<|dur||S|||SdS)Nhttps://rr(rYryrvr?rzr|rOrOrPretry_proxy_https_basic_auths           z+FancyURLopener.retry_proxy_https_basic_authc Cst|\}}|dd}||d}||||\}}|sD|sDdSdt|ddt|dd|f}d||} |dur|| S|| |SdS)Nr(rYryrvr?rxr rr{r rJ rrKrIrLr~rrr.rArrOrOrPrns       z$FancyURLopener.retry_http_basic_authc Cst|\}}|dd}||d}||||\}}|sD|sDdSdt|ddt|dd|f}d||} |dur|| S|| |SdS)Nr(rYryrvr?r~rrrOrOrPretry_https_basic_auth s       z%FancyURLopener.retry_https_basic_authrcCs`|d|}||jvr2|r(|j|=n |j|S|||\}}|sJ|rX||f|j|<||fS)Nr()r|rkprompt_user_passwd)rr~rIr'rr.rArOrOrPr{ s   zFancyURLopener.get_user_passwdcCsVddl}z.td||f}|d|||f}||fWStyPtYdS0dS)z#Override this in a GUI environment!rNzEnter username for %s at %s: z#Enter password for %s in %s at %s: rL)getpassinputKeyboardInterruptprint)rr~rIrr.rArOrOrPr! s  z!FancyURLopener.prompt_user_passwd)N)N)N)N)NF)NF)N)N)N)N)r)rrrrrrr#ror$r%r&rrr}rrnrr{rrOrOrOrPr9Zs(           r9cCstdurtdatS)z8Return the IP address of the magic hostname 'localhost'.Nr) _localhostrrrOrOrOrPr1 s rcCsNtdurJztttdaWn&tjyHttddaYn0tS)z,Return the IP addresses of the current host.Nr:r) _thishostrHrrrrrOrOrOrPr]9 s r]cCstdurddl}|jatS)z1Return the set of errors raised by the FTP class.Nr) _ftperrorsrr )rrOrOrPr`D sr`cCstdurtdatS)z%Return an empty email Message object.Nrv) _noheadersrrrOrOrOrP noheadersM s rc@sJeZdZdZdddZddZdd Zd d Zd d ZddZ ddZ dS)rz;Class used by open_ftp() for cache of open FTP connections.NTcCsX||_||_||_||_||_||_d|_||_z |Wn| Yn0dSr) r.rAr~rSrrMrefcount keepaliveinitr)rr.rAr~rSrrMrrOrOrPrZ s zftpwrapper.__init__cCs\ddl}d|_||_|j|j|j|j|j|j |j d |j }|j |dS)Nrr)rbusyZFTPrconnectr~rSrMloginr.rAr!rcwd)rr_targetrOrOrPrj s  zftpwrapper.initc Csddl}||dvr"d}d}n d|}d}z|j|Wn(|jyf||j|Yn0d}|r|szd|}|j|\}}WnT|jy}z:t|dddkrt d | t d WYd}~n d}~00|s|jd|rz|j } zXz|j|Wn6|jyP}zt d ||WYd}~n d}~00W|j| n|j| 0d |}nd }|j|\}}d|_t|d |j} |jd7_|| |fS)Nr)rrzTYPE ArYzTYPE zRETR rcZ550rr:zLIST LISTr)r endtransferrZvoidcmdr rZ ntransfercmdZ error_permrrrrrpwdrrrmakefile file_closerr) rrRrrcmdisdirr&rrrZftpobjrOrOrPr s sJ     & zftpwrapper.retrfilecCs d|_dSr)rrrOrOrPr szftpwrapper.endtransfercCsd|_|jdkr|dS)NFr)rr real_closerrOrOrPr s zftpwrapper.closecCs2||jd8_|jdkr.|js.|dS)NrYr)rrrrrrOrOrPr szftpwrapper.file_closecCs0|z|jWnty*Yn0dSrQ)rrrr`rrOrOrPr s zftpwrapper.real_close)NT) rrrrrrr rrrrrOrOrOrPrW s  -rcCsi}tjD]4\}}|}|r|dddkr|||dd<qdtjvrZ|ddtjD]J\}}|dddkrd|}|r|||dd<qd||dddqd|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. iN_proxyZREQUEST_METHODr)r^environrr|r)r6rcrrOrOrPgetproxies_environment s   rcCs|durt}z |d}Wnty.YdS0|dkr|dd>B|dd >B|d BS) Nrr)rrrrrrYrr:rrc)rhrr rfrh)ZipAddrrRrOrOrPip2num s   z,_proxy_bypass_macosx_sysconf..ip2numrZexclude_simpleTN exceptionsrOz(\d+(?:\.\d+)*)(/\d+)?rYr:r F) rr rr{rurrrugroupcountrf) r~proxy_settingsrrrSrZhostIPrrrTmaskrOrOrP_proxy_bypass_macosx_sysconf s<          rdarwin)_get_proxy_settings _get_proxiescCst}t||SrQ)rr)r~rrOrOrPproxy_bypass_macosx_sysconf> srcCstS)zReturn a dictionary of scheme -> proxy server URL mappings. This function uses the MacOSX framework SystemConfiguration to fetch the proxy information. )rrOrOrOrPgetproxies_macosx_sysconfB srcCs t}|rt||St|SdS)zReturn True, if host should be bypassed. Checks proxy settings gathered from the environment, if specified, or from the MacOSX framework SystemConfiguration. N)rrrr~r6rOrOrPr<L s r<cCs tp tSrQ)rrrOrOrOrPr5Y sr5c CsBi}z ddl}Wnty&|YS0z||jd}||dd}|rt||dd}d|vr|d|vr|d|}|dD]J}|dd \}}t d |s|d vrd |}n|d krd|}|||<q| d rt dd|d }| dp||d<| dp||d<| Wnt ttfy<Yn0|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 ProxyServerrrbzhttp={0};https={0};ftp={0}rYz (?:[^/:]+)://)rrrrxsockszsocks://z ^socks://z socks4://rr)winreg ImportErrorOpenKeyHKEY_CURRENT_USER QueryValueExrrrhr{rurr{CloserurBr)r6rinternetSettings proxyEnableZ proxyServerpraddressrOrOrPgetproxies_registry^ sL         rcCs tp tS)zReturn a dictionary of scheme -> proxy server URL mappings. Returns settings gathered from the environment, if specified, or the registry. )rrrOrOrOrPr5 sc Csrz ddl}Wnty YdS0z6||jd}||dd}t||dd}WntylYdS0|rv|szdSt|\}}|g}z t |}||kr| |WntyYn0z t |}||kr| |WntyYn0| d}|D]j} | dkr d|vr dS| dd } | d d } | d d} |D] } t| | tjrHdSqHqdS) NrrrZ ProxyOverriderbzrrYz\.rz.*?)rrrrrrrur rrregetfqdnrhr r{rur}) r~rrrZ proxyOverrideZrawHostrSaddrZfqdnrUrrOrOrPproxy_bypass_registry s`               rcCs t}|rt||St|SdS)zReturn True, if host should be bypassed. Checks proxy settings gathered from the environment, if specified, or the registry. N)rrrrrOrOrPr< s )NNN)N)~rr=rrr http.clientrr,r^ posixpathr{rrrrrar[r?Z urllib.errorrrr urllib.parserrrrr r r r r rrrrrrrrrZurllib.responserrrDrrC__all__ version_inforrIrr0r1rdr6r7r|ASCIIrzrrrr2rr/rrr0rr r!r"r#r$r%urandomrr&r'r(rr)rrrHrerr.rrr*rr+r,r-r_rcZ nturl2pathr4r3r;r8r9rrrr]rr`rrrrrrplatformZ_scproxyrrrrr<r5rrrOrOrOrPsSP   M ?m$q!+@ o  v  +3:5! @W  _ %A    1 2