g{dZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlmZmZmZddlmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'ddl(m)Z)m*Z* ddl+Z+dZ,gdZ.d e j^dd zZ0da1de jdfddddd d Z3d Z4gZ5dgdZ6dZ7e jpde jrZ:dZ;GddZ<GddZ=dZ>GddZ?Gdde?Z@Gdde?ZAGdde?ZBdZCGd d!e?ZDGd"d#ZEGd$d%eEZFGd&d'eFZGGd(d)ZHGd*d+eHe?ZIGd,d-eHe?ZJejZLGd.d/ZMGd0d1e?eMZNGd2d3e?eMZOGd4d5e?ZPGd6d7ePZQeRejd8rGd9d:ePZTe.jd:Gd;de?ZWd?ZXd@ZYGdAdBe?ZZdCZ[GdDdEe?Z\GdFdGe\Z]GdHdIe?Z^dJZ_ejdKk(r ddLlambZbmcZcndMZbdNZciZdGdOdPZeGdQdReeZfdagdSZhdaidTZjdakdUZldamdVZnGdWdXZodYZpdhdZZqd[Zrd\Zse jd]k(rdd^lumvZvmwZwd_Zxd`ZydaZzdbZ{yejdKk(r dcZ|ddZ{deZ}dfZzyepZ{eqZzy#e-$rdZ,Y[wxYw)ia 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, 307, and 308 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 addclosehookTF)!RequestOpenerDirector BaseHandlerHTTPDefaultErrorHandlerHTTPRedirectHandlerHTTPCookieProcessor ProxyHandlerHTTPPasswordMgrHTTPPasswordMgrWithDefaultRealmHTTPPasswordMgrWithPriorAuthAbstractBasicAuthHandlerHTTPBasicAuthHandlerProxyBasicAuthHandlerAbstractDigestAuthHandlerHTTPDigestAuthHandlerProxyDigestAuthHandler HTTPHandler FileHandler FTPHandlerCacheFTPHandler DataHandlerUnknownHandlerHTTPErrorProcessorurlopeninstall_opener build_opener pathname2url url2pathname getproxies urlretrieve urlcleanup URLopenerFancyURLopenerz%d.%d)cafilecapath cadefaultcontextc|s|s|rddl}|jdtd| tdts tdt j t jj||}|jdgt| }t|} n3|rt| }t|} nt txa } nt} | j|||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=zhttp/1.1r?)warningswarnDeprecationWarning ValueError _have_sslsslcreate_default_contextPurpose SERVER_AUTHset_alpn_protocols HTTPSHandlerr3_openeropen) urldatatimeoutr<r=r>r?rB https_handleropeners 5/opt/alt/python312/lib64/python3.12/urllib/request.pyr1r1sh9 01CQ H   89 9,,S[[-D-D4:4:< ""J<0$W5 m, $W5 m, '>)& ;;sD' **c|ayN)rM)rSs rTr2r2sGrUct|\}}tjt||5}|j }|dk(r,|s*t j j||fcdddS|r t|d}n7tjd}|j}tj||5||f} d} d} d} d} d |vrt|d } |r || | | |j| x}rD| t!|z } |j#|| d z } |r || | | |j| x}rDdddddd dk\r | krt%d | | fz  S#1swY.xYw#1swY2xYw) 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 contextlibclosingr1infoospathnormpathrNtempfileNamedTemporaryFilename_url_tempfilesappendintreadlenwriter)rOfilename reporthookrPurl_typerffpheaderstfpresultbssizernblocknumblocks rTr7r7s  _NHd   GC. /2'') v h77##D)72 0 / x&C--U;CxxH  ! !( + w&FBDDH7*7#3458R.772;&%&E " % A xT2 772;&%&! 0F qyTD[" ?Tl "$ $ M1S! 0 /s+8E30AE38BE':E3'E0 ,E33E<ctD]} tj|tdd=trdayy#t$rY9wxYw)z0Clean up temporary files from urlretrieve calls.N)rkreunlinkOSErrorrM) temp_files rTr8r8sH#   IIi $ q    s5 AAz:\d+$c|j}t|d}|dk(r|jdd}tj d|d}|j S)zReturn request-host, as defined by RFC 2965. Variation from RFC: returned value is lowercased, for convenient comparison. r`Host)full_urlr get_header _cut_port_resublower)requestrOhosts rT request_hostr)sX   C C= D rz!!&"-   Ba (D ::<rUceZdZdidddfdZedZej dZejdZedZej dZejd Zd Z d Z d Z d Z dZ dZdZdZddZdZdZy)rNFc||_i|_i|_d|_||_d|_|j D]\}}|j||| t|}||_ ||_ |r||_ yyrW) rruunredirected_hdrs_datarP _tunnel_hostitems add_headerrorigin_req_host unverifiablemethod) selfrOrPrurrrkeyvalues rT__init__zRequest.__init__;s  !#   !--/JC OOC '*  "*40O.(  DK rUc~|jr&dj|j|jS|jS)Nz{}#{})fragmentformat _full_urlrs rTrzRequest.full_urlMs, ==>>$..$--@ @~~rUct||_t|j\|_|_|j yrW)r rrr_parserrOs rTrzRequest.full_urlSs/ (1$..(A%  rUc.d|_d|_d|_y)Nr)rrselectorrs rTrzRequest.full_urlZs  rUc|jSrW)rrs rTrPz Request.data`s zzrUcx||jk7r+||_|jdr|jdyyy)NContent-length)r has_header remove_header)rrPs rTrPz Request.datads= 4:: DJ/0""#341 rUcd|_yrW)rPrs rTrPz Request.datans  rUct|j\|_}|jtd|jzt |\|_|_|j rt|j |_yy)Nzunknown url type: %r) r rtyperErr rrr )rrests rTrzRequest._parsersd$T^^4 4 99 3dmmCD D#-d#3  4= 99 *DI rUc<|jdnd}t|d|S)z3Return a string indicating the HTTP request method.POSTGETr)rPgetattr)rdefault_methods rT get_methodzRequest.get_methodzs!#'99#8etX~66rUc|jSrW)rrs rT get_full_urlzRequest.get_full_urls }}rUc|jdk(r%|js|j|_||_y||_|j|_||_y)Nhttps)rrrrr)rrrs rT set_proxyzRequest.set_proxysF 99 (9(9 $ D  DI MMDM rUc4|j|jk(SrW)rrrs rT has_proxyzRequest.has_proxys}} --rUc>||j|j<yrW)ru capitalizerrvals rTrzRequest.add_headers), S^^%&rUc>||j|j<yrW)rrrs rTadd_unredirected_headerzRequest.add_unredirected_headers36s~~/0rUc>||jvxs||jvSrW)rurr header_names rTrzRequest.has_headers&t||+6t555 7rUcn|jj||jj||SrW)rugetr)rrdefaults rTrzRequest.get_headers2||   " " & &{G <> >rUct|jj|d|jj|dyrW)rupoprrs rTrzRequest.remove_headers, d+ "";5rUchi|j|j}t|jSrW)rrulistr)rhdrss rT header_itemszRequest.header_itemss,9$((9DLL9DJJL!!rUrW)__name__ __module__ __qualname__rpropertyrsetterdeleterrPrrrrrrrrrrrrUrTrr9s!%r!%E!$ __   [[55 \\+7 .-77> 6"rUrcReZdZdZdZdZdZdejfdZ d dZ dZ y) rcpdtz}d|fg|_g|_i|_i|_i|_i|_y)NPython-urllib/%sz User-agent) __version__ addheadershandlers handle_open handle_errorprocess_responseprocess_request)rclient_versions rTrzOpenerDirector.__init__sB+k9(.9:  "!rUct|dstdt|zd}t|D] }|dvr |j d}|d|}||dzd}|j drW|j d|zdz}||dzd} t |}|jj|i} | |j|<n=|dk(r|}|j} n)|d k(r|}|j} n|d k(r|}|j} n| j|g} | rtj| |n| j!|d } |r2tj|j"||j%|yy#t$rYwxYw) N add_parentz%expected BaseHandler instance, got %rF)redirect_requestdo_open proxy_open_r`errorrNresponserT)hasattr TypeErrorrdirfind startswithrmrErrrrr setdefaultbisectinsortrlrr) rhandleraddedmethiprotocol conditionjkindlookuprs rT add_handlerzOpenerDirector.add_handlersw -C M*+ +LDDD #ABQxHQqST I##G,NN3'!+a/AaCDzt9D**..x<.4!!(+f$))j(..i'--((r2H h0(EG!J  MM$-- 1   t $ /"s E33 E?>E?cyrWrrs rTclosezOpenerDirector.close rUcd|j|d}|D]}t||}||}||cSy)Nr)rr) rchainr meth_nameargsrrfuncrws rT _call_chainzOpenerDirector._call_chains>99T2&G7I.D4[F!  rUNct|tr t||}n |}|||_||_|j }|dz}|j j|gD]}t||}||}tjd|j|j|j|j|j||} |dz}|jj|gD]}t||}||| } | S)N_requestzurllib.Request _response) isinstancestrrrPrQrrrrsysauditrrur_openr) rfullurlrPrQreqrr processorrrs rTrNzOpenerDirector.opens gs #'4(CC 88Z' --11(B?I9i0Ds)C@ "CLL#((CKKIYZ::c4([( ..228R@I9i0DC*HArUc|j|jdd|}|r|S|j}|j|j||dz|}|r|S|j|jdd|S)Nr default_openrunknown unknown_open)rrr)rr rPrwrs rTrzOpenerDirector._open s!!$"2"2I"0#7 M88!!$"2"2Hh")?*+.0 M 0 0) .5 5rUc|dvr|jd}|d}d|z}d}|}n|j}|dz}d}|||f|z}|j|}|r|S|r|dd fz}|j|Sy) Nhttprrr;z http_error_%sr`_errorrrhttp_error_default)rr)rprotordictrhttp_err orig_argsrws rTrzOpenerDirector.errors % %$$V,DGE'%/IHI$$D(IHeY'$.!!!4( M )%9:YFD#4##T* * rUrW) rrrrrrrsocket_GLOBAL_DEFAULT_TIMEOUTrNrrrrUrTrrs3 "-%^  "&v/M/M: 5+rUrc ht}ttttt t tttg }ttjdr|jtt}|D]V}|D]O}t!|t"rt%||s |j'|2t!||s?|j'|QX|D]}|j)||D]}|j+||D]*}t!|t"r|}|j+|,|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)rr r/r*rrr,r+r0r.rrclientrlrLsetrr issubclassaddremover)rrSdefault_classesskipklasscheckhs rTr3r35s F#^[.0C!;0B"$Ot{{-.|, 5D E%&eU+HHUOE5) !u%!57#! a A1 MrUc"eZdZdZdZdZdZy)rc||_yrW)parent)rr)s rTrzBaseHandler.add_parent\s  rUcyrWrrs rTrzBaseHandler.close_rrUcNt|dsy|j|jkS)N handler_orderT)rr,)rothers rT__lt__zBaseHandler.__lt__cs(uo.!!E$7$777rUN)rrrr,rrr.rrUrTrrYsM 8rUrceZdZdZdZdZeZy)r0zProcess HTTP error responses.ic|j|j|j}}}d|cxkrdks"n|jj d|||||}|S)N,r)codemsgrdr)r)rrrr3r4rs rT http_responsez HTTPErrorProcessor.http_responsepsT"--x}}4ct!c!{{((4dr?r@r z%20)r^z content-typeT)rurr) rrrreplacerurrrr) rr rtr3r4runewurlmCONTENT_HEADERSkv newheaderss rTrz$HTTPRedirectHandler.redirect_requests NN 22qO7K&1;CLL$WbA AU+<'*{{'8'8':;':tq!/9d': ;v)'*':':$(* *;s,B'cZd|vr|d}n d|vr|d}nyt|}|jdvrt|||d|d|||js|jrt |}d|d<t |}t|dtj }t|j|}|j||||||}|yt|d rp|jx} |_| j|d |j k\st#| |j$k\r6t|j||j&|z||ix} x|_|_| j|d d z| |<|j)|j+|j,j/||j0 S)Nlocationurirrftprz - Redirection to url 'z' is not allowed/r;z iso-8859-1)encodingsafe redirect_dictrr`rQ)rschemerrfnetlocrrr string punctuationrrrrrRr max_repeatsromax_redirectionsinf_msgrnrr)rNrQ) rr rtr3r4rurDurlpartsnewvisiteds rThttp_error_302z"HTTPRedirectHandler.http_error_302s  Z(F g U^F F# ??"> >ADfM  }}H~HHQKH%  \0B0BDv. ##CT3H ;  3 (*-*;*; ;Gc' FA&$*:*::G  5 55 d $ s 2GRAA?A @G @c'#*;!++fa014    {{S[[99rUzoThe HTTP server returned a redirect error that would lead to an infinite loop. The last 30x error message was: N) rrrrXrYrr^http_error_301http_error_303http_error_307http_error_308rZrrUrTrrs<K *L::xIWVNV^Vn~2GrUrcft|\}}|jdsd}|}ne|jdstd|zd|vr$|jd}|jd|}n|jdd}|dk(rd}|d|}t |\}}|t |\}} ndx}} ||| |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. rON//zproxy URL with no authority: %r@r;r])r rrErrr) proxyrTr_scheme authorityhost_separatorenduserinfohostportuserpasswords rT _parse_proxyros"%(FH   s # ""4(>FG G (?%]]3/N--^4C--Q'C "9CQsO #I.Hh%h/hx 48 ++rUceZdZdZddZdZy)r dNc| t}t|dsJd||_|jD]4\}}|j }t |d|z|||j fd6y)Nkeysproxies must be a mappingz%s_openc||||SrWr)rrfrrs rTz'ProxyHandler.__init__..sQt,rU)r6rproxiesrrsetattrr)rrxrrOs rTrzProxyHandler.__init__sk ? lGw'D)DD'  ID#::rUr c,eZdZdZdZdZddZdZy)r!ci|_yrW)passwdrs rTrzHTTPPasswordMgr.__init__@s  rUct|tr|g}|jvrij|<dD]+tfd|D}||fj||<-y)NTFc3BK|]}j|ywrW) reduce_uri).0u default_portrs rT z/HTTPPasswordMgr.add_password..Js  ?:=Q<0#s)rrrtuple)rrealmrLrmr reduced_urirs` @rT add_passwordzHTTPPasswordMgr.add_passwordCsf c3 %C  #!#DKK 'L ?:= ??K/3VnDKK { +(rUc|jj|i}dD]M}|j||}|jD]&\}}|D]}|j ||s|cccS(Oy)NrNN)rrrr is_suburi) rrauthuridomainsrreduced_authuriurisauthinforLs rTfind_user_passwordz"HTTPPasswordMgr.find_user_passwordNsf++//%,'L"oog|DO")--/hC~~c?;' #2( rUct|}|dr|d}|d}|dxsd}nd}|}d}t|\}}|r!||dddj|} | d || fz}||fS) z@Accept authority or URI and extract only the authority and path.r`rr;rONPirz%s:%d)rrr) rrLrpartsrTrhrfrportdports rTrzHTTPPasswordMgr.reduce_uriXs  81XFaI8?sDFID * d DLV-?!s6{  #tUm3 $rUcr||k(ry|d|dk7ry|d}|dddk7r|dz }|dj|S)zcCheck if test is below base in a URI tree Both args must be URIs in reduced form. TrFr`r]NrO)r)rbasetestprefixs rTrzHTTPPasswordMgr.is_suburiosV 4< 7d1g a "#;#  cMFAw!!&))rUN)T)rrrrrrrrrrUrTr!r!>s =. *rUr!ceZdZdZy)r"cptj|||\}}|||fStj|d|SrW)r!r)rrrrmrns rTrz2HTTPPasswordMgrWithDefaultRealm.find_user_passwordsC(;;D% !11$gFFrUN)rrrrrrUrTr"r"~sGrUr"c8eZdZfdZdfd ZddZdZxZS)r#c2i|_t||i|yrW) authenticatedsuperr)rrkwargs __class__s rTrz%HTTPPasswordMgrWithPriorAuth.__init__s $)&)rUcv|j|||t| d|||t| ||||yrW)update_authenticatedrr)rrrLrmris_authenticatedrs rTrz)HTTPPasswordMgrWithPriorAuth.add_passwords@ !!#'78   G sD& 9 UCv6rUct|tr|g}dD]*}|D]#}|j||}||j|<%,yNr)rrrr)rrLrrrrs rTrz1HTTPPasswordMgrWithPriorAuth.update_authenticatedsG c3 %C'L"ooa> 2B"";/(rUcdD]J}|j||}|jD]'}|j||s|j|ccSLyr)rrr)rrrrrLs rTrz-HTTPPasswordMgrWithPriorAuth.is_authenticatedsK'L"oog|DO))>>#7--c22*(rU)F)rrrrrrr __classcell__)rs@rTr#r#s*7C3rUr#cteZdZejdej Zd dZdZdZ dZ dZ dZ e Z e Zy) r$z1(?:^|,)[ ]*([^ ,]+)[ ]+realm=(["']?)([^"']*)\2Nc`| t}||_|jj|_yrW)r!rr)r password_mgrs rTrz!AbstractBasicAuthHandler.__init__s)  *,L"  KK44rUc#Kd}tjj|D]=}|j\}}}|dvrt j dt d||fd}?|s|r|jd}nd}|dfyyw)NF)"'zBasic Auth Realm was unquotedTrr)r$rxfinditergroupsrBrC UserWarningsplit)rheaderfound_challengemorTr rs rT _parse_realmz%AbstractBasicAuthHandler._parse_realms*--66v>B#%99; FE5J& =)1.5/ !"O?*4. sBBc|j|}|syd}|D]J}|j|D]4\}}|jdk7r|}||j|||ccSL|t dy)Nbasicz@AbstractBasicAuthHandler does not support the following scheme: )get_allrrretry_http_basic_authrE) rauthreqrr ru unsupportedrrTrs rThttp_error_auth_reqedz.AbstractBasicAuthHandler.http_error_auth_reqeds//'*  F!%!2!26!: <<>W,"(K$ 55dCGG";  " &)* * #rUc|jj||\}}||d|}dtj|j j dz}|j |jd|k(ry|j|j||jj||jSy)Nr{r~r|rS) rrrrrrr auth_headerrr)rNrQ)rrr rrmpwrawauths rTrz.AbstractBasicAuthHandler.retry_http_basic_auths;;11%>b >!2&Cf..szz|<CCGLLD~~d..5=  ' '(8(8$ ?;;##C#= =rUct|jdr%|jj|js|S|j ds|jj d|j\}}dj ||j}tj|j}|jddj |j|S)Nr Authorizationz{0}:{1}zBasic {}) rrrrrrrrrstandard_b64encoderrstrip)rr rmr credentialsauth_strs rT http_requestz%AbstractBasicAuthHandler.http_requests %78{{++CLL9J~~o.;;99$ MLD&#**48??AK00=DDFH  ' '(2(9(9(..:J(K M rUct|jdrfd|jcxkrdkr+nn(|jj|jd|S|jj|jd|S)Nrr1r2TF)rrr3rr)rr rs rTr5z&AbstractBasicAuthHandler.http_response s` 4;; 2 3hmm)c) 00tD 00uErUrW)rrrrecompileIrrrrrrr5 https_requestr7rrUrTr$r$sL 1DD B5 !(*4  !M"NrUr$ceZdZdZdZy)r%rcF|j}|jd|||}|S)Nwww-authenticate)rr)rr rtr3r4rurOrs rThttp_error_401z#HTTPBasicAuthHandler.http_error_401s*ll--.@*-sG=rUN)rrrrrrrUrTr%r%s !KrUr%ceZdZdZdZy)r&r}cF|j}|jd|||}|SNproxy-authenticate)rr)rr rtr3r4rurhrs rThttp_error_407z$ProxyBasicAuthHandler.http_error_407%s- HH --.B*3S'CrUN)rrrrrrrUrTr&r&!s 'KrUr&c>eZdZd dZdZdZdZdZdZdZ d Z y) r'Nc| t}||_|jj|_d|_d|_d|_yNr)r!rrretried nonce_count last_nonce)rrs rTrz"AbstractDigestAuthHandler.__init__?s> >$&F  KK44 rUcd|_yr)rrs rTreset_retry_countz+AbstractDigestAuthHandler.reset_retry_countHs  rUcZ|j|d}|jdkDrt|jdd|d|xjdz c_|rZ|j d}|j dk(r|j ||S|j dk7rtd|zyy) Nizdigest auth failedr`rdigestrzEAbstractDigestAuthHandler does not support the following scheme: '%s')rrrrrrretry_http_digest_authrE)rrrr rurrTs rTrz/AbstractDigestAuthHandler.http_error_auth_reqedKs++k40 < > #'ucll")+  Of, ,D  Of, ,D "Y..  H HD g  s?G G#"G#cV|dk(rdn|dk(rdntd|zfd}|fS)Nrcftj|jdjSNr|)rmd5rrxs rTrwz?AbstractDigestAuthHandler.get_algorithm_impls..s'++ahhw&78BBDrUSHAcftj|jdjSr!)rrrrr#s rTrwz?AbstractDigestAuthHandler.get_algorithm_impls..s',,qxx'89CCErUz.Unsupported digest authentication algorithm %rc|d|S)Nr{r)r drs rTrwz?AbstractDigestAuthHandler.get_algorithm_impls..s!q!,-rU)rE)rrrrs @rTrz-AbstractDigestAuthHandler.get_algorithm_implssG  DA % EA,.789 9 -"u rUcyrWr)rrPrs rTrz+AbstractDigestAuthHandler.get_entity_digestsrUrW) rrrrrrrr rrrrrUrTr'r'4s,I(  <| rUr'ceZdZdZdZdZdZy)r(zAn authentication protocol defined by RFC 2069 Digest authentication improves on basic authentication because it does not transmit passwords in the clear. rc~t|jd}|jd|||}|j|S)Nr`r)rrrrrr rtr3r4rurretrys rTrz$HTTPDigestAuthHandler.http_error_401s@ %a(**+=+/g?   rUN)rrrr6rr,rrrUrTr(r(s "KMrUr(ceZdZdZdZdZy)r)Proxy-Authorizationr+cf|j}|jd|||}|j|Sr)rrrr-s rTrz%ProxyDigestAuthHandler.http_error_407s6xx**+?+/g?   rUN)rrrrr,rrrUrTr)r)s'KMrUr)c,eZdZddZdZdZdZdZy)AbstractHTTPHandlerNcj|||_ytjjj|_yrW)rrHTTPConnection debuglevel _debuglevel)rr6s rTrzAbstractHTTPHandler.__init__s&)3)?:T[[E_E_EjEjrUc||_yrW)r7)rlevels rTset_http_debuglevelz'AbstractHTTPHandler.set_http_debuglevels  rUctjjj|j|j SrW)rrr5_get_content_lengthrPrrrs rTr<z'AbstractHTTPHandler._get_content_lengths2{{))== LL    " "rUc|j}|s td|j|j}t|tr d}t ||j ds|jdd|j dsR|j dsA|j|}||jdt |n|jdd|}|jr&t|j\}}t|\}} |j ds|jd||jjD]9\} } | j} |j | r(|j| | ;|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-encodingchunkedr)rrrPrrrrrr<rr rr r)rr) rrrrPr4content_lengthsel_hostrTselsel_pathrjrs rT do_request_zAbstractHTTPHandler.do_request_sj||?+ + << #<L B  $ #..*CLL#((G),8K)LN A 66 FFLLNAF  " e-G  $sm# $  GGI s7G 8GAG G( G% G  G%%G((G;rW)rrrrr:r<rGrrrUrTr3r3sk!" $L@rUr3c*eZdZdZej Zy)r*cV|jtjj|SrW)rrrr5rr s rT http_openzHTTPHandler.http_open\s||DKK66<|jj|||SrW)riextract_cookies)rrrs rTr5z!HTTPCookieProcessor.http_responses &&x9rUrW)rrrrrr5rr7rrUrTrrws# !M"NrUrceZdZdZy)r/c6|j}td|z)Nzunknown url type: %s)rr)rr rs rTrzUnknownHandler.unknown_opensxx-455rUN)rrrrrrUrTr/r/s6rUr/cvi}|D]1}|jdd\}}|ddk(r |ddk(r|dd}|||<3|S)z>Parse list of key=value strings where keys are not duplicated.=r`rrr])r)lparsedeltrGrHs rTrrsU Fyya 1 Q43;1R5C<!BAq  MrUcg}d}dx}}|D]H}|r||z }d} |r|dk(rd}|dk(rd}||z }$|dk(r|j|d}=|dk(rd}||z }J|r|j||Dcgc]}|jc}Scc}w)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. rF\Trr)rlr)r respartescaper curs rTrrs C DFU  CKDF  d{ CKD  #: JJt D  #:E  -2  4%( )STDJJLS )) )s-Bc"eZdZdZdZdZdZy)r+c|j}|dddk(rK|dddk7rC|jr7|jdk7r(|j|jvr tdy|j |S)Nr;rdrrO localhost-file:// scheme is supported only on localhost)rr get_namesropen_local_file)rr rOs rT file_openzFileHandler.file_opensmll r7d?s1Qx3CHHK'88t~~//NOO0'', ,rUNctjf ttjddtjtj dzt_tjStjS#tj $r1tjdft_YtjSwxYw)Nr~r;)r+namesrrgethostbyname_ex gethostnamegaierror gethostbynamers rTrzFileHandler.get_namess    $ I$)++K8;++F,>,>,@A!DE%F !    {   ?? I%+%9%9+%F$H !    IsAB2C  C cDddl}ddl}|j}|j}t |} t j |}|j}|jj|jd} |j|d} |jd| xsd|| fz} |rt|\}} |r sBt||jvr'|r d|z|z} nd|z} t!t#|d| | St'd#t$$r}t'|d}~wwxYw) NrTusegmtz6Content-type: %s Content-length: %d Last-modified: %s text/plainfile://rbzfile not on local host) email.utils mimetypesrrr5restatst_sizeutils formatdatest_mtime guess_typemessage_from_stringr_safe_gethostbynamerrrNr~r)rr emailrrrq localfilestatsrymodifiedmtyperurorigurlexps rTrzFileHandler.open_local_files$xx<< *  GGI&E==D{{--ennT-JH((215E/e//K&,h789G'- d1$74>>;KK'$.9G'(2G!$y$"7'JJ/00 3-  sC D D DD)rrrrrrrrrUrTr+r+s- E!1rUr+c` tj|S#tj$rYywxYwrW)rrr)rs rTrrs.##D)) ??s --ceZdZdZdZy)r,c$ddl}ddl}|j}|s tdt |\}}| |j }n t |}t|\}}|rt|\}}nd}t|}|xsd}|xsd} tj|}t|j\} } | jd} t!t#t| } | dd| d} } | r | ds| dd} |j%||||| |j&} | xrdxsd}| D]9}t)|\}}|j+d k(s%|d vs*|j-};| j/| |\}}d}|j1|j2d}|r|d |zz }| |dk\r|d |zz }t5j6|}t9|||j2S#t$r}t|d}~wwxYw#|j:$r}t||d}~wwxYw) Nrftp error: no host givenrrOr]r`rDraArrr(rzContent-type: %s zContent-length: %d )ftplibrrrrFTP_PORTrmrrr rrr~rrrrmap connect_ftprQrrupperretrfilerrrrr all_errors)rr rrrrrmrr4rfattrsdirsrYfwrattrrrtretrlenrurrs rTftp_openzFTPHandler.ftp_opens$xx56 6% d <??Dt9D % d '-LD&Ft}zr2 ''-D!. ezz#C&'#2YRd Q8D )!!$dD#++NBG1AG/G/B G/ G, G''G,/H> H  Hc &t||||||dS)NF) persistent) ftpwrapper)rrmrrrrrQs rTrzFTPHandler.connect_ftp1s$dD'%*, ,rUN)rrrrrrrUrTr,r,s 2)h,rUr,c0eZdZdZdZdZdZdZdZy)r-cJi|_i|_d|_d|_d|_y)Nr<r)cacherQsoonestdelay max_connsrs rTrzCacheFTPHandler.__init__8s%    rUc||_yrW)r)rts rT setTimeoutzCacheFTPHandler.setTimeout?s  rUc||_yrW)r)rrEs rT setMaxConnszCacheFTPHandler.setMaxConnsBs rUc||||dj||f}||jvr/tj|jz|j|<nKt |||||||j|<tj|jz|j|<|j |j|S)NrO)joinrrrrQr check_cache)rrmrrrrrQrs rTrzCacheFTPHandler.connect_ftpEsD$7 $**  $ djj 8DLL (vtT)-w8DJJsO $ djj 8DLL  zz#rUctj}|j|krht|jj D]B\}}||ks |j |j |j |=|j|=Dtt|jj|_t|j |jk(rt|jj D]0\}}||jk(s|j |=|j|=ntt|jj|_yyrW) rrrrQrrrminvaluesror)rrrGrHs rTrzCacheFTPHandler.check_cachePs  IIK <<1 T\\//121q5JJqM'') 1  Q 3 4 3 3 567  tzz?dnn ,T\\//121 $ 1  Q 3 tDLL$7$7$9:;DL -rUc|jjD]}|j|jj|jjyrW)rrrclearrQ)rconns rT clear_cachezCacheFTPHandler.clear_cachedsBJJ%%'D JJL(  rUN) rrrrrrrrrrrUrTr-r-5s  <(rUr-ceZdZdZy)r.ch|j}|jdd\}}|jdd\}}t|}|jdrt j |}|dd}|sd}t jd|t|fz}ttj|||S)Nr{r`rz;base64itext/plain;charset=US-ASCIIz$Content-type: %s Content-length: %d ) rrrendswithr decodebytesrrrorioBytesIO)rr rOrTrP mediatyperus rT data_openzDataHandler.data_openksllyyQ' **S+ 4 %   i (%%d+D!#2I5I++,T D "-#$"**T*GS99rUN)rrrrrrUrTr.r.js:rUr.r<nt)r5r4c|dddk(r|dd}n |dddk(r|dd}tj}tj}t|||S) zOS-specific conversion from a relative URL of the 'file' scheme to a file system path; not recommended for general use.Nrz///r; z //localhost/ rPerrors)rgetfilesystemencodinggetfilesystemencodeerrorsr pathnamerPrs rTr5r5sc BQ<5  |H cr]n ,}H,,...0x(6BBrUc|dddk(rd|z}tj}tj}t|||S)zOS-specific conversion from a file system path to a relative URL of the 'file' scheme; not recommended for general use.Nr;rdr)rrrr rs rTr4r4sH BQ<4 hH,,...0X@@rUceZdZdZdZdezZddZdZdZ dZ dZ dd Z dd Z dd Zdd Zd ZddZddZdZerdZddZdZdZdZddZy)r9a,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).Nrc dd|jjiz}tj|td| t }t |dsJd||_|jd|_ |jd|_ d |jfd g|_ g|_ tj|_d|_t$|_y) NzW%(class)s style of invoking requests is deprecated. Use newer urlopen functions/methodsclassr) stacklevelrsrtkey_file cert_filez User-Agent)Acceptz*/*)rrrBrCrDr6rrxrrrversionr_URLopener__tempfilesrer}_URLopener__unlink tempcacheftpcache)rrxx509r4s rTrzURLopener.__init__s47>@W@W6XY c-!< ? lGw'D)DD' , +.($,,79JK  ! rUc$|jyrW)rrs rT__del__zURLopener.__del__s  rUc$|jyrW)cleanuprs rTrzURLopener.closes  rUc|jr2|jD]} |j||jdd=|jr|jj yy#t$rYYwxYwrW)rrr~rr)rrYs rTrzURLopener.cleanupsn   ((MM$')   # >> NN " sA'' A32A3c:|jj|y)zdAdd a header to be used by the HTTP interface only e.g. u.addheader('Accept', 'sound/basic')N)rrl)rrs rT addheaderzURLopener.addheaders t$rUctt|}t|d}|jr9||jvr+|j|\}}t |d}t |||St |\}}|sd}||jvr0|j|}t |\}} t| \} } | |f}nd}d|z} ||_ | jdd} t|| r| d k(r'|r|j|||S|j||S |t|| |St|| ||S#tt f$rt"$r} t#d | | d} ~ wwxYw) z6Use URLopener().open(file) instead of open(file, 'r').z%/:=&?~#+!$,;'@()*[]|rQrrYNopen_-rrz socket error)r rr rrNrr rxr rrCropen_unknown_proxy open_unknownrrrr~)rrrPrqrurturltyperOrf proxyhostrrrjr4s rTrNzURLopener.opensz7+,&=> >>g7 $w 7 Hgh%Bb'73 3!'* G dll "LL)E!+E!2 GY' 2ND(/CE  ||C%tT"d.?&?..ugtDD(($77 8|*wtT*3//*wtT*3558$   8.#.C 7 8sD7$D77E! EE!c8t|\}}tdd|)/Overridable interface to open unknown URL type. url errorzunknown url typer r~)rrrPrrOs rTrzURLopener.open_unknowns w' ck#5t<t|\}}tdd|z|)rrzinvalid proxy for %sr)rrfrrPrrOs rTrzURLopener.open_unknown_proxys%w' ck#9D#@%HHrUc,tt|}|jr||jvr|j|St|\}}|R|r|dk(rK |j |}|j }|j tt|d|fS|j||} |j } |r t|d} nt|\} } t| xsd\} } t| xsd\} } t| xsd\} } tjj| d} t!j"| \}}|j$j'|tj(|d} || f}|j||j|<d}d}d}d}d| vrt+| d }|r |||||j-|x}rD|t/|z }| j1||dz }|r |||||j-|x}rD| j  |j |dk\r||krt3d ||fz||S#t$rYwxYw#| j wxYw#|j wxYw) ztretrieve(url) returns (filename, headers) for a local object or (tempfilename, headers) for a remote object.rYr`rZrr\r]rr^r_ra)r rrr rrdrr5r r~rNrrrerfsplitextrhmkstemprrlfdopenrmrnrorpr)rrOrqrrrPrurl1rtrrurvgarbagerfsuffixfdrwrxryrnrzr{s rTretrievezURLopener.retrievesYs^$ >>cT^^3>>#& &_ d  TTV^ ))$/wwy #Jt$4Q$78$>>YYsD !" ggiG8T* *3  *4:2 6  +DJB 7 g *4:2 6 g))$/2!)!1!1&!9X  ''1iiD) !7*>>-*0DNN3'#w.w'789DxT2!wwr{*e*CJ&DIIe$MH!"8R6 "wwr{*e* HHJ 19&C, &( ( [  F HHJs9A I3CJBI,J I)(I),I>>JJcd}d}t|tr,t|\}}|rt|\}}t |}|}nq|\}}t|\}}t |\} } | }d}| j dk7rd}n6t| \}} |rt|\}}|r | d|| }t|r|}|s tdd|r>t |}tj|jjd} nd} |r>t |}tj|jjd} nd} ||} i}| rd| z|d<| rd| z|d <|r||d <d |d <|jD] \}}|||< |d |d<| jd|||n| jd|| | j}d|j(cxkrdkr(nn%t+||j,d|z|j(S|j/||j0|j(|j2|j,|S#t j"j$$r t'dwxYw)aMake an HTTP connection using connection_class. This is an internal method that should be called from open_http() or open_https(). Arguments: - connection_factory should take a host name and return an HTTPConnection instance. - url is the url to retrieval or a host, relative-path pair. - data is payload for a POST request or None. Nrz://z http errorr?r|zBasic %sr0rrrrIr@z Content-TyperrrJz$http protocol error: bad status liner1r2http:)rrr rr r rrr~rrrrrrrPrr BadStatusLinerstatusrr4 http_errorrtrR)rconnection_factoryrOrP user_passwd proxy_passwdrrrealhostrr proxy_authr http_connrurrrs rT_open_generic_httpzURLopener._open_generic_http\s  c3 '_ND($.t$4! Tt}H ND(!+D!1 L$&x0MGTCK}}&(!+D!1$,6x,@)K.5xFH)#D7<AA "<0L)),*=*=*?@GGPJJ !+.K##K$6$6$89@@IDD&t,  -7*-DG) * (2T(9GO $ &GFO !( !__MFE#GFO-  &IGN #   fhg >   eXw  ? C ,,.H (// 'C 'h gm&oo/ /??X[[(,,F F{{(( CAB B Cs 8I)I,cX|jtjj||S)zUse HTTP protocol.)rrrr5rrOrPs rT open_httpzURLopener.open_https!&&t{{'A'A3MMrUcd|z}t||r,t||}| ||||||} n |||||||} | r| S|j|||||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_%d)rrr) rrOrterrcodeerrmsgrurPrjrrws rTrzURLopener.http_errorso ( 4 T4(F|R&'BR&'4Hf}&&sBIIrUc@|jt||||d)z>Default error handler: close the connection and raise OSError.N)rrrrOrtrrrus rTrzURLopener.http_error_defaults  Wfgt<??% d% d  T 2vft}tzr"2&##D) ??Dt9D & et}zz##2YRd QQR Q3aD$. t}}  +$--(8 a(A a(GGI )  9$--'tVT4> c"$)$/ e::<6):: ;;=D  !MM#.77dCMR((#6q9EG/%77"w!|1G;;//8Gb'6C<8 8{ 9[./S 8 9s&AI8(I8-B I88 JJJc Tt|ts td |jdd\}}|sd}|j d}|dk\rd ||d vr||dzd }|d |}nd }g}|jd tjd tjtjz|jd|z|dk(r4tj|jdjd}n t|}|jdt!|z|jd |j|dj#|}t%j&|}t)j*|}t-|||S#t$r t ddwxYw)zUse "data" URL.zEdata error: proxy support for data protocol currently not implementedrr`z data errorz bad data URLr;rrrNrzDate: %sz%a, %d %b %Y %H:%M:%S GMTzContent-type: %srr|zlatin-1zContent-Length: %d )rrrrrEr~rfindrlrstrftimegmtimerrrrr rorrrrStringIOr) rrOrPrsemirPr4rufs rT open_datazURLopener.open_dataFs#s#bc c 899S!,LT40Dzz# 19DK/DFG}H;DH :dmm,G,0KK ,DFF G %,- x %%dkk'&:;BB9MD4=D '#d)34 2 4iin++C0 KK !Wc**5 8,7 7 8s FF'rWre)rrrr6rrrrrrrrrNrrr rrrrrFr#r%r'rr2r<rrUrTr9r9sK ;.G!4 #% "8H= I :|ZFxNJ =  F N->@89t'+rUr9ceZdZdZdZdZddZdZddZddZ dd Z dd Z dd Z dd Z dd ZddZddZddZddZdZy)r:z?Derived class with handlers for errors we can handle (perhaps).c`tj|g|i|i|_d|_d|_y)Nrr<)r9r auth_cachetriesmaxtries)rrrs rTrzFancyURLopener.__init__ss/41$1&1  rUc$t||d|z|S)z3Default error handling -- don't raise an exception.r )rrs rTrz!FancyURLopener.http_error_defaultys"gw}g>>rUNc>|xjdz c_ |jrQ|j|jk\r8t|dr |j}n |j}|||dd|d|_S|j ||||||}|d|_S#d|_wxYw)z%Error 302 -- relocated (temporarily).r`http_error_500r'z)Internal Server Error: Redirect Recursionr)r@rArrDrredirect_internal) rrOrtrrrurPrrws rTr^zFancyURLopener.http_error_302}s a  }}t}}!<4!12..D22DCSG#%DJ ++CWf,3T;FDJDJsAB4B Bcd|vr|d}n d|vr|d}ny|jt|jdz|z|}t|}|jdvrt |||d|zz|||j |S)NrKrLr{rMz( Redirection to url '%s' is not allowed.)rrrrrTrrN) rrOrtrrrurPrDr[s rTrEz FancyURLopener.redirect_internals  Z(F g U^F   S3.7F# ??"> >FG"FOP#R) ) yy  rUc.|j||||||S)z*Error 301 -- also relocated (permanently).r^rrOrtrrrurPs rTr_zFancyURLopener.http_error_301""3GVWdKKrUc.|j||||||S)z;Error 303 -- also relocated (essentially identical to 302).rHrIs rTr`zFancyURLopener.http_error_303rJrUc\||j||||||S|j|||||S)z1Error 307 -- relocated, but turn POST into error.)r^rrIs rTrazFancyURLopener.http_error_307; <&&sB$O O**3GVWM MrUc\||j||||||S|j|||||S)z1Error 308 -- relocated, but turn POST into error.)r_rrIs rTrbzFancyURLopener.http_error_308rMrUcd|vrtj|||||||d}tjd|} | stj||||||| j \} } | j dk7rtj|||||||stj||||||d|j zdz} |t|| || St|| || |S)z_Error 401 -- authentication required. This function supports Basic authentication only.r![ ]*([^ ]+)[ ]+realm="([^"]*)"rretry_ _basic_authr9rrmatchrrrr rrOrtrrrurPr.stuffrTrTrrjs rTrzFancyURLopener.http_error_401s W ,  ( (sB)0&' C*+?G  ( (sB)0&' C   <<>W $  ( (sB)0&' C  ( (sB $))#m3 <%74%c51 1%74%c5$7 7rUcd|vrtj|||||||d}tjd|} | stj||||||| j \} } | j dk7rtj|||||||stj||||||d|j zdz} |t|| || St|| || |S)zeError 407 -- proxy authentication required. This function supports Basic authentication only.rrPr retry_proxy_rRrSrUs rTrzFancyURLopener.http_error_407s w .  ( (sB)0&' C,-?G  ( (sB)0&' C   <<>W $  ( (sB)0&' C  ( (sB  )M9 <%74%c51 1%74%c5$7 7rUct|\}}d|z|z}|jd}t|\}} t| \} } | jddz} | | d} |j | || \} } | s| syt | ddt | dd| } d| z| z|jd<||j |S|j ||S)Nhttp://rrer`rrr{r rxr rget_user_passwdr rNrrOrrPrrrDrfrr proxyselectorrrmrs rTretry_proxy_http_basic_authz*FancyURLopener.retry_proxy_http_basic_auths#ChT!H, V$'.#-i#8 = NN3 ! #abM ++Iua@ f"'2"6"'R"8)E (94}D V <99V$ $99VT* *rUct|\}}d|z|z}|jd}t|\}} t| \} } | jddz} | | d} |j | || \} } | s| syt | ddt | dd| } d| z| z|jd<||j |S|j ||S)Nhttps://rrer`rrr{r[r]s rTretry_proxy_https_basic_authz+FancyURLopener.retry_proxy_https_basic_auth s#Chd"X- W%'.#-i#8 = NN3 ! #abM ++Iua@ f"'2"6"'R"8)E *Y 6 F W <99V$ $99VT* *rUc t|\}}|jddz}||d}|j|||\}}|s|syt|ddt|dd|}d|z|z} ||j | S|j | |S)Nrer`rrr{rZr rr\r rN rrOrrPrrrrmrrDs rTrz$FancyURLopener.retry_http_basic_auth s#Ch IIcNQ ABx++D%; f"4b1"63T;T!H, <99V$ $99VT* *rUc t|\}}|jddz}||d}|j|||\}}|s|syt|ddt|dd|}d|z|z} ||j | S|j | |S)Nrer`rrr{rardres rTretry_https_basic_authz%FancyURLopener.retry_https_basic_auth% s#Ch IIcNQ ABx++D%; f"4b1"63T;d"X- <99V$ $99VT* *rUc|dz|jz}||jvr|r|j|=n|j|S|j||\}}|s|r||f|j|<||fS)Nre)rr?prompt_user_passwd)rrrrrrmrs rTr\zFancyURLopener.get_user_passwd3 svckDJJL( $// !OOC(s++..tU; f 64.4??3/V|rUc ddl} td|d|d}|jd|d|d|d}||fS#t$r tYywxYw) z#Override this in a GUI environment!rNzEnter username for z at z: zEnter password for z in r)getpassinputKeyboardInterruptprint)rrrrkrmrs rTriz!FancyURLopener.prompt_user_passwd> sT E4HID__ud&$%F<    G s07A  A rW)NF)r)rrrr6rrr^rEr_r`rarbrrr_rbrrgr\rirrUrTr:r:psmI ?$!8LLNNFJ82FJ82+$+$ + +  rUr:cDttjdatS)z8Return the IP address of the magic hostname 'localhost'.r~) _localhostrrrrUrTr~r~N s ))+6 rUc t: ttjtjdatStS#tj $r)ttjddaYtSwxYw)z,Return the IP addresses of the current host.r;r~) _thishostrrrrrrrUrTr*r*V sw Gf55f6H6H6JKANOI 9 Gf55kB1EFI  Gs3A4BBc:tddl}|jatS)z1Return the set of errors raised by the FTP class.Nr) _ftperrorsrr)rs rTr1r1a s&& rUcDttjdatS)z%Return an empty email Message object.r) _noheadersrrrrUrT noheadersrwj s ..r2 rUc@eZdZdZ d dZdZdZdZdZdZ d Z y) rz;Class used by open_ftp() for cache of open FTP connections.Nc||_||_||_||_||_||_d|_||_ |jy#|jxYwr) rmrrrrrQrefcount keepaliveinitr)rrmrrrrrQrs rTrzftpwrapper.__init__w s[       #  IIK  JJL s A Acddl}d|_|j|_|jj |j |j |j|jj|j|jdj|j}|jj|y)NrrO)rbusyFTPrNconnectrrrQloginrmrrrcwd)rr_targets rTr|zftpwrapper.init sw ::< DIIt||< tyy$++.((499%  WrUc8ddl}|j|dvrd}d}nd|z}d} |jj|d}|r&|s$ d|z}|jj |\}}|s|jjd|rY|jj} |jj| |jj| d |z}nd }|jj |\}}d|_ t|jd |j} |xj dz c_|j#| fS#|j$r/|j |jj|YTwxYw#|j$r+}t|dddk7rtd ||Yd}~cd}~wwxYw#|j$r}td |z|d}~wwxYw#|jj| wxYw)Nr)r(rzTYPE Ar`zTYPE zRETR r550r/z ftp error: %rzLIST LISTr)r endtransferrNvoidcmdrr| ntransfercmd error_permrrpwdrr~rmakefile file_closerzr) rrYrrcmdisdirrrrRrftpobjs rTrzftpwrapper.retrfile s  : XsqudNcAE " HH  S !  Gn $ 5 5c : g HH  X &hhlln&M T*HHLL%n HH11#6MD' dmmD14??C     G   " IIK HH  S ! "$$ Gv;r?e+"[#9:F, G",,M&'?@fLMHHLL%sME#F&G:FFG( GGG9%G44G99G<<Hc|jsyd|_ |jjy#t$rYywxYwr)r~rNvoidrespr1rs rTrzftpwrapper.endtransfer s<yy    HH   {   s1 AAcRd|_|jdkr|jyy)NFr)r{rz real_closers rTrzftpwrapper.close s$ ==A  OO  rUc|j|xjdzc_|jdkr|js|jyyy)Nr`r)rrzr{rrs rTrzftpwrapper.file_close s@   ==A dnn OO '5 rUc|j |jjy#t$rYywxYwrW)rrNrr1rs rTrzftpwrapper.real_close s5   HHNN {   s - ==)NT) rrrr6rr|rrrrrrrUrTrrt s/E?C  *!X  rUrci}g}tjjD]s}t|dkDs|ddk(s|ddj dk(s2tj|}|ddj }|j |||f|so|||<udtjvr|j dd|D])\}}}|ddd k(s|r|||<|j |d+|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. rirNrfREQUEST_METHODr_proxy)reenvironrsrorrlr)rx environmentrjr proxy_names rTgetproxies_environmentr sGK ! t9q=T"X_bc1Bg1MJJt$Ecr*J   eZ8 9&+ #"2::% FD!#.eZ 9 &+ # J- $/ NrUc| t} |d}|dk(ry|j}t|\}}|j dD]k}|j }|s|j d}|j}||k(s||k(ryd|z}|j|s|j|skyy#t$rYywxYw)zTest 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. noF*Tr.)rrrrrrlstripr)rrxno_proxyhostonlyrrjs rTproxy_bypass_environmentr s(*4=3 ::.ip2num3 sm S!Se_% u:?\)2A.EaB58r>2eAh!mDuQxOOrUrexclude_simpleTN exceptionsrz(\d+(?:\.\d+)*)(/\d+)?r`r;r F) r ipaddressrrrrmrrrTgroupcount) rproxy_settingsrrrrrrhostIPrrErmasks rT_proxy_bypass_macosx_sysconfr" s, 8%NHdP $ * + F [*+ ##L"5h HH. 6 =V/!''!*%D771:D|AGGAJ,,S1A5648}ax4"99D$DDL1 T5 !/62 9    sC;;DDcddlm}t|\}}|jd}|D])}|j}|dk(rd|vsy|||s)yy)a Return True if the host should bypass the proxy server. The proxy override list is obtained from the Windows Internet settings proxy override registry value. An example of a proxy override value is: "www.example.com;*.example.net; 192.168.0.1" rrr4zrTF)rrrr)roverriderrproxy_overriders rT_proxy_bypass_winreg_overriderb s\ GD!^^C(Nzz| 9 $ T4  rUdarwin)_get_proxy_settings _get_proxiesc.t}t||SrW)rr)rrs rTproxy_bypass_macosx_sysconfr} s,.+D.AArUctS)zReturn a dictionary of scheme -> proxy server URL mappings. This function uses the MacOSX framework SystemConfiguration to fetch the proxy information. )rrrUrTgetproxies_macosx_sysconfr s ~rUcHt}|r t||St|S)zReturn True, if host should be bypassed. Checks proxy settings gathered from the environment, if specified, or from the MacOSX framework SystemConfiguration. )rrrrrxs rTrr s')* +D': :.t4 4rUc.txs tSrW)rrrrUrTr6r6 s%'F+D+FFrUci} ddl} |j|jd}|j |dd}|rt |j |dd}d|vrd|vrdj |}|jdD]F}|jdd \}}tjd |s|d vrd |z}n |d k(rd|z}|||<H|jd rJtjdd|d }|jdxs||d<|jdxs||d<|j|S#t$r|cYSwxYw#tttf$rY|SwxYw)zxReturn a dictionary of scheme -> proxy server URL mappings. Win32 uses the registry to store proxies. rN;Software\Microsoft\Windows\CurrentVersion\Internet Settings ProxyEnable ProxyServerrrr4zhttp={0};https={0};ftp={0}r`z (?:[^/:]+)://)rrrNrZsockszsocks://z ^socks://z socks4://rr)winreg ImportErrorOpenKeyHKEY_CURRENT_USER QueryValueExrrrrrTrrCloser~rEr)rxrinternetSettings proxyEnable proxyServerpraddresss rTgetproxies_registryr s   " %~~f.F.FN P  --.>/<>>?AK!&"5"56F7D#FFG#IJ k)c.D">"E"Ek"RK$**3/A()Q%Hg88OW=#'??&/'&9G%0&07&:G(/GH%0;;w' ff\;@PQG&-kk&&9&DWGFO'.{{7';'FwGG$  " " $ M N BY/    s#D:D/E : EE E#"E#c.txs tS)zReturn a dictionary of scheme -> proxy server URL mappings. Returns settings gathered from the environment, if specified, or the registry. )rrrrUrTr6r6 s&'@+>+@@rUc  ddl} |j|jd}|j |dd}t |j |dd}|r|syt||S#t$rYywxYw#t $rYywxYw)NrFrr ProxyOverride)rrrrrrr~r)rrrr proxyOverrides rTproxy_bypass_registryr s   %~~f.F.FN P  --.>/<>>?AK 3 34D5D!FFG!IJM -,T=AA    s#A'AA6' A32A36 BBcHt}|r t||St|S)zReturn True, if host should be bypassed. Checks proxy settings gathered from the environment, if specified, or the registry. )rrrrs rTrr s')* +D': :(. .rUrerW)~r6rrrr http.clientrrrerrrVrrrhrbrB urllib.errorrrr urllib.parserrrr r r r r rrrrrrrrrrurllib.responserrrGrFr__all__ version_inforrMrr1r2rkr7r8rASCIIrrrrr3rr0rrror r!r"r#r$r%r&urandomrr'r(r)r3r*rrrLrlrr/rrr+rr,r-r.r0rj nturl2pathr5r4rr9r:rpr~rrr*rtr1rvrwrrrrrplatform_scproxyrrrrrr6rrrrUrTrsCf  CB""""" 5I $((!,, F$B$BM+45$M+^:x rzz(BHH-  k"k"ZI+I+^"H88&##";k;n2+n2b,B)>;)>V=*=*@GoG3#B3>k#k#^3[ 4k  zz OOdK)B$ [*C s+sl3%3 4;;)*8*8$ NN>"#+#$6[6 )*V11+11f 7,7,r3j3j:+:B 77d?55 C A ++DXYXz     aaH#J J<@0<<8:B 5GWW_/bAB( /(J+LWTIs:KKK