\d؎8dZddlZddlZddlZddlZddlZddlZddlZddl 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+ ddl,Z,dZ-n #e.$rdZ-YnwxYwgdZ/d e j0dd zZ1da2de j3fddddd d Z4d Z5gZ6dfdZ7dZ8e j9de j:Z;dZ<GddZ=GddZ>dZ?GddZ@Gdde@ZAGdde@ZBGdde@ZCdZDGd d!e@ZEGd"d#ZFGd$d%eFZGGd&d'eGZHGd(d)ZIGd*d+eIe@ZJGd,d-eIe@ZKejLZMGd.d/ZNGd0d1e@eNZOGd2d3e@eNZPGd4d5e@ZQGd6d7eQZReSejTd8r#Gd9d:eQZUe/Vd:Gd;de@ZXd?ZYd@ZZGdAdBe@Z[dCZ\GdDdEe@Z]GdFdGe]Z^GdHdIe@Z_dJZ`ejadKkr ddLlbmcZcmdZdndMZcdNZdiZeGdOdPZfGdQdRefZgdahdSZidajdTZkdaldUZmdandVZoGdWdXZpdYZqdgdZZrd[Zse jtd\krdd]lumvZvmwZwd^Zxd_Zyd`ZzdaZ{dSejadKkrdbZ|dcZ{ddZ}deZzdSeqZ{erZzdS)ha 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|tdtstdt jt jj||}| dgt| }t|} nA|r t| }t|} nttxa } 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=zhttp/1.1)r?)warningswarnDeprecationWarning ValueError _have_sslsslcreate_default_contextPurpose SERVER_AUTHset_alpn_protocols HTTPSHandlerr3_openeropen) urldatatimeoutr<r=r>r?rA https_handleropeners ..\python\lib\urllib\request.pyr1r1s/h9 01CQ H H H    :899 9,S[-D4:4:<<< ""J<000$W555 m,, $W555 m,, '>>)&& ;;sD' * **c |adSN)rL)rRs rSr2r2s GGGrTcLt|\}}tjt||5}|}|dkr/|s-t j||fcdddS|rt|d}n6tj d}|j }t ||5||f} d} d} d} d} d |vrt|d } |r || | |  || }|sn<| t!|z } ||| d z } |r || | | T dddn #1swxYwYdddn #1swxYwY| dkr| | krt%d | | fz| | 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-LengthT1retrieval incomplete: got only %i out of %i bytes)r contextlibclosingr1infoospathnormpathrMtempfileNamedTemporaryFilename_url_tempfilesappendintreadlenwriter)rNfilename reporthookrOurl_typerefpheaderstfpresultbssizermblocknumblocks rSr7r7s  __NHd  GC.. / /$32'')) v  h 7##D))72 $3$3$3$3$3$3$3$3  ,x&&CC-U;;;CxH  ! !( + + +  3 3w&FBDDH7**7#3455 / 8R... 3 E " %   A 3JxT222 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3!$3$3$3$3$3$3$3$3$3$3$3$3$3$3$3L qyyTD[[" ?Tl "$$ $ Ms==E8?A E8 B E! E8!E% %E8(E% )E88E<?E<ctD]'} tj|#t$rY$wxYwtdd=trdadSdS)z0Clean up temporary files from urlretrieve calls.N)rjrdunlinkOSErrorrL) temp_files rSr8r8sr#   Ii     D  qqqs   --z:\d+$c|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. r_Host)full_urlr get_header _cut_port_resublower)requestrNhosts rS request_hostr-sa  C C== D rzz!!&"--   Ba ( (D ::<<rTceZdZdidddfdZedZejdZejdZedZejdZejd Zd Z d Z d Z d Z dZ dZdZdZddZdZdZdS)rNFc||_i|_i|_d|_||_d|_|D]\}}||||t|}||_ ||_ |r ||_ dSdSrV) rrtunredirected_hdrs_datarO _tunnel_hostitems add_headerrorigin_req_host unverifiablemethod) selfrNrOrtrrrkeyvalues rS__init__zRequest.__init__?s  !#   !--// ( (JC OOC ' ' ' '  "*400O.(  ! DKKK ! !rTc^|jr d|j|jS|jS)Nz{}#{})fragmentformat _full_urlrs rSrzRequest.full_urlQs- = A>>$.$-@@ @~rTct||_t|j\|_|_|dSrV)r rrr_parserrNs rSrzRequest.full_urlWs: (1$.(A(A%  rTc0d|_d|_d|_dS)Nr)rrselectorrs rSrzRequest.full_url^s  rTc|jSrV)rrs rSrOz Request.datads zrTc||jkr3||_|dr|ddSdSdS)NContent-length)r has_header remove_header)rrOs rSrOz Request.datahsZ 4:  DJ/00 5""#344444    5 5rTcd|_dSrV)rOrs rSrOz Request.datars  rTct|j\|_}|jtd|jzt |\|_|_|jrt|j|_dSdS)Nzunknown url type: %r) r rtyperDrr rrr )rrests rSrzRequest._parsevst$T^44 4 9 3dmCDD D#-d#3#3  4= 9 + **DIII + +rTc:|jdnd}t|d|S)z3Return a string indicating the HTTP request method.NPOSTGETr)rOgetattr)rdefault_methods rS get_methodzRequest.get_method~s$#'9#8etX~666rTc|jSrV)rrs rS get_full_urlzRequest.get_full_urls }rTcx|jdkr|js |j|_n||_|j|_||_dS)Nhttps)rrrrr)rrrs rS set_proxyzRequest.set_proxys? 9  (9  $ D  DI MDM rTc"|j|jkSrV)rrrs rS has_proxyzRequest.has_proxys} --rTc>||j|<dSrV)rt capitalizerrvals rSrzRequest.add_headers), S^^%%&&&rTc>||j|<dSrV)rrrs rSadd_unredirected_headerzRequest.add_unredirected_headers36s~~//000rTc&||jvp||jvSrV)rtrr header_names rSrzRequest.has_headers!t|+6t55 7rTcj|j||j||SrV)rtgetr)rrdefaults rSrzRequest.get_headers5|   " & &{G < <>> >rTcr|j|d|j|ddSrV)rtpoprrs rSrzRequest.remove_headers9 d+++ "";55555rTcdi|j|j}t|SrV)rrtlistr)rhdrss rS header_itemszRequest.header_itemss,9$(9DL9DJJLL!!!rTrV)__name__ __module__ __qualname__rpropertyrsetterdeleterrOrrrrrrrrrrrrTrSrr=s!%r!%E!!!!$X __  X [55[5 \\+++777 ...---777777>>>> 666"""""rTrcJeZdZdZdZdZdZdejfdZ d dZ dZ dS) rctdtz}d|fg|_g|_i|_i|_i|_i|_dS)NPython-urllib/%sz User-agent) __version__ addheadershandlers handle_open handle_errorprocess_responseprocess_request)rclient_versions rSrzOpenerDirector.__init__sH+k9(.9:  "!rTcLt|dstdt|zd}t|D].}|dvr|d}|d|}||dzd}|dro|d|zdz}||dzd} t |}n#t$rYnwxYw|j |i} | |j|<n1|dkr |}|j } n!|d kr |}|j } n|d kr |}|j } n| |g} | rtj| |n| |d }0|r1tj|j|||dSdS) N add_parentz%expected BaseHandler instance, got %rF)redirect_requestdo_open proxy_open_r_errorrMresponserT)hasattr TypeErrorrdirfind startswithrlrDrrrrr setdefaultbisectinsortrkrr) rhandleraddedmethiprotocol conditionjkindlookuprs rS add_handlerzOpenerDirector.add_handlersw -- +C MM*++ +LL# # DDDD #ABQBxHQqSTT I##G,, NN3''!+a/AaCDDzt99DD!D*..x<<.4!(++f$$)j((.i''-((r22H ) h0000(((EE  % M$- 1 1 1   t $ $ $ $ $ % %s3C CCcdSrVrrs rSclosezOpenerDirector.close rTcr||d}|D]}t||}||}||cSdS)Nr)rr) rchainr meth_nameargsrrfuncrvs rS _call_chainzOpenerDirector._call_chains^99T2&&  G7I..DT4[F! "  rTNct|trt||}n |}|||_||_|j}|dz}|j|gD]}t||}||}tj d|j |j|j | |||} |dz}|j|gD]}t||}||| } | S)N_requestzurllib.Request _response) isinstancestrrrOrPrrrrsysauditrrtr_openr) rfullurlrOrPreqrr processorrrs rSrMzOpenerDirector.opens" gs # # '4((CCC 8Z' -11(B??  I9i00D$s))CC "CL#(CKIYIYZZZ::c4(([( .228R@@ + +I9i00DtC**HHrTc||jdd|}|r|S|j}||j||dz|}|r|S||jdd|S)Nr default_openrunknown unknown_open)rrr)rrrOrvrs rSrzOpenerDirector._opens!!$"2I"0#77  M8!!$"2Hh")?*+.00  M 0) .55 5rTc|dvr|jd}|d}d|z}d}|}n|j}|dz}d}|||f|z}|j|}|r|S|r|dd f|z}|j|SdS) Nhttprrr;z http_error_%sr__errorrrhttp_error_default)rr)rprotordictrhttp_err orig_argsrvs rSrzOpenerDirector.error s % % %$V,DGE'%/IHII$D(IHeY'$.!!4(  M  +)%9:YFD#4#T* * + +rTrV) rrrrrrrsocket_GLOBAL_DEFAULT_TIMEOUTrMrrrrTrSrrs " " "-%-%-%^      "&v/M: 5 5 5 5+++++rTrc t}ttttt t tttg }ttj dr| tt}|D]g}|D]b}t!|t"r&t%||r||=t!||r||ch|D]}|||D]}|| |D]6}t!|t"r |}||7|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.rrclientrkrKsetrr issubclassaddremover)rrRdefault_classesskipklasscheckhs rSr3r39sw  F#^[.0C!;0B"$Ot{-..-|,,, 55D     E%&& eU++$HHUOOOE5))   &&u%%%% $$5577####  a   A1 MrTc$eZdZdZdZdZdZdS)rc||_dSrV)parent)rr(s rSrzBaseHandler.add_parent`s  rTcdSrVrrs rSrzBaseHandler.closecrrTcFt|dsdS|j|jkS)N handler_orderT)rr+)rothers rS__lt__zBaseHandler.__lt__gs,uo.. 4!E$777rTN)rrrr+rrr-rrTrSrr]sFM   88888rTrc eZdZdZdZdZeZdS)r0zProcess HTTP error responses.ic|j|j|}}}d|cxkrdks!n|jd|||||}|S)N,r)codemsgrcr(r)rrrr2r3rs rS http_responsez HTTPErrorProcessor.http_responsetsg"-x}}4ct!!!!c!!!!{((4d<r?r z%20)r]z content-typecHi|]\}}|v||Sr)r).0kvCONTENT_HEADERSs rS z8HTTPRedirectHandler.redirect_request..s;;;;tq!/99999rTT)rtrr)rrrreplacertrrr) rrrsr2r3rtnewurlm newheadersrFs @rSrz$HTTPRedirectHandler.redirect_requests NN  222qO7K7K&&1;;CL$WbAA AU++<;;;;s{'8'8':':;;; v)'*':$(*** *rTcrd|vr |d}nd|vr |d}ndSt|}|jdvrt|||d|d|||js|jrt |}d|d<t |}t|dtj }t|j |}| ||||||}|dSt|d rf|jx} |_| |d |jkst#| |jkr t|j ||j|z||nix} x|_|_| |d d z| |<|||j||j S)Nlocationurirrftprz - Redirection to url 'z' is not allowed/r;z iso-8859-1)encodingsafe redirect_dictrr_rP)rschemerrenetlocrrr string punctuationrrrrrTr max_repeatsrnmax_redirectionsinf_msgrmrr(rMrP) rrrsr2r3rtrIurlpartsnewvisiteds rShttp_error_302z"HTTPRedirectHandler.http_error_302s  Z(FF g  U^FF FF## ?"> > >ADfffM  }  H~~HHQKH%%  \0BDDDv.. ##CT3HH ; F 3 ( ( A*-*; ;Gc' FA&&$*:::G  555 d $ s 2GRAAA6?A @G @c'#*;!++fa0014    {S[999rTzoThe HTTP server returned a redirect error that would lead to an infinite loop. The last 30x error message was: N) rrrrZr[rr`http_error_301http_error_303http_error_307http_error_308r\rrTrSrrs\K * * *L::::::xIWVNV^Vn~2GGGrTrct|\}}|dsd}|}n|dstd|zd|vr,|d}|d|}n|dd}|dkrd}|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. rQN//zproxy URL with no authority: %r@r;r\)r rrDrrr) proxyrVr_scheme authorityhost_separatorenduserinfohostportuserpasswords rS _parse_proxyrqs"%((FH   s # #$ ""4(( H>FGG G (??%]]3//N--^44CC--Q''C "99CQsUO #I..Hh%h//hhx 48 ++rTc eZdZdZddZdZdS)r dNc|t}t|ds Jd||_|D]7\}}|}t |d|z|||jfd8dS)Nkeysproxies must be a mappingz%s_openc||||SrVr)rrhrrs rSz'ProxyHandler.__init__..#sQt,,rT)r6rproxiesrrsetattrr)rrzrrNs rSrzProxyHandler.__init__s ? llGw''DD)DDDD   . .ID#::<>>>>rTr c.eZdZdZdZdZddZdZdS) r!ci|_dSrV)passwdrs rSrzHTTPPasswordMgr.__init__Ds  rTct|tr|g}|jvr ij|<dD]0tfd|D}||fj||<1dS)NTFc3DK|]}|VdSrV) reduce_uri)rCu default_portrs rS z/HTTPPasswordMgr.add_password..NsB ? ?56<00 ? ? ? ? ? ?rT)rrrtuple)rrealmrNror reduced_urirs` @rS add_passwordzHTTPPasswordMgr.add_passwordGs c3   %C  # #!#DK ' = =L ? ? ? ? ?:= ? ? ???K/3VnDK { + + = =rTc|j|i}dD]U}|||}|D](\}}|D] }|||r|cccS!)VdS)NrNN)rrrr is_suburi) rrauthuridomainsrreduced_authuriurisauthinforNs rSfind_user_passwordz"HTTPPasswordMgr.find_user_passwordRs+//%,,' ( (L"oog|DDO")--// ( (h((C~~c?;;('(( (zrTTct|}|dr|d}|d}|dpd}nd}|}d}t|\}}|r%|#|!ddd|} | d || fz}||fS) z@Accept authority or URI and extract only the authority and path.r_rr;rQNPirz%s:%d)rrr) rrNrpartsrVrjrerportdports rSrzHTTPPasswordMgr.reduce_uri\s  8 1XFaI8?sDDFID ** d  4DLV-?!s6{{  #tUm3 $rTc||krdS|d|dkrdS|d}|dddkr|dz }|d|S)zcCheck if test is below base in a URI tree Both args must be URIs in reduced form. TrFr_r\NrQ)r)rbasetestprefixs rSrzHTTPPasswordMgr.is_suburissg 4<<4 7d1g  5a "##;#   cMFAw!!&)))rTN)T)rrrrrrrrrrTrSr!r!Bsd = = =. * * * * *rTr!ceZdZdZdS)r"ct|||\}}|||fSt|d|SrV)r!r)rrrrorps rSrz2HTTPPasswordMgrWithDefaultRealm.find_user_passwordsL(;;D% !11$gFFFrTN)rrrrrrTrSr"r"s(GGGGGrTr"c8eZdZfdZdfd ZddZdZxZS)r#cHi|_tj|i|dSrV) authenticatedsuperr)rrkwargs __class__s rSrz%HTTPPasswordMgrWithPriorAuth.__init__s-$)&)))))rTFc||||$td|||t||||dSrV)update_authenticatedrr)rrrNroris_authenticatedrs rSrz)HTTPPasswordMgrWithPriorAuth.add_passwordsb !!#'7888   GG sD& 9 9 9 UCv66666rTct|tr|g}dD]'}|D]"}|||}||j|<#(dSNr)rrrr)rrNrrrrs rSrz1HTTPPasswordMgrWithPriorAuth.update_authenticatedsr c3   %C' C CL C C"ooa>> 2B";// C C CrTcdD]I}|||}|jD])}|||r|j|ccS*JdSr)rrr)rrrrrNs rSrz-HTTPPasswordMgrWithPriorAuth.is_authenticatedsz' 3 3L"oog|DDO) 3 3>>#773-c2222223 3 3 3rT)F)rrrrrrr __classcell__)rs@rSr#r#s}*****777777CCCC3333333rTr#cheZdZejdejZd dZdZdZ dZ dZ dZ e Z e ZdS) r$z1(?:^|,)[ ]*([^ ,]+)[ ]+realm=(["']?)([^"']*)\2NcV|t}||_|jj|_dSrV)r!rr)r password_mgrs rSrz!AbstractBasicAuthHandler.__init__s-  *,,L"  K4rTc#"Kd}tj|D]A}|\}}}|dvrt jdt d||fVd}B|s'|r|d}nd}|dfVdSdS)NF)"'zBasic Auth Realm was unquotedTrr)r$rxfinditergroupsrArB UserWarningsplit)rheaderfound_challengemorVr rs rS _parse_realmz%AbstractBasicAuthHandler._parse_realms*-66v>> # #B#%99;; FE5J&& =)1...5/ ! ! !"OO ! *4.  ! !rTc||}|sdSd}|D]U}||D]=\}}|dkr|} |||||ccS>V|t d|dS)Nbasicz@AbstractBasicAuthHandler does not support the following scheme: )get_allrrretry_http_basic_authrD) rauthreqrrrt unsupportedrrVrs rShttp_error_auth_reqedz.AbstractBasicAuthHandler.http_error_auth_reqeds//'**  F  H HF!%!2!26!:!: H H <<>>W,,"(K$ 55dCGGGGGGG % H  "* &)** * # "rTc|j||\}}||d|}dtj|dz}||jd|krdS||j||j ||j SdS)Nr}rr~rU) rrrrrrr auth_headerrr(rMrP)rrrrropwrawauths rSrz.AbstractBasicAuthHandler.retry_http_basic_auths;11%>>b >!TT22&Cf.szz||<<CCGLLLD~~d.55==t  ' '(8$ ? ? ?;##C#== =4rTct|jdr|j|js|S|ds|jd|j\}}d||}tj | }| dd| |S)Nr Authorizationz{0}:{1}zBasic {}) rrrrrrrrrstandard_b64encoderrstrip)rrror credentialsauth_strs rS http_requestz%AbstractBasicAuthHandler.http_requests %788 {++CL99 J~~o.. M;99$ MMLD&#**488??AAK0==DDFFH  ' '(2(9(9(..:J:J(K(K M M M rTct|jdrVd|jcxkrdkr$nn!|j|jdn |j|jd|S)Nrr0r1TF)rrr2rr)rrrs rSr4z&AbstractBasicAuthHandler.http_response sx 4; 2 3 3 Fhm))))c))))) 00tDDDD 00uEEErTrV)rrrrecompileIrrrrrrr4 https_requestr6rrTrSr$r$s 1D  B5555 !!!(***4      !M"NNNrTr$ceZdZdZdZdS)r%rcD|j}|d|||}|S)Nwww-authenticate)rr)rrrsr2r3rtrNrs rShttp_error_401z#HTTPBasicAuthHandler.http_error_401s-l--.@*-sG==rTN)rrrrrrrTrSr%r%s(!KrTr%ceZdZdZdZdS)r&rcD|j}|d|||}|SNproxy-authenticate)rr)rrrsr2r3rtrjrs rShttp_error_407z$ProxyBasicAuthHandler.http_error_407)s1 H --.B*3S'CCrTN)rrrrrrrTrSr&r&%s('KrTr&c@eZdZd dZdZdZdZdZdZdZ d Z dS) r'Nc|t}||_|jj|_d|_d|_d|_dSNr)r!rrretried nonce_count last_nonce)rrs rSrz"AbstractDigestAuthHandler.__init__Cs@ >$&&F  K4 rTcd|_dSr)rrs rSreset_retry_countz+AbstractDigestAuthHandler.reset_retry_countLs  rTc||d}|jdkrt|jdd|d|xjdz c_|rr|d}|dkr|||S|dkrtd|zdSdS) Nizdigest auth failedr_rdigestrzEAbstractDigestAuthHandler does not support the following scheme: '%s')rrrrrrretry_http_digest_authrD)rrrrrtrrVs rSrz/AbstractDigestAuthHandler.http_error_auth_reqedOs++k400 > > #'$$uuuclll")''+  - Of, ,D  - Of, ,D "Y..  I DH HD sAA A"!A"cb|dkrdn|dkrdntd|zfd}|fS)Nrcttj|dSNr~)rmd5rrxs rSryz?AbstractDigestAuthHandler.get_algorithm_impls..s('+ahhw&7&788BBDDrTSHActtj|dSr")rrrrr$s rSryz?AbstractDigestAuthHandler.get_algorithm_impls..s(',qxx'8'899CCEErTz.Unsupported digest authentication algorithm %rc$|d|S)Nr}r)r drs rSryz?AbstractDigestAuthHandler.get_algorithm_impls..s!!qqq!!,--rT)rD)rrrrs @rSrz-AbstractDigestAuthHandler.get_algorithm_implsse   DDAA %  EEAA,.7899 9 - - - -"u rTcdSrVr)rrOrs rSrz+AbstractDigestAuthHandler.get_entity_digeststrTrV) rrrrrrrr rrrrrTrSr'r'8sIII(      <<<|   rTr'c eZdZdZdZdZdZdS)r(zAn authentication protocol defined by RFC 2069 Digest authentication improves on basic authentication because it does not transmit passwords in the clear. rct|jd}|d|||}||S)Nr_r)rrrrrrrsr2r3rtrretrys rSrz$HTTPDigestAuthHandler.http_error_401sL %%a(**+=+/g??     rTN)rrrr5rr+rrrTrSr(r(s9 "KMrTr(ceZdZdZdZdZdS)r)Proxy-Authorizationr,cl|j}|d|||}||Sr)rrrr.s rSrz%ProxyDigestAuthHandler.http_error_407s?x**+?+/g??     rTN)rrrrr+rrrTrSr)r)s-'KMrTr)c.eZdZddZdZdZdZdZdS) AbstractHTTPHandlerrc||_dSrV _debuglevel)r debuglevels rSrzAbstractHTTPHandler.__init__s%rTc||_dSrVr6)rlevels rSset_http_debuglevelz'AbstractHTTPHandler.set_http_debuglevels rTcztjj|j|SrV)rrHTTPConnection_get_content_lengthrOrrrs rSr>z'AbstractHTTPHandler._get_content_lengths3{)== L    "" "rTc`|j}|std|j|j}t|trd}t ||ds|dd|dsf|dsQ||}|$|dt |n|dd|}| r)t|j \}}t|\}} |ds|d||j jD]D\} } | } || s|| | E|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)rrrOrrrrrr>rr rr r(rr) rrrrOr3content_lengthsel_hostrVselsel_pathrirs rS do_request_zAbstractHTTPHandler.do_request_s| ,?++ + < #  + +FH = = =;1 = =KD%??$$D%%d++ =//e<<<rTc  |j}|std||fd|ji|}||jt |j  fd|j Dd d<d D |j r2i}d}| vr |||< |=| |j | | | |j|j |d  n!#t"$r}t|d }~wwxYw|} n#|xYw|jr |jd |_|| _| j| _| S) zReturn an HTTPResponse object for the request, using http_class. http_class must implement the HTTPConnection API from http.client. rArPc$i|] \}}|v || Srr)rCrDrErts rSrGz/AbstractHTTPHandler.do_open..)s3---AG++1+++rTr Connectionc>i|]\}}||Sr)title)rCrirs rSrGz/AbstractHTTPHandler.do_open..6s&FFFs4::<<FFFrTr1rtrC)encode_chunkedN)rrrPset_debuglevelr7rrupdatertrr set_tunnelrrrrOrr} getresponsersockrrNreasonr3) r http_classrhttp_conn_argsrr$tunnel_headersproxy_auth_hdrerrrxrts @rSrzAbstractHTTPHandler.do_opens x ,?++ + Jt C CS[ CN C C )***s,------):):)<)<--- . . .!( FFgmmooFFF   CN2N((181H~.N+ LL)>L B B B  $ #..**CL#(G),8K)L)LNNNN $ $ $smm# $ AA  GGIII  6  FLLNNNAF  "" s+.A D87E.8 EEEE..FNr)rrrrr;r>rIrrrTrSr4r4sj&&&&!!!""" $$$L@@@@@rTr4c"eZdZdZejZdS)r*cL|tjj|SrV)rrrr=rrs rS http_openzHTTPHandler.http_open`s||DK6<< 2 2 2 2  L L L,7 rTrKc*eZdZddZdZdZeZeZdS)rNcRddl}||j}||_dSr)http.cookiejar cookiejar CookieJar)rrkrs rSrzHTTPCookieProcessor.__init__ws2  0022I"rTc:|j||SrV)rkadd_cookie_headerr?s rSrz HTTPCookieProcessor.http_request}s ((111rTc<|j|||SrV)rkextract_cookies)rrrs rSr4z!HTTPCookieProcessor.http_responses &&x999rTrV)rrrrrr4rr6rrTrSrrvsL#### !M"NNNrTrceZdZdZdS)r/c4|j}td|z)Nzunknown url type: %s)rr)rrrs rSr zUnknownHandler.unknown_opensx-4555rTN)rrrr rrTrSr/r/s#66666rTr/ci}|D]B}|dd\}}|ddkr|ddkr |dd}|||<C|S)z>Parse list of key=value strings where keys are not duplicated.=r_rrr\)r)lparsedeltrDrEs rSrrsc Fyya  1 Q43;;1R5C<<!B$Aq MrTcg}d}dx}}|D]P}|r||z }d} |r|dkrd}|dkrd}||z }%|dkr||d}C|dkrd}||z }Q|r||d|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. rF\Trrc6g|]}|Sr)r)rCparts rS z#parse_http_list..s ) ) )TDJJLL ) ) )rT)rk)r resr{escaper curs rSrrs C DFU   CKDF   d{{ CKD  #:: JJt   D  #::E    4 ) )S ) ) ))rTc$eZdZdZdZdZdZdS)r+c|j}|dddkrL|dddkr>|jr7|jdkr,|j|vrtddS||S)Nr;rfrrQ localhost-file:// scheme is supported only on localhost)rr get_namesropen_local_file)rrrNs rS file_openzFileHandler.file_opensl rr7d??s1Q3x3CHK''8t~~////NOOO0/'',, ,rTNcXtj ttjddtjtjdzt_n4#tj$r"tjdft_YnwxYwtjS)Nrr;)r+namesrrgethostbyname_ex gethostnamegaierror gethostbynamers rSrzFileHandler.get_namess   $ I$)+K88;+F,>,@,@AA!DE%F%F !!? I I I%+%9+%F%F$H !!! I  sAA,,.BBcbddl}ddl}|j}|j}t |} t j|}|j}|j |j d} | |d} |j d| pd|| fz} |rt|\}} |r%| sRt||vr/|r d|z|z} nd|z} t!t#|d| | Sn!#t$$r}t'|d}~wwxYwt'd) NrTusegmtz6Content-type: %s Content-length: %d Last-modified: %s text/plainfile://rbzfile not on local host) email.utils mimetypesrrr5rdstatst_sizeutils formatdatest_mtime guess_typemessage_from_stringr_safe_gethostbynamerrrMr}r)rremailrrrp localfilestatsrxmodifiedmtypertrorigurlexps rSrzFileHandler.open_local_filessx< **  GI&&E=D{--enT-JJH((2215E/e/K&,h7899G .'-- d K K1$774>>;K;KKK3'$.9GG'(2G!$y$"7"7'JJJ   3--  /000sCD D DD)rrrrrrrrrTrSr+r+sH--- E!!!11111rTr+cX tj|S#tj$rYdSwxYwrV)rrr)rs rSrrs<#D))) ?tts ))ceZdZdZdZdS)r,cddl}ddl}|j}|stdt |\}}||j}nt |}t|\}}|rt|\}}nd}t|}|pd}|pd} tj |}n!#t$r}t|d}~wwxYwt|j\} } | d} t!t#t| } | dd| d} } | r| ds | dd} |||||| |j} | rdpd}| D]D}t)|\}}|d kr|d vr|}E| | |\}}d}||jd}|r|d |zz }||dkr|d |zz }t5j|}t9|||jS#|j$r}t||d}~wwxYw) Nrftp error: no host givenrrQr\r_rDraArrr)rzContent-type: %s zContent-length: %d )ftplibrrrrFTP_PORTrlrrr rrr}rrrrmap connect_ftprPrrupperretrfilerrrrr all_errors)rrrrrrrorr3reattrsdirsrXfwrattrrrsretrlenrtrrs rSftp_openzFTPHandler.ftp_opens x 7566 6%% d <?DDt99D %% d  '--LD&&Ft}}zr2 '--DD   3--   .. ezz#C&&''#2#YRd  Q 8D )!!$dD#+NNBs  rTc||_dSrV)r)rrJs rS setMaxConnszCacheFTPHandler.setMaxConnsAs rTcP|||d||f}||jvr$tj|jz|j|<n?t |||||||j|<tj|jz|j|<||j|S)NrQ)joinrrrrPr check_cache)rrorrrrrPrs rSrzCacheFTPHandler.connect_ftpDsD$7 $*   $ dj 8DL  (vtT)-w88DJsO $ dj 8DL  z#rTctj}|j|krat|jD]:\}}||kr/|j||j|=|j|=;tt|j|_t|j|j krt|jD]"\}}||jkr|j|=|j|=n#tt|j|_dSdSrV) rrrrPrrrminvaluesrnr)rrrDrEs rSrzCacheFTPHandler.check_cacheOs8 IKK <1  T\//1122 ( (1q55JqM''))) 1  Q4 3 3 5 56677  tz??dn , ,T\//1122  1 $$ 1  QE%tDL$7$7$9$9::;;DLLL - ,rTc|jD]}||j|jdSrV)rrrclearrP)rconns rS clear_cachezCacheFTPHandler.clear_cachecs\J%%''  D JJLLLL  rTN) rrrrrrrrrrrTrSr-r-4sn   <<<(rTr-ceZdZdZdS)r.c|j}|dd\}}|dd\}}t|}|drt j|}|dd}|sd}t jd|t|fz}ttj |||S)Nr}r_rz;base64itext/plain;charset=US-ASCIIz$Content-type: %s Content-length: %d ) rrrendswithr decodebytesrrrnrioBytesIO)rrrNrVrO mediatyperts rS data_openzDataHandler.data_openjslyyQ'' **S++ 4 %%   i ( ( '%d++D!#2#I 65I+,T D "-#$$"*T**GS999rTN)rrrrrrTrSr.r.is#:::::rTr.r;nt)r5r4c t|S)zOS-specific conversion from a relative URL of the 'file' scheme to a file system path; not recommended for general use.)r pathnames rSr5r5sx   rTc t|S)zOS-specific conversion from a file system path to a relative URL of the 'file' scheme; not recommended for general use.)r rs rSr4r4sXrTceZdZdZdZdezZddZdZdZ dZ dZ dd Z dd Z dd Zdd Zd ZddZddZdZerdZddZdZdZdZddZdS)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 |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/methodsclassr) stacklevelrurvkey_file cert_filez User-Agent)Acceptz*/*)rrrArBrCr6rrzrrrversionr_URLopener__tempfilesrdr|_URLopener__unlink tempcacheftpcache)rrzx509r3s rSrzURLopener.__init__s47>@W6XY c-!<<<< ? llGw''DD)DDDD ,, +..($,79JK  ! rTc.|dSrV)rrs rS__del__zURLopener.__del__s rTc.|dSrV)cleanuprs rSrzURLopener.closes rTc|jr:|jD](} ||#t$rY%wxYw|jdd=|jr|jdSdSrV)rrr}rr)rrXs rSrzURLopener.cleanups   $(  MM$''''D # > # N " " " " " # #s ( 55c:|j|dS)zdAdd a header to be used by the HTTP interface only e.g. u.addheader('Accept', 'sound/basic')N)rrk)rrs rS addheaderzURLopener.addheaders  t$$$$$rTc.tt|}t|d}|jr:||jvr1|j|\}}t |d}t |||St |\}}|sd}||jvr6|j|}t |\}} t| \} } | |f}nd}d|z} ||_ | dd} t|| r| d kr/|r| |||S| ||S |t|| |St|| ||S#tt f$rt"$r} t#d | | d} ~ wwxYw) z6Use URLopener().open(file) instead of open(file, 'r').z%/:=&?~#+!$,;'@()*[]|rSrrXNopen_-rrz socket error)r rr rrMrr rzr rrHropen_unknown_proxy open_unknownrrrr})rrrOrprtrsurltyperNrh proxyhostrrrir3s rSrMzURLopener.opens7++,,&=>>> > 4g77 $w 7 Hgh%%Bb'733 3!'**  G dl " "L)E!+E!2!2 GY' 22ND(/CCE  ||C%%tT"" 8d.?&?&? 8..ugtDDD(($777 8|*wtT**3///*wtT**35558$     8 8 8.#..C 7 8s.E# E##F>FFcHt|\}}tdd|)/Overridable interface to open unknown URL type. url errorzunknown url typer r})rrrOrrNs rSrzURLopener.open_unknowns&w'' ck#5t<< 'cT^33>#& &__ d  T TV^^ ))$//wwyy #Jt$4$4Q$788$>>     YYsD ! !% ggiiG *8T** *3  *4:2 6 6  +DJB 7 7 g *4:2 6 6 g))$//2!)!1&!9!9X ''111iD)) !7*>-*0DN3'#w..w'7899D3JxT2227GGBKKE CJJ&DIIe$$$MH!7" 8R6667  HHJJJJBHHJJJJ 199&C, &(( ( s9A B88 CCC JBI0J0JJJ5c<d}d}t|tr8t|\}}|r!t|\}}t |}|}n|\}}t|\}}t |\} } | }d}| dkrd}nBt| \}} |rt|\}}|r | d|| }t|r|}|stdd|rIt |}tj |  d} nd} |rIt |}tj |  d} nd} ||} i}| rd| z|d<| rd| z|d <|r||d <d |d <|j D] \}}|||< |d |d<| d|||n| d|| | }n'#t jj$rt'dwxYwd|jcxkrdkr"nnt+||jd|z|jS|||j|j|j|j|S)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 errorrAr~zBasic %sr1rrrrLrBz Content-TyperrrOz$http protocol error: bad status liner0r1http:)rrr rr r rrr}rrrrrrrTrr BadStatusLinerstatusrr3 http_errorrsrV)rconnection_factoryrNrO user_passwd proxy_passwdrrrealhostrr proxy_authr http_connrtrrrs rS_open_generic_httpzURLopener._open_generic_httpOs:  c3   $'__ND( %$.t$4$4! Tt}}HH ND(!+D!1!1 L$&x00MGTCK}}&((!+D!1!1$A,6x,@,@)KG.5ggxxFH))$#DA7<AAA  "<00L),*=*=*?*?@@GGPPJJJ  !+..K#K$6$6$8$899@@IIDDD&&t,,   E-7*-DG) *  :(2T(9GO $  '&GFO !( !_ $ $MFE#GFOO  &IGN #   fhg > > > >   eXw  ? ? ? C ,,..HH{( C C CABB B C (/ ' ' ' 'C ' ' ' ' 'h gm&o// /??X[(,FF Fs H$H9cN|tjj||S)zUse HTTP protocol.)rrrr=rrNrOs rS open_httpzURLopener.open_https&&t{'A3MMMrTcd|z}t||r6t||}|||||||} n|||||||} | r| 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_%d)rrr) rrNrserrcodeerrmsgrtrOrirrvs rSrzURLopener.http_errors ( 4   %T4((F|R&'BBR&'4HH $f}&&sBIIIrTcP|t||||d)z>Default error handler: close the connection and raise OSError.N)rrrrNrsrrrts rSrzURLopener.http_error_defaults%  Wfgt<<???%% d%% d   T 2 2vvft}}tzr""2&&#D))  MMM?DDt99D && et}}zz##2#YRd 0Q0QRR .Q.3aD$. t}   + +$-((  88 a(A a(GGIII 9$-''tVT4>> c" $ ) ))$// e::<<6))::: ;;==D M#.77dCCMR((#66q9EG 8/%77"w!||1G;;/88Gb'6C<88 8{{ 9 9 9...//S 8 9sC7K K2K--K2c t|tstd |dd\}}n#t$rt ddwxYw|sd}|d}|dkr$d ||d vr||dzd }|d |}nd }g}|d tj d tj tjz|d|z|dkr;tj | dd}nt|}|dt!|z|d ||d|}t%j|}t)j|}t-|||S)zUse "data" URL.zEdata error: proxy support for data protocol currently not implementedrr_z data errorz bad data URLr;rrtNrzDate: %sz%a, %d %b %Y %H:%M:%S GMTzContent-type: %srr~zlatin-1zContent-Length: %d )rrrrrDr}rfindrkrstrftimegmtimerrrrr rnrrrrStringIOr) rrNrOrsemirRr3rtfs rS open_datazURLopener.open_data1s#s## dbcc c 899S!,,LT44 8 8 8,77 7 8 10Dzz# 199DK//DFGG}H;DDH :dm,G,0K ,D,DFFF G G G %,--- x  %dkk'&:&:;;BB9MMDD4==D '#d))3444 2 4iinn+C00 K  !Wc***s AArVNNN)rrrr5rrrrrrrrrMrrr rrrrrErr!r$rr/r9rrTrSr9r9sK ;.G!!!!4 # # #%%% "8"8"8"8H==== IIII ====BZFZFZFxNNNNJJJJ === N E E E  N N N N--->>>@898989t'+'+'+'+'+'+rTr9ceZdZdZdZdZddZdZddZddZ dd Z dd Z dd Z dd Z ddZddZddZddZddZdZdS)r:z?Derived class with handlers for errors we can handle (perhaps).cZtj|g|Ri|i|_d|_d|_dS)Nrr;)r9r auth_cachetriesmaxtries)rrrs rSrzFancyURLopener.__init__^s<41$111&111  rTc,t||d|z|S)z3Default error handling -- don't raise an exception.r )rrs rSrz!FancyURLopener.http_error_defaultds"gw}g>>>rTNc|xjdz c_ |jrE|j|jkr5t|dr|j}n|j}|||dd|d|_S|||||||}|d|_S#d|_wxYw)z%Error 302 -- relocated (temporarily).r_http_error_500r&z)Internal Server Error: Redirect Recursionr)r>r?rrBrredirect_internal) rrNrsrrrtrOrrvs rSr`zFancyURLopener.http_error_302hs a  } %t}! > >FG"FOP#R)) ) yy   rTc6|||||||S)z*Error 301 -- also relocated (permanently).r`rrNrsrrrtrOs rSrazFancyURLopener.http_error_301 ""3GVWdKKKrTc6|||||||S)z;Error 303 -- also relocated (essentially identical to 302).rFrGs rSrbzFancyURLopener.http_error_303rHrTcl||||||||S||||||S)z1Error 307 -- relocated, but turn POST into error.)r`rrGs rSrczFancyURLopener.http_error_307A <&&sB$OO O**3GVWMM MrTcl||||||||S||||||S)z1Error 308 -- relocated, but turn POST into error.)rarrGs rSrdzFancyURLopener.http_error_308rKrTFc*d|vrt|||||||d}tjd|} | st||||||| \} } | dkrt|||||||st||||||d|jzdz} |t|| || St|| || |S)z_Error 401 -- authentication required. This function supports Basic authentication only.r![ ]*([^ ]+)[ ]+realm="([^"]*)"rretry_ _basic_authr9rrmatchrrrr rrNrsrrrtrOr/stuffrRrVrris rSrzFancyURLopener.http_error_401sN W , ,  ( (sB)0&' C C C*+?GG C  ( (sB)0&' C C C   <<>>W $ $  ( (sB)0&' C C C   ( (sB   $)#m3 <%74%%c511 1%74%%c5$77 7rTc*d|vrt|||||||d}tjd|} | st||||||| \} } | dkrt|||||||st||||||d|jzdz} |t|| || St|| || |S)zeError 407 -- proxy authentication required. This function supports Basic authentication only.rrNr retry_proxy_rPrQrSs rSrzFancyURLopener.http_error_407sN w . .  ( (sB)0&' C C C,-?GG C  ( (sB)0&' C C C   <<>>W $ $  ( (sB)0&' C C C   ( (sB    )M9 <%74%%c511 1%74%%c5$77 7rTct|\}}d|z|z}|jd}t|\}} t| \} } | ddz} | | d} || || \} } | s| sdSt | ddt | dd| } d| z| z|jd<|||S|||S)Nhttp://rrgr_rrr}r rzr rget_user_passwdr rMrrNrrOrrrIrhrr proxyselectorrrors rSretry_proxy_http_basic_authz*FancyURLopener.retry_proxy_http_basic_auths#ChT!H, V$'..#-i#8#8 = NN3  ! #abbM ++Iua@@ f,,"'2"6"6"6"6"6"'R"8"8"8"8"8))E (94}D V <99V$$ $99VT** *rTct|\}}d|z|z}|jd}t|\}} t| \} } | ddz} | | d} || || \} } | s| sdSt | ddt | dd| } d| z| z|jd<|||S|||S)Nhttps://rrgr_rrr}rYr[s rSretry_proxy_https_basic_authz+FancyURLopener.retry_proxy_https_basic_auths#Chd"X- W%'..#-i#8#8 = NN3  ! #abbM ++Iua@@ f,,"'2"6"6"6"6"6"'R"8"8"8"8"8))E *Y 6 F W <99V$$ $99VT** *rTcdt|\}}|ddz}||d}||||\}}|s|sdSt|ddt|dd|}d|z|z} ||| S|| |S)Nrgr_rrr}rXr rrZr rM rrNrrOrrrrorrIs rSrz$FancyURLopener.retry_http_basic_auth s#Ch IIcNNQ ABBx++D%;; f,,"4b11111"633333TT;T!H, <99V$$ $99VT** *rTcdt|\}}|ddz}||d}||||\}}|s|sdSt|ddt|dd|}d|z|z} ||| S|| |S)Nrgr_rrr}r_rbrcs rSretry_https_basic_authz%FancyURLopener.retry_https_basic_auth s#Ch IIcNNQ ABBx++D%;; f,,"4b11111"633333TT;d"X- <99V$$ $99VT** *rTrc|dz|z}||jvr|r |j|=n |j|S|||\}}|s|r ||f|j|<||fS)Nrg)rr=prompt_user_passwd)rrrrrrors rSrZzFancyURLopener.get_user_passwd sckDJJLL( $/ ! ! ,OC((s++..tU;; f @6@4.4?3/V|rTc ddl} td|d|d}|d|d|d|d}||fS#t$rtYdSwxYw) z#Override this in a GUI environment!rNzEnter username for z at z: zEnter password for z in r)getpassinputKeyboardInterruptprint)rrrrirors rSrgz!FancyURLopener.prompt_user_passwd) s 5EEE444HIID___uuuddd&$%%F<      GGG:: s8?AArV)NFr\)rrrr5rrr`rCrarbrcrdrrr]r`rrerZrgrrTrSr:r:[sjII ???$!!!8LLLLLLLLNNNNNNNNFJ88882FJ88882++++$++++$ + + + + + + + +         rTr:cFttjdatS)z8Return the IP address of the magic hostname 'localhost'.Nr) _localhostrrrrTrSrr9 s )+66 rTc tv ttjtjdan<#tj$r*ttjddaYnwxYwtS)z,Return the IP addresses of the current host.Nr;r) _thishostrrrrrrrTrSr'r'A s Gf5f6H6J6JKKANOOII G G Gf5kBB1EFFIII G s8A6A;:A;c4t ddl}|jatS)z1Return the set of errors raised by the FTP class.Nr) _ftperrorsrr)rs rSr.r.L s! & rTcFttjdatS)z%Return an empty email Message object.Nr) _noheadersrrrrTrS noheadersruU s .r22 rTcBeZdZdZ d dZdZdZdZdZd Z d Z dS) rz;Class used by open_ftp() for cache of open FTP connections.NTc||_||_||_||_||_||_d|_||_ |dS#| xYwr) rorrrrrPrefcount keepaliveinitr)rrorrrrrPrs rSrzftpwrapper.__init__b si       #  IIKKKKK  JJLLL s AA'cVddl}d|_||_|j|j|j|j|j|j |j d |j }|j |dS)NrrQ)rbusyFTPrPconnectrrrPloginrorrrcwd)rr_targets rSrzzftpwrapper.initr s  ::<< DIt|<<< ty$+...((49%%  WrTcDddl}||dvrd}d}nd|z}d} |j|n>#|j$r1||j|YnwxYwd}|rk|si d|z}|j|\}}nE#|j$r8}t|dddkrtd ||Yd}~nd}~wwxYw|s|jd|r|j } |j |n%#|j$r}td |z|d}~wwxYw |j | n#|j | wxYwd |z}nd }|j|\}}d|_ t|d |j} |xjdz c_|| |fS)Nr)r)rzTYPE Ar_zTYPE zRETR r550r,z ftp error: %rzLIST LISTr)r endtransferrPvoidcmdrrz ntransfercmd error_permrrpwdrr|rmakefile file_closerxr) rrXrrcmdisdirrrrVrftpobjs rSrzftpwrapper.retrfile{ s   :  XsquudNcAE " H  S ! ! ! !  " " " IIKKK H  S ! ! ! ! ! "  G G Gn $ 5 5c : : gg$ G G Gv;;rr?e++"#9#9#9::F,++++ G 7 H  X & & & hllnn&M T****!,MMM&'?@@fLM+HLL%%%%DHLL%%%%n H11#66MD' dmmD114?CC     sSA8B?B "B-- C/7.C**C/+EF E(E##E((FF#c|jsdSd|_ |jdS#t$rYdSwxYwr)r|rPvoidrespr.rs rSrzftpwrapper.endtransfer s]y  F   H       {{    DD s-AAcVd|_|jdkr|dSdS)NFr)ryrx real_closers rSrzftpwrapper.close s4 =A   OO       rTc||xjdzc_|jdkr|js|dSdSdS)Nr_r)rrxryrrs rSrzftpwrapper.file_close s\   =A  dn  OO         rTc| |jdS#t$rYdSwxYwrV)rrPrr.rs rSrzftpwrapper.real_close sW   HNN     {{    DD s1AA)NT) rrrr5rrzrrrrrrrTrSrr_ sEE?C  *!*!*!X  rTrci}tjD]6\}}|}|r|dddkr |||dd<7dtjvr|ddtjD]U\}}|dddkrB|}|r|||dd<7||dddV|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_proxyREQUEST_METHODr)rdenvironrrr)rzrirs rSgetproxies_environmentr s Gz''))'' ezz||  'T"##Y(**!&GD"I  2:%% FD!!!z''))-- e 9 ::<.ip2num s S!!Se__%% u::??\\\)2A2.EaB58r>2eAh!mDuQxOOrTrexclude_simpleTN exceptionsrz(\d+(?:\.\d+)*)(/\d+)?r_r;r F) rrrrrRrrr}groupcountrl) rproxy_settingsrrrrhostIPrrJrmasks rS_proxy_bypass_macosx_sysconfr s %%NHdPPP $ * + 4 F##L"55h H. 6 6 =~#1(;;F#VF^^FFH6!''!**%%D771::D|AGGAJJ,,S11A5648}}axx4"999D$DDL11tt2WT5 ! ! 44  5s!B B Bdarwin)_get_proxy_settings _get_proxiesc>t}t||SrV)rr)rrs rSproxy_bypass_macosx_sysconfrK s,..+D.AAArTctS)zReturn a dictionary of scheme -> proxy server URL mappings. This function uses the MacOSX framework SystemConfiguration to fetch the proxy information. )rrrTrSgetproxies_macosx_sysconfrO s ~~rTc`t}|rt||St|S)zReturn True, if host should be bypassed. Checks proxy settings gathered from the environment, if specified, or from the MacOSX framework SystemConfiguration. )rrrrrzs rSrrY s5)**  5+D':: :.t44 4rTc:tp tSrV)rrrrTrSr6r6f s%''F+D+F+FFrTc*i} ddl}n#t$r|cYSwxYw ||jd}||dd}|r t ||dd}d|vrd|vrd|}|dD]J}|dd \}}tj d |s|d vrd |z}n |d krd|z}|||<K| d rPtj dd|d }| dp||d<| dp||d<| n#tttf$rYnwxYw|S)zxReturn a dictionary of scheme -> proxy server URL mappings. Win32 uses the registry to store proxies. rN;Software\Microsoft\Windows\CurrentVersion\Internet Settings ProxyEnable ProxyServerrtr1zhttp={0};https={0};ftp={0}r_z (?:[^/:]+)://)rrrPrXsockszsocks://z ^socks://z socks4://rr)winreg ImportErrorOpenKeyHKEY_CURRENT_USER QueryValueExrrrrrRrrCloser}rDr)rzrinternetSettings proxyEnable proxyServerpraddresss rSgetproxies_registryrk s   MMMM   NNN " %~~f.FN P P  --.>/<>>>?AK G!&"5"56F7D#F#FFG#IJJ k))c.D.D">"E"Ek"R"RK$**3// 0 0A()Q%Hg8OW==;#'???&/'&9GG%00&07&:G(/GH%%;;w''G f\;@PQQG&-kk&&9&9&DWGFO'.{{7';';'FwGG$  " " $ $ $ $Y/    D   s EE66FFc:tp tS)zReturn a dictionary of scheme -> proxy server URL mappings. Returns settings gathered from the environment, if specified, or the registry. )rrrrTrSr6r6 s&''@+>+@+@@rTcx ddl}n#t$rYdSwxYw ||jd}||dd}t ||dd}n#t $rYdSwxYw|r|sdSt|\}}|g} tj |}||kr| |n#t $rYnwxYw tj |}||kr| |n#t $rYnwxYw| d}|D]z} | dkrd|vrdS| dd } | d d } | d d} |D]&} tj| | tjrdS'{dS) Nrrr ProxyOverrider1zrr_z\.rz.*?)rrrrrrr}rrrrkgetfqdnrrHrrRr) rrrr proxyOverriderawHostraddrfqdnrrs rSproxy_bypass_registryr s]  MMMM   11  %~~f.FN P P  --.>/<>>>?AK 3 34D5D!F!FFG!IJJMM   11  - 1"4(( y '00Dw D!!!    D  >'**Dw D!!!    D  &++C00 !  Dy  g%%11<<U++D<<U++D<<T**D  8D#rt,,111 qsB A A:: BB'/C C$#C$(/D D%$D%c`t}|rt||St|S)zReturn True, if host should be bypassed. Checks proxy settings gathered from the environment, if specified, or the registry. )rrrrs rSrr s5)**  /+D':: :(.. .rTr:rV)~r5rrrr http.clientrrrd posixpathrrrXrrrgrarA urllib.errorrrr urllib.parserrrr r r r r rrrrrrrrrrurllib.responserrrFrEr__all__ version_inforrLrr1r2rjr7r8rASCIIrrrrr3rr0rrrqr r!r"r#r$r%r&urandomrr'r(r)r4r*rrrKrkrr/rrr+rr,r-r.r-ri nturl2pathr5r4rr9r:rnrrpr'rrr.rtrurrrrplatform_scproxyrrrrrr6rrrrTrSrs CCf   CBBBBBBBBB"""""""""""""""""""""""""""""""""""""""" 54444444JJJIIIII    $(!,, F$BM+45$M+M+M+M+M+^====~   rz(BH--  k"k"k"k"k"k"k"k"ZI+I+I+I+I+I+I+I+^"""H88888888&########";;;;;k;;;n2n2n2n2n2+n2n2n2b,,,B)>)>)>)>)>;)>)>)>V=*=*=*=*=*=*=*=*@GGGGGoGGG33333#B333>k#k#k#k#k#k#k#k#^3[     4k    z OOOOOOOOdK)B$     [*C   sssss+sssl33333%333 74;)**# 8 8 8 8 8* 8 8 8 NN>"""#####+###$66666[666 )*)*)*V1111111111+111111f 7,7,7,7,7,7,7,7,r33333j333j:::::+:::B 7d??555555555!!!  z+z+z+z+z+z+z+z+z XXXXXYXXXz     aaaaaaaaH>    J>>>B<8::::::::BBB 5 5 5GGGGGW__///bAAA000d / / / / /(J+LLLs>BBB