/usr/lib64/python3.9/urllib/__pycache__
NameSizeModeActions
error.cpython-39.opt-1.pyc28260644editdlrm
error.cpython-39.opt-2.pyc21510644editdlrm
error.cpython-39.pyc28260644editdlrm
parse.cpython-39.opt-1.pyc359730644editdlrm
parse.cpython-39.opt-2.pyc252370644editdlrm
parse.cpython-39.pyc359730644editdlrm
request.cpython-39.opt-1.pyc724840644editdlrm
request.cpython-39.opt-2.pyc602170644editdlrm
request.cpython-39.pyc725770644editdlrm
response.cpython-39.opt-1.pyc34560644editdlrm
response.cpython-39.opt-2.pyc28770644editdlrm
response.cpython-39.pyc34560644editdlrm
robotparser.cpython-39.opt-1.pyc73270644editdlrm
robotparser.cpython-39.opt-2.pyc59590644editdlrm
robotparser.cpython-39.pyc73270644editdlrm
__init__.cpython-39.opt-1.pyc1300644editdlrm
__init__.cpython-39.opt-2.pyc1300644editdlrm
__init__.cpython-39.pyc1300644editdlrm
Edit: /usr/lib64/python3.9/urllib/__pycache__/request.cpython-39.opt-1.pyc (72484B)
a ´iº‹ã@sŽdZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlmZmZmZddlmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(ddl)m*Z*m+Z+z ddl,Z,Wne-�ydZ.Yn0dZ.gd¢Z/d e j0dd …Z1da2de j3fddddd œd d „Z4dd„Z5gZ6d�dd„Z7dd„Z8e  9de j:¡Z;dd„Zdd„Z?Gdd„dƒZ@Gdd „d e@ƒZAGd!d"„d"e@ƒZBGd#d$„d$e@ƒZCd%d&„ZDGd'd(„d(e@ƒZEGd)d*„d*ƒZFGd+d,„d,eFƒZGGd-d.„d.eGƒZHGd/d0„d0ƒZIGd1d2„d2eIe@ƒZJGd3d4„d4eIe@ƒZKejLZMGd5d6„d6ƒZNGd7d8„d8e@eNƒZOGd9d:„d:e@eNƒZPGd;d<„d„d>eQƒZReSejTd?ƒ�rêGd@dA„dAeQƒZUe/ VdA¡GdBdC„dCe@ƒZWGdDdE„dEe@ƒZXdFdG„ZYdHdI„ZZGdJdK„dKe@ƒZ[dLdM„Z\GdNdO„dOe@ƒZ]GdPdQ„dQe]ƒZ^GdRdS„dSe@ƒZ_dTZ`ejadUk�r„ddVlbmcZcmdZdndWdX„ZcdYdZ„ZdiZeGd[d\„d\ƒZfGd]d^„d^efƒZgdahd_d`„Zidajdadb„Zkdaldcdd„Zmdandedf„ZoGdgdh„dhƒZpdidj„Zqd‚dkdl„Zrdmdn„Zsdodp„Zte judqk�rTddrlvmwZwmxZxdsdt„Zydudv„Zzdwdx„Z{dydz„Z|n6ejadUk�r‚d{d|„Z}d}dz„Z|d~d„Z~d€dx„Z{neqZ|erZ{dS)ƒ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Ú HTTPErrorÚContentTooShortError)ÚurlparseÚurlsplitÚurljoinÚunwrapÚquoteÚunquoteÚ _splittypeÚ _splithostÚ _splitportÚ _splituserÚ _splitpasswdÚ _splitattrÚ _splitqueryÚ _splitvalueÚ _splittagÚ _to_bytesÚunquote_to_bytesÚ urlunparse)Ú addinfourlÚ addclosehookFT)!ÚRequestÚOpenerDirectorÚ BaseHandlerÚHTTPDefaultErrorHandlerÚHTTPRedirectHandlerÚHTTPCookieProcessorÚ ProxyHandlerÚHTTPPasswordMgrÚHTTPPasswordMgrWithDefaultRealmÚHTTPPasswordMgrWithPriorAuthÚAbstractBasicAuthHandlerÚHTTPBasicAuthHandlerÚProxyBasicAuthHandlerÚAbstractDigestAuthHandlerÚHTTPDigestAuthHandlerÚProxyDigestAuthHandlerÚ HTTPHandlerÚ FileHandlerÚ FTPHandlerÚCacheFTPHandlerÚ DataHandlerÚUnknownHandlerÚHTTPErrorProcessorÚurlopenÚinstall_openerÚ build_openerÚ pathname2urlÚ url2pathnameÚ getproxiesÚ urlretrieveÚ urlcleanupÚ URLopenerÚFancyURLopenerz%d.%dé)ÚcafileÚcapathÚ cadefaultÚcontextc Cs¤|s |s |rfddl}| dtd¡|dur2tdƒ‚ts>tdƒ‚tjtjj||d�}t |d�}t |ƒ} n0|r~t |d�}t |ƒ} nt dur’t ƒa } nt } |   |||¡S) aùOpen the URL url, which can be either a string or a Request object. *data* must be an object specifying additional data to be sent to the server, or None if no such data is needed. See Request for details. urllib.request module uses HTTP/1.1 and includes a "Connection:close" header in its HTTP requests. The optional *timeout* parameter specifies a timeout in seconds for blocking operations like the connection attempt (if not specified, the global default timeout setting will be used). This only works for HTTP, HTTPS and FTP connections. If *context* is specified, it must be a ssl.SSLContext instance describing the various SSL options. See HTTPSConnection for more details. The optional *cafile* and *capath* parameters specify a set of trusted CA certificates for HTTPS requests. cafile should point to a single file containing a bundle of CA certificates, whereas capath should point to a directory of hashed certificate files. More information can be found in ssl.SSLContext.load_verify_locations(). The *cadefault* parameter is ignored. This function always returns an object which can work as a context manager and has 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>) ÚwarningsÚwarnÚDeprecationWarningÚ ValueErrorÚ _have_sslÚsslZcreate_default_contextZPurposeZ SERVER_AUTHÚ HTTPSHandlerr2Ú_openerÚopen) ÚurlÚdataÚtimeoutr;r<r=r>r?Z https_handlerÚopener©rLú&/usr/lib64/python3.9/urllib/request.pyr0‹s04 ÿÿ þ     r0cCs|adS©N)rF)rKrLrLrMr1Øsr1c Cslt|ƒ\}}t t||ƒ¡��}| ¡}|dkrR|sRtj |¡|fWdƒS|rbt|dƒ}nt j dd�}|j }t   |¡|�Ž||f} d} d} d} d} d |vr°t|d ƒ} |rÀ|| | | ƒ| | ¡}|sÒ�q| t|ƒ7} | |¡| d 7} |rÀ|| | | ƒqÀWdƒn1�s0YWdƒn1�s80Y| dk�rh| | k�rhtd | | 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. ÚfileNÚwbF)Údeleteé éÿÿÿÿrúcontent-lengthúContent-Lengthéú1retrieval incomplete: got only %i out of %i bytes)r Ú contextlibÚclosingr0ÚinfoÚosÚpathÚnormpathrGÚtempfileÚNamedTemporaryFileÚnameÚ_url_tempfilesÚappendÚintÚreadÚlenÚwriter)rHÚfilenameÚ reporthookrIZurl_typer\ÚfpÚheadersÚtfpÚresultÚbsÚsizerdÚblocknumÚblockrLrLrMr6ÝsH          Nÿþr6c CsBtD]&}zt |¡Wqty(Yq0qtdd…=tr>dadS)z0Clean up temporary files from urlretrieve calls.N)rar[ÚunlinkÚOSErrorrF)Z temp_filerLrLrMr7s  r7z:\d+$cCs<|j}t|ƒd}|dkr&| dd¡}t d|d¡}| ¡S)zˆReturn request-host, as defined by RFC 2965. Variation from RFC: returned value is lowercased, for convenient comparison. rVÚÚHost)Úfull_urlrÚ get_headerÚ _cut_port_reÚsubÚlower)ÚrequestrHÚhostrLrLrMÚ request_host+s   r|c@sÊeZdZdidddfdd„Zedd„ƒZejdd„ƒZejdd„ƒZed d „ƒZejd d „ƒZejd d „ƒZd d„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zd#dd„Zdd „Zd!d"„ZdS)$rNFc Csl||_i|_i|_d|_||_d|_| ¡D]\}}| ||¡q,|durRt|ƒ}||_ ||_ |rh||_ dSrN) rurjÚunredirected_hdrsÚ_datarIÚ _tunnel_hostÚitemsÚ add_headerr|Úorigin_req_hostÚ unverifiableÚmethod) ÚselfrHrIrjr‚rƒr„ÚkeyÚvaluerLrLrMÚ__init__=szRequest.__init__cCs|jrd |j|j¡S|jS)Nz{}#{})ÚfragmentÚformatÚ _full_url©r…rLrLrMruOszRequest.full_urlcCs(t|ƒ|_t|jƒ\|_|_| ¡dSrN)rr‹rr‰Ú_parse©r…rHrLrLrMruUs cCsd|_d|_d|_dS)Nrs)r‹r‰ÚselectorrŒrLrLrMru\scCs|jSrN)r~rŒrLrLrMrIbsz Request.datacCs(||jkr$||_| d¡r$| d¡dS)NúContent-length)r~Ú has_headerÚ remove_header)r…rIrLrLrMrIfs  cCs d|_dSrN)rIrŒrLrLrMrIpscCsNt|jƒ\|_}|jdur(td|jƒ‚t|ƒ\|_|_|jrJt|jƒ|_dS)Nzunknown url type: %r) r r‹ÚtyperBrur r{r�r )r…ÚrestrLrLrMr�ts  zRequest._parsecCs|jdurdnd}t|d|ƒS)z3Return a string indicating the HTTP request method.NÚPOSTÚGETr„)rIÚgetattr)r…Zdefault_methodrLrLrMÚ get_method|szRequest.get_methodcCs|jSrN)rurŒrLrLrMÚ get_full_url�szRequest.get_full_urlcCs2|jdkr|js|j|_n||_|j|_||_dS)NÚhttps)r“rr{rur�)r…r{r“rLrLrMÚ set_proxy„s  zRequest.set_proxycCs |j|jkSrN)r�rurŒrLrLrMÚ has_proxyŒszRequest.has_proxycCs||j| ¡<dSrN)rjÚ capitalize©r…r†ÚvalrLrLrMr��szRequest.add_headercCs||j| ¡<dSrN)r}r�ržrLrLrMÚadd_unredirected_header“szRequest.add_unredirected_headercCs||jvp||jvSrN)rjr}©r…Ú header_namerLrLrMr‘—s ÿzRequest.has_headercCs|j ||j ||¡¡SrN)rjÚgetr})r…r¢ÚdefaultrLrLrMrv›s þzRequest.get_headercCs |j |d¡|j |d¡dSrN)rjÚpopr}r¡rLrLrMr’ szRequest.remove_headercCsi|j¥|j¥}t| ¡ƒSrN)r}rjÚlistr€)r…ÚhdrsrLrLrMÚ header_items¤szRequest.header_items)N)Ú__name__Ú __module__Ú __qualname__rˆÚpropertyruÚsetterÚdeleterrIr�r˜r™r›rœr�r r‘rvr’r¨rLrLrLrMr;s6þ        rc@sNeZdZdd„Zdd„Zdd„Zdd„Zd ejfd d „Z dd d „Z dd„Z d S)rcCs6dt}d|fg|_g|_i|_i|_i|_i|_dS)NúPython-urllib/%sz User-agent)Ú __version__Ú addheadersÚhandlersÚ handle_openÚ handle_errorÚprocess_responseÚprocess_request)r…Zclient_versionrLrLrMrˆ©s zOpenerDirector.__init__c CsRt|dƒstdt|ƒƒ‚d}t|ƒD�]}|dvr6q&| d¡}|d|…}||dd…}| d¡rÂ| d¡|d}||dd…}z t|ƒ}Wnty¦Yn0|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_requestÚdo_openÚ proxy_openÚ_rVÚerrorrGÚresponserzT)ÚhasattrÚ TypeErrorr“ÚdirÚfindÚ startswithrcrBr´r£r³rµr¶Ú setdefaultÚbisectÚinsortrbr²r·) r…ÚhandlerZaddedÚmethÚiÚprotocolZ conditionÚjÚkindÚlookupr²rLrLrMÚ add_handler´sL ÿ        zOpenerDirector.add_handlercCsdSrNrLrŒrLrLrMÚcloseãszOpenerDirector.closec Gs<| |d¡}|D]&}t||ƒ}||Ž}|dur|SqdS)NrL)r£r—) r…ÚchainrËÚ meth_nameÚargsr²rÆÚfuncrlrLrLrMÚ _call_chainçs   zOpenerDirector._call_chainNc Cs¾t|tƒrt||ƒ}n|}|dur(||_||_|j}|d}|j |g¡D]}t||ƒ}||ƒ}qJt   d|j |j|j |  ¡¡| ||¡} |d}|j |g¡D]}t||ƒ}||| ƒ} q | S)NZ_requestzurllib.RequestZ _response)Ú isinstanceÚstrrrIrJr“r¶r£r—ÚsysÚauditrurjr˜Ú_openrµ) r…ÚfullurlrIrJÚreqrÉrÐZ processorrÇr½rLrLrMrGòs$       zOpenerDirector.opencCsP| |jdd|¡}|r|S|j}| |j||d|¡}|r>|S| |jdd|¡S)Nr¤Z default_openrØÚunknownÚ unknown_open)rÓr³r“)r…rÚrIrlrÉrLrLrMrØs  ÿ ÿÿ ÿzOpenerDirector._opencGs~|dvr,|jd}|d}d|}d}|}n|j}|d}d}|||f|}|j|Ž}|r^|S|rz|dd f|}|j|ŽSdS) N©ÚhttpršrÞr:z http_error_%srVÚ_errorrr¤Úhttp_error_default)r´rÓ)r…ÚprotorÑÚdictrÐZhttp_errZ orig_argsrlrLrLrMr¼s   zOpenerDirector.error)N) r©rªr«rˆrÍrÎrÓÚsocketÚ_GLOBAL_DEFAULT_TIMEOUTrGrØr¼rLrLrLrMr¨s /  rc GsÒtƒ}ttttttttt g }t t j dƒr2|  t¡tƒ}|D]B}|D]8}t|tƒrht||ƒr|| |¡qDt||ƒrD| |¡qDq<|D]}| |¡q„|D]}| |ƒ¡q˜|D]}t|tƒrÂ|ƒ}| |¡q®|S)a*Create an opener object from a list of handlers. The opener will use several default handlers, including support for HTTP, FTP and when applicable HTTPS. If any of the handlers passed as arguments are subclasses of the default handlers, the default handlers will not be used. ÚHTTPSConnection)rrr.r)rrr+r*r/r-r¾rÞÚclientrbrEÚsetrÔr“Ú issubclassÚaddÚremoverÍ)r²rKZdefault_classesÚskipÚklassÚcheckÚhrLrLrMr27s2 ý         r2c@s(eZdZdZdd„Zdd„Zdd„ZdS) réôcCs ||_dSrN)Úparent)r…rðrLrLrMr·^szBaseHandler.add_parentcCsdSrNrLrŒrLrLrMrÎaszBaseHandler.closecCst|dƒsdS|j|jkS)NÚ handler_orderT)r¾rñ)r…ÚotherrLrLrMÚ__lt__es zBaseHandler.__lt__N)r©rªr«rñr·rÎrórLrLrLrMr[src@s eZdZdZdZdd„ZeZdS)r/zProcess HTTP error responses.iècCsH|j|j| ¡}}}d|kr,dksDn|j d|||||¡}|S)NéÈé,rÞ)ÚcodeÚmsgrZrðr¼)r…rzr½rör÷r§rLrLrMÚ http_responsers  ÿz HTTPErrorProcessor.http_responseN)r©rªr«Ú__doc__rñrøÚhttps_responserLrLrLrMr/ns r/c@seZdZdd„ZdS)rcCst|j||||ƒ‚dSrN)rru)r…rÚrirör÷r§rLrLrMrà€sz*HTTPDefaultErrorHandler.http_error_defaultN)r©rªr«ràrLrLrLrMrsrc@s4eZdZdZdZdd„Zdd„ZeZZZ dZ dS) réé c st| ¡}|dvr|dvs:|dvr(|dks:t|j||||ƒ‚| dd¡}d‰‡fdd „|j ¡Dƒ}t|||jd d �S) a­Return a Request or None in response to a redirect. This is called by the http_error_30x methods when a redirection response is received. If a redirection should take place, return a new Request to allow http_error_30x to perform the redirect. Otherwise, raise HTTPError if no-one else should try to handle this url. Return None if you can't but another Handler might. )é-é.é/i3)r–ZHEAD)rýrþrÿr•ú z%20)rTz content-typecs"i|]\}}| ¡ˆvr||“qSrL)ry©Ú.0ÚkÚv©ZCONTENT_HEADERSrLrMÚ ¦s  ÿz8HTTPRedirectHandler.redirect_request..T)rjr‚rƒ)r˜rruÚreplacerjr€rr‚) r…rÚrirör÷rjÚnewurlÚmZ newheadersrLrrMr¸‹s ÿÿ ýz$HTTPRedirectHandler.redirect_requestc CsLd|vr|d}nd|vr$|d}ndSt|ƒ}|jdvrRt||d||f||ƒ‚|jsn|jrnt|ƒ}d|d<t|ƒ}t|dtj d�}t |j |ƒ}|  ||||||¡}|dur²dSt |d ƒ�r|j} |_|  |d ¡|jksìt| ƒ|jk�rt|j ||j|||ƒ‚ni} |_|_|  |d ¡d | |<| ¡| ¡|jj||jd �S) NÚlocationÚuri©rÞršÚftprsz+%s - Redirection to url '%s' is not allowedú/r:z iso-8859-1)ÚencodingÚsafeÚ redirect_dictrrV©rJ)rÚschemerr\Únetlocr¦rr ÚstringÚ punctuationrrur¸r¾rr£Ú max_repeatsreÚmax_redirectionsÚinf_msgrdrÎrðrGrJ) r…rÚrirör÷rjrÚurlpartsÚnewZvisitedrLrLrMÚhttp_error_302±sH    ý ÿ    ÿ ÿz"HTTPRedirectHandler.http_error_302zoThe HTTP server returned a redirect error that would lead to an infinite loop. The last 30x error message was: N) r©rªr«rrr¸rÚhttp_error_301Úhttp_error_303Úhttp_error_307rrLrLrLrMrƒs &< rc Cs°t|ƒ\}}| d¡s d}|}nZ| d¡s6td|ƒ‚d|vrV| d¡}| d|¡}n | dd¡}|dkrnd}|d|…}t|ƒ\}}|durœt|ƒ\}} nd}} ||| |fS)a Return (scheme, user, password, host/port) given a URL or an authority. If a URL is supplied, it must have an authority (host:port) component. According to RFC 3986, having an authority component means the URL must have two slashes after the scheme. rNú//zproxy URL with no authority: %rú@r:rS)r rÂrBrÁrr) ÚproxyrZr_schemeÚ authorityZhost_separatorÚendÚuserinfoÚhostportÚuserÚpasswordrLrLrMÚ _parse_proxyôs$        r)c@s"eZdZdZddd„Zdd„ZdS)rédNcCsP|durtƒ}||_| ¡D].\}}| ¡}t|d||||jfdd„ƒqdS)Nz%s_opencSs ||||ƒSrNrL)Úrr"r“rÇrLrLrMÚ!sz'ProxyHandler.__init__..)r5Úproxiesr€ryÚsetattrrº)r…r-r“rHrLrLrMrˆs ÿzProxyHandler.__init__c Cs´|j}t|ƒ\}}}}|dur"|}|jr6t|jƒr6dS|rv|rvdt|ƒt|ƒf} t |  ¡¡ d¡} |  dd| ¡t|ƒ}|  ||¡||ksš|dkrždS|j j ||j d�SdS)Nú%s:%sÚasciiúProxy-authorizationúBasic ršr)r“r)r{Ú proxy_bypassr Úbase64Ú b64encodeÚencodeÚdecoder�r›rðrGrJ) r…rÚr"r“Z orig_typeZ proxy_typer'r(r&Z user_passZcredsrLrLrMrº$s"ÿ zProxyHandler.proxy_open)N)r©rªr«rñrˆrºrLrLrLrMrs rc@s6eZdZdd„Zdd„Zdd„Zd dd „Zd d „Zd S)r cCs i|_dSrN)ÚpasswdrŒrLrLrMrˆBszHTTPPasswordMgr.__init__cs\t|tƒr|g}|ˆjvr$iˆj|<dD].‰t‡‡fdd„|Dƒƒ}||fˆj||<q(dS)N©TFc3s|]}ˆ |ˆ¡VqdSrN)Ú reduce_uri)rÚu©Ú default_portr…rLrMÚ Lsz/HTTPPasswordMgr.add_password..)rÔrÕr8Útuple)r…Úrealmr r'r8Ú reduced_urirLr<rMÚ add_passwordEs   ÿzHTTPPasswordMgr.add_passwordc Cs`|j |i¡}dD]H}| ||¡}| ¡D].\}}|D] }| ||¡r6|Sq6q*qdS)Nr9©NN)r8r£r:r€Ú is_suburi) r…r@ÚauthuriZdomainsr=Úreduced_authuriZurisZauthinfor rLrLrMÚfind_user_passwordPs  z"HTTPPasswordMgr.find_user_passwordTc Cs†t|ƒ}|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.rVrr:rNéPi»rÝz%s:%d)rr r£) r…r r=Úpartsrr#r\r{ÚportZdportrLrLrMr:Zs$ ÿþ zHTTPPasswordMgr.reduce_uricCsN||kr dS|d|dkr dS|d}|dd…dkr@|d7}|d |¡S)zcCheck if test is below base in a URI tree Both args must be URIs in reduced form. TrFrVrSNr)rÂ)r…ÚbaseÚtestÚprefixrLrLrMrDqszHTTPPasswordMgr.is_suburiN)T)r©rªr«rˆrBrGr:rDrLrLrLrMr @s   r c@seZdZdd„ZdS)r!cCs0t |||¡\}}|dur"||fSt |d|¡SrN)r rG)r…r@rEr'r(rLrLrMrG‚s ÿz2HTTPPasswordMgrWithDefaultRealm.find_user_passwordN)r©rªr«rGrLrLrLrMr!€sr!cs<eZdZ‡fdd„Zd ‡fdd„ Zd dd„Zdd „Z‡ZS) r"csi|_tƒj|i|¤ŽdSrN)Ú authenticatedÚsuperrˆ©r…rÑÚkwargs©Ú __class__rLrMrˆŒsz%HTTPPasswordMgrWithPriorAuth.__init__Fcs<| ||¡|dur&tƒ d|||¡tƒ ||||¡dSrN)Úupdate_authenticatedrOrB)r…r@r r'r8Úis_authenticatedrRrLrMrB�s z)HTTPPasswordMgrWithPriorAuth.add_passwordcCs>t|tƒr|g}dD]$}|D]}| ||¡}||j|<qqdS©Nr9)rÔrÕr:rN)r…r rUr=r;rArLrLrMrT—s   z1HTTPPasswordMgrWithPriorAuth.update_authenticatedcCsDdD]:}| ||¡}|jD]"}| ||¡r|j|SqqdSrV)r:rNrD)r…rEr=rFr rLrLrMrU¡s    z-HTTPPasswordMgrWithPriorAuth.is_authenticated)F)F)r©rªr«rˆrBrTrUÚ __classcell__rLrLrRrMr"Šs  r"c@sTeZdZe dej¡Zddd„Zdd„Zdd„Z d d „Z d d „Z d d„Z e Z e ZdS)r#z1(?:^|,)[ ]*([^ ,]+)[ ]+realm=(["']?)([^"']*)\2NcCs"|durtƒ}||_|jj|_dSrN)r r8rB)r…Z password_mgrrLrLrMrˆ¾sz!AbstractBasicAuthHandler.__init__ccspd}tj |¡D]6}| ¡\}}}|dvr8t dtd¡||fVd}q|sl|r^| ¡d}nd}|dfVdS)NF)ú"ú'zBasic Auth Realm was unquotedéTrrs)r#ÚrxÚfinditerÚgroupsr?r@Ú UserWarningÚsplit)r…ÚheaderZfound_challengeÚmorr r@rLrLrMÚ _parse_realmÄsÿ z%AbstractBasicAuthHandler._parse_realmc Cs~| |¡}|sdSd}|D]H}| |¡D]8\}}| ¡dkrB|}q(|dur(| |||¡Sq(q|durztd|fƒ‚dS)NÚbasiczBAbstractBasicAuthHandler does not support the following scheme: %r)Zget_allrbryÚretry_http_basic_authrB) r…Úauthreqr{rÚrjZ unsupportedr`rr@rLrLrMÚhttp_error_auth_reqedØs  þz.AbstractBasicAuthHandler.http_error_auth_reqedcCs||j ||¡\}}|durtd||f}dt | ¡¡ d¡}| |jd¡|krTdS| |j|¡|j j ||j d�SdSdS)Nr/r2r0r) r8rGr4r5r6r7rvÚ auth_headerr rðrGrJ)r…r{rÚr@r'ÚpwÚrawÚauthrLrLrMrdòs z.AbstractBasicAuthHandler.retry_http_basic_authcCstt|jdƒr|j |j¡s|S| d¡sp|j d|j¡\}}d ||¡ ¡}t  |¡  ¡}|  dd |  ¡¡¡|S)NrUÚ Authorizationz{0}:{1}zBasic {}) r¾r8rUrur‘rGrŠr6r4Zstandard_b64encoder7r Ústrip)r…rÚr'r8Z credentialsZauth_strrLrLrMÚ http_requestþs  ÿ  ÿz%AbstractBasicAuthHandler.http_requestcCsLt|jdƒrHd|jkr"dkr8nn|j |jd¡n|j |jd¡|S)NrUrôrõTF)r¾r8rörTru)r…rÚr½rLrLrMrø s  z&AbstractBasicAuthHandler.http_response)N)r©rªr«ÚreÚcompileÚIr[rˆrbrfrdrmrøÚ https_requestrúrLrLrLrMr#©sø   r#c@seZdZdZdd„ZdS)r$rkcCs|j}| d|||¡}|S)Núwww-authenticate)rurf)r…rÚrirör÷rjrHr½rLrLrMÚhttp_error_401s ÿz#HTTPBasicAuthHandler.http_error_401N)r©rªr«rgrsrLrLrLrMr$sr$c@seZdZdZdd„ZdS)r%r1cCs|j}| d|||¡}|S©Núproxy-authenticate)r{rf)r…rÚrirör÷rjr#r½rLrLrMÚhttp_error_407's ÿz$ProxyBasicAuthHandler.http_error_407N)r©rªr«rgrvrLrLrLrMr%#sr%c@sNeZdZddd„Zdd„Zdd„Zdd „Zd d „Zd d „Zdd„Z dd„Z dS)r&NcCs4|durtƒ}||_|jj|_d|_d|_d|_dS©Nr)r r8rBÚretriedÚ nonce_countÚ last_nonce)r…r8rLrLrMrˆAs z"AbstractDigestAuthHandler.__init__cCs d|_dSrw)rxrŒrLrLrMÚreset_retry_countJsz+AbstractDigestAuthHandler.reset_retry_countcCs|| |d¡}|jdkr*t|jdd|dƒ‚n|jd7_|rx| ¡d}| ¡dkr`| ||¡S| ¡dkrxtd|ƒ‚dS) Néi‘zdigest auth failedrVrÚdigestrczEAbstractDigestAuthHandler does not support the following scheme: '%s')r£rxrrur_ryÚretry_http_digest_authrB)r…rgr{rÚrjrerrLrLrMrfMs   ÿ    ÿz/AbstractDigestAuthHandler.http_error_auth_reqedcCsz| dd¡\}}ttdt|ƒƒƒ}| ||¡}|rvd|}|j |jd¡|krRdS| |j|¡|j j ||j d�}|SdS)NrrVz Digest %sr) r_Úparse_keqv_listÚfilterÚparse_http_listÚget_authorizationrjr£rgr rðrGrJ)r…rÚrjÚtokenZ challengeÚchalZauth_valZresprLrLrMr~as z0AbstractDigestAuthHandler.retry_http_digest_authcCs@d|j|t ¡f}| d¡tdƒ}t |¡ ¡}|dd…S)Nz %s:%s:%s:r0éé)ryÚtimeÚctimer6Ú _randombytesÚhashlibÚsha1Ú hexdigest)r…ÚnonceÚsÚbÚdigrLrLrMÚ get_cnoncemsz$AbstractDigestAuthHandler.get_cnoncecCsÄz6|d}|d}| d¡}| dd¡}| dd¡}WntyJYdS0| |¡\}} |durfdS|j ||j¡\} } | dur†dS|jdur | |j|¡} nd} d| || f} d| ¡|j f}|durè| || ƒd|||ƒfƒ}n~d |  d ¡v�rZ||j k�r|j d 7_ n d |_ ||_ d |j }|  |¡}d |||d ||ƒf}| || ƒ|ƒ}n td|ƒ‚d| |||j |f}|�rŒ|d|7}| �rž|d| 7}|d|7}|�rÀ|d||f7}|S)Nr@r�ÚqopÚ algorithmÚMD5Úopaquez%s:%s:%sr/rjú,rVz%08xz%s:%s:%s:%s:%szqop '%s' is not supported.z>username="%s", realm="%s", nonce="%s", uri="%s", response="%s"z , opaque="%s"z , digest="%s"z, algorithm="%s"z, qop=auth, nc=%s, cnonce="%s")r£ÚKeyErrorÚget_algorithm_implsr8rGrurIÚget_entity_digestr˜r�r_rzryr‘r)r…rÚr„r@r�r’r“r•ÚHÚKDr'rhZentdigZA1ZA2ZrespdigZncvalueZcnonceZnoncebitrKrLrLrMr‚xs\    þ     ÿÿ   z+AbstractDigestAuthHandler.get_authorizationcsD|dkrdd„‰n|dkr$dd„‰n td|ƒ‚‡fdd„}ˆ|fS)Nr”cSst | d¡¡ ¡S©Nr0)rŠÚmd5r6rŒ©ÚxrLrLrMr,¹óz?AbstractDigestAuthHandler.get_algorithm_impls..ZSHAcSst | d¡¡ ¡Srœ)rŠr‹r6rŒržrLrLrMr,»r z.Unsupported digest authentication algorithm %rcsˆd||fƒS)Nr/rL)rŽÚd©ršrLrMr,Àr )rB)r…r“r›rLr¢rMr˜¶s  ÿ z-AbstractDigestAuthHandler.get_algorithm_implscCsdSrNrL)r…rIr„rLrLrMr™Ãsz+AbstractDigestAuthHandler.get_entity_digest)N) r©rªr«rˆr{rfr~r‘r‚r˜r™rLrLrLrMr&6s   > r&c@s eZdZdZdZdZdd„ZdS)r'z¨An authentication protocol defined by RFC 2069 Digest authentication improves on basic authentication because it does not transmit passwords in the clear. rkéêcCs*t|jƒd}| d|||¡}| ¡|S)NrVrr)rrurfr{©r…rÚrirör÷rjr{ÚretryrLrLrMrsÒs ÿz$HTTPDigestAuthHandler.http_error_401N)r©rªr«rùrgrñrsrLrLrLrMr'Èsr'c@seZdZdZdZdd„ZdS)r(úProxy-Authorizationr£cCs"|j}| d|||¡}| ¡|Srt)r{rfr{r¤rLrLrMrvßs ÿz%ProxyDigestAuthHandler.http_error_407N)r©rªr«rgrñrvrLrLrLrMr(Úsr(c@s6eZdZd dd„Zdd„Zdd„Zdd „Zd d „Zd S)ÚAbstractHTTPHandlerrcCs ||_dSrN©Ú _debuglevel)r…Ú debuglevelrLrLrMrˆèszAbstractHTTPHandler.__init__cCs ||_dSrNr¨)r…ÚlevelrLrLrMÚset_http_debuglevelësz'AbstractHTTPHandler.set_http_debuglevelcCstjj |j| ¡¡SrN)rÞræÚHTTPConnectionÚ_get_content_lengthrIr˜©r…rzrLrLrMr®îsþz'AbstractHTTPHandler._get_content_lengthc Cs|j}|stdƒ‚|jdur’|j}t|tƒr8d}t|ƒ‚| d¡sN| dd¡| d¡s’| d¡s’| |¡}|dur†| dt|ƒ¡n | dd¡|}|  ¡r¸t |j ƒ\}}t |ƒ\}} | d¡sÎ| d|¡|j jD]&\} } |  ¡} | | ¡sÖ| | | ¡qÖ|S) Nú no host givenz\POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str.z Content-typeú!application/x-www-form-urlencodedr�úTransfer-encodingZchunkedrt)r{rrIrÔrÕr¿r‘r r®rœr r�r rðr±r�) r…rzr{rIr÷Zcontent_lengthZsel_hostrZselZsel_pathr`r‡rLrLrMÚ do_request_ósF   þ ÿ ÿÿ    zAbstractHTTPHandler.do_request_c sV|j}|stdƒ‚||fd|ji|¤Ž}| |j¡t|jƒ‰ˆ ‡fdd„|j  ¡Dƒ¡dˆd<dd„ˆ  ¡Dƒ‰|j r®i}d}|ˆvržˆ|||<ˆ|=|j |j |d �zbz&|j |  ¡|j|jˆ| d ¡d �Wn.t�y}zt|ƒ‚WYd }~n d }~00| ¡} Wn| ¡‚Yn0|j�r@|j ¡d |_| ¡| _| j| _| S) z•Return an HTTPResponse object for the request, using http_class. http_class must implement the HTTPConnection API from http.client. r°rJcsi|]\}}|ˆvr||“qSrLrLr©rjrLrMr's ÿz/AbstractHTTPHandler.do_open..rÎÚ ConnectioncSsi|]\}}| ¡|“qSrL)Útitle)rr`rŸrLrLrMr4r r¦r´r²)Zencode_chunkedN)r{rrJZset_debuglevelr©râr}Úupdaterjr€rZ set_tunnelrzr˜r�rIr‘rrÚ getresponserÎÚsockr™rHÚreasonr÷) r…Z http_classrÚZhttp_conn_argsr{rîZtunnel_headersZproxy_auth_hdrÚerrr+rLr´rMr¹sB    ÿ    zAbstractHTTPHandler.do_openN)r)r©rªr«rˆr¬r®r³r¹rLrLrLrMr§æs  &r§c@seZdZdd„ZejZdS)r)cCs| tjj|¡SrN)r¹rÞrær­©r…rÚrLrLrMÚ http_open^szHTTPHandler.http_openN)r©rªr«r½r§r³rmrLrLrLrMr)\sr)råc@s$eZdZddd„Zdd„ZejZdS)rErNcCst ||¡||_||_dSrN)r§rˆÚ_contextÚ_check_hostname)r…rªr>Úcheck_hostnamerLrLrMrˆgs zHTTPSHandler.__init__cCs|jtjj||j|jd�S)N)r>rÀ)r¹rÞrærår¾r¿r¼rLrLrMÚ https_openls ÿzHTTPSHandler.https_open)rNN)r©rªr«rˆrÁr§r³rqrLrLrLrMrEes rEc@s.eZdZddd„Zdd„Zdd„ZeZeZdS) rNcCs$ddl}|dur|j ¡}||_dSrw)Zhttp.cookiejarÚ cookiejarZ CookieJar)r…rÂrÞrLrLrMrˆus zHTTPCookieProcessor.__init__cCs|j |¡|SrN)rÂZadd_cookie_headerr¯rLrLrMrm{s z HTTPCookieProcessor.http_requestcCs|j ||¡|SrN)rÂZextract_cookies)r…rzr½rLrLrMrøsz!HTTPCookieProcessor.http_response)N)r©rªr«rˆrmrørqrúrLrLrLrMrts  rc@seZdZdd„ZdS)r.cCs|j}td|ƒ‚dS)Nzunknown url type: %s)r“r)r…rÚr“rLrLrMr܇szUnknownHandler.unknown_openN)r©rªr«rÜrLrLrLrMr.†sr.cCsNi}|D]@}| dd¡\}}|ddkr@|ddkr@|dd…}|||<q|S)z>Parse list of key=value strings where keys are not duplicated.ú=rVrrXrS)r_)ÚlÚparsedÚeltrrrLrLrMr‹s  rcCsžg}d}d}}|D]l}|r*||7}d}q|rT|dkr>d}qn |dkrJd}||7}q|dkrl| |¡d}q|dkrxd}||7}q|r�| |¡dd„|DƒS) apParse lists as described by RFC 2068 Section 2. In particular, parse comma-separated lists where the elements of the list may include quoted-strings. A quoted-string could contain a comma. A non-quoted string could have quotes in the middle. Neither commas nor quotes count if they are escaped. Only double-quotes count, not single-quotes. rsFú\TrXr–cSsg|] }| ¡‘qSrL)rl)rÚpartrLrLrMÚ ¾r z#parse_http_list..)rb)rŽÚresrÈÚescaper ZcurrLrLrMr�•s4    r�c@s(eZdZdd„ZdZdd„Zdd„ZdS)r*cCs\|j}|dd…dkrN|dd…dkrN|jrN|jdkrN|j| ¡vrXtdƒ‚n | |¡SdS)Nr:r rZrÚ localhostú-file:// scheme is supported only on localhost)r�r{Ú get_namesrÚopen_local_file)r…rÚrHrLrLrMÚ file_openÂs&ÿ zFileHandler.file_openNcCs^tjdurXz*tt d¡dt t ¡¡dƒt_Wn"tjyVt d¡ft_Yn0tjS)NrÌr:)r*Únamesr?rãÚgethostbyname_exÚ gethostnameÚgaierrorÚ gethostbynamerŒrLrLrMrÎÍs  ÿÿ zFileHandler.get_namesc Csddl}ddl}|j}|j}t|ƒ}z¢t |¡}|j}|jj |j dd�} |  |¡d} |  d| pbd|| f¡} |r~t |ƒ\}} |r–| sÄt|ƒ| ¡vrÄ|r¨d||} nd|} tt|dƒ| | ƒWSWn,tyò}zt|ƒ‚WYd}~n d}~00tdƒ‚dS) NrT©Zusegmtz6Content-type: %s Content-length: %d Last-modified: %s ú text/plainúfile://Úrbzfile not on local host)Ú email.utilsÚ mimetypesr{r�r4r[ÚstatÚst_sizeÚutilsÚ formatdateÚst_mtimeÚ guess_typeÚmessage_from_stringr Ú_safe_gethostbynamerÎrrGrrr)r…rÚÚemailrÛr{rgZ localfileÚstatsrnÚmodifiedÚmtyperjrJZorigurlÚexprLrLrMrÏØs:  ÿÿ ÿÿzFileHandler.open_local_file)r©rªr«rÐrÑrÎrÏrLrLrLrMr*Às  r*cCs(z t |¡WStjy"YdS0dSrN)rãrÕrÔ)r{rLrLrMrãós rãc@seZdZdd„Zdd„ZdS)r+c Cs.ddl}ddl}|j}|s"tdƒ‚t|ƒ\}}|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| d�s| dd…} zÎ| ||||| |j¡} | �r8d�p:d}| D]2}t|ƒ\}}| ¡d k�r@|d v�r@| ¡}�q@|  | |¡\}}d}| |j¡d}|�rª|d |7}|du�rÊ|dk�rÊ|d |7}t |¡}t|||jƒWS|j�y(}z*td |ƒ}| t  ¡d¡‚WYd}~n d}~00dS)Nrúftp error: no host givenrsrrSrVrpÚDr“©ÚaÚArÈrpr¡rêzContent-type: %s zContent-length: %d ú ftp error: %rr:)!ÚftplibrÛr{rr ÚFTP_PORTrcrrr rãrÕrrrr�r_r¦ÚmapÚ connect_ftprJrryÚupperÚretrfilerárurärârÚ all_errorsÚwith_tracebackrÖÚexc_info)r…rÚrïrÛr{rJr'r8r÷r\ÚattrsÚdirsrOÚfwr“Úattrr‡riÚretrlenrjrçrèÚexcrLrLrMÚftp_openús^     ÿ     zFTPHandler.ftp_openc Cst||||||dd�S)NF)Ú persistent)Ú ftpwrapper)r…r'r8r{rJrùrJrLrLrMrò/sÿzFTPHandler.connect_ftpN)r©rªr«rþròrLrLrLrMr+ùs5r+c@s<eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd S)r,cCs"i|_i|_d|_d|_d|_dS)Nré<r†)ÚcacherJÚsoonestÚdelayÚ max_connsrŒrLrLrMrˆ6s zCacheFTPHandler.__init__cCs ||_dSrN)r)r…ÚtrLrLrMÚ setTimeout=szCacheFTPHandler.setTimeoutcCs ||_dSrN)r)r…r rLrLrMÚ setMaxConns@szCacheFTPHandler.setMaxConnscCsr|||d |¡|f}||jvr4t ¡|j|j|<n,t||||||ƒ|j|<t ¡|j|j|<| ¡|j|S)Nr)Újoinrr‡rrJrÚ check_cache)r…r'r8r{rJrùrJr†rLrLrMròCs  ÿ zCacheFTPHandler.connect_ftpcCsÂt ¡}|j|krPt|j ¡ƒD].\}}||kr |j| ¡|j|=|j|=q tt|j ¡ƒƒ|_t |jƒ|j kr¾t|j ¡ƒD]&\}}||jkr‚|j|=|j|=qªq‚tt|j ¡ƒƒ|_dSrN) r‡rr¦rJr€rrÎÚminÚvaluesrer)r…rrrrLrLrMr Ns   zCacheFTPHandler.check_cachecCs0|j ¡D] }| ¡q |j ¡|j ¡dSrN)rr rÎÚclearrJ)r…ÚconnrLrLrMÚ clear_cachebs  zCacheFTPHandler.clear_cacheN) r©rªr«rˆrrròr rrLrLrLrMr,3s  r,c@seZdZdd„ZdS)r-cCs~|j}| dd¡\}}| dd¡\}}t|ƒ}| d¡rNt |¡}|dd…}|sVd}t d|t|ƒf¡}t t   |¡||ƒS)Nú:rVr–z;base64iùÿÿÿútext/plain;charset=US-ASCIIz$Content-type: %s Content-length: %d ) rur_rÚendswithr4Ú decodebytesrärârerÚioÚBytesIO)r…rÚrHrrIZ mediatyperjrLrLrMÚ data_openis     ÿzDataHandler.data_openN)r©rªr«rrLrLrLrMr-hsr-rüÚnt)r4r3cCst|ƒS)zOS-specific conversion from a relative URL of the 'file' scheme to a file system path; not recommended for general use.)r ©ÚpathnamerLrLrMr4�sr4cCst|ƒS)zOS-specific conversion from a file system path to a relative URL of the 'file' scheme; not recommended for general use.)r rrLrLrMr3”sr3c@sÊeZdZdZdZdeZd*dd„Zdd„Zdd „Z d d „Z d d „Z d+dd„Z d,dd„Z d-dd„Zd.dd„Zdd„Zd/dd„Zd0dd„Zdd„Zer¤dd„Zd1d d!„Zd"d#„Zd$d%„Zd&d'„Zd2d(d)„ZdS)3r8a,Class to open URLs. This is a class rather than just a subroutine because we may need more than one set of global protocol-specific options. Note -- this is a base class for those who don't want the automatic handling of errors type 302 (relocated) and 401 (authorization needed).Nr¯cKszdd|jji}tj|tdd�|dur.tƒ}||_| d¡|_| d¡|_ d|j fdg|_ g|_ t j|_d|_t|_dS) NzW%(class)s style of invoking requests is deprecated. Use newer urlopen functions/methodsÚclassrZ)Ú stacklevelÚkey_fileÚ cert_filez User-Agent)ZAcceptz*/*)rSr©r?r@rAr5r-r£rrÚversionr±Ú_URLopener__tempfilesr[rqÚ_URLopener__unlinkÚ tempcacheÚftpcache)r…r-Zx509r÷rLrLrMrˆªs ÿ  zURLopener.__init__cCs | ¡dSrN)rÎrŒrLrLrMÚ__del__ÄszURLopener.__del__cCs | ¡dSrN)ÚcleanuprŒrLrLrMrÎÇszURLopener.closec CsT|jr@|jD]&}z| |¡Wq ty0Yq 0q |jdd…=|jrP|j ¡dSrN)rr rrr!r )r…rOrLrLrMr$Ês   zURLopener.cleanupcGs|j |¡dS)zdAdd a header to be used by the HTTP interface only e.g. u.addheader('Accept', 'sound/basic')N)r±rb)r…rÑrLrLrMÚ addheaderØszURLopener.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|du�rt|| ƒ|ƒWSt|| ƒ||ƒWSWnVttf�y.‚Yn>t�yj} z$td | ƒ t ¡d ¡‚WYd} ~ n d} ~ 00dS) z6Use URLopener().open(file) instead of open(file, 'r').z%/:=&?~#+!$,;'@()*[]|©rrÙrONZopen_ú-r»rÏz socket errorr:)rrr r!rGrr r-r r“rr¾Úopen_unknown_proxyÚ open_unknownr—rrrrrörÖr÷)r…rÙrIrgrjriÚurltyperHr"Ú proxyhostr{r�r`r÷rLrLrMrGÞs<             zURLopener.opencCst|ƒ\}}tdd|ƒ‚dS)ú/Overridable interface to open unknown URL type.ú url errorzunknown url typeN©r rr)r…rÙrIr“rHrLrLrMr)s zURLopener.open_unknowncCs t|ƒ\}}tdd||ƒ‚dS)r,r-zinvalid proxy for %sNr.)r…r"rÙrIr“rHrLrLrMr(s zURLopener.open_unknown_proxycCstt|ƒƒ}|jr&||jvr&|j|St|ƒ\}}|durŠ|rF|dkrŠz0| |¡}| ¡}| ¡tt|ƒdƒ|fWSt yˆYn0|  ||¡}�zL| ¡} |r²t |dƒ} nrt|ƒ\} } t| pÆdƒ\} } t | pÖdƒ\} } t | pædƒ\} } t j | ¡d} t | ¡\}}|j |¡t  |d¡} zª|| f}|jdu�rD||j|<d}d}d}d}d | v�rjt| d ƒ}|�r|||||ƒ| |¡}|�s��qÄ|t|ƒ7}|  |¡|d7}|�r|||||ƒ�q|W|  ¡n |  ¡0W| ¡n | ¡0|dk�r||k�rtd ||f|ƒ‚|S) ztretrieve(url) returns (filename, headers) for a local object or (tempfilename, headers) for a remote object.NrOrVrPrsrRrSrrTrUrW)rrr!r rÏrZrÎr4r rrrGrrr[r\Úsplitextr^ÚmkstemprrbÚfdopenrcrdrerfr)r…rHrgrhrIr“Zurl1rir§rjrkZgarbager\ÚsuffixÚfdrlrmrnrdrorprLrLrMÚretrieve sn                  ÿþzURLopener.retrievecCs"d}d}t|tƒrDefault error handler: close the connection and raise OSError.N)rÎr©r…rHrir;r<rjrLrLrMrà¾szURLopener.http_error_defaultcCstjj||j|jd�S)N)rr)rÞrærårr)r…r{rLrLrMÚ_https_connectionÄsþzURLopener._https_connectioncCs| |j||¡S)zUse HTTPS protocol.)r8r>r9rLrLrMÚ open_httpsÉszURLopener.open_httpscCs^t|tƒstdƒ‚|dd…dkrP|dd…dkrP|dd… ¡dkrPtd ƒ‚n | |¡SdS) z/Use local file or FTP depending on form of URL.zEfile error: proxy support for file protocol currently not implementedNr:r rZré z localhost/rÍ)rÔrÕrryrBrÏrŽrLrLrMÚ open_fileÍs  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| p˜d| | f¡} |sÖ|} |dd…dkrÄd |} tt|d ƒ| | ƒSt|ƒ\}}|�sRt |¡tƒftƒv�rR|} |dd…dk�r"d |} n|dd …d k�r@td |ƒ‚tt|d ƒ| | ƒStdƒ‚dS)zUse local file.rNTrÖz6Content-Type: %s Content-Length: %d Last-modified: %s r×rVrrØrÙr:z./zAlocal file url may start with / or file:. Unknown url of type: %sz#local file error: not on local host)rÚrÛr r4r[rÜrrrÚstrerrorrgrÝrÞrßràrárârrGr rãrÕrÌÚthishostrB)r…rHrärÛr{rOZ localnameråÚernrærçrjZurlfilerJrLrLrMrÏÖs@ $ ÿÿ ÿ  zURLopener.open_local_filec CsŽt|tƒstdƒ‚ddl}t|ƒ\}}|s2tdƒ‚t|ƒ\}}t|ƒ\}}|r\t|ƒ\}}nd}t|ƒ}t|ppdƒ}t|p|dƒ}t   |¡}|sžddl }|j }nt |ƒ}t|ƒ\}} t|ƒ}| d¡} | dd…| d} } | rò| dsò| dd…} | �r | d�s d| d<|||d | ¡f} t|jƒtk�rbt|jƒD]*} | | k�r6|j| }|j| =| ¡�q6zä| |jv�r†t||||| ƒ|j| <| �s’d }nd }| D]2}t|ƒ\}}| ¡d k�rš|d v�rš| ¡}�qš|j|  | |¡\}}| d |¡d}d}|�r |d|7}|du�r,|dk�r,|d|7}t |¡}t||d |ƒWStƒ�yˆ}z&td|ƒ  t! "¡d¡‚WYd}~n d}~00dS)zUse FTP protocol.zCftp error: proxy support for ftp protocol currently not implementedrNrérsrrSrVrêrpr“rëzftp:zContent-Type: %s zContent-Length: %d z ftp error %rr:)#rÔrÕrrÛr r rrr rãrÕrïrðrcrr_r rer"Ú MAXFTPCACHEr¦rÎrrryrórôrárärârÚ ftperrorsrörÖr÷)r…rHrÛr{r\rJr'r8rïrørùrOr†rrr“rûr‡rirürçrjrèrLrLrMÚopen_ftpösj              ÿ  ÿ    zURLopener.open_ftpc Cs:t|tƒstdƒ‚z| dd¡\}}WntyBtddƒ‚Yn0|sLd}| d¡}|dkrŒd ||d …vrŒ||dd …}|d |…}nd }g}| d t  d t  t ¡¡¡¡| d|¡|dkrât   |  d¡¡ d¡}nt|ƒ}| dt|ƒ¡| d ¡| |¡d |¡}t |¡}t |¡}t|||ƒS)zUse "data" URL.zEdata error: proxy support for data protocol currently not implementedr–rVz data errorz bad data URLrú;rrÃNrszDate: %sz%a, %d %b %Y %H:%M:%S GMTzContent-type: %sr4r0zlatin-1zContent-Length: %dÚ )rÔrÕrr_rBrrÚrfindrbr‡ÚstrftimeÚgmtimer4rr6r7r rer rärârÚStringIOr) r…rHrIr“Zsemirr÷rjÚfrLrLrMÚ open_data0s8     ÿ     zURLopener.open_data)N)N)N)N)NNN)N)N)N)N)r©rªr«rùrr°rrˆr#rÎr$r%rGr)r(r4r8r:r7ràrCr>r?rArÏrGrOrLrLrLrMr8�s.  $   A\     :r8c@sžeZdZdZdd„Zdd„Zd#dd„Zd d „Zd$d d „Zd%d d„Z d&dd„Z d'dd„Z d(dd„Z d)dd„Z d*dd„Zd+dd„Zd,dd„Zd-dd „Zd!d"„ZdS).r9z?Derived class with handlers for errors we can handle (perhaps).cOs.tj|g|¢Ri|¤Ži|_d|_d|_dS)Nrrü)r8rˆÚ auth_cacheÚtriesÚmaxtriesrPrLrLrMrˆ]szFancyURLopener.__init__cCst||d||ƒS)z3Default error handling -- don't raise an exception.r5)rr=rLrLrMràcsz!FancyURLopener.http_error_defaultNc Cs~|jd7_zb|jrR|j|jkrRt|dƒr4|j}n|j}|||dd|ƒWd|_S| ||||||¡}|Wd|_Sd|_0dS)z%Error 302 -- relocated (temporarily).rVÚhttp_error_500rïz)Internal Server Error: Redirect RecursionrN)rQrRr¾rSràÚredirect_internal) r…rHrir;r<rjrIrÇrlrLrLrMrgs& þù ÿþzFancyURLopener.http_error_302c Csxd|vr|d}nd|vr$|d}ndS| ¡t|jd||ƒ}t|ƒ}|jdvrnt|||d|||ƒ‚| |¡S)Nr r rr z( Redirection to url '%s' is not allowed.)rÎrr“rrrrG) r…rHrir;r<rjrIrrrLrLrMrTys    ÿýz FancyURLopener.redirect_internalcCs| ||||||¡S)z*Error 301 -- also relocated (permanently).©r©r…rHrir;r<rjrIrLrLrMr•szFancyURLopener.http_error_301cCs| ||||||¡S)z;Error 303 -- also relocated (essentially identical to 302).rUrVrLrLrMr™szFancyURLopener.http_error_303cCs2|dur| ||||||¡S| |||||¡SdS)z1Error 307 -- relocated, but turn POST into error.N)rràrVrLrLrMr�szFancyURLopener.http_error_307Fc CsÈd|vrt ||||||¡|d}t d|¡} | sHt ||||||¡|  ¡\} } |  ¡dkrtt ||||||¡|sŒt ||||||¡d|jd} |dur²t|| ƒ|| ƒSt|| ƒ|| |ƒSdS)z_Error 401 -- authentication required. This function supports Basic authentication only.rrú![ ]*([^ ]+)[ ]+realm="([^"]*)"rcZretry_Ú _basic_authN©r8ràrnÚmatchr]ryr“r—© r…rHrir;r<rjrIr¥ÚstuffrZrr@r`rLrLrMrs¤s. ÿ  ÿ   ÿÿzFancyURLopener.http_error_401c CsÈd|vrt ||||||¡|d}t d|¡} | sHt ||||||¡|  ¡\} } |  ¡dkrtt ||||||¡|sŒt ||||||¡d|jd} |dur²t|| ƒ|| ƒSt|| ƒ|| |ƒSdS)zeError 407 -- proxy authentication required. This function supports Basic authentication only.rurWrcZ retry_proxy_rXNrYr[rLrLrMrv½s. ÿ  ÿ   ÿÿzFancyURLopener.http_error_407cCsÄt|ƒ\}}d||}|jd}t|ƒ\}} t| ƒ\} } |  d¡d} | | d…} | | || ¡\} } | sr| srdSdt| dd�t| dd�| f} d| | |jd<|dur´| |¡S| ||¡SdS)Núhttp://rÞr!rVú%s:%s@%srsr&©r r-r rÁÚget_user_passwdr rG©r…rHr@rIr{r�rr"r*r+Z proxyselectorrÈr'r8rLrLrMÚretry_proxy_http_basic_authÖs          ÿ z*FancyURLopener.retry_proxy_http_basic_authcCsÄt|ƒ\}}d||}|jd}t|ƒ\}} t| ƒ\} } |  d¡d} | | d…} | | || ¡\} } | sr| srdSdt| dd�t| dd�| f} d| | |jd<|dur´| |¡S| ||¡SdS)Núhttps://ršr!rVr^rsr&r_rarLrLrMÚretry_proxy_https_basic_authès          ÿ z+FancyURLopener.retry_proxy_https_basic_authc Cs�t|ƒ\}}| d¡d}||d…}| |||¡\}}|sD|sDdSdt|dd�t|dd�|f}d||} |dur€| | ¡S| | |¡SdS)Nr!rVr^rsr&r]©r rÁr`r rG© r…rHr@rIr{r�rÈr'r8rrLrLrMrdús     ÿ  z$FancyURLopener.retry_http_basic_authc Cs�t|ƒ\}}| d¡d}||d…}| |||¡\}}|sD|sDdSdt|dd�t|dd�|f}d||} |dur€| | ¡S| | |¡SdS)Nr!rVr^rsr&rcrerfrLrLrMÚretry_https_basic_auth s     ÿ  z%FancyURLopener.retry_https_basic_authrcCs`|d| ¡}||jvr2|r(|j|=n |j|S| ||¡\}}|sJ|rX||f|j|<||fS)Nr!)ryrPÚprompt_user_passwd)r…r{r@rr†r'r8rLrLrMr` s   zFancyURLopener.get_user_passwdcCsVddl}z.td||fƒ}| d|||f¡}||fWStyPtƒYdS0dS)z#Override this in a GUI environment!rNzEnter username for %s at %s: z#Enter password for %s in %s at %s: rC)ÚgetpassÚinputÚKeyboardInterruptÚprint)r…r{r@rir'r8rLrLrMrh! sÿ  z!FancyURLopener.prompt_user_passwd)N)N)N)N)NF)NF)N)N)N)N)r)r©rªr«rùrˆràrrTrrrrsrvrbrdrdrgr`rhrLrLrLrMr9Zs(    ÿ ÿ      r9cCstdurt d¡atS)z8Return the IP address of the magic hostname 'localhost'.NrÌ)Ú _localhostrãrÕrLrLrLrMrÌ1 s rÌcCsNtdurJztt t ¡¡dƒaWn&tjyHtt d¡dƒaYn0tS)z,Return the IP addresses of the current host.Nr:rÌ)Ú _thishostr?rãrÒrÓrÔrLrLrLrMrC9 s rCcCstdurddl}|jatS)z1Return the set of errors raised by the FTP class.Nr)Ú _ftperrorsrïrõ)rïrLrLrMrFD srFcCstdurt d¡atS)z%Return an empty email Message object.Nrs)Ú _noheadersrärârLrLrLrMÚ noheadersM s rqc@sJeZdZdZddd„Zdd„Zdd „Zd d „Zd d „Zdd„Z dd„Z dS)rz;Class used by open_ftp() for cache of open FTP connections.NTcCsX||_||_||_||_||_||_d|_||_z | ¡Wn|  ¡‚Yn0dSrw) r'r8r{rJrùrJÚrefcountÚ keepaliveÚinitrÎ)r…r'r8r{rJrùrJrÿrLrLrMrˆZ s zftpwrapper.__init__cCs\ddl}d|_| ¡|_|j |j|j|j¡|j |j |j ¡d  |j ¡}|j  |¡dS)Nrr)rïÚbusyZFTPr Úconnectr{rJrJZloginr'r8r rùÚcwd)r…rïÚ_targetrLrLrMrtj s  zftpwrapper.initc CsÄddl}| ¡|dvr"d}d}n d|}d}z|j |¡Wn(|jyf| ¡|j |¡Yn0d}|ræ|sæzd|}|j |¡\}}WnT|jyä}z:t|ƒdd…dkrÐt d |ƒ  t   ¡d ¡‚WYd}~n d}~00|�sŽ|j d¡|�rz|j  ¡} zXz|j |¡Wn6|j�yP}zt d |ƒ|‚WYd}~n d}~00W|j | ¡n|j | ¡0d |}nd }|j |¡\}}d|_t| d ¡|jƒ} |jd7_| ¡| |fS)Nr)r¡rêzTYPE ArVzTYPE zRETR rZZ550rîr:zLIST ÚLISTrÙ)rïÚ endtransferr ZvoidcmdrõrtZ ntransfercmdZ error_permrÕrrörÖr÷ÚpwdrwrurÚmakefileÚ file_closerrrÎ) r…rOr“rïÚcmdÚisdirrrürºr{ZftpobjrLrLrMrôs sJ   ÿ  & zftpwrapper.retrfilecCs d|_dSrw)rurŒrLrLrMrz  szftpwrapper.endtransfercCsd|_|jdkr| ¡dS)NFr)rsrrÚ real_closerŒrLrLrMrΣ s zftpwrapper.closecCs2| ¡|jd8_|jdkr.|js.| ¡dS)NrVr)rzrrrsr€rŒrLrLrMr}¨ szftpwrapper.file_closecCs0| ¡z|j ¡Wntƒy*Yn0dSrN)rzr rÎrFrŒrLrLrMr€® s zftpwrapper.real_close)NT) r©rªr«rùrˆrtrôrzrÎr}r€rLrLrLrMrW sÿ  -rcCs´i}tj ¡D]4\}}| ¡}|r|dd…dkr|||dd…<qdtjvrZ| dd¡tj ¡D]J\}}|dd…dkrd| ¡}|rš|||dd…<qd| |dd…d¡qd|S)aReturn a dictionary of scheme -> proxy server URL mappings. Scan the environment for variables named _proxy; this seems to be the standard convention. If you need a different way, you can pass a proxies dictionary to the [Fancy]URLopener constructor. iúÿÿÿNÚ_proxyZREQUEST_METHODrÞ)r[Úenvironr€ryr¥)r-r`r‡rLrLrMÚgetproxies_environment¶ s   rƒcCsº|durtƒ}z |d}Wnty.YdS0|dkr|dd>B|dd >B|d BS) Nr†rû)rrrrrérVr†r:r…rZ)r_r¦rñrcre)ZipAddrrIrLrLrMÚip2num s   z,_proxy_bypass_macosx_sysconf..ip2numr†Zexclude_simpleTNÚ exceptionsrLz(\d+(?:\.\d+)*)(/\d+)?rVr:r…é F) r‹Ú ipaddressrŒr�r rcr£rnrZÚgroupÚcount) r{Úproxy_settingsr‹rŒr�rˆrJr�ZhostIPr‡r rKÚmaskrLrLrMÚ_proxy_bypass_macosx_sysconfú s:      r—cCs`ddlm}t|ƒ\}}| d¡}|D]4}| ¡}|dkrJd|vrZdSq&|||ƒr&dSq&dS)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" rrŠrHzr†TF)r‹r r_rl)r{Úoverrider‹r»Zproxy_overriderLrLrLrMÚ_proxy_bypass_winreg_override: s    r™Údarwin)Ú_get_proxy_settingsÚ _get_proxiescCstƒ}t||ƒSrN)r›r—)r{r•rLrLrMÚproxy_bypass_macosx_sysconfU sr�cCstƒS)z±Return a dictionary of scheme -> proxy server URL mappings. This function uses the MacOSX framework SystemConfiguration to fetch the proxy information. )rœrLrLrLrMÚgetproxies_macosx_sysconfY sržcCs tƒ}|rt||ƒSt|ƒSdS)z¸Return True, if host should be bypassed. Checks proxy settings gathered from the environment, if specified, or from the MacOSX framework SystemConfiguration. N)rƒr‰r�©r{r-rLrLrMr3c s r3cCs tƒp tƒSrN)rƒržrLrLrLrMr5p sr5c CsBi}z ddl}Wnty&|YS0zú| |jd¡}| |d¡d}|�rt| |d¡dƒ}d|vr|d|vr|d |¡}| d¡D]J}| dd ¡\}}t  d |¡sÈ|d vr¸d |}n|d krÈd|}|||<q†|  d ¡�rt  dd|d ¡}|  d¡�pþ||d<|  d¡�p||d<|  ¡Wnt ttf�y<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 ProxyServerrÃrHzhttp={0};https={0};ftp={0}rVz (?:[^/:]+)://)rÞršr r]Zsockszsocks://z ^socks://z socks4://rÞrš)ÚwinregÚ ImportErrorÚOpenKeyÚHKEY_CURRENT_USERÚ QueryValueExrÕrŠr_rnrZr£rxÚCloserrrBr¿)r-r¢ÚinternetSettingsÚ proxyEnableZ proxyServerÚprÉÚaddressrLrLrMÚgetproxies_registryu sL   ÿÿÿÿÿ      r¬cCs tƒp tƒS)z¥Return a dictionary of scheme -> proxy server URL mappings. Returns settings gathered from the environment, if specified, or the registry. )rƒr¬rLrLrLrMr5¦ scCs„z ddl}Wnty YdS0z6| |jd¡}| |d¡d}t| |d¡dƒ}WntylYdS0|rv|szdSt||ƒS)NrFr r¡Z ProxyOverride)r¢r£r¤r¥r¦rÕrrr™)r{r¢r¨r©Z proxyOverriderLrLrMÚproxy_bypass_registry¯ s.  ÿÿÿÿÿ  r­cCs tƒ}|rt||ƒSt|ƒSdS)z—Return True, if host should be bypassed. Checks proxy settings gathered from the environment, if specified, or the registry. N)rƒr‰r­rŸrLrLrMr3à s )NNN)N)rùr4rÄrärŠZ http.clientrÞrr[Ú posixpathrnrãrrÖr‡r^rXr?Z urllib.errorrrrÚ urllib.parserrrrr r r r r rrrrrrrrrZurllib.responserrrDr£rCÚ__all__Ú version_infor°rFrär0r1rar6r7roÚASCIIrwr|rrr2rr/rrr)rr r!r"r#r$r%Úurandomr‰r&r'r(r§r)r¾rærErbrr.rr�r*rãr+r,r-rEr`Z nturl2pathr4r3r"r8r9rmrÌrnrCrorFrprqrrƒr‰r—r™ÚplatformZ_scproxyr›rœr�ržr3r5r¬r­rLrLrLrMÚsÚSP  ÿ M ?m$q!+@ o  v  +3:5! @W  _ %@    1