asda?‰PNG  IHDR ? f ??C1 sRGB ??é gAMA ±? üa pHYs ? ??o¨d GIDATx^íüL”÷e÷Y?a?("Bh?_ò???¢§?q5k?*:t0A-o??¥]VkJ¢M??f?±8\k2íll£1]q?ù???T request.py000064400000306567151026775530006642 0ustar00"""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/') """ # XXX issues: # If an authentication error handler that tries to perform # authentication for some reason but fails, how should the error be # signalled? The client needs to know the HTTP error code. But if # the handler knows that the problem was, e.g., that it didn't know # that hash algo that requested in the challenge, it would be good to # pass that information along to the client, too. # ftp errors aren't handled cleanly # check digest against correct (i.e. non-apache) implementation # Possible extensions: # complex proxies XXX not sure what exactly was meant by this # abstract factory for opener import base64 import bisect import email import hashlib import http.client import io import os import posixpath import re import socket import string import sys import time import tempfile import contextlib import warnings from urllib.error import URLError, HTTPError, ContentTooShortError from urllib.parse import ( urlparse, urlsplit, urljoin, unwrap, quote, unquote, _splittype, _splithost, _splitport, _splituser, _splitpasswd, _splitattr, _splitquery, _splitvalue, _splittag, _to_bytes, unquote_to_bytes, urlunparse) from urllib.response import addinfourl, addclosehook # check for SSL try: import ssl except ImportError: _have_ssl = False else: _have_ssl = True __all__ = [ # Classes 'Request', 'OpenerDirector', 'BaseHandler', 'HTTPDefaultErrorHandler', 'HTTPRedirectHandler', 'HTTPCookieProcessor', 'ProxyHandler', 'HTTPPasswordMgr', 'HTTPPasswordMgrWithDefaultRealm', 'HTTPPasswordMgrWithPriorAuth', 'AbstractBasicAuthHandler', 'HTTPBasicAuthHandler', 'ProxyBasicAuthHandler', 'AbstractDigestAuthHandler', 'HTTPDigestAuthHandler', 'ProxyDigestAuthHandler', 'HTTPHandler', 'FileHandler', 'FTPHandler', 'CacheFTPHandler', 'DataHandler', 'UnknownHandler', 'HTTPErrorProcessor', # Functions 'urlopen', 'install_opener', 'build_opener', 'pathname2url', 'url2pathname', 'getproxies', # Legacy interface 'urlretrieve', 'urlcleanup', 'URLopener', 'FancyURLopener', ] # used in User-Agent header sent __version__ = '%d.%d' % sys.version_info[:2] _opener = None def urlopen(url, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, *, cafile=None, capath=None, cadefault=False, context=None): '''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. ''' global _opener if cafile or capath or cadefault: import warnings warnings.warn("cafile, capath and cadefault are deprecated, use a " "custom context instead.", DeprecationWarning, 2) if context is not None: raise ValueError( "You can't pass both context and any of cafile, capath, and " "cadefault" ) if not _have_ssl: raise ValueError('SSL support not available') context = ssl.create_default_context(ssl.Purpose.SERVER_AUTH, cafile=cafile, capath=capath) # send ALPN extension to indicate HTTP/1.1 protocol context.set_alpn_protocols(['http/1.1']) https_handler = HTTPSHandler(context=context) opener = build_opener(https_handler) elif context: https_handler = HTTPSHandler(context=context) opener = build_opener(https_handler) elif _opener is None: _opener = opener = build_opener() else: opener = _opener return opener.open(url, data, timeout) def install_opener(opener): global _opener _opener = opener _url_tempfiles = [] def urlretrieve(url, filename=None, reporthook=None, data=None): """ 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. """ url_type, path = _splittype(url) with contextlib.closing(urlopen(url, data)) as fp: headers = fp.info() # Just return the local path and the "headers" for file:// # URLs. No sense in performing a copy unless requested. if url_type == "file" and not filename: return os.path.normpath(path), headers # Handle temporary file setup. if filename: tfp = open(filename, 'wb') else: tfp = tempfile.NamedTemporaryFile(delete=False) filename = tfp.name _url_tempfiles.append(filename) with tfp: result = filename, headers bs = 1024*8 size = -1 read = 0 blocknum = 0 if "content-length" in headers: size = int(headers["Content-Length"]) if reporthook: reporthook(blocknum, bs, size) while True: block = fp.read(bs) if not block: break read += len(block) tfp.write(block) blocknum += 1 if reporthook: reporthook(blocknum, bs, size) if size >= 0 and read < size: raise ContentTooShortError( "retrieval incomplete: got only %i out of %i bytes" % (read, size), result) return result def urlcleanup(): """Clean up temporary files from urlretrieve calls.""" for temp_file in _url_tempfiles: try: os.unlink(temp_file) except OSError: pass del _url_tempfiles[:] global _opener if _opener: _opener = None # copied from cookielib.py _cut_port_re = re.compile(r":\d+$", re.ASCII) def request_host(request): """Return request-host, as defined by RFC 2965. Variation from RFC: returned value is lowercased, for convenient comparison. """ url = request.full_url host = urlparse(url)[1] if host == "": host = request.get_header("Host", "") # remove port, if present host = _cut_port_re.sub("", host, 1) return host.lower() class Request: def __init__(self, url, data=None, headers={}, origin_req_host=None, unverifiable=False, method=None): self.full_url = url self.headers = {} self.unredirected_hdrs = {} self._data = None self.data = data self._tunnel_host = None for key, value in headers.items(): self.add_header(key, value) if origin_req_host is None: origin_req_host = request_host(self) self.origin_req_host = origin_req_host self.unverifiable = unverifiable if method: self.method = method @property def full_url(self): if self.fragment: return '{}#{}'.format(self._full_url, self.fragment) return self._full_url @full_url.setter def full_url(self, url): # unwrap('') --> 'type://host/path' self._full_url = unwrap(url) self._full_url, self.fragment = _splittag(self._full_url) self._parse() @full_url.deleter def full_url(self): self._full_url = None self.fragment = None self.selector = '' @property def data(self): return self._data @data.setter def data(self, data): if data != self._data: self._data = data # issue 16464 # if we change data we need to remove content-length header # (cause it's most probably calculated for previous value) if self.has_header("Content-length"): self.remove_header("Content-length") @data.deleter def data(self): self.data = None def _parse(self): self.type, rest = _splittype(self._full_url) if self.type is None: raise ValueError("unknown url type: %r" % self.full_url) self.host, self.selector = _splithost(rest) if self.host: self.host = unquote(self.host) def get_method(self): """Return a string indicating the HTTP request method.""" default_method = "POST" if self.data is not None else "GET" return getattr(self, 'method', default_method) def get_full_url(self): return self.full_url def set_proxy(self, host, type): if self.type == 'https' and not self._tunnel_host: self._tunnel_host = self.host else: self.type= type self.selector = self.full_url self.host = host def has_proxy(self): return self.selector == self.full_url def add_header(self, key, val): # useful for something like authentication self.headers[key.capitalize()] = val def add_unredirected_header(self, key, val): # will not be added to a redirected request self.unredirected_hdrs[key.capitalize()] = val def has_header(self, header_name): return (header_name in self.headers or header_name in self.unredirected_hdrs) def get_header(self, header_name, default=None): return self.headers.get( header_name, self.unredirected_hdrs.get(header_name, default)) def remove_header(self, header_name): self.headers.pop(header_name, None) self.unredirected_hdrs.pop(header_name, None) def header_items(self): hdrs = {**self.unredirected_hdrs, **self.headers} return list(hdrs.items()) class OpenerDirector: def __init__(self): client_version = "Python-urllib/%s" % __version__ self.addheaders = [('User-agent', client_version)] # self.handlers is retained only for backward compatibility self.handlers = [] # manage the individual handlers self.handle_open = {} self.handle_error = {} self.process_response = {} self.process_request = {} def add_handler(self, handler): if not hasattr(handler, "add_parent"): raise TypeError("expected BaseHandler instance, got %r" % type(handler)) added = False for meth in dir(handler): if meth in ["redirect_request", "do_open", "proxy_open"]: # oops, coincidental match continue i = meth.find("_") protocol = meth[:i] condition = meth[i+1:] if condition.startswith("error"): j = condition.find("_") + i + 1 kind = meth[j+1:] try: kind = int(kind) except ValueError: pass lookup = self.handle_error.get(protocol, {}) self.handle_error[protocol] = lookup elif condition == "open": kind = protocol lookup = self.handle_open elif condition == "response": kind = protocol lookup = self.process_response elif condition == "request": kind = protocol lookup = self.process_request else: continue handlers = lookup.setdefault(kind, []) if handlers: bisect.insort(handlers, handler) else: handlers.append(handler) added = True if added: bisect.insort(self.handlers, handler) handler.add_parent(self) def close(self): # Only exists for backwards compatibility. pass def _call_chain(self, chain, kind, meth_name, *args): # Handlers raise an exception if no one else should try to handle # the request, or return None if they can't but another handler # could. Otherwise, they return the response. handlers = chain.get(kind, ()) for handler in handlers: func = getattr(handler, meth_name) result = func(*args) if result is not None: return result def open(self, fullurl, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT): # accept a URL or a Request object if isinstance(fullurl, str): req = Request(fullurl, data) else: req = fullurl if data is not None: req.data = data req.timeout = timeout protocol = req.type # pre-process request meth_name = protocol+"_request" for processor in self.process_request.get(protocol, []): meth = getattr(processor, meth_name) req = meth(req) sys.audit('urllib.Request', req.full_url, req.data, req.headers, req.get_method()) response = self._open(req, data) # post-process response meth_name = protocol+"_response" for processor in self.process_response.get(protocol, []): meth = getattr(processor, meth_name) response = meth(req, response) return response def _open(self, req, data=None): result = self._call_chain(self.handle_open, 'default', 'default_open', req) if result: return result protocol = req.type result = self._call_chain(self.handle_open, protocol, protocol + '_open', req) if result: return result return self._call_chain(self.handle_open, 'unknown', 'unknown_open', req) def error(self, proto, *args): if proto in ('http', 'https'): # XXX http[s] protocols are special-cased dict = self.handle_error['http'] # https is not different than http proto = args[2] # YUCK! meth_name = 'http_error_%s' % proto http_err = 1 orig_args = args else: dict = self.handle_error meth_name = proto + '_error' http_err = 0 args = (dict, proto, meth_name) + args result = self._call_chain(*args) if result: return result if http_err: args = (dict, 'default', 'http_error_default') + orig_args return self._call_chain(*args) # XXX probably also want an abstract factory that knows when it makes # sense to skip a superclass in favor of a subclass and when it might # make sense to include both def build_opener(*handlers): """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. """ opener = OpenerDirector() default_classes = [ProxyHandler, UnknownHandler, HTTPHandler, HTTPDefaultErrorHandler, HTTPRedirectHandler, FTPHandler, FileHandler, HTTPErrorProcessor, DataHandler] if hasattr(http.client, "HTTPSConnection"): default_classes.append(HTTPSHandler) skip = set() for klass in default_classes: for check in handlers: if isinstance(check, type): if issubclass(check, klass): skip.add(klass) elif isinstance(check, klass): skip.add(klass) for klass in skip: default_classes.remove(klass) for klass in default_classes: opener.add_handler(klass()) for h in handlers: if isinstance(h, type): h = h() opener.add_handler(h) return opener class BaseHandler: handler_order = 500 def add_parent(self, parent): self.parent = parent def close(self): # Only exists for backwards compatibility pass def __lt__(self, other): if not hasattr(other, "handler_order"): # Try to preserve the old behavior of having custom classes # inserted after default ones (works only for custom user # classes which are not aware of handler_order). return True return self.handler_order < other.handler_order class HTTPErrorProcessor(BaseHandler): """Process HTTP error responses.""" handler_order = 1000 # after all other processing def http_response(self, request, response): code, msg, hdrs = response.code, response.msg, response.info() # According to RFC 2616, "2xx" code indicates that the client's # request was successfully received, understood, and accepted. if not (200 <= code < 300): response = self.parent.error( 'http', request, response, code, msg, hdrs) return response https_response = http_response class HTTPDefaultErrorHandler(BaseHandler): def http_error_default(self, req, fp, code, msg, hdrs): raise HTTPError(req.full_url, code, msg, hdrs, fp) class HTTPRedirectHandler(BaseHandler): # maximum number of redirections to any single URL # this is needed because of the state that cookies introduce max_repeats = 4 # maximum total number of redirections (regardless of URL) before # assuming we're in a loop max_redirections = 10 def redirect_request(self, req, fp, code, msg, headers, newurl): """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. """ m = req.get_method() if (not (code in (301, 302, 303, 307, 308) and m in ("GET", "HEAD") or code in (301, 302, 303) and m == "POST")): raise HTTPError(req.full_url, code, msg, headers, fp) # Strictly (according to RFC 2616), 301 or 302 in response to # a POST MUST NOT cause a redirection without confirmation # from the user (of urllib.request, in this case). In practice, # essentially all clients do redirect in this case, so we do # the same. # Be conciliant with URIs containing a space. This is mainly # redundant with the more complete encoding done in http_error_302(), # but it is kept for compatibility with other callers. newurl = newurl.replace(' ', '%20') CONTENT_HEADERS = ("content-length", "content-type") newheaders = {k: v for k, v in req.headers.items() if k.lower() not in CONTENT_HEADERS} return Request(newurl, headers=newheaders, origin_req_host=req.origin_req_host, unverifiable=True) # Implementation note: To avoid the server sending us into an # infinite loop, the request object needs to track what URLs we # have already seen. Do this by adding a handler-specific # attribute to the Request object. def http_error_302(self, req, fp, code, msg, headers): # Some servers (incorrectly) return multiple Location headers # (so probably same goes for URI). Use first header. if "location" in headers: newurl = headers["location"] elif "uri" in headers: newurl = headers["uri"] else: return # fix a possible malformed URL urlparts = urlparse(newurl) # For security reasons we don't allow redirection to anything other # than http, https or ftp. if urlparts.scheme not in ('http', 'https', 'ftp', ''): raise HTTPError( newurl, code, "%s - Redirection to url '%s' is not allowed" % (msg, newurl), headers, fp) if not urlparts.path and urlparts.netloc: urlparts = list(urlparts) urlparts[2] = "/" newurl = urlunparse(urlparts) # http.client.parse_headers() decodes as ISO-8859-1. Recover the # original bytes and percent-encode non-ASCII bytes, and any special # characters such as the space. newurl = quote( newurl, encoding="iso-8859-1", safe=string.punctuation) newurl = urljoin(req.full_url, newurl) # XXX Probably want to forget about the state of the current # request, although that might interact poorly with other # handlers that also use handler-specific request attributes new = self.redirect_request(req, fp, code, msg, headers, newurl) if new is None: return # loop detection # .redirect_dict has a key url if url was previously visited. if hasattr(req, 'redirect_dict'): visited = new.redirect_dict = req.redirect_dict if (visited.get(newurl, 0) >= self.max_repeats or len(visited) >= self.max_redirections): raise HTTPError(req.full_url, code, self.inf_msg + msg, headers, fp) else: visited = new.redirect_dict = req.redirect_dict = {} visited[newurl] = visited.get(newurl, 0) + 1 # Don't close the fp until we are sure that we won't use it # with HTTPError. fp.read() fp.close() return self.parent.open(new, timeout=req.timeout) http_error_301 = http_error_303 = http_error_307 = http_error_308 = http_error_302 inf_msg = "The HTTP server returned a redirect error that would " \ "lead to an infinite loop.\n" \ "The last 30x error message was:\n" def _parse_proxy(proxy): """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. """ scheme, r_scheme = _splittype(proxy) if not r_scheme.startswith("/"): # authority scheme = None authority = proxy else: # URL if not r_scheme.startswith("//"): raise ValueError("proxy URL with no authority: %r" % proxy) # We have an authority, so for RFC 3986-compliant URLs (by ss 3. # and 3.3.), path is empty or starts with '/' if '@' in r_scheme: host_separator = r_scheme.find('@') end = r_scheme.find("/", host_separator) else: end = r_scheme.find("/", 2) if end == -1: end = None authority = r_scheme[2:end] userinfo, hostport = _splituser(authority) if userinfo is not None: user, password = _splitpasswd(userinfo) else: user = password = None return scheme, user, password, hostport class ProxyHandler(BaseHandler): # Proxies must be in front handler_order = 100 def __init__(self, proxies=None): if proxies is None: proxies = getproxies() assert hasattr(proxies, 'keys'), "proxies must be a mapping" self.proxies = proxies for type, url in proxies.items(): type = type.lower() setattr(self, '%s_open' % type, lambda r, proxy=url, type=type, meth=self.proxy_open: meth(r, proxy, type)) def proxy_open(self, req, proxy, type): orig_type = req.type proxy_type, user, password, hostport = _parse_proxy(proxy) if proxy_type is None: proxy_type = orig_type if req.host and proxy_bypass(req.host): return None if user and password: user_pass = '%s:%s' % (unquote(user), unquote(password)) creds = base64.b64encode(user_pass.encode()).decode("ascii") req.add_header('Proxy-authorization', 'Basic ' + creds) hostport = unquote(hostport) req.set_proxy(hostport, proxy_type) if orig_type == proxy_type or orig_type == 'https': # let other handlers take care of it return None else: # need to start over, because the other handlers don't # grok the proxy's URL type # e.g. if we have a constructor arg proxies like so: # {'http': 'ftp://proxy.example.com'}, we may end up turning # a request for http://acme.example.com/a into one for # ftp://proxy.example.com/a return self.parent.open(req, timeout=req.timeout) class HTTPPasswordMgr: def __init__(self): self.passwd = {} def add_password(self, realm, uri, user, passwd): # uri could be a single URI or a sequence if isinstance(uri, str): uri = [uri] if realm not in self.passwd: self.passwd[realm] = {} for default_port in True, False: reduced_uri = tuple( self.reduce_uri(u, default_port) for u in uri) self.passwd[realm][reduced_uri] = (user, passwd) def find_user_password(self, realm, authuri): domains = self.passwd.get(realm, {}) for default_port in True, False: reduced_authuri = self.reduce_uri(authuri, default_port) for uris, authinfo in domains.items(): for uri in uris: if self.is_suburi(uri, reduced_authuri): return authinfo return None, None def reduce_uri(self, uri, default_port=True): """Accept authority or URI and extract only the authority and path.""" # note HTTP URLs do not have a userinfo component parts = urlsplit(uri) if parts[1]: # URI scheme = parts[0] authority = parts[1] path = parts[2] or '/' else: # host or host:port scheme = None authority = uri path = '/' host, port = _splitport(authority) if default_port and port is None and scheme is not None: dport = {"http": 80, "https": 443, }.get(scheme) if dport is not None: authority = "%s:%d" % (host, dport) return authority, path def is_suburi(self, base, test): """Check if test is below base in a URI tree Both args must be URIs in reduced form. """ if base == test: return True if base[0] != test[0]: return False prefix = base[1] if prefix[-1:] != '/': prefix += '/' return test[1].startswith(prefix) class HTTPPasswordMgrWithDefaultRealm(HTTPPasswordMgr): def find_user_password(self, realm, authuri): user, password = HTTPPasswordMgr.find_user_password(self, realm, authuri) if user is not None: return user, password return HTTPPasswordMgr.find_user_password(self, None, authuri) class HTTPPasswordMgrWithPriorAuth(HTTPPasswordMgrWithDefaultRealm): def __init__(self, *args, **kwargs): self.authenticated = {} super().__init__(*args, **kwargs) def add_password(self, realm, uri, user, passwd, is_authenticated=False): self.update_authenticated(uri, is_authenticated) # Add a default for prior auth requests if realm is not None: super().add_password(None, uri, user, passwd) super().add_password(realm, uri, user, passwd) def update_authenticated(self, uri, is_authenticated=False): # uri could be a single URI or a sequence if isinstance(uri, str): uri = [uri] for default_port in True, False: for u in uri: reduced_uri = self.reduce_uri(u, default_port) self.authenticated[reduced_uri] = is_authenticated def is_authenticated(self, authuri): for default_port in True, False: reduced_authuri = self.reduce_uri(authuri, default_port) for uri in self.authenticated: if self.is_suburi(uri, reduced_authuri): return self.authenticated[uri] class AbstractBasicAuthHandler: # XXX this allows for multiple auth-schemes, but will stupidly pick # the last one with a realm specified. # allow for double- and single-quoted realm values # (single quotes are a violation of the RFC, but appear in the wild) rx = re.compile('(?:^|,)' # start of the string or ',' '[ \t]*' # optional whitespaces '([^ \t,]+)' # scheme like "Basic" '[ \t]+' # mandatory whitespaces # realm=xxx # realm='xxx' # realm="xxx" 'realm=(["\']?)([^"\']*)\\2', re.I) # XXX could pre-emptively send auth info already accepted (RFC 2617, # end of section 2, and section 1.2 immediately after "credentials" # production). def __init__(self, password_mgr=None): if password_mgr is None: password_mgr = HTTPPasswordMgr() self.passwd = password_mgr self.add_password = self.passwd.add_password def _parse_realm(self, header): # parse WWW-Authenticate header: accept multiple challenges per header found_challenge = False for mo in AbstractBasicAuthHandler.rx.finditer(header): scheme, quote, realm = mo.groups() if quote not in ['"', "'"]: warnings.warn("Basic Auth Realm was unquoted", UserWarning, 3) yield (scheme, realm) found_challenge = True if not found_challenge: if header: scheme = header.split()[0] else: scheme = '' yield (scheme, None) def http_error_auth_reqed(self, authreq, host, req, headers): # host may be an authority (without userinfo) or a URL with an # authority headers = headers.get_all(authreq) if not headers: # no header found return unsupported = None for header in headers: for scheme, realm in self._parse_realm(header): if scheme.lower() != 'basic': unsupported = scheme continue if realm is not None: # Use the first matching Basic challenge. # Ignore following challenges even if they use the Basic # scheme. return self.retry_http_basic_auth(host, req, realm) if unsupported is not None: raise ValueError("AbstractBasicAuthHandler does not " "support the following scheme: %r" % (scheme,)) def retry_http_basic_auth(self, host, req, realm): user, pw = self.passwd.find_user_password(realm, host) if pw is not None: raw = "%s:%s" % (user, pw) auth = "Basic " + base64.b64encode(raw.encode()).decode("ascii") if req.get_header(self.auth_header, None) == auth: return None req.add_unredirected_header(self.auth_header, auth) return self.parent.open(req, timeout=req.timeout) else: return None def http_request(self, req): if (not hasattr(self.passwd, 'is_authenticated') or not self.passwd.is_authenticated(req.full_url)): return req if not req.has_header('Authorization'): user, passwd = self.passwd.find_user_password(None, req.full_url) credentials = '{0}:{1}'.format(user, passwd).encode() auth_str = base64.standard_b64encode(credentials).decode() req.add_unredirected_header('Authorization', 'Basic {}'.format(auth_str.strip())) return req def http_response(self, req, response): if hasattr(self.passwd, 'is_authenticated'): if 200 <= response.code < 300: self.passwd.update_authenticated(req.full_url, True) else: self.passwd.update_authenticated(req.full_url, False) return response https_request = http_request https_response = http_response class HTTPBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler): auth_header = 'Authorization' def http_error_401(self, req, fp, code, msg, headers): url = req.full_url response = self.http_error_auth_reqed('www-authenticate', url, req, headers) return response class ProxyBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler): auth_header = 'Proxy-authorization' def http_error_407(self, req, fp, code, msg, headers): # http_error_auth_reqed requires that there is no userinfo component in # authority. Assume there isn't one, since urllib.request does not (and # should not, RFC 3986 s. 3.2.1) support requests for URLs containing # userinfo. authority = req.host response = self.http_error_auth_reqed('proxy-authenticate', authority, req, headers) return response # Return n random bytes. _randombytes = os.urandom class AbstractDigestAuthHandler: # Digest authentication is specified in RFC 2617. # XXX The client does not inspect the Authentication-Info header # in a successful response. # XXX It should be possible to test this implementation against # a mock server that just generates a static set of challenges. # XXX qop="auth-int" supports is shaky def __init__(self, passwd=None): if passwd is None: passwd = HTTPPasswordMgr() self.passwd = passwd self.add_password = self.passwd.add_password self.retried = 0 self.nonce_count = 0 self.last_nonce = None def reset_retry_count(self): self.retried = 0 def http_error_auth_reqed(self, auth_header, host, req, headers): authreq = headers.get(auth_header, None) if self.retried > 5: # Don't fail endlessly - if we failed once, we'll probably # fail a second time. Hm. Unless the Password Manager is # prompting for the information. Crap. This isn't great # but it's better than the current 'repeat until recursion # depth exceeded' approach raise HTTPError(req.full_url, 401, "digest auth failed", headers, None) else: self.retried += 1 if authreq: scheme = authreq.split()[0] if scheme.lower() == 'digest': return self.retry_http_digest_auth(req, authreq) elif scheme.lower() != 'basic': raise ValueError("AbstractDigestAuthHandler does not support" " the following scheme: '%s'" % scheme) def retry_http_digest_auth(self, req, auth): token, challenge = auth.split(' ', 1) chal = parse_keqv_list(filter(None, parse_http_list(challenge))) auth = self.get_authorization(req, chal) if auth: auth_val = 'Digest %s' % auth if req.headers.get(self.auth_header, None) == auth_val: return None req.add_unredirected_header(self.auth_header, auth_val) resp = self.parent.open(req, timeout=req.timeout) return resp def get_cnonce(self, nonce): # The cnonce-value is an opaque # quoted string value provided by the client and used by both client # and server to avoid chosen plaintext attacks, to provide mutual # authentication, and to provide some message integrity protection. # This isn't a fabulous effort, but it's probably Good Enough. s = "%s:%s:%s:" % (self.nonce_count, nonce, time.ctime()) b = s.encode("ascii") + _randombytes(8) dig = hashlib.sha1(b).hexdigest() return dig[:16] def get_authorization(self, req, chal): try: realm = chal['realm'] nonce = chal['nonce'] qop = chal.get('qop') algorithm = chal.get('algorithm', 'MD5') # mod_digest doesn't send an opaque, even though it isn't # supposed to be optional opaque = chal.get('opaque', None) except KeyError: return None H, KD = self.get_algorithm_impls(algorithm) if H is None: return None user, pw = self.passwd.find_user_password(realm, req.full_url) if user is None: return None # XXX not implemented yet if req.data is not None: entdig = self.get_entity_digest(req.data, chal) else: entdig = None A1 = "%s:%s:%s" % (user, realm, pw) A2 = "%s:%s" % (req.get_method(), # XXX selector: what about proxies and full urls req.selector) # NOTE: As per RFC 2617, when server sends "auth,auth-int", the client could use either `auth` # or `auth-int` to the response back. we use `auth` to send the response back. if qop is None: respdig = KD(H(A1), "%s:%s" % (nonce, H(A2))) elif 'auth' in qop.split(','): if nonce == self.last_nonce: self.nonce_count += 1 else: self.nonce_count = 1 self.last_nonce = nonce ncvalue = '%08x' % self.nonce_count cnonce = self.get_cnonce(nonce) noncebit = "%s:%s:%s:%s:%s" % (nonce, ncvalue, cnonce, 'auth', H(A2)) respdig = KD(H(A1), noncebit) else: # XXX handle auth-int. raise URLError("qop '%s' is not supported." % qop) # XXX should the partial digests be encoded too? base = 'username="%s", realm="%s", nonce="%s", uri="%s", ' \ 'response="%s"' % (user, realm, nonce, req.selector, respdig) if opaque: base += ', opaque="%s"' % opaque if entdig: base += ', digest="%s"' % entdig base += ', algorithm="%s"' % algorithm if qop: base += ', qop=auth, nc=%s, cnonce="%s"' % (ncvalue, cnonce) return base def get_algorithm_impls(self, algorithm): # lambdas assume digest modules are imported at the top level if algorithm == 'MD5': H = lambda x: hashlib.md5(x.encode("ascii")).hexdigest() elif algorithm == 'SHA': H = lambda x: hashlib.sha1(x.encode("ascii")).hexdigest() # XXX MD5-sess else: raise ValueError("Unsupported digest authentication " "algorithm %r" % algorithm) KD = lambda s, d: H("%s:%s" % (s, d)) return H, KD def get_entity_digest(self, data, chal): # XXX not implemented yet return None class HTTPDigestAuthHandler(BaseHandler, AbstractDigestAuthHandler): """An authentication protocol defined by RFC 2069 Digest authentication improves on basic authentication because it does not transmit passwords in the clear. """ auth_header = 'Authorization' handler_order = 490 # before Basic auth def http_error_401(self, req, fp, code, msg, headers): host = urlparse(req.full_url)[1] retry = self.http_error_auth_reqed('www-authenticate', host, req, headers) self.reset_retry_count() return retry class ProxyDigestAuthHandler(BaseHandler, AbstractDigestAuthHandler): auth_header = 'Proxy-Authorization' handler_order = 490 # before Basic auth def http_error_407(self, req, fp, code, msg, headers): host = req.host retry = self.http_error_auth_reqed('proxy-authenticate', host, req, headers) self.reset_retry_count() return retry class AbstractHTTPHandler(BaseHandler): def __init__(self, debuglevel=0): self._debuglevel = debuglevel def set_http_debuglevel(self, level): self._debuglevel = level def _get_content_length(self, request): return http.client.HTTPConnection._get_content_length( request.data, request.get_method()) def do_request_(self, request): host = request.host if not host: raise URLError('no host given') if request.data is not None: # POST data = request.data if isinstance(data, str): msg = "POST data should be bytes, an iterable of bytes, " \ "or a file object. It cannot be of type str." raise TypeError(msg) if not request.has_header('Content-type'): request.add_unredirected_header( 'Content-type', 'application/x-www-form-urlencoded') if (not request.has_header('Content-length') and not request.has_header('Transfer-encoding')): content_length = self._get_content_length(request) if content_length is not None: request.add_unredirected_header( 'Content-length', str(content_length)) else: request.add_unredirected_header( 'Transfer-encoding', 'chunked') sel_host = host if request.has_proxy(): scheme, sel = _splittype(request.selector) sel_host, sel_path = _splithost(sel) if not request.has_header('Host'): request.add_unredirected_header('Host', sel_host) for name, value in self.parent.addheaders: name = name.capitalize() if not request.has_header(name): request.add_unredirected_header(name, value) return request def do_open(self, http_class, req, **http_conn_args): """Return an HTTPResponse object for the request, using http_class. http_class must implement the HTTPConnection API from http.client. """ host = req.host if not host: raise URLError('no host given') # will parse host:port h = http_class(host, timeout=req.timeout, **http_conn_args) h.set_debuglevel(self._debuglevel) headers = dict(req.unredirected_hdrs) headers.update({k: v for k, v in req.headers.items() if k not in headers}) # TODO(jhylton): Should this be redesigned to handle # persistent connections? # We want to make an HTTP/1.1 request, but the addinfourl # class isn't prepared to deal with a persistent connection. # It will try to read all remaining data from the socket, # which will block while the server waits for the next request. # So make sure the connection gets closed after the (only) # request. headers["Connection"] = "close" headers = {name.title(): val for name, val in headers.items()} if req._tunnel_host: tunnel_headers = {} proxy_auth_hdr = "Proxy-Authorization" if proxy_auth_hdr in headers: tunnel_headers[proxy_auth_hdr] = headers[proxy_auth_hdr] # Proxy-Authorization should not be sent to origin # server. del headers[proxy_auth_hdr] h.set_tunnel(req._tunnel_host, headers=tunnel_headers) try: try: h.request(req.get_method(), req.selector, req.data, headers, encode_chunked=req.has_header('Transfer-encoding')) except OSError as err: # timeout error raise URLError(err) r = h.getresponse() except: h.close() raise # If the server does not send us a 'Connection: close' header, # HTTPConnection assumes the socket should be left open. Manually # mark the socket to be closed when this response object goes away. if h.sock: h.sock.close() h.sock = None r.url = req.get_full_url() # This line replaces the .msg attribute of the HTTPResponse # with .headers, because urllib clients expect the response to # have the reason in .msg. It would be good to mark this # attribute is deprecated and get then to use info() or # .headers. r.msg = r.reason return r class HTTPHandler(AbstractHTTPHandler): def http_open(self, req): return self.do_open(http.client.HTTPConnection, req) http_request = AbstractHTTPHandler.do_request_ if hasattr(http.client, 'HTTPSConnection'): class HTTPSHandler(AbstractHTTPHandler): def __init__(self, debuglevel=0, context=None, check_hostname=None): AbstractHTTPHandler.__init__(self, debuglevel) self._context = context self._check_hostname = check_hostname def https_open(self, req): return self.do_open(http.client.HTTPSConnection, req, context=self._context, check_hostname=self._check_hostname) https_request = AbstractHTTPHandler.do_request_ __all__.append('HTTPSHandler') class HTTPCookieProcessor(BaseHandler): def __init__(self, cookiejar=None): import http.cookiejar if cookiejar is None: cookiejar = http.cookiejar.CookieJar() self.cookiejar = cookiejar def http_request(self, request): self.cookiejar.add_cookie_header(request) return request def http_response(self, request, response): self.cookiejar.extract_cookies(response, request) return response https_request = http_request https_response = http_response class UnknownHandler(BaseHandler): def unknown_open(self, req): type = req.type raise URLError('unknown url type: %s' % type) def parse_keqv_list(l): """Parse list of key=value strings where keys are not duplicated.""" parsed = {} for elt in l: k, v = elt.split('=', 1) if v[0] == '"' and v[-1] == '"': v = v[1:-1] parsed[k] = v return parsed def parse_http_list(s): """Parse 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. """ res = [] part = '' escape = quote = False for cur in s: if escape: part += cur escape = False continue if quote: if cur == '\\': escape = True continue elif cur == '"': quote = False part += cur continue if cur == ',': res.append(part) part = '' continue if cur == '"': quote = True part += cur # append last part if part: res.append(part) return [part.strip() for part in res] class FileHandler(BaseHandler): # Use local file or FTP depending on form of URL def file_open(self, req): url = req.selector if url[:2] == '//' and url[2:3] != '/' and (req.host and req.host != 'localhost'): if not req.host in self.get_names(): raise URLError("file:// scheme is supported only on localhost") else: return self.open_local_file(req) # names for the localhost names = None def get_names(self): if FileHandler.names is None: try: FileHandler.names = tuple( socket.gethostbyname_ex('localhost')[2] + socket.gethostbyname_ex(socket.gethostname())[2]) except socket.gaierror: FileHandler.names = (socket.gethostbyname('localhost'),) return FileHandler.names # not entirely sure what the rules are here def open_local_file(self, req): import email.utils import mimetypes host = req.host filename = req.selector localfile = url2pathname(filename) try: stats = os.stat(localfile) size = stats.st_size modified = email.utils.formatdate(stats.st_mtime, usegmt=True) mtype = mimetypes.guess_type(filename)[0] headers = email.message_from_string( 'Content-type: %s\nContent-length: %d\nLast-modified: %s\n' % (mtype or 'text/plain', size, modified)) if host: host, port = _splitport(host) if not host or \ (not port and _safe_gethostbyname(host) in self.get_names()): if host: origurl = 'file://' + host + filename else: origurl = 'file://' + filename return addinfourl(open(localfile, 'rb'), headers, origurl) except OSError as exp: raise URLError(exp) raise URLError('file not on local host') def _safe_gethostbyname(host): try: return socket.gethostbyname(host) except socket.gaierror: return None class FTPHandler(BaseHandler): def ftp_open(self, req): import ftplib import mimetypes host = req.host if not host: raise URLError('ftp error: no host given') host, port = _splitport(host) if port is None: port = ftplib.FTP_PORT else: port = int(port) # username/password handling user, host = _splituser(host) if user: user, passwd = _splitpasswd(user) else: passwd = None host = unquote(host) user = user or '' passwd = passwd or '' try: host = socket.gethostbyname(host) except OSError as msg: raise URLError(msg) path, attrs = _splitattr(req.selector) dirs = path.split('/') dirs = list(map(unquote, dirs)) dirs, file = dirs[:-1], dirs[-1] if dirs and not dirs[0]: dirs = dirs[1:] try: fw = self.connect_ftp(user, passwd, host, port, dirs, req.timeout) type = file and 'I' or 'D' for attr in attrs: attr, value = _splitvalue(attr) if attr.lower() == 'type' and \ value in ('a', 'A', 'i', 'I', 'd', 'D'): type = value.upper() fp, retrlen = fw.retrfile(file, type) headers = "" mtype = mimetypes.guess_type(req.full_url)[0] if mtype: headers += "Content-type: %s\n" % mtype if retrlen is not None and retrlen >= 0: headers += "Content-length: %d\n" % retrlen headers = email.message_from_string(headers) return addinfourl(fp, headers, req.full_url) except ftplib.all_errors as exp: raise URLError(exp) from exp def connect_ftp(self, user, passwd, host, port, dirs, timeout): return ftpwrapper(user, passwd, host, port, dirs, timeout, persistent=False) class CacheFTPHandler(FTPHandler): # XXX would be nice to have pluggable cache strategies # XXX this stuff is definitely not thread safe def __init__(self): self.cache = {} self.timeout = {} self.soonest = 0 self.delay = 60 self.max_conns = 16 def setTimeout(self, t): self.delay = t def setMaxConns(self, m): self.max_conns = m def connect_ftp(self, user, passwd, host, port, dirs, timeout): key = user, host, port, '/'.join(dirs), timeout if key in self.cache: self.timeout[key] = time.time() + self.delay else: self.cache[key] = ftpwrapper(user, passwd, host, port, dirs, timeout) self.timeout[key] = time.time() + self.delay self.check_cache() return self.cache[key] def check_cache(self): # first check for old ones t = time.time() if self.soonest <= t: for k, v in list(self.timeout.items()): if v < t: self.cache[k].close() del self.cache[k] del self.timeout[k] self.soonest = min(list(self.timeout.values())) # then check the size if len(self.cache) == self.max_conns: for k, v in list(self.timeout.items()): if v == self.soonest: del self.cache[k] del self.timeout[k] break self.soonest = min(list(self.timeout.values())) def clear_cache(self): for conn in self.cache.values(): conn.close() self.cache.clear() self.timeout.clear() class DataHandler(BaseHandler): def data_open(self, req): # data URLs as specified in RFC 2397. # # ignores POSTed data # # syntax: # dataurl := "data:" [ mediatype ] [ ";base64" ] "," data # mediatype := [ type "/" subtype ] *( ";" parameter ) # data := *urlchar # parameter := attribute "=" value url = req.full_url scheme, data = url.split(":",1) mediatype, data = data.split(",",1) # even base64 encoded data URLs might be quoted so unquote in any case: data = unquote_to_bytes(data) if mediatype.endswith(";base64"): data = base64.decodebytes(data) mediatype = mediatype[:-7] if not mediatype: mediatype = "text/plain;charset=US-ASCII" headers = email.message_from_string("Content-type: %s\nContent-length: %d\n" % (mediatype, len(data))) return addinfourl(io.BytesIO(data), headers, url) # Code move from the old urllib module MAXFTPCACHE = 10 # Trim the ftp cache beyond this size # Helper for non-unix systems if os.name == 'nt': from nturl2path import url2pathname, pathname2url else: def url2pathname(pathname): """OS-specific conversion from a relative URL of the 'file' scheme to a file system path; not recommended for general use.""" return unquote(pathname) def pathname2url(pathname): """OS-specific conversion from a file system path to a relative URL of the 'file' scheme; not recommended for general use.""" return quote(pathname) ftpcache = {} class URLopener: """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).""" __tempfiles = None version = "Python-urllib/%s" % __version__ # Constructor def __init__(self, proxies=None, **x509): msg = "%(class)s style of invoking requests is deprecated. " \ "Use newer urlopen functions/methods" % {'class': self.__class__.__name__} warnings.warn(msg, DeprecationWarning, stacklevel=3) if proxies is None: proxies = getproxies() assert hasattr(proxies, 'keys'), "proxies must be a mapping" self.proxies = proxies self.key_file = x509.get('key_file') self.cert_file = x509.get('cert_file') self.addheaders = [('User-Agent', self.version), ('Accept', '*/*')] self.__tempfiles = [] self.__unlink = os.unlink # See cleanup() self.tempcache = None # Undocumented feature: if you assign {} to tempcache, # it is used to cache files retrieved with # self.retrieve(). This is not enabled by default # since it does not work for changing documents (and I # haven't got the logic to check expiration headers # yet). self.ftpcache = ftpcache # Undocumented feature: you can use a different # ftp cache by assigning to the .ftpcache member; # in case you want logically independent URL openers # XXX This is not threadsafe. Bah. def __del__(self): self.close() def close(self): self.cleanup() def cleanup(self): # This code sometimes runs when the rest of this module # has already been deleted, so it can't use any globals # or import anything. if self.__tempfiles: for file in self.__tempfiles: try: self.__unlink(file) except OSError: pass del self.__tempfiles[:] if self.tempcache: self.tempcache.clear() def addheader(self, *args): """Add a header to be used by the HTTP interface only e.g. u.addheader('Accept', 'sound/basic')""" self.addheaders.append(args) # External interface def open(self, fullurl, data=None): """Use URLopener().open(file) instead of open(file, 'r').""" fullurl = unwrap(_to_bytes(fullurl)) fullurl = quote(fullurl, safe="%/:=&?~#+!$,;'@()*[]|") if self.tempcache and fullurl in self.tempcache: filename, headers = self.tempcache[fullurl] fp = open(filename, 'rb') return addinfourl(fp, headers, fullurl) urltype, url = _splittype(fullurl) if not urltype: urltype = 'file' if urltype in self.proxies: proxy = self.proxies[urltype] urltype, proxyhost = _splittype(proxy) host, selector = _splithost(proxyhost) url = (host, fullurl) # Signal special case to open_*() else: proxy = None name = 'open_' + urltype self.type = urltype name = name.replace('-', '_') if not hasattr(self, name) or name == 'open_local_file': if proxy: return self.open_unknown_proxy(proxy, fullurl, data) else: return self.open_unknown(fullurl, data) try: if data is None: return getattr(self, name)(url) else: return getattr(self, name)(url, data) except (HTTPError, URLError): raise except OSError as msg: raise OSError('socket error', msg) from msg def open_unknown(self, fullurl, data=None): """Overridable interface to open unknown URL type.""" type, url = _splittype(fullurl) raise OSError('url error', 'unknown url type', type) def open_unknown_proxy(self, proxy, fullurl, data=None): """Overridable interface to open unknown URL type.""" type, url = _splittype(fullurl) raise OSError('url error', 'invalid proxy for %s' % type, proxy) # External interface def retrieve(self, url, filename=None, reporthook=None, data=None): """retrieve(url) returns (filename, headers) for a local object or (tempfilename, headers) for a remote object.""" url = unwrap(_to_bytes(url)) if self.tempcache and url in self.tempcache: return self.tempcache[url] type, url1 = _splittype(url) if filename is None and (not type or type == 'file'): try: fp = self.open_local_file(url1) hdrs = fp.info() fp.close() return url2pathname(_splithost(url1)[1]), hdrs except OSError: pass fp = self.open(url, data) try: headers = fp.info() if filename: tfp = open(filename, 'wb') else: garbage, path = _splittype(url) garbage, path = _splithost(path or "") path, garbage = _splitquery(path or "") path, garbage = _splitattr(path or "") suffix = os.path.splitext(path)[1] (fd, filename) = tempfile.mkstemp(suffix) self.__tempfiles.append(filename) tfp = os.fdopen(fd, 'wb') try: result = filename, headers if self.tempcache is not None: self.tempcache[url] = result bs = 1024*8 size = -1 read = 0 blocknum = 0 if "content-length" in headers: size = int(headers["Content-Length"]) if reporthook: reporthook(blocknum, bs, size) while 1: block = fp.read(bs) if not block: break read += len(block) tfp.write(block) blocknum += 1 if reporthook: reporthook(blocknum, bs, size) finally: tfp.close() finally: fp.close() # raise exception if actual size does not match content-length header if size >= 0 and read < size: raise ContentTooShortError( "retrieval incomplete: got only %i out of %i bytes" % (read, size), result) return result # Each method named open_ knows how to open that type of URL def _open_generic_http(self, connection_factory, url, data): """Make 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. """ user_passwd = None proxy_passwd= None if isinstance(url, str): host, selector = _splithost(url) if host: user_passwd, host = _splituser(host) host = unquote(host) realhost = host else: host, selector = url # check whether the proxy contains authorization information proxy_passwd, host = _splituser(host) # now we proceed with the url we want to obtain urltype, rest = _splittype(selector) url = rest user_passwd = None if urltype.lower() != 'http': realhost = None else: realhost, rest = _splithost(rest) if realhost: user_passwd, realhost = _splituser(realhost) if user_passwd: selector = "%s://%s%s" % (urltype, realhost, rest) if proxy_bypass(realhost): host = realhost if not host: raise OSError('http error', 'no host given') if proxy_passwd: proxy_passwd = unquote(proxy_passwd) proxy_auth = base64.b64encode(proxy_passwd.encode()).decode('ascii') else: proxy_auth = None if user_passwd: user_passwd = unquote(user_passwd) auth = base64.b64encode(user_passwd.encode()).decode('ascii') else: auth = None http_conn = connection_factory(host) headers = {} if proxy_auth: headers["Proxy-Authorization"] = "Basic %s" % proxy_auth if auth: headers["Authorization"] = "Basic %s" % auth if realhost: headers["Host"] = realhost # Add Connection:close as we don't support persistent connections yet. # This helps in closing the socket and avoiding ResourceWarning headers["Connection"] = "close" for header, value in self.addheaders: headers[header] = value if data is not None: headers["Content-Type"] = "application/x-www-form-urlencoded" http_conn.request("POST", selector, data, headers) else: http_conn.request("GET", selector, headers=headers) try: response = http_conn.getresponse() except http.client.BadStatusLine: # something went wrong with the HTTP status line raise URLError("http protocol error: bad status line") # According to RFC 2616, "2xx" code indicates that the client's # request was successfully received, understood, and accepted. if 200 <= response.status < 300: return addinfourl(response, response.msg, "http:" + url, response.status) else: return self.http_error( url, response.fp, response.status, response.reason, response.msg, data) def open_http(self, url, data=None): """Use HTTP protocol.""" return self._open_generic_http(http.client.HTTPConnection, url, data) def http_error(self, url, fp, errcode, errmsg, headers, data=None): """Handle http errors. Derived class can override this, or provide specific handlers named http_error_DDD where DDD is the 3-digit error code.""" # First check if there's a specific handler for this error name = 'http_error_%d' % errcode if hasattr(self, name): method = getattr(self, name) if data is None: result = method(url, fp, errcode, errmsg, headers) else: result = method(url, fp, errcode, errmsg, headers, data) if result: return result return self.http_error_default(url, fp, errcode, errmsg, headers) def http_error_default(self, url, fp, errcode, errmsg, headers): """Default error handler: close the connection and raise OSError.""" fp.close() raise HTTPError(url, errcode, errmsg, headers, None) if _have_ssl: def _https_connection(self, host): return http.client.HTTPSConnection(host, key_file=self.key_file, cert_file=self.cert_file) def open_https(self, url, data=None): """Use HTTPS protocol.""" return self._open_generic_http(self._https_connection, url, data) def open_file(self, url): """Use local file or FTP depending on form of URL.""" if not isinstance(url, str): raise URLError('file error: proxy support for file protocol currently not implemented') if url[:2] == '//' and url[2:3] != '/' and url[2:12].lower() != 'localhost/': raise ValueError("file:// scheme is supported only on localhost") else: return self.open_local_file(url) def open_local_file(self, url): """Use local file.""" import email.utils import mimetypes host, file = _splithost(url) localname = url2pathname(file) try: stats = os.stat(localname) except OSError as e: raise URLError(e.strerror, e.filename) size = stats.st_size modified = email.utils.formatdate(stats.st_mtime, usegmt=True) mtype = mimetypes.guess_type(url)[0] headers = email.message_from_string( 'Content-Type: %s\nContent-Length: %d\nLast-modified: %s\n' % (mtype or 'text/plain', size, modified)) if not host: urlfile = file if file[:1] == '/': urlfile = 'file://' + file return addinfourl(open(localname, 'rb'), headers, urlfile) host, port = _splitport(host) if (not port and socket.gethostbyname(host) in ((localhost(),) + thishost())): urlfile = file if file[:1] == '/': urlfile = 'file://' + file elif file[:2] == './': raise ValueError("local file url may start with / or file:. Unknown url of type: %s" % url) return addinfourl(open(localname, 'rb'), headers, urlfile) raise URLError('local file error: not on local host') def open_ftp(self, url): """Use FTP protocol.""" if not isinstance(url, str): raise URLError('ftp error: proxy support for ftp protocol currently not implemented') import mimetypes host, path = _splithost(url) if not host: raise URLError('ftp error: no host given') host, port = _splitport(host) user, host = _splituser(host) if user: user, passwd = _splitpasswd(user) else: passwd = None host = unquote(host) user = unquote(user or '') passwd = unquote(passwd or '') host = socket.gethostbyname(host) if not port: import ftplib port = ftplib.FTP_PORT else: port = int(port) path, attrs = _splitattr(path) path = unquote(path) dirs = path.split('/') dirs, file = dirs[:-1], dirs[-1] if dirs and not dirs[0]: dirs = dirs[1:] if dirs and not dirs[0]: dirs[0] = '/' key = user, host, port, '/'.join(dirs) # XXX thread unsafe! if len(self.ftpcache) > MAXFTPCACHE: # Prune the cache, rather arbitrarily for k in list(self.ftpcache): if k != key: v = self.ftpcache[k] del self.ftpcache[k] v.close() try: if key not in self.ftpcache: self.ftpcache[key] = \ ftpwrapper(user, passwd, host, port, dirs) if not file: type = 'D' else: type = 'I' for attr in attrs: attr, value = _splitvalue(attr) if attr.lower() == 'type' and \ value in ('a', 'A', 'i', 'I', 'd', 'D'): type = value.upper() (fp, retrlen) = self.ftpcache[key].retrfile(file, type) mtype = mimetypes.guess_type("ftp:" + url)[0] headers = "" if mtype: headers += "Content-Type: %s\n" % mtype if retrlen is not None and retrlen >= 0: headers += "Content-Length: %d\n" % retrlen headers = email.message_from_string(headers) return addinfourl(fp, headers, "ftp:" + url) except ftperrors() as exp: raise URLError(f'ftp error: {exp}') from exp def open_data(self, url, data=None): """Use "data" URL.""" if not isinstance(url, str): raise URLError('data error: proxy support for data protocol currently not implemented') # ignore POSTed data # # syntax of data URLs: # dataurl := "data:" [ mediatype ] [ ";base64" ] "," data # mediatype := [ type "/" subtype ] *( ";" parameter ) # data := *urlchar # parameter := attribute "=" value try: [type, data] = url.split(',', 1) except ValueError: raise OSError('data error', 'bad data URL') if not type: type = 'text/plain;charset=US-ASCII' semi = type.rfind(';') if semi >= 0 and '=' not in type[semi:]: encoding = type[semi+1:] type = type[:semi] else: encoding = '' msg = [] msg.append('Date: %s'%time.strftime('%a, %d %b %Y %H:%M:%S GMT', time.gmtime(time.time()))) msg.append('Content-type: %s' % type) if encoding == 'base64': # XXX is this encoding/decoding ok? data = base64.decodebytes(data.encode('ascii')).decode('latin-1') else: data = unquote(data) msg.append('Content-Length: %d' % len(data)) msg.append('') msg.append(data) msg = '\n'.join(msg) headers = email.message_from_string(msg) f = io.StringIO(msg) #f.fileno = None # needed for addinfourl return addinfourl(f, headers, url) class FancyURLopener(URLopener): """Derived class with handlers for errors we can handle (perhaps).""" def __init__(self, *args, **kwargs): URLopener.__init__(self, *args, **kwargs) self.auth_cache = {} self.tries = 0 self.maxtries = 10 def http_error_default(self, url, fp, errcode, errmsg, headers): """Default error handling -- don't raise an exception.""" return addinfourl(fp, headers, "http:" + url, errcode) def http_error_302(self, url, fp, errcode, errmsg, headers, data=None): """Error 302 -- relocated (temporarily).""" self.tries += 1 try: if self.maxtries and self.tries >= self.maxtries: if hasattr(self, "http_error_500"): meth = self.http_error_500 else: meth = self.http_error_default return meth(url, fp, 500, "Internal Server Error: Redirect Recursion", headers) result = self.redirect_internal(url, fp, errcode, errmsg, headers, data) return result finally: self.tries = 0 def redirect_internal(self, url, fp, errcode, errmsg, headers, data): if 'location' in headers: newurl = headers['location'] elif 'uri' in headers: newurl = headers['uri'] else: return fp.close() # In case the server sent a relative URL, join with original: newurl = urljoin(self.type + ":" + url, newurl) urlparts = urlparse(newurl) # For security reasons, we don't allow redirection to anything other # than http, https and ftp. # We are using newer HTTPError with older redirect_internal method # This older method will get deprecated in 3.3 if urlparts.scheme not in ('http', 'https', 'ftp', ''): raise HTTPError(newurl, errcode, errmsg + " Redirection to url '%s' is not allowed." % newurl, headers, fp) return self.open(newurl) def http_error_301(self, url, fp, errcode, errmsg, headers, data=None): """Error 301 -- also relocated (permanently).""" return self.http_error_302(url, fp, errcode, errmsg, headers, data) def http_error_303(self, url, fp, errcode, errmsg, headers, data=None): """Error 303 -- also relocated (essentially identical to 302).""" return self.http_error_302(url, fp, errcode, errmsg, headers, data) def http_error_307(self, url, fp, errcode, errmsg, headers, data=None): """Error 307 -- relocated, but turn POST into error.""" if data is None: return self.http_error_302(url, fp, errcode, errmsg, headers, data) else: return self.http_error_default(url, fp, errcode, errmsg, headers) def http_error_308(self, url, fp, errcode, errmsg, headers, data=None): """Error 308 -- relocated, but turn POST into error.""" if data is None: return self.http_error_301(url, fp, errcode, errmsg, headers, data) else: return self.http_error_default(url, fp, errcode, errmsg, headers) def http_error_401(self, url, fp, errcode, errmsg, headers, data=None, retry=False): """Error 401 -- authentication required. This function supports Basic authentication only.""" if 'www-authenticate' not in headers: URLopener.http_error_default(self, url, fp, errcode, errmsg, headers) stuff = headers['www-authenticate'] match = re.match('[ \t]*([^ \t]+)[ \t]+realm="([^"]*)"', stuff) if not match: URLopener.http_error_default(self, url, fp, errcode, errmsg, headers) scheme, realm = match.groups() if scheme.lower() != 'basic': URLopener.http_error_default(self, url, fp, errcode, errmsg, headers) if not retry: URLopener.http_error_default(self, url, fp, errcode, errmsg, headers) name = 'retry_' + self.type + '_basic_auth' if data is None: return getattr(self,name)(url, realm) else: return getattr(self,name)(url, realm, data) def http_error_407(self, url, fp, errcode, errmsg, headers, data=None, retry=False): """Error 407 -- proxy authentication required. This function supports Basic authentication only.""" if 'proxy-authenticate' not in headers: URLopener.http_error_default(self, url, fp, errcode, errmsg, headers) stuff = headers['proxy-authenticate'] match = re.match('[ \t]*([^ \t]+)[ \t]+realm="([^"]*)"', stuff) if not match: URLopener.http_error_default(self, url, fp, errcode, errmsg, headers) scheme, realm = match.groups() if scheme.lower() != 'basic': URLopener.http_error_default(self, url, fp, errcode, errmsg, headers) if not retry: URLopener.http_error_default(self, url, fp, errcode, errmsg, headers) name = 'retry_proxy_' + self.type + '_basic_auth' if data is None: return getattr(self,name)(url, realm) else: return getattr(self,name)(url, realm, data) def retry_proxy_http_basic_auth(self, url, realm, data=None): host, selector = _splithost(url) newurl = 'http://' + host + selector proxy = self.proxies['http'] urltype, proxyhost = _splittype(proxy) proxyhost, proxyselector = _splithost(proxyhost) i = proxyhost.find('@') + 1 proxyhost = proxyhost[i:] user, passwd = self.get_user_passwd(proxyhost, realm, i) if not (user or passwd): return None proxyhost = "%s:%s@%s" % (quote(user, safe=''), quote(passwd, safe=''), proxyhost) self.proxies['http'] = 'http://' + proxyhost + proxyselector if data is None: return self.open(newurl) else: return self.open(newurl, data) def retry_proxy_https_basic_auth(self, url, realm, data=None): host, selector = _splithost(url) newurl = 'https://' + host + selector proxy = self.proxies['https'] urltype, proxyhost = _splittype(proxy) proxyhost, proxyselector = _splithost(proxyhost) i = proxyhost.find('@') + 1 proxyhost = proxyhost[i:] user, passwd = self.get_user_passwd(proxyhost, realm, i) if not (user or passwd): return None proxyhost = "%s:%s@%s" % (quote(user, safe=''), quote(passwd, safe=''), proxyhost) self.proxies['https'] = 'https://' + proxyhost + proxyselector if data is None: return self.open(newurl) else: return self.open(newurl, data) def retry_http_basic_auth(self, url, realm, data=None): host, selector = _splithost(url) i = host.find('@') + 1 host = host[i:] user, passwd = self.get_user_passwd(host, realm, i) if not (user or passwd): return None host = "%s:%s@%s" % (quote(user, safe=''), quote(passwd, safe=''), host) newurl = 'http://' + host + selector if data is None: return self.open(newurl) else: return self.open(newurl, data) def retry_https_basic_auth(self, url, realm, data=None): host, selector = _splithost(url) i = host.find('@') + 1 host = host[i:] user, passwd = self.get_user_passwd(host, realm, i) if not (user or passwd): return None host = "%s:%s@%s" % (quote(user, safe=''), quote(passwd, safe=''), host) newurl = 'https://' + host + selector if data is None: return self.open(newurl) else: return self.open(newurl, data) def get_user_passwd(self, host, realm, clear_cache=0): key = realm + '@' + host.lower() if key in self.auth_cache: if clear_cache: del self.auth_cache[key] else: return self.auth_cache[key] user, passwd = self.prompt_user_passwd(host, realm) if user or passwd: self.auth_cache[key] = (user, passwd) return user, passwd def prompt_user_passwd(self, host, realm): """Override this in a GUI environment!""" import getpass try: user = input("Enter username for %s at %s: " % (realm, host)) passwd = getpass.getpass("Enter password for %s in %s at %s: " % (user, realm, host)) return user, passwd except KeyboardInterrupt: print() return None, None # Utility functions _localhost = None def localhost(): """Return the IP address of the magic hostname 'localhost'.""" global _localhost if _localhost is None: _localhost = socket.gethostbyname('localhost') return _localhost _thishost = None def thishost(): """Return the IP addresses of the current host.""" global _thishost if _thishost is None: try: _thishost = tuple(socket.gethostbyname_ex(socket.gethostname())[2]) except socket.gaierror: _thishost = tuple(socket.gethostbyname_ex('localhost')[2]) return _thishost _ftperrors = None def ftperrors(): """Return the set of errors raised by the FTP class.""" global _ftperrors if _ftperrors is None: import ftplib _ftperrors = ftplib.all_errors return _ftperrors _noheaders = None def noheaders(): """Return an empty email Message object.""" global _noheaders if _noheaders is None: _noheaders = email.message_from_string("") return _noheaders # Utility classes class ftpwrapper: """Class used by open_ftp() for cache of open FTP connections.""" def __init__(self, user, passwd, host, port, dirs, timeout=None, persistent=True): self.user = user self.passwd = passwd self.host = host self.port = port self.dirs = dirs self.timeout = timeout self.refcount = 0 self.keepalive = persistent try: self.init() except: self.close() raise def init(self): import ftplib self.busy = 0 self.ftp = ftplib.FTP() self.ftp.connect(self.host, self.port, self.timeout) self.ftp.login(self.user, self.passwd) _target = '/'.join(self.dirs) self.ftp.cwd(_target) def retrfile(self, file, type): import ftplib self.endtransfer() if type in ('d', 'D'): cmd = 'TYPE A'; isdir = 1 else: cmd = 'TYPE ' + type; isdir = 0 try: self.ftp.voidcmd(cmd) except ftplib.all_errors: self.init() self.ftp.voidcmd(cmd) conn = None if file and not isdir: # Try to retrieve as a file try: cmd = 'RETR ' + file conn, retrlen = self.ftp.ntransfercmd(cmd) except ftplib.error_perm as reason: if str(reason)[:3] != '550': raise URLError(f'ftp error: {reason}') from reason if not conn: # Set transfer mode to ASCII! self.ftp.voidcmd('TYPE A') # Try a directory listing. Verify that directory exists. if file: pwd = self.ftp.pwd() try: try: self.ftp.cwd(file) except ftplib.error_perm as reason: raise URLError('ftp error: %r' % reason) from reason finally: self.ftp.cwd(pwd) cmd = 'LIST ' + file else: cmd = 'LIST' conn, retrlen = self.ftp.ntransfercmd(cmd) self.busy = 1 ftpobj = addclosehook(conn.makefile('rb'), self.file_close) self.refcount += 1 conn.close() # Pass back both a suitably decorated object and a retrieval length return (ftpobj, retrlen) def endtransfer(self): if not self.busy: return self.busy = 0 try: self.ftp.voidresp() except ftperrors(): pass def close(self): self.keepalive = False if self.refcount <= 0: self.real_close() def file_close(self): self.endtransfer() self.refcount -= 1 if self.refcount <= 0 and not self.keepalive: self.real_close() def real_close(self): self.endtransfer() try: self.ftp.close() except ftperrors(): pass # Proxy handling def getproxies_environment(): """Return 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. """ proxies = {} # in order to prefer lowercase variables, process environment in # two passes: first matches any, second pass matches lowercase only for name, value in os.environ.items(): name = name.lower() if value and name[-6:] == '_proxy': proxies[name[:-6]] = value # CVE-2016-1000110 - If we are running as CGI script, forget HTTP_PROXY # (non-all-lowercase) as it may be set from the web server by a "Proxy:" # header from the client # If "proxy" is lowercase, it will still be used thanks to the next block if 'REQUEST_METHOD' in os.environ: proxies.pop('http', None) for name, value in os.environ.items(): if name[-6:] == '_proxy': name = name.lower() if value: proxies[name[:-6]] = value else: proxies.pop(name[:-6], None) return proxies def proxy_bypass_environment(host, proxies=None): """Test if proxies should not be used for a particular host. Checks the proxy dict for the value of no_proxy, which should be a list of comma separated DNS suffixes, or '*' for all hosts. """ if proxies is None: proxies = getproxies_environment() # don't bypass, if no_proxy isn't specified try: no_proxy = proxies['no'] except KeyError: return False # '*' is special case for always bypass if no_proxy == '*': return True host = host.lower() # strip port off host hostonly, port = _splitport(host) # check if the host ends with any of the DNS suffixes for name in no_proxy.split(','): name = name.strip() if name: name = name.lstrip('.') # ignore leading dots name = name.lower() if hostonly == name or host == name: return True name = '.' + name if hostonly.endswith(name) or host.endswith(name): return True # otherwise, don't bypass return False # This code tests an OSX specific data structure but is testable on all # platforms def _proxy_bypass_macosx_sysconf(host, proxy_settings): """ Return True iff this host shouldn't be accessed using a proxy This function uses the MacOSX framework SystemConfiguration to fetch the proxy information. proxy_settings come from _scproxy._get_proxy_settings or get mocked ie: { 'exclude_simple': bool, 'exceptions': ['foo.bar', '*.bar.com', '127.0.0.1', '10.1', '10.0/16'] } """ from fnmatch import fnmatch from ipaddress import AddressValueError, IPv4Address hostonly, port = _splitport(host) def ip2num(ipAddr): parts = ipAddr.split('.') parts = list(map(int, parts)) if len(parts) != 4: parts = (parts + [0, 0, 0, 0])[:4] return (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8) | parts[3] # Check for simple host names: if '.' not in host: if proxy_settings['exclude_simple']: return True hostIP = None try: hostIP = int(IPv4Address(hostonly)) except AddressValueError: pass for value in proxy_settings.get('exceptions', ()): # Items in the list are strings like these: *.local, 169.254/16 if not value: continue m = re.match(r"(\d+(?:\.\d+)*)(/\d+)?", value) if m is not None and hostIP is not None: base = ip2num(m.group(1)) mask = m.group(2) if mask is None: mask = 8 * (m.group(1).count('.') + 1) else: mask = int(mask[1:]) if mask < 0 or mask > 32: # System libraries ignore invalid prefix lengths continue mask = 32 - mask if (hostIP >> mask) == (base >> mask): return True elif fnmatch(host, value): return True return False # Same as _proxy_bypass_macosx_sysconf, testable on all platforms def _proxy_bypass_winreg_override(host, override): """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" """ from fnmatch import fnmatch host, _ = _splitport(host) proxy_override = override.split(';') for test in proxy_override: test = test.strip() # "" should bypass the proxy server for all intranet addresses if test == '': if '.' not in host: return True elif fnmatch(host, test): return True return False if sys.platform == 'darwin': from _scproxy import _get_proxy_settings, _get_proxies def proxy_bypass_macosx_sysconf(host): proxy_settings = _get_proxy_settings() return _proxy_bypass_macosx_sysconf(host, proxy_settings) def getproxies_macosx_sysconf(): """Return a dictionary of scheme -> proxy server URL mappings. This function uses the MacOSX framework SystemConfiguration to fetch the proxy information. """ return _get_proxies() def proxy_bypass(host): """Return True, if host should be bypassed. Checks proxy settings gathered from the environment, if specified, or from the MacOSX framework SystemConfiguration. """ proxies = getproxies_environment() if proxies: return proxy_bypass_environment(host, proxies) else: return proxy_bypass_macosx_sysconf(host) def getproxies(): return getproxies_environment() or getproxies_macosx_sysconf() elif os.name == 'nt': def getproxies_registry(): """Return a dictionary of scheme -> proxy server URL mappings. Win32 uses the registry to store proxies. """ proxies = {} try: import winreg except ImportError: # Std module, so should be around - but you never know! return proxies try: internetSettings = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r'Software\Microsoft\Windows\CurrentVersion\Internet Settings') proxyEnable = winreg.QueryValueEx(internetSettings, 'ProxyEnable')[0] if proxyEnable: # Returned as Unicode but problems if not converted to ASCII proxyServer = str(winreg.QueryValueEx(internetSettings, 'ProxyServer')[0]) if '=' not in proxyServer and ';' not in proxyServer: # Use one setting for all protocols. proxyServer = 'http={0};https={0};ftp={0}'.format(proxyServer) for p in proxyServer.split(';'): protocol, address = p.split('=', 1) # See if address has a type:// prefix if not re.match('(?:[^/:]+)://', address): # Add type:// prefix to address without specifying type if protocol in ('http', 'https', 'ftp'): # The default proxy type of Windows is HTTP address = 'http://' + address elif protocol == 'socks': address = 'socks://' + address proxies[protocol] = address # Use SOCKS proxy for HTTP(S) protocols if proxies.get('socks'): # The default SOCKS proxy type of Windows is SOCKS4 address = re.sub(r'^socks://', 'socks4://', proxies['socks']) proxies['http'] = proxies.get('http') or address proxies['https'] = proxies.get('https') or address internetSettings.Close() except (OSError, ValueError, TypeError): # Either registry key not found etc, or the value in an # unexpected format. # proxies already set up to be empty so nothing to do pass return proxies def getproxies(): """Return a dictionary of scheme -> proxy server URL mappings. Returns settings gathered from the environment, if specified, or the registry. """ return getproxies_environment() or getproxies_registry() def proxy_bypass_registry(host): try: import winreg except ImportError: # Std modules, so should be around - but you never know! return False try: internetSettings = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r'Software\Microsoft\Windows\CurrentVersion\Internet Settings') proxyEnable = winreg.QueryValueEx(internetSettings, 'ProxyEnable')[0] proxyOverride = str(winreg.QueryValueEx(internetSettings, 'ProxyOverride')[0]) # ^^^^ Returned as Unicode but problems if not converted to ASCII except OSError: return False if not proxyEnable or not proxyOverride: return False return _proxy_bypass_winreg_override(host, proxyOverride) def proxy_bypass(host): """Return True, if host should be bypassed. Checks proxy settings gathered from the environment, if specified, or the registry. """ proxies = getproxies_environment() if proxies: return proxy_bypass_environment(host, proxies) else: return proxy_bypass_registry(host) else: # By default use environment variables getproxies = getproxies_environment proxy_bypass = proxy_bypass_environment parse.py000064400000127444151026775530006257 0ustar00"""Parse (absolute and relative) URLs. urlparse module is based upon the following RFC specifications. RFC 3986 (STD66): "Uniform Resource Identifiers" by T. Berners-Lee, R. Fielding and L. Masinter, January 2005. RFC 2732 : "Format for Literal IPv6 Addresses in URL's by R.Hinden, B.Carpenter and L.Masinter, December 1999. RFC 2396: "Uniform Resource Identifiers (URI)": Generic Syntax by T. Berners-Lee, R. Fielding, and L. Masinter, August 1998. RFC 2368: "The mailto URL scheme", by P.Hoffman , L Masinter, J. Zawinski, July 1998. RFC 1808: "Relative Uniform Resource Locators", by R. Fielding, UC Irvine, June 1995. RFC 1738: "Uniform Resource Locators (URL)" by T. Berners-Lee, L. Masinter, M. McCahill, December 1994 RFC 3986 is considered the current standard and any future changes to urlparse module should conform with it. The urlparse module is currently not entirely compliant with this RFC due to defacto scenarios for parsing, and for backward compatibility purposes, some parsing quirks from older RFCs are retained. The testcases in test_urlparse.py provides a good indicator of parsing behavior. The WHATWG URL Parser spec should also be considered. We are not compliant with it either due to existing user code API behavior expectations (Hyrum's Law). It serves as a useful guide when making changes. """ from collections import namedtuple import functools import re import sys import types import warnings import ipaddress __all__ = ["urlparse", "urlunparse", "urljoin", "urldefrag", "urlsplit", "urlunsplit", "urlencode", "parse_qs", "parse_qsl", "quote", "quote_plus", "quote_from_bytes", "unquote", "unquote_plus", "unquote_to_bytes", "DefragResult", "ParseResult", "SplitResult", "DefragResultBytes", "ParseResultBytes", "SplitResultBytes"] # A classification of schemes. # The empty string classifies URLs with no scheme specified, # being the default value returned by “urlsplit” and “urlparse”. uses_relative = ['', 'ftp', 'http', 'gopher', 'nntp', 'imap', 'wais', 'file', 'https', 'shttp', 'mms', 'prospero', 'rtsp', 'rtsps', 'rtspu', 'sftp', 'svn', 'svn+ssh', 'ws', 'wss'] uses_netloc = ['', 'ftp', 'http', 'gopher', 'nntp', 'telnet', 'imap', 'wais', 'file', 'mms', 'https', 'shttp', 'snews', 'prospero', 'rtsp', 'rtsps', 'rtspu', 'rsync', 'svn', 'svn+ssh', 'sftp', 'nfs', 'git', 'git+ssh', 'ws', 'wss'] uses_params = ['', 'ftp', 'hdl', 'prospero', 'http', 'imap', 'https', 'shttp', 'rtsp', 'rtsps', 'rtspu', 'sip', 'sips', 'mms', 'sftp', 'tel'] # These are not actually used anymore, but should stay for backwards # compatibility. (They are undocumented, but have a public-looking name.) non_hierarchical = ['gopher', 'hdl', 'mailto', 'news', 'telnet', 'wais', 'imap', 'snews', 'sip', 'sips'] uses_query = ['', 'http', 'wais', 'imap', 'https', 'shttp', 'mms', 'gopher', 'rtsp', 'rtsps', 'rtspu', 'sip', 'sips'] uses_fragment = ['', 'ftp', 'hdl', 'http', 'gopher', 'news', 'nntp', 'wais', 'https', 'shttp', 'snews', 'file', 'prospero'] # Characters valid in scheme names scheme_chars = ('abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' '0123456789' '+-.') # Leading and trailing C0 control and space to be stripped per WHATWG spec. # == "".join([chr(i) for i in range(0, 0x20 + 1)]) _WHATWG_C0_CONTROL_OR_SPACE = '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f ' # Unsafe bytes to be removed per WHATWG spec _UNSAFE_URL_BYTES_TO_REMOVE = ['\t', '\r', '\n'] def clear_cache(): """Clear internal performance caches. Undocumented; some tests want it.""" urlsplit.cache_clear() _byte_quoter_factory.cache_clear() # Helpers for bytes handling # For 3.2, we deliberately require applications that # handle improperly quoted URLs to do their own # decoding and encoding. If valid use cases are # presented, we may relax this by using latin-1 # decoding internally for 3.3 _implicit_encoding = 'ascii' _implicit_errors = 'strict' def _noop(obj): return obj def _encode_result(obj, encoding=_implicit_encoding, errors=_implicit_errors): return obj.encode(encoding, errors) def _decode_args(args, encoding=_implicit_encoding, errors=_implicit_errors): return tuple(x.decode(encoding, errors) if x else '' for x in args) def _coerce_args(*args): # Invokes decode if necessary to create str args # and returns the coerced inputs along with # an appropriate result coercion function # - noop for str inputs # - encoding function otherwise str_input = isinstance(args[0], str) for arg in args[1:]: # We special-case the empty string to support the # "scheme=''" default argument to some functions if arg and isinstance(arg, str) != str_input: raise TypeError("Cannot mix str and non-str arguments") if str_input: return args + (_noop,) return _decode_args(args) + (_encode_result,) # Result objects are more helpful than simple tuples class _ResultMixinStr(object): """Standard approach to encoding parsed results from str to bytes""" __slots__ = () def encode(self, encoding='ascii', errors='strict'): return self._encoded_counterpart(*(x.encode(encoding, errors) for x in self)) class _ResultMixinBytes(object): """Standard approach to decoding parsed results from bytes to str""" __slots__ = () def decode(self, encoding='ascii', errors='strict'): return self._decoded_counterpart(*(x.decode(encoding, errors) for x in self)) class _NetlocResultMixinBase(object): """Shared methods for the parsed result objects containing a netloc element""" __slots__ = () @property def username(self): return self._userinfo[0] @property def password(self): return self._userinfo[1] @property def hostname(self): hostname = self._hostinfo[0] if not hostname: return None # Scoped IPv6 address may have zone info, which must not be lowercased # like http://[fe80::822a:a8ff:fe49:470c%tESt]:1234/keys separator = '%' if isinstance(hostname, str) else b'%' hostname, percent, zone = hostname.partition(separator) return hostname.lower() + percent + zone @property def port(self): port = self._hostinfo[1] if port is not None: if port.isdigit() and port.isascii(): port = int(port) else: raise ValueError(f"Port could not be cast to integer value as {port!r}") if not (0 <= port <= 65535): raise ValueError("Port out of range 0-65535") return port __class_getitem__ = classmethod(types.GenericAlias) class _NetlocResultMixinStr(_NetlocResultMixinBase, _ResultMixinStr): __slots__ = () @property def _userinfo(self): netloc = self.netloc userinfo, have_info, hostinfo = netloc.rpartition('@') if have_info: username, have_password, password = userinfo.partition(':') if not have_password: password = None else: username = password = None return username, password @property def _hostinfo(self): netloc = self.netloc _, _, hostinfo = netloc.rpartition('@') _, have_open_br, bracketed = hostinfo.partition('[') if have_open_br: hostname, _, port = bracketed.partition(']') _, _, port = port.partition(':') else: hostname, _, port = hostinfo.partition(':') if not port: port = None return hostname, port class _NetlocResultMixinBytes(_NetlocResultMixinBase, _ResultMixinBytes): __slots__ = () @property def _userinfo(self): netloc = self.netloc userinfo, have_info, hostinfo = netloc.rpartition(b'@') if have_info: username, have_password, password = userinfo.partition(b':') if not have_password: password = None else: username = password = None return username, password @property def _hostinfo(self): netloc = self.netloc _, _, hostinfo = netloc.rpartition(b'@') _, have_open_br, bracketed = hostinfo.partition(b'[') if have_open_br: hostname, _, port = bracketed.partition(b']') _, _, port = port.partition(b':') else: hostname, _, port = hostinfo.partition(b':') if not port: port = None return hostname, port _DefragResultBase = namedtuple('DefragResult', 'url fragment') _SplitResultBase = namedtuple( 'SplitResult', 'scheme netloc path query fragment') _ParseResultBase = namedtuple( 'ParseResult', 'scheme netloc path params query fragment') _DefragResultBase.__doc__ = """ DefragResult(url, fragment) A 2-tuple that contains the url without fragment identifier and the fragment identifier as a separate argument. """ _DefragResultBase.url.__doc__ = """The URL with no fragment identifier.""" _DefragResultBase.fragment.__doc__ = """ Fragment identifier separated from URL, that allows indirect identification of a secondary resource by reference to a primary resource and additional identifying information. """ _SplitResultBase.__doc__ = """ SplitResult(scheme, netloc, path, query, fragment) A 5-tuple that contains the different components of a URL. Similar to ParseResult, but does not split params. """ _SplitResultBase.scheme.__doc__ = """Specifies URL scheme for the request.""" _SplitResultBase.netloc.__doc__ = """ Network location where the request is made to. """ _SplitResultBase.path.__doc__ = """ The hierarchical path, such as the path to a file to download. """ _SplitResultBase.query.__doc__ = """ The query component, that contains non-hierarchical data, that along with data in path component, identifies a resource in the scope of URI's scheme and network location. """ _SplitResultBase.fragment.__doc__ = """ Fragment identifier, that allows indirect identification of a secondary resource by reference to a primary resource and additional identifying information. """ _ParseResultBase.__doc__ = """ ParseResult(scheme, netloc, path, params, query, fragment) A 6-tuple that contains components of a parsed URL. """ _ParseResultBase.scheme.__doc__ = _SplitResultBase.scheme.__doc__ _ParseResultBase.netloc.__doc__ = _SplitResultBase.netloc.__doc__ _ParseResultBase.path.__doc__ = _SplitResultBase.path.__doc__ _ParseResultBase.params.__doc__ = """ Parameters for last path element used to dereference the URI in order to provide access to perform some operation on the resource. """ _ParseResultBase.query.__doc__ = _SplitResultBase.query.__doc__ _ParseResultBase.fragment.__doc__ = _SplitResultBase.fragment.__doc__ # For backwards compatibility, alias _NetlocResultMixinStr # ResultBase is no longer part of the documented API, but it is # retained since deprecating it isn't worth the hassle ResultBase = _NetlocResultMixinStr # Structured result objects for string data class DefragResult(_DefragResultBase, _ResultMixinStr): __slots__ = () def geturl(self): if self.fragment: return self.url + '#' + self.fragment else: return self.url class SplitResult(_SplitResultBase, _NetlocResultMixinStr): __slots__ = () def geturl(self): return urlunsplit(self) class ParseResult(_ParseResultBase, _NetlocResultMixinStr): __slots__ = () def geturl(self): return urlunparse(self) # Structured result objects for bytes data class DefragResultBytes(_DefragResultBase, _ResultMixinBytes): __slots__ = () def geturl(self): if self.fragment: return self.url + b'#' + self.fragment else: return self.url class SplitResultBytes(_SplitResultBase, _NetlocResultMixinBytes): __slots__ = () def geturl(self): return urlunsplit(self) class ParseResultBytes(_ParseResultBase, _NetlocResultMixinBytes): __slots__ = () def geturl(self): return urlunparse(self) # Set up the encode/decode result pairs def _fix_result_transcoding(): _result_pairs = ( (DefragResult, DefragResultBytes), (SplitResult, SplitResultBytes), (ParseResult, ParseResultBytes), ) for _decoded, _encoded in _result_pairs: _decoded._encoded_counterpart = _encoded _encoded._decoded_counterpart = _decoded _fix_result_transcoding() del _fix_result_transcoding def urlparse(url, scheme='', allow_fragments=True): """Parse a URL into 6 components: :///;?# The result is a named 6-tuple with fields corresponding to the above. It is either a ParseResult or ParseResultBytes object, depending on the type of the url parameter. The username, password, hostname, and port sub-components of netloc can also be accessed as attributes of the returned object. The scheme argument provides the default value of the scheme component when no scheme is found in url. If allow_fragments is False, no attempt is made to separate the fragment component from the previous component, which can be either path or query. Note that % escapes are not expanded. """ url, scheme, _coerce_result = _coerce_args(url, scheme) splitresult = urlsplit(url, scheme, allow_fragments) scheme, netloc, url, query, fragment = splitresult if scheme in uses_params and ';' in url: url, params = _splitparams(url) else: params = '' result = ParseResult(scheme, netloc, url, params, query, fragment) return _coerce_result(result) def _splitparams(url): if '/' in url: i = url.find(';', url.rfind('/')) if i < 0: return url, '' else: i = url.find(';') return url[:i], url[i+1:] def _splitnetloc(url, start=0): delim = len(url) # position of end of domain part of url, default is end for c in '/?#': # look for delimiters; the order is NOT important wdelim = url.find(c, start) # find first of this delim if wdelim >= 0: # if found delim = min(delim, wdelim) # use earliest delim position return url[start:delim], url[delim:] # return (domain, rest) def _checknetloc(netloc): if not netloc or netloc.isascii(): return # looking for characters like \u2100 that expand to 'a/c' # IDNA uses NFKC equivalence, so normalize for this check import unicodedata n = netloc.replace('@', '') # ignore characters already included n = n.replace(':', '') # but not the surrounding text n = n.replace('#', '') n = n.replace('?', '') netloc2 = unicodedata.normalize('NFKC', n) if n == netloc2: return for c in '/?#@:': if c in netloc2: raise ValueError("netloc '" + netloc + "' contains invalid " + "characters under NFKC normalization") def _check_bracketed_netloc(netloc): # Note that this function must mirror the splitting # done in NetlocResultMixins._hostinfo(). hostname_and_port = netloc.rpartition('@')[2] before_bracket, have_open_br, bracketed = hostname_and_port.partition('[') if have_open_br: # No data is allowed before a bracket. if before_bracket: raise ValueError("Invalid IPv6 URL") hostname, _, port = bracketed.partition(']') # No data is allowed after the bracket but before the port delimiter. if port and not port.startswith(":"): raise ValueError("Invalid IPv6 URL") else: hostname, _, port = hostname_and_port.partition(':') _check_bracketed_host(hostname) # Valid bracketed hosts are defined in # https://www.rfc-editor.org/rfc/rfc3986#page-49 and https://url.spec.whatwg.org/ def _check_bracketed_host(hostname): if hostname.startswith('v'): if not re.match(r"\Av[a-fA-F0-9]+\..+\Z", hostname): raise ValueError(f"IPvFuture address is invalid") else: ip = ipaddress.ip_address(hostname) # Throws Value Error if not IPv6 or IPv4 if isinstance(ip, ipaddress.IPv4Address): raise ValueError(f"An IPv4 address cannot be in brackets") # typed=True avoids BytesWarnings being emitted during cache key # comparison since this API supports both bytes and str input. @functools.lru_cache(typed=True) def urlsplit(url, scheme='', allow_fragments=True): """Parse a URL into 5 components: :///?# The result is a named 5-tuple with fields corresponding to the above. It is either a SplitResult or SplitResultBytes object, depending on the type of the url parameter. The username, password, hostname, and port sub-components of netloc can also be accessed as attributes of the returned object. The scheme argument provides the default value of the scheme component when no scheme is found in url. If allow_fragments is False, no attempt is made to separate the fragment component from the previous component, which can be either path or query. Note that % escapes are not expanded. """ url, scheme, _coerce_result = _coerce_args(url, scheme) # Only lstrip url as some applications rely on preserving trailing space. # (https://url.spec.whatwg.org/#concept-basic-url-parser would strip both) url = url.lstrip(_WHATWG_C0_CONTROL_OR_SPACE) scheme = scheme.strip(_WHATWG_C0_CONTROL_OR_SPACE) for b in _UNSAFE_URL_BYTES_TO_REMOVE: url = url.replace(b, "") scheme = scheme.replace(b, "") allow_fragments = bool(allow_fragments) netloc = query = fragment = '' i = url.find(':') if i > 0 and url[0].isascii() and url[0].isalpha(): for c in url[:i]: if c not in scheme_chars: break else: scheme, url = url[:i].lower(), url[i+1:] if url[:2] == '//': netloc, url = _splitnetloc(url, 2) if (('[' in netloc and ']' not in netloc) or (']' in netloc and '[' not in netloc)): raise ValueError("Invalid IPv6 URL") if '[' in netloc and ']' in netloc: _check_bracketed_netloc(netloc) if allow_fragments and '#' in url: url, fragment = url.split('#', 1) if '?' in url: url, query = url.split('?', 1) _checknetloc(netloc) v = SplitResult(scheme, netloc, url, query, fragment) return _coerce_result(v) def urlunparse(components): """Put a parsed URL back together again. This may result in a slightly different, but equivalent URL, if the URL that was parsed originally had redundant delimiters, e.g. a ? with an empty query (the draft states that these are equivalent).""" scheme, netloc, url, params, query, fragment, _coerce_result = ( _coerce_args(*components)) if params: url = "%s;%s" % (url, params) return _coerce_result(urlunsplit((scheme, netloc, url, query, fragment))) def urlunsplit(components): """Combine the elements of a tuple as returned by urlsplit() into a complete URL as a string. The data argument can be any five-item iterable. This may result in a slightly different, but equivalent URL, if the URL that was parsed originally had unnecessary delimiters (for example, a ? with an empty query; the RFC states that these are equivalent).""" scheme, netloc, url, query, fragment, _coerce_result = ( _coerce_args(*components)) if netloc or (scheme and scheme in uses_netloc) or url[:2] == '//': if url and url[:1] != '/': url = '/' + url url = '//' + (netloc or '') + url if scheme: url = scheme + ':' + url if query: url = url + '?' + query if fragment: url = url + '#' + fragment return _coerce_result(url) def urljoin(base, url, allow_fragments=True): """Join a base URL and a possibly relative URL to form an absolute interpretation of the latter.""" if not base: return url if not url: return base base, url, _coerce_result = _coerce_args(base, url) bscheme, bnetloc, bpath, bparams, bquery, bfragment = \ urlparse(base, '', allow_fragments) scheme, netloc, path, params, query, fragment = \ urlparse(url, bscheme, allow_fragments) if scheme != bscheme or scheme not in uses_relative: return _coerce_result(url) if scheme in uses_netloc: if netloc: return _coerce_result(urlunparse((scheme, netloc, path, params, query, fragment))) netloc = bnetloc if not path and not params: path = bpath params = bparams if not query: query = bquery return _coerce_result(urlunparse((scheme, netloc, path, params, query, fragment))) base_parts = bpath.split('/') if base_parts[-1] != '': # the last item is not a directory, so will not be taken into account # in resolving the relative path del base_parts[-1] # for rfc3986, ignore all base path should the first character be root. if path[:1] == '/': segments = path.split('/') else: segments = base_parts + path.split('/') # filter out elements that would cause redundant slashes on re-joining # the resolved_path segments[1:-1] = filter(None, segments[1:-1]) resolved_path = [] for seg in segments: if seg == '..': try: resolved_path.pop() except IndexError: # ignore any .. segments that would otherwise cause an IndexError # when popped from resolved_path if resolving for rfc3986 pass elif seg == '.': continue else: resolved_path.append(seg) if segments[-1] in ('.', '..'): # do some post-processing here. if the last segment was a relative dir, # then we need to append the trailing '/' resolved_path.append('') return _coerce_result(urlunparse((scheme, netloc, '/'.join( resolved_path) or '/', params, query, fragment))) def urldefrag(url): """Removes any existing fragment from URL. Returns a tuple of the defragmented URL and the fragment. If the URL contained no fragments, the second element is the empty string. """ url, _coerce_result = _coerce_args(url) if '#' in url: s, n, p, a, q, frag = urlparse(url) defrag = urlunparse((s, n, p, a, q, '')) else: frag = '' defrag = url return _coerce_result(DefragResult(defrag, frag)) _hexdig = '0123456789ABCDEFabcdef' _hextobyte = None def unquote_to_bytes(string): """unquote_to_bytes('abc%20def') -> b'abc def'.""" # Note: strings are encoded as UTF-8. This is only an issue if it contains # unescaped non-ASCII characters, which URIs should not. if not string: # Is it a string-like object? string.split return b'' if isinstance(string, str): string = string.encode('utf-8') bits = string.split(b'%') if len(bits) == 1: return string res = [bits[0]] append = res.append # Delay the initialization of the table to not waste memory # if the function is never called global _hextobyte if _hextobyte is None: _hextobyte = {(a + b).encode(): bytes.fromhex(a + b) for a in _hexdig for b in _hexdig} for item in bits[1:]: try: append(_hextobyte[item[:2]]) append(item[2:]) except KeyError: append(b'%') append(item) return b''.join(res) _asciire = re.compile('([\x00-\x7f]+)') def unquote(string, encoding='utf-8', errors='replace'): """Replace %xx escapes by their single-character equivalent. The optional encoding and errors parameters specify how to decode percent-encoded sequences into Unicode characters, as accepted by the bytes.decode() method. By default, percent-encoded sequences are decoded with UTF-8, and invalid sequences are replaced by a placeholder character. unquote('abc%20def') -> 'abc def'. """ if isinstance(string, bytes): return unquote_to_bytes(string).decode(encoding, errors) if '%' not in string: string.split return string if encoding is None: encoding = 'utf-8' if errors is None: errors = 'replace' bits = _asciire.split(string) res = [bits[0]] append = res.append for i in range(1, len(bits), 2): append(unquote_to_bytes(bits[i]).decode(encoding, errors)) append(bits[i + 1]) return ''.join(res) def parse_qs(qs, keep_blank_values=False, strict_parsing=False, encoding='utf-8', errors='replace', max_num_fields=None, separator='&'): """Parse a query given as a string argument. Arguments: qs: percent-encoded query string to be parsed keep_blank_values: flag indicating whether blank values in percent-encoded queries should be treated as blank strings. A true value indicates that blanks should be retained as blank strings. The default false value indicates that blank values are to be ignored and treated as if they were not included. strict_parsing: flag indicating what to do with parsing errors. If false (the default), errors are silently ignored. If true, errors raise a ValueError exception. encoding and errors: specify how to decode percent-encoded sequences into Unicode characters, as accepted by the bytes.decode() method. max_num_fields: int. If set, then throws a ValueError if there are more than n fields read by parse_qsl(). separator: str. The symbol to use for separating the query arguments. Defaults to &. Returns a dictionary. """ parsed_result = {} pairs = parse_qsl(qs, keep_blank_values, strict_parsing, encoding=encoding, errors=errors, max_num_fields=max_num_fields, separator=separator) for name, value in pairs: if name in parsed_result: parsed_result[name].append(value) else: parsed_result[name] = [value] return parsed_result def parse_qsl(qs, keep_blank_values=False, strict_parsing=False, encoding='utf-8', errors='replace', max_num_fields=None, separator='&'): """Parse a query given as a string argument. Arguments: qs: percent-encoded query string to be parsed keep_blank_values: flag indicating whether blank values in percent-encoded queries should be treated as blank strings. A true value indicates that blanks should be retained as blank strings. The default false value indicates that blank values are to be ignored and treated as if they were not included. strict_parsing: flag indicating what to do with parsing errors. If false (the default), errors are silently ignored. If true, errors raise a ValueError exception. encoding and errors: specify how to decode percent-encoded sequences into Unicode characters, as accepted by the bytes.decode() method. max_num_fields: int. If set, then throws a ValueError if there are more than n fields read by parse_qsl(). separator: str. The symbol to use for separating the query arguments. Defaults to &. Returns a list, as G-d intended. """ if not separator or not isinstance(separator, (str, bytes)): raise ValueError("Separator must be of type string or bytes.") if isinstance(qs, str): if not isinstance(separator, str): separator = str(separator, 'ascii') eq = '=' def _unquote(s): return unquote_plus(s, encoding=encoding, errors=errors) else: if not qs: return [] # Use memoryview() to reject integers and iterables, # acceptable by the bytes constructor. qs = bytes(memoryview(qs)) if isinstance(separator, str): separator = bytes(separator, 'ascii') eq = b'=' def _unquote(s): return unquote_to_bytes(s.replace(b'+', b' ')) if not qs: return [] # If max_num_fields is defined then check that the number of fields # is less than max_num_fields. This prevents a memory exhaustion DOS # attack via post bodies with many fields. if max_num_fields is not None: num_fields = 1 + qs.count(separator) if max_num_fields < num_fields: raise ValueError('Max number of fields exceeded') r = [] for name_value in qs.split(separator): if name_value or strict_parsing: name, has_eq, value = name_value.partition(eq) if not has_eq and strict_parsing: raise ValueError("bad query field: %r" % (name_value,)) if value or keep_blank_values: name = _unquote(name) value = _unquote(value) r.append((name, value)) return r def unquote_plus(string, encoding='utf-8', errors='replace'): """Like unquote(), but also replace plus signs by spaces, as required for unquoting HTML form values. unquote_plus('%7e/abc+def') -> '~/abc def' """ string = string.replace('+', ' ') return unquote(string, encoding, errors) _ALWAYS_SAFE = frozenset(b'ABCDEFGHIJKLMNOPQRSTUVWXYZ' b'abcdefghijklmnopqrstuvwxyz' b'0123456789' b'_.-~') _ALWAYS_SAFE_BYTES = bytes(_ALWAYS_SAFE) def __getattr__(name): if name == 'Quoter': warnings.warn('Deprecated in 3.11. ' 'urllib.parse.Quoter will be removed in Python 3.14. ' 'It was not intended to be a public API.', DeprecationWarning, stacklevel=2) return _Quoter raise AttributeError(f'module {__name__!r} has no attribute {name!r}') class _Quoter(dict): """A mapping from bytes numbers (in range(0,256)) to strings. String values are percent-encoded byte values, unless the key < 128, and in either of the specified safe set, or the always safe set. """ # Keeps a cache internally, via __missing__, for efficiency (lookups # of cached keys don't call Python code at all). def __init__(self, safe): """safe: bytes object.""" self.safe = _ALWAYS_SAFE.union(safe) def __repr__(self): return f"" def __missing__(self, b): # Handle a cache miss. Store quoted string in cache and return. res = chr(b) if b in self.safe else '%{:02X}'.format(b) self[b] = res return res def quote(string, safe='/', encoding=None, errors=None): """quote('abc def') -> 'abc%20def' Each part of a URL, e.g. the path info, the query, etc., has a different set of reserved characters that must be quoted. The quote function offers a cautious (not minimal) way to quote a string for most of these parts. RFC 3986 Uniform Resource Identifier (URI): Generic Syntax lists the following (un)reserved characters. unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" reserved = gen-delims / sub-delims gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@" sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=" Each of the reserved characters is reserved in some component of a URL, but not necessarily in all of them. The quote function %-escapes all characters that are neither in the unreserved chars ("always safe") nor the additional chars set via the safe arg. The default for the safe arg is '/'. The character is reserved, but in typical usage the quote function is being called on a path where the existing slash characters are to be preserved. Python 3.7 updates from using RFC 2396 to RFC 3986 to quote URL strings. Now, "~" is included in the set of unreserved characters. string and safe may be either str or bytes objects. encoding and errors must not be specified if string is a bytes object. The optional encoding and errors parameters specify how to deal with non-ASCII characters, as accepted by the str.encode method. By default, encoding='utf-8' (characters are encoded with UTF-8), and errors='strict' (unsupported characters raise a UnicodeEncodeError). """ if isinstance(string, str): if not string: return string if encoding is None: encoding = 'utf-8' if errors is None: errors = 'strict' string = string.encode(encoding, errors) else: if encoding is not None: raise TypeError("quote() doesn't support 'encoding' for bytes") if errors is not None: raise TypeError("quote() doesn't support 'errors' for bytes") return quote_from_bytes(string, safe) def quote_plus(string, safe='', encoding=None, errors=None): """Like quote(), but also replace ' ' with '+', as required for quoting HTML form values. Plus signs in the original string are escaped unless they are included in safe. It also does not have safe default to '/'. """ # Check if ' ' in string, where string may either be a str or bytes. If # there are no spaces, the regular quote will produce the right answer. if ((isinstance(string, str) and ' ' not in string) or (isinstance(string, bytes) and b' ' not in string)): return quote(string, safe, encoding, errors) if isinstance(safe, str): space = ' ' else: space = b' ' string = quote(string, safe + space, encoding, errors) return string.replace(' ', '+') # Expectation: A typical program is unlikely to create more than 5 of these. @functools.lru_cache def _byte_quoter_factory(safe): return _Quoter(safe).__getitem__ def quote_from_bytes(bs, safe='/'): """Like quote(), but accepts a bytes object rather than a str, and does not perform string-to-bytes encoding. It always returns an ASCII string. quote_from_bytes(b'abc def\x3f') -> 'abc%20def%3f' """ if not isinstance(bs, (bytes, bytearray)): raise TypeError("quote_from_bytes() expected bytes") if not bs: return '' if isinstance(safe, str): # Normalize 'safe' by converting to bytes and removing non-ASCII chars safe = safe.encode('ascii', 'ignore') else: # List comprehensions are faster than generator expressions. safe = bytes([c for c in safe if c < 128]) if not bs.rstrip(_ALWAYS_SAFE_BYTES + safe): return bs.decode() quoter = _byte_quoter_factory(safe) return ''.join([quoter(char) for char in bs]) def urlencode(query, doseq=False, safe='', encoding=None, errors=None, quote_via=quote_plus): """Encode a dict or sequence of two-element tuples into a URL query string. If any values in the query arg are sequences and doseq is true, each sequence element is converted to a separate parameter. If the query arg is a sequence of two-element tuples, the order of the parameters in the output will match the order of parameters in the input. The components of a query arg may each be either a string or a bytes type. The safe, encoding, and errors parameters are passed down to the function specified by quote_via (encoding and errors only if a component is a str). """ if hasattr(query, "items"): query = query.items() else: # It's a bother at times that strings and string-like objects are # sequences. try: # non-sequence items should not work with len() # non-empty strings will fail this if len(query) and not isinstance(query[0], tuple): raise TypeError # Zero-length sequences of all types will get here and succeed, # but that's a minor nit. Since the original implementation # allowed empty dicts that type of behavior probably should be # preserved for consistency except TypeError as err: raise TypeError("not a valid non-string sequence " "or mapping object") from err l = [] if not doseq: for k, v in query: if isinstance(k, bytes): k = quote_via(k, safe) else: k = quote_via(str(k), safe, encoding, errors) if isinstance(v, bytes): v = quote_via(v, safe) else: v = quote_via(str(v), safe, encoding, errors) l.append(k + '=' + v) else: for k, v in query: if isinstance(k, bytes): k = quote_via(k, safe) else: k = quote_via(str(k), safe, encoding, errors) if isinstance(v, bytes): v = quote_via(v, safe) l.append(k + '=' + v) elif isinstance(v, str): v = quote_via(v, safe, encoding, errors) l.append(k + '=' + v) else: try: # Is this a sufficient test for sequence-ness? x = len(v) except TypeError: # not a sequence v = quote_via(str(v), safe, encoding, errors) l.append(k + '=' + v) else: # loop over the sequence for elt in v: if isinstance(elt, bytes): elt = quote_via(elt, safe) else: elt = quote_via(str(elt), safe, encoding, errors) l.append(k + '=' + elt) return '&'.join(l) def to_bytes(url): warnings.warn("urllib.parse.to_bytes() is deprecated as of 3.8", DeprecationWarning, stacklevel=2) return _to_bytes(url) def _to_bytes(url): """to_bytes(u"URL") --> 'URL'.""" # Most URL schemes require ASCII. If that changes, the conversion # can be relaxed. # XXX get rid of to_bytes() if isinstance(url, str): try: url = url.encode("ASCII").decode() except UnicodeError: raise UnicodeError("URL " + repr(url) + " contains non-ASCII characters") return url def unwrap(url): """Transform a string like '' into 'scheme://host/path'. The string is returned unchanged if it's not a wrapped URL. """ url = str(url).strip() if url[:1] == '<' and url[-1:] == '>': url = url[1:-1].strip() if url[:4] == 'URL:': url = url[4:].strip() return url def splittype(url): warnings.warn("urllib.parse.splittype() is deprecated as of 3.8, " "use urllib.parse.urlparse() instead", DeprecationWarning, stacklevel=2) return _splittype(url) _typeprog = None def _splittype(url): """splittype('type:opaquestring') --> 'type', 'opaquestring'.""" global _typeprog if _typeprog is None: _typeprog = re.compile('([^/:]+):(.*)', re.DOTALL) match = _typeprog.match(url) if match: scheme, data = match.groups() return scheme.lower(), data return None, url def splithost(url): warnings.warn("urllib.parse.splithost() is deprecated as of 3.8, " "use urllib.parse.urlparse() instead", DeprecationWarning, stacklevel=2) return _splithost(url) _hostprog = None def _splithost(url): """splithost('//host[:port]/path') --> 'host[:port]', '/path'.""" global _hostprog if _hostprog is None: _hostprog = re.compile('//([^/#?]*)(.*)', re.DOTALL) match = _hostprog.match(url) if match: host_port, path = match.groups() if path and path[0] != '/': path = '/' + path return host_port, path return None, url def splituser(host): warnings.warn("urllib.parse.splituser() is deprecated as of 3.8, " "use urllib.parse.urlparse() instead", DeprecationWarning, stacklevel=2) return _splituser(host) def _splituser(host): """splituser('user[:passwd]@host[:port]') --> 'user[:passwd]', 'host[:port]'.""" user, delim, host = host.rpartition('@') return (user if delim else None), host def splitpasswd(user): warnings.warn("urllib.parse.splitpasswd() is deprecated as of 3.8, " "use urllib.parse.urlparse() instead", DeprecationWarning, stacklevel=2) return _splitpasswd(user) def _splitpasswd(user): """splitpasswd('user:passwd') -> 'user', 'passwd'.""" user, delim, passwd = user.partition(':') return user, (passwd if delim else None) def splitport(host): warnings.warn("urllib.parse.splitport() is deprecated as of 3.8, " "use urllib.parse.urlparse() instead", DeprecationWarning, stacklevel=2) return _splitport(host) # splittag('/path#tag') --> '/path', 'tag' _portprog = None def _splitport(host): """splitport('host:port') --> 'host', 'port'.""" global _portprog if _portprog is None: _portprog = re.compile('(.*):([0-9]*)', re.DOTALL) match = _portprog.fullmatch(host) if match: host, port = match.groups() if port: return host, port return host, None def splitnport(host, defport=-1): warnings.warn("urllib.parse.splitnport() is deprecated as of 3.8, " "use urllib.parse.urlparse() instead", DeprecationWarning, stacklevel=2) return _splitnport(host, defport) def _splitnport(host, defport=-1): """Split host and port, returning numeric port. Return given default port if no ':' found; defaults to -1. Return numerical port if a valid number is found after ':'. Return None if ':' but not a valid number.""" host, delim, port = host.rpartition(':') if not delim: host = port elif port: if port.isdigit() and port.isascii(): nport = int(port) else: nport = None return host, nport return host, defport def splitquery(url): warnings.warn("urllib.parse.splitquery() is deprecated as of 3.8, " "use urllib.parse.urlparse() instead", DeprecationWarning, stacklevel=2) return _splitquery(url) def _splitquery(url): """splitquery('/path?query') --> '/path', 'query'.""" path, delim, query = url.rpartition('?') if delim: return path, query return url, None def splittag(url): warnings.warn("urllib.parse.splittag() is deprecated as of 3.8, " "use urllib.parse.urlparse() instead", DeprecationWarning, stacklevel=2) return _splittag(url) def _splittag(url): """splittag('/path#tag') --> '/path', 'tag'.""" path, delim, tag = url.rpartition('#') if delim: return path, tag return url, None def splitattr(url): warnings.warn("urllib.parse.splitattr() is deprecated as of 3.8, " "use urllib.parse.urlparse() instead", DeprecationWarning, stacklevel=2) return _splitattr(url) def _splitattr(url): """splitattr('/path;attr1=value1;attr2=value2;...') -> '/path', ['attr1=value1', 'attr2=value2', ...].""" words = url.split(';') return words[0], words[1:] def splitvalue(attr): warnings.warn("urllib.parse.splitvalue() is deprecated as of 3.8, " "use urllib.parse.parse_qsl() instead", DeprecationWarning, stacklevel=2) return _splitvalue(attr) def _splitvalue(attr): """splitvalue('attr=value') --> 'attr', 'value'.""" attr, delim, value = attr.partition('=') return attr, (value if delim else None) response.py000064400000004471151026775530006775 0ustar00"""Response classes used by urllib. The base class, addbase, defines a minimal file-like interface, including read() and readline(). The typical response object is an addinfourl instance, which defines an info() method that returns headers and a geturl() method that returns the url. """ import tempfile __all__ = ['addbase', 'addclosehook', 'addinfo', 'addinfourl'] class addbase(tempfile._TemporaryFileWrapper): """Base class for addinfo and addclosehook. Is a good idea for garbage collection.""" # XXX Add a method to expose the timeout on the underlying socket? def __init__(self, fp): super(addbase, self).__init__(fp, '', delete=False) # Keep reference around as this was part of the original API. self.fp = fp def __repr__(self): return '<%s at %r whose fp = %r>' % (self.__class__.__name__, id(self), self.file) def __enter__(self): if self.fp.closed: raise ValueError("I/O operation on closed file") return self def __exit__(self, type, value, traceback): self.close() class addclosehook(addbase): """Class to add a close hook to an open file.""" def __init__(self, fp, closehook, *hookargs): super(addclosehook, self).__init__(fp) self.closehook = closehook self.hookargs = hookargs def close(self): try: closehook = self.closehook hookargs = self.hookargs if closehook: self.closehook = None self.hookargs = None closehook(*hookargs) finally: super(addclosehook, self).close() class addinfo(addbase): """class to add an info() method to an open file.""" def __init__(self, fp, headers): super(addinfo, self).__init__(fp) self.headers = headers def info(self): return self.headers class addinfourl(addinfo): """class to add info() and geturl() methods to an open file.""" def __init__(self, fp, headers, url, code=None): super(addinfourl, self).__init__(fp, headers) self.url = url self.code = code @property def status(self): return self.code def getcode(self): return self.code def geturl(self): return self.url robotparser.py000064400000022320151026775530007472 0ustar00""" robotparser.py Copyright (C) 2000 Bastian Kleineidam You can choose between two licenses when using this package: 1) GNU GPLv2 2) PSF license for Python 2.2 The robots.txt Exclusion Protocol is implemented as specified in http://www.robotstxt.org/norobots-rfc.txt """ import collections import urllib.parse import urllib.request __all__ = ["RobotFileParser"] RequestRate = collections.namedtuple("RequestRate", "requests seconds") class RobotFileParser: """ This class provides a set of methods to read, parse and answer questions about a single robots.txt file. """ def __init__(self, url=''): self.entries = [] self.sitemaps = [] self.default_entry = None self.disallow_all = False self.allow_all = False self.set_url(url) self.last_checked = 0 def mtime(self): """Returns the time the robots.txt file was last fetched. This is useful for long-running web spiders that need to check for new robots.txt files periodically. """ return self.last_checked def modified(self): """Sets the time the robots.txt file was last fetched to the current time. """ import time self.last_checked = time.time() def set_url(self, url): """Sets the URL referring to a robots.txt file.""" self.url = url self.host, self.path = urllib.parse.urlparse(url)[1:3] def read(self): """Reads the robots.txt URL and feeds it to the parser.""" try: f = urllib.request.urlopen(self.url) except urllib.error.HTTPError as err: if err.code in (401, 403): self.disallow_all = True elif err.code >= 400 and err.code < 500: self.allow_all = True else: raw = f.read() self.parse(raw.decode("utf-8").splitlines()) def _add_entry(self, entry): if "*" in entry.useragents: # the default entry is considered last if self.default_entry is None: # the first default entry wins self.default_entry = entry else: self.entries.append(entry) def parse(self, lines): """Parse the input lines from a robots.txt file. We allow that a user-agent: line is not preceded by one or more blank lines. """ # states: # 0: start state # 1: saw user-agent line # 2: saw an allow or disallow line state = 0 entry = Entry() self.modified() for line in lines: if not line: if state == 1: entry = Entry() state = 0 elif state == 2: self._add_entry(entry) entry = Entry() state = 0 # remove optional comment and strip line i = line.find('#') if i >= 0: line = line[:i] line = line.strip() if not line: continue line = line.split(':', 1) if len(line) == 2: line[0] = line[0].strip().lower() line[1] = urllib.parse.unquote(line[1].strip()) if line[0] == "user-agent": if state == 2: self._add_entry(entry) entry = Entry() entry.useragents.append(line[1]) state = 1 elif line[0] == "disallow": if state != 0: entry.rulelines.append(RuleLine(line[1], False)) state = 2 elif line[0] == "allow": if state != 0: entry.rulelines.append(RuleLine(line[1], True)) state = 2 elif line[0] == "crawl-delay": if state != 0: # before trying to convert to int we need to make # sure that robots.txt has valid syntax otherwise # it will crash if line[1].strip().isdigit(): entry.delay = int(line[1]) state = 2 elif line[0] == "request-rate": if state != 0: numbers = line[1].split('/') # check if all values are sane if (len(numbers) == 2 and numbers[0].strip().isdigit() and numbers[1].strip().isdigit()): entry.req_rate = RequestRate(int(numbers[0]), int(numbers[1])) state = 2 elif line[0] == "sitemap": # According to http://www.sitemaps.org/protocol.html # "This directive is independent of the user-agent line, # so it doesn't matter where you place it in your file." # Therefore we do not change the state of the parser. self.sitemaps.append(line[1]) if state == 2: self._add_entry(entry) def can_fetch(self, useragent, url): """using the parsed robots.txt decide if useragent can fetch url""" if self.disallow_all: return False if self.allow_all: return True # Until the robots.txt file has been read or found not # to exist, we must assume that no url is allowable. # This prevents false positives when a user erroneously # calls can_fetch() before calling read(). if not self.last_checked: return False # search for given user agent matches # the first match counts parsed_url = urllib.parse.urlparse(urllib.parse.unquote(url)) url = urllib.parse.urlunparse(('','',parsed_url.path, parsed_url.params,parsed_url.query, parsed_url.fragment)) url = urllib.parse.quote(url) if not url: url = "/" for entry in self.entries: if entry.applies_to(useragent): return entry.allowance(url) # try the default entry last if self.default_entry: return self.default_entry.allowance(url) # agent not found ==> access granted return True def crawl_delay(self, useragent): if not self.mtime(): return None for entry in self.entries: if entry.applies_to(useragent): return entry.delay if self.default_entry: return self.default_entry.delay return None def request_rate(self, useragent): if not self.mtime(): return None for entry in self.entries: if entry.applies_to(useragent): return entry.req_rate if self.default_entry: return self.default_entry.req_rate return None def site_maps(self): if not self.sitemaps: return None return self.sitemaps def __str__(self): entries = self.entries if self.default_entry is not None: entries = entries + [self.default_entry] return '\n\n'.join(map(str, entries)) class RuleLine: """A rule line is a single "Allow:" (allowance==True) or "Disallow:" (allowance==False) followed by a path.""" def __init__(self, path, allowance): if path == '' and not allowance: # an empty value means allow all allowance = True path = urllib.parse.urlunparse(urllib.parse.urlparse(path)) self.path = urllib.parse.quote(path) self.allowance = allowance def applies_to(self, filename): return self.path == "*" or filename.startswith(self.path) def __str__(self): return ("Allow" if self.allowance else "Disallow") + ": " + self.path class Entry: """An entry has one or more user-agents and zero or more rulelines""" def __init__(self): self.useragents = [] self.rulelines = [] self.delay = None self.req_rate = None def __str__(self): ret = [] for agent in self.useragents: ret.append(f"User-agent: {agent}") if self.delay is not None: ret.append(f"Crawl-delay: {self.delay}") if self.req_rate is not None: rate = self.req_rate ret.append(f"Request-rate: {rate.requests}/{rate.seconds}") ret.extend(map(str, self.rulelines)) return '\n'.join(ret) def applies_to(self, useragent): """check if this entry applies to the specified agent""" # split the name token and make it lower case useragent = useragent.split("/")[0].lower() for agent in self.useragents: if agent == '*': # we have the catch-all agent return True agent = agent.lower() if agent in useragent: return True return False def allowance(self, filename): """Preconditions: - our agent applies to this entry - filename is URL decoded""" for line in self.rulelines: if line.applies_to(filename): return line.allowance return True __pycache__/request.cpython-311.pyc000064400000367124151026775530013176 0ustar00 !A?hw>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+ ddl,Z,dZ-n #e.$rdZ-YnwxYwgdZ/d e j0dd zZ1da2de j3fddddd d Z4d Z5gZ6dgdZ7dZ8e 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 ddLlbmcZcmdZdndMZcdNZdiZeGdOdPZfGdQdRefZgdahdSZidajdTZkdaldUZmdandVZoGdWdXZpdYZqdhdZZrd[Zsd\Zte jud]krdd^lvmwZwmxZxd_Zyd`ZzdaZ{dbZ|dSejadKkrdcZ}ddZ|deZ~dfZ{dSeqZ|erZ{dS)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|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 '/usr/lib64/python3.11/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)DDD'   . .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)DDD' ,, +..($,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) r ipaddressrrrrlrrrRgroupcount) rproxy_settingsrrrrrrhostIPrrJrmasks rS_proxy_bypass_macosx_sysconfr s 88888888%%NHdPPP $ * + 4 F [[**++       ##L"55h H. 6 6 =V/6!''!**%%D771::D|AGGAJJ,,S11A5648}}axx4"999D$DDL11tt2WT5 ! ! 44  5sAAAcddlm}t|\}}|d}|D]3}|}|dkrd|vrdS$|||rdS4dS)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" rrr1zrTF)rrrr)roverriderrproxy_overriders rS_proxy_bypass_winreg_overriderG s GD!^^C((Nzz|| 9  $tt WT4  44  5rTdarwin)_get_proxy_settings _get_proxiesc>t}t||SrV)rr)rrs rSproxy_bypass_macosx_sysconfrb 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_sysconfrf 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 rSrrp s5)**  5+D':: :.t44 4rTc:tp tSrV)rrrrTrSr6r6} 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_registryr 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&''@+>+@+@@rTcB ddl}n#t$rYdSwxYw ||jd}||dd}t ||dd}n#t $rYdSwxYw|r|sdSt||S)NrFrr ProxyOverride)rrrrrrr}r)rrrr proxyOverrides rSproxy_bypass_registryr s  MMMM   55  %~~f.FN P P  --.>/<>>>?AK 3 34D5D!F!FFG!IJJMM   55  - 5,T=AAAs A A:: BBc`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.rtrurrrrrplatform_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<<<@0<8::::::::BBB 5 5 5GGGGGW__///bAAABBB( / / / / /(J+LLLs>BBB__pycache__/parse.cpython-311.opt-1.pyc000064400000154354151026775530013556 0ustar00 !A?h$2dZddlmZddlZddlZddlZddlZddlZddlZgdZ gdZ gdZ gdZ gdZ gd Zgd Zd Zd Zgd ZdZdZdZdZeefdZeefdZdZGddeZGddeZGddeZGddeeZGddeeZedd Z ed!d"Z!ed#d$Z"d%e _d&e j#_d'e j$_d(e!_d)e!j%_d*e!j&_d+e!j'_d,e!j(_d-e!j$_d.e"_e!j%je"j%_e!j&je"j&_e!j'je"j'_d/e"j)_e!j(je"j(_e!j$je"j$_eZ*Gd0de eZ+Gd1d!e!eZ,Gd2d#e"eZ-Gd3d4e eZ.Gd5d6e!eZ/Gd7d8e"eZ0d9Z1e1[1dud<Z2d=Z3dvd>Z4d?Z5d@Z6dAZ7ej8d;BdudCZ9dDZ:dEZ;dwdFZda?dIZ@ejAdJZBdxdMZC dydPZD dydQZEdxdRZFeGdSZHeIeHZJdTZKGdUdVeLZMdzdXZNd{dYZOej8dZZPd|d[ZQdNd:ddeOfd\ZRd]ZSd^ZTd_ZUd`ZVdaWdaZXdbZYdaZdcZ[ddZ\deZ]dfZ^dgZ_dhZ`daadiZbd}dkZcd}dlZddmZednZfdoZgdpZhdqZidrZjdsZkdtZldS)~a3Parse (absolute and relative) URLs. urlparse module is based upon the following RFC specifications. RFC 3986 (STD66): "Uniform Resource Identifiers" by T. Berners-Lee, R. Fielding and L. Masinter, January 2005. RFC 2732 : "Format for Literal IPv6 Addresses in URL's by R.Hinden, B.Carpenter and L.Masinter, December 1999. RFC 2396: "Uniform Resource Identifiers (URI)": Generic Syntax by T. Berners-Lee, R. Fielding, and L. Masinter, August 1998. RFC 2368: "The mailto URL scheme", by P.Hoffman , L Masinter, J. Zawinski, July 1998. RFC 1808: "Relative Uniform Resource Locators", by R. Fielding, UC Irvine, June 1995. RFC 1738: "Uniform Resource Locators (URL)" by T. Berners-Lee, L. Masinter, M. McCahill, December 1994 RFC 3986 is considered the current standard and any future changes to urlparse module should conform with it. The urlparse module is currently not entirely compliant with this RFC due to defacto scenarios for parsing, and for backward compatibility purposes, some parsing quirks from older RFCs are retained. The testcases in test_urlparse.py provides a good indicator of parsing behavior. The WHATWG URL Parser spec should also be considered. We are not compliant with it either due to existing user code API behavior expectations (Hyrum's Law). It serves as a useful guide when making changes. ) namedtupleN)urlparse urlunparseurljoin urldefragurlsplit urlunsplit urlencodeparse_qs parse_qslquote quote_plusquote_from_bytesunquote unquote_plusunquote_to_bytes DefragResult ParseResult SplitResultDefragResultBytesParseResultBytesSplitResultBytes)ftphttpgophernntpimapwaisfilehttpsshttpmmsprosperortsprtspsrtspusftpsvnsvn+sshwswss)rrrrrtelnetrrr r#r!r"snewsr$r%r&r'rsyncr)r*r(nfsgitzgit+sshr+r,)rrhdlr$rrr!r"r%r&r'sipsipsr#r(tel) rr2mailtonewsr-rrr.r3r4) rrrrr!r"r#rr%r&r'r3r4) rrr2rrr7rrr!r"r.r r$zAabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-.z!  )   cjttdS)zDClear internal performance caches. Undocumented; some tests want it.N)r cache_clear_byte_quoter_factory%/usr/lib64/python3.11/urllib/parse.py clear_cacherA^s, $$&&&&&r?asciistrictc|SNr>)objs r@_nooprGls Jr?c.|||SrEencode)rFencodingerrorss r@_encode_resultrMos ::h ' ''r?c>tfd|DS)Nc3LK|]}|r|ndVdS)rNdecode.0xrKrLs r@ z_decode_args..us;GGQq8(F+++bGGGGGGr?)tuple)argsrKrLs ``r@ _decode_argsrXss* GGGGG$GGG G GGr?ct|dt}|ddD],}|r(t|t|krtd-|r |tfzSt |t fzS)Nrz$Cannot mix str and non-str arguments) isinstancestr TypeErrorrGrXrM)rW str_inputargs r@ _coerce_argsr`ws 47C((IABBxDD  D:c3''944BCC Cuh    1 11r?ceZdZdZdZddZdS)_ResultMixinStrz>Standard approach to encoding parsed results from str to bytesr>rBrCc4|jfd|DS)Nc3DK|]}|VdSrErIrRs r@rUz)_ResultMixinStr.encode..1*T*T!188Hf+E+E*T*T*T*T*T*Tr?)_encoded_counterpartselfrKrLs ``r@rJz_ResultMixinStr.encode,(t(*T*T*T*T*Tt*T*T*TUUr?NrBrC)__name__ __module__ __qualname____doc__ __slots__rJr>r?r@rbrb9HHIVVVVVVr?rbceZdZdZdZddZdS)_ResultMixinBytesz>Standard approach to decoding parsed results from bytes to strr>rBrCc4|jfd|DS)Nc3DK|]}|VdSrErPrRs r@rUz+_ResultMixinBytes.decode..rer?)_decoded_counterpartrgs ``r@rQz_ResultMixinBytes.decoderir?Nrj)rkrlrmrnrorQr>r?r@rrrrrpr?rrceZdZdZdZedZedZedZedZ e e j Z dS)_NetlocResultMixinBasezHShared methods for the parsed result objects containing a netloc elementr>c|jdS)Nr _userinforhs r@usernamez_NetlocResultMixinBase.username~a  r?c|jdS)NrZryr{s r@passwordz_NetlocResultMixinBase.passwordr}r?c|jd}|sdSt|trdnd}||\}}}||z|zS)Nr%%) _hostinfor[r\ partitionlower)rhhostname separatorpercentzones r@rz_NetlocResultMixinBase.hostnamesi>!$ 4&h44>CC$ "*"4"4Y"?"?'4~~')D00r?c|jd}|h|r$|rt|}nt d|d|cxkrdksnt d|S)NrZz+Port could not be cast to integer value as rizPort out of range 0-65535)risdigitisasciiint ValueError)rhports r@rz_NetlocResultMixinBase.ports~a   ||~~ Y$,,.. Y4yy !Wt!W!WXXX&&&&&&&& !<=== r?N)rkrlrmrnropropertyr|rrr classmethodtypes GenericAlias__class_getitem__r>r?r@rwrwsRRI !!X!!!X!11X1  X $ E$677r?rwc>eZdZdZedZedZdS)_NetlocResultMixinStrr>c|j}|d\}}}|r|d\}}}|sd}ndx}}||fS)N@:netloc rpartitionrrhruserinfo have_infohostinfor| have_passwordrs r@rzz_NetlocResultMixinStr._userinfosh(.(9(9#(>(>%)X  '080B0B30G0G -HmX  "& &Hx!!r?c |j}|d\}}}|d\}}}|r3|d\}}}|d\}}}n|d\}}}|sd}||fS)Nr[]rrrhr_r have_open_br bracketedrrs r@rz_NetlocResultMixinStr._hostinfos**3//1h%-%7%7%<%<"<  8 ) 3 3C 8 8 Ha,,JAq$$ ( 2 23 7 7 Ha D~r?Nrkrlrmrorrzrr>r?r@rrMI  " "X "  X   r?rc>eZdZdZedZedZdS)_NetlocResultMixinBytesr>c|j}|d\}}}|r|d\}}}|sd}ndx}}||fS)N@:rrs r@rzz!_NetlocResultMixinBytes._userinfosh(.(9(9$(?(?%)X  '080B0B40H0H -HmX  "& &Hx!!r?c |j}|d\}}}|d\}}}|r3|d\}}}|d\}}}n|d\}}}|sd}||fS)Nr[]rrrs r@rz!_NetlocResultMixinBytes._hostinfos**4001h%-%7%7%=%="<  9 ) 3 3D 9 9 Ha--JAq$$ ( 2 24 8 8 Ha D~r?Nrr>r?r@rrrr?rrz url fragmentrz!scheme netloc path query fragmentrz(scheme netloc path params query fragmentz DefragResult(url, fragment) A 2-tuple that contains the url without fragment identifier and the fragment identifier as a separate argument. z$The URL with no fragment identifier.z Fragment identifier separated from URL, that allows indirect identification of a secondary resource by reference to a primary resource and additional identifying information. z SplitResult(scheme, netloc, path, query, fragment) A 5-tuple that contains the different components of a URL. Similar to ParseResult, but does not split params. z%Specifies URL scheme for the request.z0 Network location where the request is made to. z@ The hierarchical path, such as the path to a file to download. z The query component, that contains non-hierarchical data, that along with data in path component, identifies a resource in the scope of URI's scheme and network location. z Fragment identifier, that allows indirect identification of a secondary resource by reference to a primary resource and additional identifying information. zq ParseResult(scheme, netloc, path, params, query, fragment) A 6-tuple that contains components of a parsed URL. z Parameters for last path element used to dereference the URI in order to provide access to perform some operation on the resource. ceZdZdZdZdS)rr>cB|jr|jdz|jzS|jS)N#fragmenturlr{s r@geturlzDefragResult.geturlEs& = 8c>DM1 18Or?Nrkrlrmrorr>r?r@rrC(Ir?ceZdZdZdZdS)rr>c t|SrEr r{s r@rzSplitResult.geturlM$r?Nrr>r?r@rrK(I     r?ceZdZdZdZdS)rr>c t|SrErr{s r@rzParseResult.geturlRrr?Nrr>r?r@rrPrr?ceZdZdZdZdS)rr>cB|jr|jdz|jzS|jS)N#rr{s r@rzDefragResultBytes.geturlXs& = 8d?T]2 28Or?Nrr>r?r@rrVrr?rceZdZdZdZdS)rr>c t|SrErr{s r@rzSplitResultBytes.geturl`rr?Nrr>r?r@rr^rr?rceZdZdZdZdS)rr>c t|SrErr{s r@rzParseResultBytes.geturlerr?Nrr>r?r@rrcrr?rcttfttftt ff}|D]\}}||_||_dSrE)rrrrrrrfru) _result_pairs_decoded_encodeds r@_fix_result_transcodingrisW () &' &'M ,11((0%(0%%11r?rTct||\}}}t|||}|\}}}}}|tvrd|vrt|\}}nd}t ||||||} || S)aParse a URL into 6 components: :///;?# The result is a named 6-tuple with fields corresponding to the above. It is either a ParseResult or ParseResultBytes object, depending on the type of the url parameter. The username, password, hostname, and port sub-components of netloc can also be accessed as attributes of the returned object. The scheme argument provides the default value of the scheme component when no scheme is found in url. If allow_fragments is False, no attempt is made to separate the fragment component from the previous component, which can be either path or query. Note that % escapes are not expanded. ;r)r`r uses_params _splitparamsr) rschemeallow_fragments_coerce_result splitresultrqueryrparamsresults r@rrvs(#/sF";";C388K+6(FFC "3'' VV feX F FF >& ! !!r?cd|vr4|d|d}|dkr|dfSn|d}|d|||dzdfS)N/rrrrZ)findrfind)ris r@rrso s{{ HHS#))C.. ) ) q557N  HHSMM rr7C!I r?ct|}dD].}|||}|dkrt||}/|||||dfS)Nz/?#r)lenrmin)rstartdelimcwdelims r@ _splitnetlocrsd HHE ''!U## Q;;v&&E uU{ S[ ((r?cl|r|rdSddl}|dd}|dd}|dd}|dd}|d|}||krdSdD]}||vrt d |zd zd zdS) Nrrrrr?NFKCz/?#@:znetloc 'z' contains invalid z#characters under NFKC normalization)r unicodedatareplace normalizer)rrnnetloc2rs r@ _checknetlocrs V^^%%sBA #rA #rA #rA##FA..GG|| DD <<Z&03HHBCDD D DDr?cd|dd}|d\}}}|rQ|rtd|d\}}}|r$|dstdn|d\}}}t |dS)NrrInvalid IPv6 URLrr)rrr startswith_check_bracketed_host)rhostname_and_portbefore_bracketrrrrrs r@_check_bracketed_netlocrs))#..q1.?.I.I#.N.N+NL) =  1/00 0%//44!T  1,, 1/00 0-77<<!T(#####r?c|dr&tjd|stddSt j|}t |tjrtddS)Nvz\Av[a-fA-F0-9]+\..+\ZzIPvFuture address is invalidz%An IPv4 address cannot be in brackets)rrematchr ipaddress ip_addressr[ IPv4Address)rips r@rrs3Gx0(;; ><== = > > !( + + b)/ 0 0 GEFF F G Gr?)typedct||\}}}|t}|t}tD].}||d}||d}/t |}dx}x}}|d}|dkru|dr[|d rA|d|D] } | tvrn*|d| ||dzd}}|dddkrIt|d\}}d|vrd |vsd |vrd|vrtd d|vrd |vrt||rd |vr|d d\}}d |vr|d d\}}t!|t#|||||} || S) aParse a URL into 5 components: :///?# The result is a named 5-tuple with fields corresponding to the above. It is either a SplitResult or SplitResultBytes object, depending on the type of the url parameter. The username, password, hostname, and port sub-components of netloc can also be accessed as attributes of the returned object. The scheme argument provides the default value of the scheme component when no scheme is found in url. If allow_fragments is False, no attempt is made to separate the fragment component from the previous component, which can be either path or query. Note that % escapes are not expanded. rrrNrZr//rrrrr)r`lstrip_WHATWG_C0_CONTROL_OR_SPACEstrip_UNSAFE_URL_BYTES_TO_REMOVErboolrrisalpha scheme_charsrrrrsplitrr) rrrrbrrrrrrs r@rrs,#/sF";";C **0 1 1C \\5 6 6F (''kk!R  2&&?++O ""F"UX  A1uuQ!!uc!fnn&6&6uRaR 5 5A $$%bqb'--//3qstt9CF 2A2w$"3**  F]]s&003f#4#4/00 0 &==SF]] #F + + +*3#:: #q)) X czzYYsA&& UFFC99A >!  r?c pt|\}}}}}}}|r|d|}|t|||||fS)zPut a parsed URL back together again. This may result in a slightly different, but equivalent URL, if the URL that was parsed originally had redundant delimiters, e.g. a ? with an empty query (the draft states that these are equivalent).r)r`r ) componentsrrrrrrrs r@rr s[ 3? 2KAFFC. &ff% >*ffc5(%KLL M MMr?ct|\}}}}}}|s|r |tvs|dddkr|r|dddkrd|z}d|pdz|z}|r|dz|z}|r|dz|z}|r|d z|z}||S) akCombine the elements of a tuple as returned by urlsplit() into a complete URL as a string. The data argument can be any five-item iterable. This may result in a slightly different, but equivalent URL, if the URL that was parsed originally had unnecessary delimiters (for example, a ? with an empty query; the RFC states that these are equivalent).NrrrZrrrrr)r` uses_netloc)rrrrrrrs r@r r s+7 *C9FFC. *&*V{22s2A2w$ 23rr7c>>s3fl#c) !slS   Ci%#Ci(" >#  r?c |s|S|s|St||\}}}t|d|\}}}}}} t|||\} } } } }}| |ks | tvr ||S| tvr"| r|t | | | | ||fS|} | s(| s&|} |} |s|}|t | | | | ||fS|d}|ddkr|d=| dddkr| d}n5|| dz}t d|dd|dd<g}|D]J}|dkr& |#t$rY*wxYw|dkr5| |K|ddvr| d|t | | d |pd| ||fS) zaJoin a base URL and a possibly relative URL to form an absolute interpretation of the latter.rrNrZ...)rr) r`r uses_relativerrr filterpop IndexErrorappendjoin)baserrrbschemebnetlocbpathbparamsbquery bfragmentrrpathrrr base_partssegments resolved_pathsegs r@rr+s   ,T3 7 7D#~ T2 / /8GWeWfi S'? 3 32FFD&%F-77~c"""   I!>*ffd.4eX.G#H#HII I EE E~j&&$*0%*CDDEE ES!!J"~ rN BQBx3::c?? 3/ hqtn552M & & $;; !!####    CZZ    % % % %|{"" R   >*ffchh777vuh&899 : ::sE E('E(ct|\}}d|vr,t|\}}}}}}t|||||df}nd}|}|t||S)zRemoves any existing fragment from URL. Returns a tuple of the defragmented URL and the fragment. If the URL contained no fragments, the second element is the empty string. rr)r`rrr) rrsrpaqfragdefrags r@rrpsw's++C czz&smm1aAtQ1aB/00 >,vt44 5 55r?0123456789ABCDEFabcdefc|s |jdSt|tr|d}|d}t |dkr|S|dg}|j}t dtDa|ddD]Z} |t |dd||dd5#t$r|d||YWwxYwd |S) z,unquote_to_bytes('abc%20def') -> b'abc def'.r?utf-8rrZrNci|]?}tD]5}||zt||z6@Sr>)_hexdigrJbytesfromhex)rSr*r s r@ z$unquote_to_bytes..s\99999+,1unn&& a!e(<(<9999r?r) r r[r\rJrr _hextobyter2KeyErrorr)stringbitsresritems r@rrs7  s&#(w'' <<  D 4yyA~~ 7)C ZF99&999 QRR  F:d2A2h' ( ( ( F48        F4LLL F4LLLLL  88C==s1C C*)C*z([-]+)r0rct|tr#t|||Sd|vr |j|S|d}|d}t |}|dg}|j}tdt|dD]H}|t|||||||dzId |S) aReplace %xx escapes by their single-character equivalent. The optional encoding and errors parameters specify how to decode percent-encoded sequences into Unicode characters, as accepted by the bytes.decode() method. By default, percent-encoded sequences are decoded with UTF-8, and invalid sequences are replaced by a placeholder character. unquote('abc%20def') -> 'abc def'. rNr0rrrZrr) r[r3rrQr _asciirerrangerr)r8rKrLr9r:rrs r@rrs&%  A''..x@@@ &   ~ >>& ! !D 7)C ZF 1c$ii # #Q((//&AABBBtAE{ 773<<r?F&c i}t|||||||}|D]+\} } | |vr|| | %| g|| <,|S)aXParse a query given as a string argument. Arguments: qs: percent-encoded query string to be parsed keep_blank_values: flag indicating whether blank values in percent-encoded queries should be treated as blank strings. A true value indicates that blanks should be retained as blank strings. The default false value indicates that blank values are to be ignored and treated as if they were not included. strict_parsing: flag indicating what to do with parsing errors. If false (the default), errors are silently ignored. If true, errors raise a ValueError exception. encoding and errors: specify how to decode percent-encoded sequences into Unicode characters, as accepted by the bytes.decode() method. max_num_fields: int. If set, then throws a ValueError if there are more than n fields read by parse_qsl(). separator: str. The symbol to use for separating the query arguments. Defaults to &. Returns a dictionary. )rKrLmax_num_fieldsr)r r) qskeep_blank_valuesstrict_parsingrKrLrAr parsed_resultpairsnamevalues r@r r s<M b+^'%3y J J JE** e = $  & &u - - - -#('M$   r?c|rt|ttfstdt|tr.t|tst|d}d}fd}nJ|sgStt |}t|trt|d}d}d}|sgS|-d||z} || krtd g} ||D]f} | s|r`| |\} } }| s|rtd | |s|r-|| } ||}| | |fg| S) aXParse a query given as a string argument. Arguments: qs: percent-encoded query string to be parsed keep_blank_values: flag indicating whether blank values in percent-encoded queries should be treated as blank strings. A true value indicates that blanks should be retained as blank strings. The default false value indicates that blank values are to be ignored and treated as if they were not included. strict_parsing: flag indicating what to do with parsing errors. If false (the default), errors are silently ignored. If true, errors raise a ValueError exception. encoding and errors: specify how to decode percent-encoded sequences into Unicode characters, as accepted by the bytes.decode() method. max_num_fields: int. If set, then throws a ValueError if there are more than n fields read by parse_qsl(). separator: str. The symbol to use for separating the query arguments. Defaults to &. Returns a list, as G-d intended. z*Separator must be of type string or bytes.rB=c(t|S)N)rKrL)r)r(rKrLs r@_unquotezparse_qsl.._unquote sHVDDD Dr?=cHt|ddS)N+ )rr)r(s r@rLzparse_qsl.._unquotes#AIIdD$9$9:: :r?NrZzMax number of fields exceededzbad query field: ) r[r\r3r memoryviewcountr rr)rBrCrDrKrLrAreqrL num_fieldsr name_valuerGhas_eqrHs `` r@r r s< GJy3,??GEFFF"c;)S)) 0Iw//I  E E E E E E E I:b>> " " i % % 2i11I  ; ; ;  !),,, J & &<== = Ahhy))((  ( (","6"6r":": D&% Hn H j**!FGGG () (x~~ $''' Hr?cP|dd}t|||S)zLike unquote(), but also replace plus signs by spaces, as required for unquoting HTML form values. unquote_plus('%7e/abc+def') -> '~/abc def' + )rr)r8rKrLs r@rr2s) ^^C % %F 68V , ,,r?sBABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.-~c|dkr#tjdtdtSt dt d|)NQuoterzoDeprecated in 3.11. urllib.parse.Quoter will be removed in Python 3.14. It was not intended to be a public API.r stacklevelzmodule z has no attribute )warningswarnDeprecationWarning_QuoterAttributeErrorrk)rGs r@ __getattr__rdAsY x @)Q 8 8 8 8 I8IIII J JJr?c$eZdZdZdZdZdZdS)rbzA mapping from bytes numbers (in range(0,256)) to strings. String values are percent-encoded byte values, unless the key < 128, and in either of the specified safe set, or the always safe set. cDt||_dS)zsafe: bytes object.N) _ALWAYS_SAFEunionsafe)rhris r@__init__z_Quoter.__init__Rs &&t,, r?c(dt|dS)Nz)dictr{s r@__repr__z_Quoter.__repr__Vs)$t**))))r?cj||jvrt|nd|}|||<|S)Nz%{:02X})richrformat)rhr r:s r@ __missing__z_Quoter.__missing__Ys7TYc!fffI,<,r?r@rbrbJsK---***r?rbrct|tr#|s|S|d}|d}|||}n"|td|tdt ||S)aquote('abc def') -> 'abc%20def' Each part of a URL, e.g. the path info, the query, etc., has a different set of reserved characters that must be quoted. The quote function offers a cautious (not minimal) way to quote a string for most of these parts. RFC 3986 Uniform Resource Identifier (URI): Generic Syntax lists the following (un)reserved characters. unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" reserved = gen-delims / sub-delims gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@" sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=" Each of the reserved characters is reserved in some component of a URL, but not necessarily in all of them. The quote function %-escapes all characters that are neither in the unreserved chars ("always safe") nor the additional chars set via the safe arg. The default for the safe arg is '/'. The character is reserved, but in typical usage the quote function is being called on a path where the existing slash characters are to be preserved. Python 3.7 updates from using RFC 2396 to RFC 3986 to quote URL strings. Now, "~" is included in the set of unreserved characters. string and safe may be either str or bytes objects. encoding and errors must not be specified if string is a bytes object. The optional encoding and errors parameters specify how to deal with non-ASCII characters, as accepted by the str.encode method. By default, encoding='utf-8' (characters are encoded with UTF-8), and errors='strict' (unsupported characters raise a UnicodeEncodeError). Nr0rCz,quote() doesn't support 'encoding' for bytesz*quote() doesn't support 'errors' for bytes)r[r\rJr]r)r8rirKrLs r@r r _sN&# J M  H >Fx00  JKK K  HII I FD ) ))r?ct|trd|vst|trd|vrt||||St|trd}nd}t|||z||}|ddS)zLike quote(), but also replace ' ' with '+', as required for quoting HTML form values. Plus signs in the original string are escaped unless they are included in safe. It also does not have safe default to '/'. rZrPrY)r[r\r3r r)r8rirKrLspaces r@rrs FC 5S%6%6 FE " "&7'+6'9'9VT8V444$ 64%<6 : :F >>#s # ##r?c*t|jSrE)rb __getitem__)ris r@r=r=s 4== $$r?ct|ttfstd|sdSt|tr|dd}ntd|D}|t|zs|St|d fd|DS)zLike quote(), but accepts a bytes object rather than a str, and does not perform string-to-bytes encoding. It always returns an ASCII string. quote_from_bytes(b'abc def?') -> 'abc%20def%3f' z!quote_from_bytes() expected bytesrrBignorecg|] }|dk| S)r>)rSrs r@ z$quote_from_bytes..s111ASar?c&g|] }|Sr>r>)rScharquoters r@r|z$quote_from_bytes..s!000TFF4LL000r?) r[r3 bytearrayr]r\rJrstrip_ALWAYS_SAFE_BYTESrQr=r)bsrirs @r@rrs b5), - -=;<<< r$3{{7H--1111122 99'$. / /yy{{ !$ ' 'F 770000R000 1 11r?cTt|dr|}nU t|r"t|dtst n"#t $r}t d|d}~wwxYwg}|s|D]\}} t|t r |||}n|t||||}t| t r || |} n|t| |||} ||dz| znw|D]s\}} t|t r |||}n|t||||}t| t r(|| |} ||dz| zt| tr*|| |||} ||dz| z t| } | D]Z} t| t r || |} n|t| |||} ||dz| z[.#t $r:|t| |||} ||dz| zYqwxYwd |S)a^Encode a dict or sequence of two-element tuples into a URL query string. If any values in the query arg are sequences and doseq is true, each sequence element is converted to a separate parameter. If the query arg is a sequence of two-element tuples, the order of the parameters in the output will match the order of parameters in the input. The components of a query arg may each be either a string or a bytes type. The safe, encoding, and errors parameters are passed down to the function specified by quote_via (encoding and errors only if a component is a str). itemsrz1not a valid non-string sequence or mapping objectNrJr?) hasattrrrr[rVr]r3r\rr) rdoseqrirKrL quote_viaerrlkrrTelts r@r r s"ug:  :5zz *U1Xu"="=   : : :01169 : : A (0 " "DAq!U## >Ia&&Ic!ffdHf==!U## >Ia&&Ic!ffdHf== HHQWq[ ! ! ! ! " 0 0DAq!U## >Ia&&Ic!ffdHf==!U## 0Ia&&S1%%%%As## 0Iax88S1%%%%0AA !00%c511N"+)C"6"6CC"+)CHHdHf"M"MCS3//// 0 !***! #a&&$&AAAHHQWq[)))))* 88A;;s*1A A8#A33A8 IAJJcXtjdtdt|S)Nz/urllib.parse.to_bytes() is deprecated as of 3.8rr])r_r`ra _to_bytesrs r@to_bytesrs/ MC$4444 S>>r?ct|trY |d}n0#t$r#t dt |zdzwxYw|S)zto_bytes(u"URL") --> 'URL'.ASCIIzURL z contains non-ASCII characters)r[r\rJrQ UnicodeErrorreprrs r@rrs #sA A**W%%,,..CC A A AvS 1? @AA A A Js '?-A,c t|}|dddkr*|dddkr|dd}|dddkr|dd}|S)zTransform a string like '' into 'scheme://host/path'. The string is returned unchanged if it's not a wrapped URL. NrZ 'type', 'opaquestring'.Nz ([^/:]+):(.*)) _typeprogrcompileDOTALLrgroupsr)rrrdatas r@rr8sdJ :: OOC E $||~~ ||~~t## 9r?cXtjdtdt|S)NzUurllib.parse.splithost() is deprecated as of 3.8, use urllib.parse.urlparse() insteadrr])r_r`ra _splithostrs r@ splithostrErr?cttjdtjat|}|r.|\}}|r|ddkrd|z}||fSd|fS)z;splithost('//host[:port]/path') --> 'host[:port]', '/path'.Nz//([^/#?]*)(.*)rr) _hostprogrrrrr)rr host_portr"s r@rrMsyJ0")<< OOC E ,,.. 4  DGsNN:D$ 9r?cXtjdtdt|S)NzUurllib.parse.splituser() is deprecated as of 3.8, use urllib.parse.urlparse() insteadrr])r_r`ra _splituserhosts r@ splituserr\5 M8$4444 d  r?cD|d\}}}|r|nd|fS)zJsplituser('user[:passwd]@host[:port]') --> 'user[:passwd]', 'host[:port]'.rNr)ruserrs r@rrcs.,,D% #DDtd **r?cXtjdtdt|S)NzWurllib.parse.splitpasswd() is deprecated as of 3.8, use urllib.parse.urlparse() insteadrr])r_r`ra _splitpasswd)rs r@ splitpasswdris5 M8$4444   r?cD|d\}}}||r|ndfS)z/splitpasswd('user:passwd') -> 'user', 'passwd'.rNr)rrpasswds r@rrps...--D% E+&&t ,,r?cXtjdtdt|S)NzUurllib.parse.splitport() is deprecated as of 3.8, use urllib.parse.urlparse() insteadrr])r_r`ra _splitportrs r@ splitportrvrr?cttjdtjat|}|r|\}}|r||fS|dfS)z*splitport('host:port') --> 'host', 'port'.Nz (.*):([0-9]*)) _portprogrrr fullmatchr)rrrs r@rrseJ ::    % %E \\^^ d  :  :r?rcZtjdtdt||S)NzVurllib.parse.splitnport() is deprecated as of 3.8, use urllib.parse.urlparse() insteadrr])r_r`ra _splitnport)rdefports r@ splitnportrs7 M8$4444 tW % %%r?c|d\}}}|s|}n@|r>|r$|rt|}nd}||fS||fS)zSplit host and port, returning numeric port. Return given default port if no ':' found; defaults to -1. Return numerical port if a valid number is found after ':'. Return None if ':' but not a valid number.rN)rrrr)rrrrnports r@rrsx ,,D%   <<>> dllnn IIEEEU{ =r?cXtjdtdt|S)NzVurllib.parse.splitquery() is deprecated as of 3.8, use urllib.parse.urlparse() insteadrr])r_r`ra _splitqueryrs r@ splitqueryrs5 M8$4444 s  r?cH|d\}}}|r||fS|dfS)z/splitquery('/path?query') --> '/path', 'query'.rNr)rr"rrs r@rrs6,,D% U{ 9r?cXtjdtdt|S)NzTurllib.parse.splittag() is deprecated as of 3.8, use urllib.parse.urlparse() insteadrr])r_r`ra _splittagrs r@splittagrs3 M8$4444 S>>r?cH|d\}}}|r||fS|dfS)z)splittag('/path#tag') --> '/path', 'tag'.rNr)rr"rtags r@rrs6~~c**D% Sy 9r?cXtjdtdt|S)NzUurllib.parse.splitattr() is deprecated as of 3.8, use urllib.parse.urlparse() insteadrr])r_r`ra _splitattrrs r@ splitattrrrr?cP|d}|d|ddfS)zksplitattr('/path;attr1=value1;attr2=value2;...') -> '/path', ['attr1=value1', 'attr2=value2', ...].rrrZN)r )rwordss r@rrs* IIcNNE 8U122Y r?cXtjdtdt|S)NzWurllib.parse.splitvalue() is deprecated as of 3.8, use urllib.parse.parse_qsl() insteadrr])r_r`ra _splitvalue)attrs r@ splitvaluers5 M9$4444 t  r?cD|d\}}}||r|ndfS)z-splitvalue('attr=value') --> 'attr', 'value'.rJNr)rrrHs r@rrs.,,D% 5*%%d ++r?)rT)r)T)r0r)FFr0rNr?)rNN)rNN)r)r)mrn collectionsr functoolsrsysrr_r__all__rrrnon_hierarchical uses_query uses_fragmentr rrrA_implicit_encoding_implicit_errorsrGrMrXr`objectrbrrrwrr_DefragResultBase_SplitResultBase_ParseResultBaserrrrr"rr ResultBaserrrrrrrrrrrrr lru_cacherrr rrr2r6rrr=rr r r frozensetrgr3rrdrmrbr rr=rr rrrrrrrrrrrrrrrrrrrrrrrrrrr>r?r@rsB#"""""  H H H000  --- FFFAAA %%%  \100'''"4/((((!3.HHHH222"VVVVVfVVVVVVVVVVV#8#8#8#8#8V#8#8#8L2O<46G<J~~>>:688:=??!K&" #N#!" %!  #3"9"A"2"9"A 0 5 =# "2!7!?$4$=$E! # $o     "$9        "$9   )+<     ')@        ')@   111""""<))))DDD$$$$&GGG4   555! 5n N N N&B:B:B:B:J666 #  < 2:& ' '8:?PS''''T;@QTG G G G R----y!"" U<((KKKd*4*4*4*4*l$$$$$ %%%2222(!rD"MMMM`                +++ ---      &&&&",,,,,r?__pycache__/request.cpython-311.opt-1.pyc000064400000366571151026775530014142 0ustar00 !A?hw>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+ ddl,Z,dZ-n #e.$rdZ-YnwxYwgdZ/d e j0dd zZ1da2de j3fddddd d Z4d Z5gZ6dgdZ7dZ8e 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 ddLlbmcZcmdZdndMZcdNZdiZeGdOdPZfGdQdRefZgdahdSZidajdTZkdaldUZmdandVZoGdWdXZpdYZqdhdZZrd[Zsd\Zte jud]krdd^lvmwZwmxZxd_Zyd`ZzdaZ{dbZ|dSejadKkrdcZ}ddZ|deZ~dfZ{dSeqZ|erZ{dS)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|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 '/usr/lib64/python3.11/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}||_|D]7\}}|}t |d|z|||jfd8dS)Nz%s_openc||||SrVr)rrhrrs rSz'ProxyHandler.__init__..#sQt,,rT)r6proxiesrrsetattrr)rrxrrNs rSrzProxyHandler.__init__s ? llG   . .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{r~r|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&r}cD|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 rSrwz?AbstractDigestAuthHandler.get_algorithm_impls..s('+ahhw&7&788BBDDrTSHActtj|dSr )rrrrr"s rSrwz?AbstractDigestAuthHandler.get_algorithm_impls..s(',qxx'8'899CCEErTz.Unsupported digest authentication algorithm %rc$|d|S)Nr{r)rdrs rSrwz?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||_dSrVr4)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. r?rPc$i|] \}}|v || Srr)rCrDrErts rSrGz/AbstractHTTPHandler.do_open..)s3---AG++1+++rTr Connectionc>i|]\}}||Sr)title)rCrirs rSrGz/AbstractHTTPHandler.do_open..6s&FFFs4::<<FFFrTr/rtrA)encode_chunkedN)rrrPset_debuglevelr5rrupdatertrr set_tunnelrrrrOrr} getresponsersockrrNreasonr3) r http_classrhttp_conn_argsrr$tunnel_headersproxy_auth_hdrerrrvrts @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)rrrrr9r<rGrrrTrSr2r2sj&&&&!!!""" $$$L@@@@@rTr2c"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)rrirs rSrzHTTPCookieProcessor.__init__ws2  0022I"rTc:|j||SrV)riadd_cookie_headerr=s rSrz HTTPCookieProcessor.http_request}s ((111rTc<|j|||SrV)riextract_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)rresryescaper 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 ldd|jjiz}tj|td|t }||_|d|_|d|_ d|j fdg|_ g|_ tj|_d|_t"|_dS) NzW%(class)s style of invoking requests is deprecated. Use newer urlopen functions/methodsclassr) stacklevelkey_file cert_filez User-Agent)Acceptz*/*)rrrArBrCr6rxrrrversionr_URLopener__tempfilesrdr|_URLopener__unlink tempcacheftpcache)rrxx509r3s rSrzURLopener.__init__s47>@W6XY c-!<<<< ? llG ,, +..($,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 rxr 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 errorr?r|zBasic %sr/rrrrJr@z Content-TyperrrMz$http protocol error: bad status liner0r1http:)rrr rr r rrr}rrrrrrrRrr BadStatusLinerstatusrr3 http_errorrsrT)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 rSr zURLopener.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;rrrNrzDate: %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)rrrr5rrrrrrrrrMrrrrrr rrErrr"rr-r7rrTrSr9r9sK ;.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=rr@rredirect_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).rDrEs rSrbzFancyURLopener.http_error_303rFrTcl||||||||S||||||S)z1Error 307 -- relocated, but turn POST into error.)r`rrEs rSrczFancyURLopener.http_error_307A <&&sB$OO O**3GVWMM MrTcl||||||||S||||||S)z1Error 308 -- relocated, but turn POST into error.)rarrEs rSrdzFancyURLopener.http_error_308rIrTFc*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-stuffrPrVrris 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.rrLr retry_proxy_rNrOrQs 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 rxr 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{rWrYs 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{rVr rrXr 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]r`ras 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 rSrXzFancyURLopener.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)rrrrgrors rSrez!FancyURLopener.prompt_user_passwd) s 5EEE444HIID___uuuddd&$%%F<      GGG:: s8?AArV)NFrZ)rrrr5rrr`rArarbrcrdrrr[r^rrcrXrerrTrSr: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 noheadersrsU 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 rSrxzftpwrapper.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 endtransferrPvoidcmdrrx ntransfercmd error_permrrpwdr~rzrmakefile file_closervr) rrXrrcmdisdirrrrTrftpobjs 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)rzrPvoidrespr,rs rSrzftpwrapper.endtransfer s]y  F   H       {{    DD s-AAcVd|_|jdkr|dSdS)NFr)rwrv real_closers rSrzftpwrapper.close s4 =A   OO       rTc||xjdzc_|jdkr|js|dSdSdS)Nr_r)rrvrwrrs rSrzftpwrapper.file_close s\   =A  dn  OO         rTc| |jdS#t$rYdSwxYwrV)rrPrr,rs rSrzftpwrapper.real_close sW   HNN     {{    DD s1AA)NT) rrrr5rrxrrrrrrrTrSrr_ 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)rxrirs 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) r ipaddressrrrrlrrrPgroupcount) rproxy_settingsrrrrrrhostIPrrJrmasks rS_proxy_bypass_macosx_sysconfr s 88888888%%NHdPPP $ * + 4 F [[**++       ##L"55h H. 6 6 =V/6!''!**%%D771::D|AGGAJJ,,S11A5648}}axx4"999D$DDL11tt2WT5 ! ! 44  5sAAAcddlm}t|\}}|d}|D]3}|}|dkrd|vrdS$|||rdS4dS)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" rrr/zrTF)rrrr)roverriderrproxy_overriders rS_proxy_bypass_winreg_overriderG s GD!^^C((Nzz|| 9  $tt WT4  44  5rTdarwin)_get_proxy_settings _get_proxiesc>t}t||SrV)rr)rrs rSproxy_bypass_macosx_sysconfrb 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_sysconfrf 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. )rrrrrxs rSrrp s5)**  5+D':: :.t44 4rTc:tp tSrV)rrrrTrSr6r6} 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 ProxyServerrrr/zhttp={0};https={0};ftp={0}r_z (?:[^/:]+)://)rrrPrVsockszsocks://z ^socks://z socks4://rr)winreg ImportErrorOpenKeyHKEY_CURRENT_USER QueryValueExrrrrrPrrCloser}rDr)rxrinternetSettings proxyEnable proxyServerpraddresss rSgetproxies_registryr 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&''@+>+@+@@rTcB ddl}n#t$rYdSwxYw ||jd}||dd}t ||dd}n#t $rYdSwxYw|r|sdSt||S)NrFrr ProxyOverride)rrrrrrr}r)rrrr proxyOverrides rSproxy_bypass_registryr s  MMMM   55  %~~f.FN P P  --.>/<>>>?AK 3 34D5D!F!FFG!IJJMM   55  - 5,T=AAAs A A:: BBc`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':: :(.. .rTr8rV)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)r2r*rrrKrkrr/rrr+rr,r-r.r+ri nturl2pathr5r4rr9r:rlrrnr%rpr,rrrsrrrrrplatform_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<<<@0<8::::::::BBB 5 5 5GGGGGW__///bAAABBB( / / / / /(J+LLLs>BBB__pycache__/response.cpython-311.opt-1.pyc000064400000012110151026775530014261 0ustar00 !A?h9 dZddlZgdZGddejZGddeZGdd eZGd d eZdS) aResponse classes used by urllib. The base class, addbase, defines a minimal file-like interface, including read() and readline(). The typical response object is an addinfourl instance, which defines an info() method that returns headers and a geturl() method that returns the url. N)addbase addclosehookaddinfo addinfourlc4eZdZdZfdZdZdZdZxZS)rzOBase class for addinfo and addclosehook. Is a good idea for garbage collection.cltt||dd||_dS)NzF)delete)superr__init__fp)selfr __class__s (/usr/lib64/python3.11/urllib/response.pyr zaddbase.__init__s4 g&&r+>u&MMMcRd|jjdt|d|jdS)N)r__name__idfiler s r__repr__zaddbase.__repr__s3-1^-D-D-D-/XXXXtyyyB Brc<|jjrtd|S)NzI/O operation on closed file)r closed ValueErrorrs r __enter__zaddbase.__enter__s" 7> =;<< < rc.|dSN)close)r typevalue tracebacks r__exit__zaddbase.__exit__!s r) r __module__ __qualname____doc__r rrr# __classcell__rs@rrrsnYY BBB rrc,eZdZdZfdZfdZxZS)rz*Class to add a close hook to an open file.cttt||||_||_dSr)r rr closehookhookargs)r r r+r,rs rr zaddclosehook.__init__(s3 lD!!**2..."  rc |j}|j}|rd|_d|_||tt|dS#tt|wxYwr)r+r,r rr)r r+r,rs rrzaddclosehook.close-s} .I}H %!% $  8$$ , % % + + - - - - -E, % % + + - - - -s #A)A8)rr$r%r&r rr'r(s@rrr%sW44!!!!! . . . . . . . . .rrc(eZdZdZfdZdZxZS)rz.class to add an info() method to an open file.cftt||||_dSr)r rr headers)r r r0rs rr zaddinfo.__init__<s, gt%%b))) rc|jSr)r0rs rinfoz addinfo.info@s |r)rr$r%r&r r2r'r(s@rrr9sM88rrcFeZdZdZdfd ZedZdZdZxZ S)rz9class to add info() and geturl() methods to an open file.Ncvtt|||||_||_dSr)r rr urlcode)r r r0r5r6rs rr zaddinfourl.__init__Gs5 j$((W555 rc|jSrr6rs rstatuszaddinfourl.statusLs yrc|jSrr8rs rgetcodezaddinfourl.getcodePs yrc|jSr)r5rs rgeturlzaddinfourl.geturlSs xrr) rr$r%r&r propertyr9r;r=r'r(s@rrrDs|CC Xrr)r&tempfile__all___TemporaryFileWrapperrrrrrrrCs > > >h,......7...(gr__pycache__/parse.cpython-311.pyc000064400000154354151026775530012617 0ustar00 !A?h$2dZddlmZddlZddlZddlZddlZddlZddlZgdZ gdZ gdZ gdZ gdZ gd Zgd Zd Zd Zgd ZdZdZdZdZeefdZeefdZdZGddeZGddeZGddeZGddeeZGddeeZedd Z ed!d"Z!ed#d$Z"d%e _d&e j#_d'e j$_d(e!_d)e!j%_d*e!j&_d+e!j'_d,e!j(_d-e!j$_d.e"_e!j%je"j%_e!j&je"j&_e!j'je"j'_d/e"j)_e!j(je"j(_e!j$je"j$_eZ*Gd0de eZ+Gd1d!e!eZ,Gd2d#e"eZ-Gd3d4e eZ.Gd5d6e!eZ/Gd7d8e"eZ0d9Z1e1[1dud<Z2d=Z3dvd>Z4d?Z5d@Z6dAZ7ej8d;BdudCZ9dDZ:dEZ;dwdFZda?dIZ@ejAdJZBdxdMZC dydPZD dydQZEdxdRZFeGdSZHeIeHZJdTZKGdUdVeLZMdzdXZNd{dYZOej8dZZPd|d[ZQdNd:ddeOfd\ZRd]ZSd^ZTd_ZUd`ZVdaWdaZXdbZYdaZdcZ[ddZ\deZ]dfZ^dgZ_dhZ`daadiZbd}dkZcd}dlZddmZednZfdoZgdpZhdqZidrZjdsZkdtZldS)~a3Parse (absolute and relative) URLs. urlparse module is based upon the following RFC specifications. RFC 3986 (STD66): "Uniform Resource Identifiers" by T. Berners-Lee, R. Fielding and L. Masinter, January 2005. RFC 2732 : "Format for Literal IPv6 Addresses in URL's by R.Hinden, B.Carpenter and L.Masinter, December 1999. RFC 2396: "Uniform Resource Identifiers (URI)": Generic Syntax by T. Berners-Lee, R. Fielding, and L. Masinter, August 1998. RFC 2368: "The mailto URL scheme", by P.Hoffman , L Masinter, J. Zawinski, July 1998. RFC 1808: "Relative Uniform Resource Locators", by R. Fielding, UC Irvine, June 1995. RFC 1738: "Uniform Resource Locators (URL)" by T. Berners-Lee, L. Masinter, M. McCahill, December 1994 RFC 3986 is considered the current standard and any future changes to urlparse module should conform with it. The urlparse module is currently not entirely compliant with this RFC due to defacto scenarios for parsing, and for backward compatibility purposes, some parsing quirks from older RFCs are retained. The testcases in test_urlparse.py provides a good indicator of parsing behavior. The WHATWG URL Parser spec should also be considered. We are not compliant with it either due to existing user code API behavior expectations (Hyrum's Law). It serves as a useful guide when making changes. ) namedtupleN)urlparse urlunparseurljoin urldefragurlsplit urlunsplit urlencodeparse_qs parse_qslquote quote_plusquote_from_bytesunquote unquote_plusunquote_to_bytes DefragResult ParseResult SplitResultDefragResultBytesParseResultBytesSplitResultBytes)ftphttpgophernntpimapwaisfilehttpsshttpmmsprosperortsprtspsrtspusftpsvnsvn+sshwswss)rrrrrtelnetrrr r#r!r"snewsr$r%r&r'rsyncr)r*r(nfsgitzgit+sshr+r,)rrhdlr$rrr!r"r%r&r'sipsipsr#r(tel) rr2mailtonewsr-rrr.r3r4) rrrrr!r"r#rr%r&r'r3r4) rrr2rrr7rrr!r"r.r r$zAabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-.z!  )   cjttdS)zDClear internal performance caches. Undocumented; some tests want it.N)r cache_clear_byte_quoter_factory%/usr/lib64/python3.11/urllib/parse.py clear_cacherA^s, $$&&&&&r?asciistrictc|SNr>)objs r@_nooprGls Jr?c.|||SrEencode)rFencodingerrorss r@_encode_resultrMos ::h ' ''r?c>tfd|DS)Nc3LK|]}|r|ndVdS)rNdecode.0xrKrLs r@ z_decode_args..us;GGQq8(F+++bGGGGGGr?)tuple)argsrKrLs ``r@ _decode_argsrXss* GGGGG$GGG G GGr?ct|dt}|ddD],}|r(t|t|krtd-|r |tfzSt |t fzS)Nrz$Cannot mix str and non-str arguments) isinstancestr TypeErrorrGrXrM)rW str_inputargs r@ _coerce_argsr`ws 47C((IABBxDD  D:c3''944BCC Cuh    1 11r?ceZdZdZdZddZdS)_ResultMixinStrz>Standard approach to encoding parsed results from str to bytesr>rBrCc4|jfd|DS)Nc3DK|]}|VdSrErIrRs r@rUz)_ResultMixinStr.encode..1*T*T!188Hf+E+E*T*T*T*T*T*Tr?)_encoded_counterpartselfrKrLs ``r@rJz_ResultMixinStr.encode,(t(*T*T*T*T*Tt*T*T*TUUr?NrBrC)__name__ __module__ __qualname____doc__ __slots__rJr>r?r@rbrb9HHIVVVVVVr?rbceZdZdZdZddZdS)_ResultMixinBytesz>Standard approach to decoding parsed results from bytes to strr>rBrCc4|jfd|DS)Nc3DK|]}|VdSrErPrRs r@rUz+_ResultMixinBytes.decode..rer?)_decoded_counterpartrgs ``r@rQz_ResultMixinBytes.decoderir?Nrj)rkrlrmrnrorQr>r?r@rrrrrpr?rrceZdZdZdZedZedZedZedZ e e j Z dS)_NetlocResultMixinBasezHShared methods for the parsed result objects containing a netloc elementr>c|jdS)Nr _userinforhs r@usernamez_NetlocResultMixinBase.username~a  r?c|jdS)NrZryr{s r@passwordz_NetlocResultMixinBase.passwordr}r?c|jd}|sdSt|trdnd}||\}}}||z|zS)Nr%%) _hostinfor[r\ partitionlower)rhhostname separatorpercentzones r@rz_NetlocResultMixinBase.hostnamesi>!$ 4&h44>CC$ "*"4"4Y"?"?'4~~')D00r?c|jd}|h|r$|rt|}nt d|d|cxkrdksnt d|S)NrZz+Port could not be cast to integer value as rizPort out of range 0-65535)risdigitisasciiint ValueError)rhports r@rz_NetlocResultMixinBase.ports~a   ||~~ Y$,,.. Y4yy !Wt!W!WXXX&&&&&&&& !<=== r?N)rkrlrmrnropropertyr|rrr classmethodtypes GenericAlias__class_getitem__r>r?r@rwrwsRRI !!X!!!X!11X1  X $ E$677r?rwc>eZdZdZedZedZdS)_NetlocResultMixinStrr>c|j}|d\}}}|r|d\}}}|sd}ndx}}||fS)N@:netloc rpartitionrrhruserinfo have_infohostinfor| have_passwordrs r@rzz_NetlocResultMixinStr._userinfosh(.(9(9#(>(>%)X  '080B0B30G0G -HmX  "& &Hx!!r?c |j}|d\}}}|d\}}}|r3|d\}}}|d\}}}n|d\}}}|sd}||fS)Nr[]rrrhr_r have_open_br bracketedrrs r@rz_NetlocResultMixinStr._hostinfos**3//1h%-%7%7%<%<"<  8 ) 3 3C 8 8 Ha,,JAq$$ ( 2 23 7 7 Ha D~r?Nrkrlrmrorrzrr>r?r@rrMI  " "X "  X   r?rc>eZdZdZedZedZdS)_NetlocResultMixinBytesr>c|j}|d\}}}|r|d\}}}|sd}ndx}}||fS)N@:rrs r@rzz!_NetlocResultMixinBytes._userinfosh(.(9(9$(?(?%)X  '080B0B40H0H -HmX  "& &Hx!!r?c |j}|d\}}}|d\}}}|r3|d\}}}|d\}}}n|d\}}}|sd}||fS)Nr[]rrrs r@rz!_NetlocResultMixinBytes._hostinfos**4001h%-%7%7%=%="<  9 ) 3 3D 9 9 Ha--JAq$$ ( 2 24 8 8 Ha D~r?Nrr>r?r@rrrr?rrz url fragmentrz!scheme netloc path query fragmentrz(scheme netloc path params query fragmentz DefragResult(url, fragment) A 2-tuple that contains the url without fragment identifier and the fragment identifier as a separate argument. z$The URL with no fragment identifier.z Fragment identifier separated from URL, that allows indirect identification of a secondary resource by reference to a primary resource and additional identifying information. z SplitResult(scheme, netloc, path, query, fragment) A 5-tuple that contains the different components of a URL. Similar to ParseResult, but does not split params. z%Specifies URL scheme for the request.z0 Network location where the request is made to. z@ The hierarchical path, such as the path to a file to download. z The query component, that contains non-hierarchical data, that along with data in path component, identifies a resource in the scope of URI's scheme and network location. z Fragment identifier, that allows indirect identification of a secondary resource by reference to a primary resource and additional identifying information. zq ParseResult(scheme, netloc, path, params, query, fragment) A 6-tuple that contains components of a parsed URL. z Parameters for last path element used to dereference the URI in order to provide access to perform some operation on the resource. ceZdZdZdZdS)rr>cB|jr|jdz|jzS|jS)N#fragmenturlr{s r@geturlzDefragResult.geturlEs& = 8c>DM1 18Or?Nrkrlrmrorr>r?r@rrC(Ir?ceZdZdZdZdS)rr>c t|SrEr r{s r@rzSplitResult.geturlM$r?Nrr>r?r@rrK(I     r?ceZdZdZdZdS)rr>c t|SrErr{s r@rzParseResult.geturlRrr?Nrr>r?r@rrPrr?ceZdZdZdZdS)rr>cB|jr|jdz|jzS|jS)N#rr{s r@rzDefragResultBytes.geturlXs& = 8d?T]2 28Or?Nrr>r?r@rrVrr?rceZdZdZdZdS)rr>c t|SrErr{s r@rzSplitResultBytes.geturl`rr?Nrr>r?r@rr^rr?rceZdZdZdZdS)rr>c t|SrErr{s r@rzParseResultBytes.geturlerr?Nrr>r?r@rrcrr?rcttfttftt ff}|D]\}}||_||_dSrE)rrrrrrrfru) _result_pairs_decoded_encodeds r@_fix_result_transcodingrisW () &' &'M ,11((0%(0%%11r?rTct||\}}}t|||}|\}}}}}|tvrd|vrt|\}}nd}t ||||||} || S)aParse a URL into 6 components: :///;?# The result is a named 6-tuple with fields corresponding to the above. It is either a ParseResult or ParseResultBytes object, depending on the type of the url parameter. The username, password, hostname, and port sub-components of netloc can also be accessed as attributes of the returned object. The scheme argument provides the default value of the scheme component when no scheme is found in url. If allow_fragments is False, no attempt is made to separate the fragment component from the previous component, which can be either path or query. Note that % escapes are not expanded. ;r)r`r uses_params _splitparamsr) rschemeallow_fragments_coerce_result splitresultrqueryrparamsresults r@rrvs(#/sF";";C388K+6(FFC "3'' VV feX F FF >& ! !!r?cd|vr4|d|d}|dkr|dfSn|d}|d|||dzdfS)N/rrrrZ)findrfind)ris r@rrso s{{ HHS#))C.. ) ) q557N  HHSMM rr7C!I r?ct|}dD].}|||}|dkrt||}/|||||dfS)Nz/?#r)lenrmin)rstartdelimcwdelims r@ _splitnetlocrsd HHE ''!U## Q;;v&&E uU{ S[ ((r?cl|r|rdSddl}|dd}|dd}|dd}|dd}|d|}||krdSdD]}||vrt d |zd zd zdS) Nrrrrr?NFKCz/?#@:znetloc 'z' contains invalid z#characters under NFKC normalization)r unicodedatareplace normalizer)rrnnetloc2rs r@ _checknetlocrs V^^%%sBA #rA #rA #rA##FA..GG|| DD <<Z&03HHBCDD D DDr?cd|dd}|d\}}}|rQ|rtd|d\}}}|r$|dstdn|d\}}}t |dS)NrrInvalid IPv6 URLrr)rrr startswith_check_bracketed_host)rhostname_and_portbefore_bracketrrrrrs r@_check_bracketed_netlocrs))#..q1.?.I.I#.N.N+NL) =  1/00 0%//44!T  1,, 1/00 0-77<<!T(#####r?c|dr&tjd|stddSt j|}t |tjrtddS)Nvz\Av[a-fA-F0-9]+\..+\ZzIPvFuture address is invalidz%An IPv4 address cannot be in brackets)rrematchr ipaddress ip_addressr[ IPv4Address)rips r@rrs3Gx0(;; ><== = > > !( + + b)/ 0 0 GEFF F G Gr?)typedct||\}}}|t}|t}tD].}||d}||d}/t |}dx}x}}|d}|dkru|dr[|d rA|d|D] } | tvrn*|d| ||dzd}}|dddkrIt|d\}}d|vrd |vsd |vrd|vrtd d|vrd |vrt||rd |vr|d d\}}d |vr|d d\}}t!|t#|||||} || S) aParse a URL into 5 components: :///?# The result is a named 5-tuple with fields corresponding to the above. It is either a SplitResult or SplitResultBytes object, depending on the type of the url parameter. The username, password, hostname, and port sub-components of netloc can also be accessed as attributes of the returned object. The scheme argument provides the default value of the scheme component when no scheme is found in url. If allow_fragments is False, no attempt is made to separate the fragment component from the previous component, which can be either path or query. Note that % escapes are not expanded. rrrNrZr//rrrrr)r`lstrip_WHATWG_C0_CONTROL_OR_SPACEstrip_UNSAFE_URL_BYTES_TO_REMOVErboolrrisalpha scheme_charsrrrrsplitrr) rrrrbrrrrrrs r@rrs,#/sF";";C **0 1 1C \\5 6 6F (''kk!R  2&&?++O ""F"UX  A1uuQ!!uc!fnn&6&6uRaR 5 5A $$%bqb'--//3qstt9CF 2A2w$"3**  F]]s&003f#4#4/00 0 &==SF]] #F + + +*3#:: #q)) X czzYYsA&& UFFC99A >!  r?c pt|\}}}}}}}|r|d|}|t|||||fS)zPut a parsed URL back together again. This may result in a slightly different, but equivalent URL, if the URL that was parsed originally had redundant delimiters, e.g. a ? with an empty query (the draft states that these are equivalent).r)r`r ) componentsrrrrrrrs r@rr s[ 3? 2KAFFC. &ff% >*ffc5(%KLL M MMr?ct|\}}}}}}|s|r |tvs|dddkr|r|dddkrd|z}d|pdz|z}|r|dz|z}|r|dz|z}|r|d z|z}||S) akCombine the elements of a tuple as returned by urlsplit() into a complete URL as a string. The data argument can be any five-item iterable. This may result in a slightly different, but equivalent URL, if the URL that was parsed originally had unnecessary delimiters (for example, a ? with an empty query; the RFC states that these are equivalent).NrrrZrrrrr)r` uses_netloc)rrrrrrrs r@r r s+7 *C9FFC. *&*V{22s2A2w$ 23rr7c>>s3fl#c) !slS   Ci%#Ci(" >#  r?c |s|S|s|St||\}}}t|d|\}}}}}} t|||\} } } } }}| |ks | tvr ||S| tvr"| r|t | | | | ||fS|} | s(| s&|} |} |s|}|t | | | | ||fS|d}|ddkr|d=| dddkr| d}n5|| dz}t d|dd|dd<g}|D]J}|dkr& |#t$rY*wxYw|dkr5| |K|ddvr| d|t | | d |pd| ||fS) zaJoin a base URL and a possibly relative URL to form an absolute interpretation of the latter.rrNrZ...)rr) r`r uses_relativerrr filterpop IndexErrorappendjoin)baserrrbschemebnetlocbpathbparamsbquery bfragmentrrpathrrr base_partssegments resolved_pathsegs r@rr+s   ,T3 7 7D#~ T2 / /8GWeWfi S'? 3 32FFD&%F-77~c"""   I!>*ffd.4eX.G#H#HII I EE E~j&&$*0%*CDDEE ES!!J"~ rN BQBx3::c?? 3/ hqtn552M & & $;; !!####    CZZ    % % % %|{"" R   >*ffchh777vuh&899 : ::sE E('E(ct|\}}d|vr,t|\}}}}}}t|||||df}nd}|}|t||S)zRemoves any existing fragment from URL. Returns a tuple of the defragmented URL and the fragment. If the URL contained no fragments, the second element is the empty string. rr)r`rrr) rrsrpaqfragdefrags r@rrpsw's++C czz&smm1aAtQ1aB/00 >,vt44 5 55r?0123456789ABCDEFabcdefc|s |jdSt|tr|d}|d}t |dkr|S|dg}|j}t dtDa|ddD]Z} |t |dd||dd5#t$r|d||YWwxYwd |S) z,unquote_to_bytes('abc%20def') -> b'abc def'.r?utf-8rrZrNci|]?}tD]5}||zt||z6@Sr>)_hexdigrJbytesfromhex)rSr*r s r@ z$unquote_to_bytes..s\99999+,1unn&& a!e(<(<9999r?r) r r[r\rJrr _hextobyter2KeyErrorr)stringbitsresritems r@rrs7  s&#(w'' <<  D 4yyA~~ 7)C ZF99&999 QRR  F:d2A2h' ( ( ( F48        F4LLL F4LLLLL  88C==s1C C*)C*z([-]+)r0rct|tr#t|||Sd|vr |j|S|d}|d}t |}|dg}|j}tdt|dD]H}|t|||||||dzId |S) aReplace %xx escapes by their single-character equivalent. The optional encoding and errors parameters specify how to decode percent-encoded sequences into Unicode characters, as accepted by the bytes.decode() method. By default, percent-encoded sequences are decoded with UTF-8, and invalid sequences are replaced by a placeholder character. unquote('abc%20def') -> 'abc def'. rNr0rrrZrr) r[r3rrQr _asciirerrangerr)r8rKrLr9r:rrs r@rrs&%  A''..x@@@ &   ~ >>& ! !D 7)C ZF 1c$ii # #Q((//&AABBBtAE{ 773<<r?F&c i}t|||||||}|D]+\} } | |vr|| | %| g|| <,|S)aXParse a query given as a string argument. Arguments: qs: percent-encoded query string to be parsed keep_blank_values: flag indicating whether blank values in percent-encoded queries should be treated as blank strings. A true value indicates that blanks should be retained as blank strings. The default false value indicates that blank values are to be ignored and treated as if they were not included. strict_parsing: flag indicating what to do with parsing errors. If false (the default), errors are silently ignored. If true, errors raise a ValueError exception. encoding and errors: specify how to decode percent-encoded sequences into Unicode characters, as accepted by the bytes.decode() method. max_num_fields: int. If set, then throws a ValueError if there are more than n fields read by parse_qsl(). separator: str. The symbol to use for separating the query arguments. Defaults to &. Returns a dictionary. )rKrLmax_num_fieldsr)r r) qskeep_blank_valuesstrict_parsingrKrLrAr parsed_resultpairsnamevalues r@r r s<M b+^'%3y J J JE** e = $  & &u - - - -#('M$   r?c|rt|ttfstdt|tr.t|tst|d}d}fd}nJ|sgStt |}t|trt|d}d}d}|sgS|-d||z} || krtd g} ||D]f} | s|r`| |\} } }| s|rtd | |s|r-|| } ||}| | |fg| S) aXParse a query given as a string argument. Arguments: qs: percent-encoded query string to be parsed keep_blank_values: flag indicating whether blank values in percent-encoded queries should be treated as blank strings. A true value indicates that blanks should be retained as blank strings. The default false value indicates that blank values are to be ignored and treated as if they were not included. strict_parsing: flag indicating what to do with parsing errors. If false (the default), errors are silently ignored. If true, errors raise a ValueError exception. encoding and errors: specify how to decode percent-encoded sequences into Unicode characters, as accepted by the bytes.decode() method. max_num_fields: int. If set, then throws a ValueError if there are more than n fields read by parse_qsl(). separator: str. The symbol to use for separating the query arguments. Defaults to &. Returns a list, as G-d intended. z*Separator must be of type string or bytes.rB=c(t|S)N)rKrL)r)r(rKrLs r@_unquotezparse_qsl.._unquote sHVDDD Dr?=cHt|ddS)N+ )rr)r(s r@rLzparse_qsl.._unquotes#AIIdD$9$9:: :r?NrZzMax number of fields exceededzbad query field: ) r[r\r3r memoryviewcountr rr)rBrCrDrKrLrAreqrL num_fieldsr name_valuerGhas_eqrHs `` r@r r s< GJy3,??GEFFF"c;)S)) 0Iw//I  E E E E E E E I:b>> " " i % % 2i11I  ; ; ;  !),,, J & &<== = Ahhy))((  ( (","6"6r":": D&% Hn H j**!FGGG () (x~~ $''' Hr?cP|dd}t|||S)zLike unquote(), but also replace plus signs by spaces, as required for unquoting HTML form values. unquote_plus('%7e/abc+def') -> '~/abc def' + )rr)r8rKrLs r@rr2s) ^^C % %F 68V , ,,r?sBABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.-~c|dkr#tjdtdtSt dt d|)NQuoterzoDeprecated in 3.11. urllib.parse.Quoter will be removed in Python 3.14. It was not intended to be a public API.r stacklevelzmodule z has no attribute )warningswarnDeprecationWarning_QuoterAttributeErrorrk)rGs r@ __getattr__rdAsY x @)Q 8 8 8 8 I8IIII J JJr?c$eZdZdZdZdZdZdS)rbzA mapping from bytes numbers (in range(0,256)) to strings. String values are percent-encoded byte values, unless the key < 128, and in either of the specified safe set, or the always safe set. cDt||_dS)zsafe: bytes object.N) _ALWAYS_SAFEunionsafe)rhris r@__init__z_Quoter.__init__Rs &&t,, r?c(dt|dS)Nz)dictr{s r@__repr__z_Quoter.__repr__Vs)$t**))))r?cj||jvrt|nd|}|||<|S)Nz%{:02X})richrformat)rhr r:s r@ __missing__z_Quoter.__missing__Ys7TYc!fffI,<,r?r@rbrbJsK---***r?rbrct|tr#|s|S|d}|d}|||}n"|td|tdt ||S)aquote('abc def') -> 'abc%20def' Each part of a URL, e.g. the path info, the query, etc., has a different set of reserved characters that must be quoted. The quote function offers a cautious (not minimal) way to quote a string for most of these parts. RFC 3986 Uniform Resource Identifier (URI): Generic Syntax lists the following (un)reserved characters. unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" reserved = gen-delims / sub-delims gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@" sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=" Each of the reserved characters is reserved in some component of a URL, but not necessarily in all of them. The quote function %-escapes all characters that are neither in the unreserved chars ("always safe") nor the additional chars set via the safe arg. The default for the safe arg is '/'. The character is reserved, but in typical usage the quote function is being called on a path where the existing slash characters are to be preserved. Python 3.7 updates from using RFC 2396 to RFC 3986 to quote URL strings. Now, "~" is included in the set of unreserved characters. string and safe may be either str or bytes objects. encoding and errors must not be specified if string is a bytes object. The optional encoding and errors parameters specify how to deal with non-ASCII characters, as accepted by the str.encode method. By default, encoding='utf-8' (characters are encoded with UTF-8), and errors='strict' (unsupported characters raise a UnicodeEncodeError). Nr0rCz,quote() doesn't support 'encoding' for bytesz*quote() doesn't support 'errors' for bytes)r[r\rJr]r)r8rirKrLs r@r r _sN&# J M  H >Fx00  JKK K  HII I FD ) ))r?ct|trd|vst|trd|vrt||||St|trd}nd}t|||z||}|ddS)zLike quote(), but also replace ' ' with '+', as required for quoting HTML form values. Plus signs in the original string are escaped unless they are included in safe. It also does not have safe default to '/'. rZrPrY)r[r\r3r r)r8rirKrLspaces r@rrs FC 5S%6%6 FE " "&7'+6'9'9VT8V444$ 64%<6 : :F >>#s # ##r?c*t|jSrE)rb __getitem__)ris r@r=r=s 4== $$r?ct|ttfstd|sdSt|tr|dd}ntd|D}|t|zs|St|d fd|DS)zLike quote(), but accepts a bytes object rather than a str, and does not perform string-to-bytes encoding. It always returns an ASCII string. quote_from_bytes(b'abc def?') -> 'abc%20def%3f' z!quote_from_bytes() expected bytesrrBignorecg|] }|dk| S)r>)rSrs r@ z$quote_from_bytes..s111ASar?c&g|] }|Sr>r>)rScharquoters r@r|z$quote_from_bytes..s!000TFF4LL000r?) r[r3 bytearrayr]r\rJrstrip_ALWAYS_SAFE_BYTESrQr=r)bsrirs @r@rrs b5), - -=;<<< r$3{{7H--1111122 99'$. / /yy{{ !$ ' 'F 770000R000 1 11r?cTt|dr|}nU t|r"t|dtst n"#t $r}t d|d}~wwxYwg}|s|D]\}} t|t r |||}n|t||||}t| t r || |} n|t| |||} ||dz| znw|D]s\}} t|t r |||}n|t||||}t| t r(|| |} ||dz| zt| tr*|| |||} ||dz| z t| } | D]Z} t| t r || |} n|t| |||} ||dz| z[.#t $r:|t| |||} ||dz| zYqwxYwd |S)a^Encode a dict or sequence of two-element tuples into a URL query string. If any values in the query arg are sequences and doseq is true, each sequence element is converted to a separate parameter. If the query arg is a sequence of two-element tuples, the order of the parameters in the output will match the order of parameters in the input. The components of a query arg may each be either a string or a bytes type. The safe, encoding, and errors parameters are passed down to the function specified by quote_via (encoding and errors only if a component is a str). itemsrz1not a valid non-string sequence or mapping objectNrJr?) hasattrrrr[rVr]r3r\rr) rdoseqrirKrL quote_viaerrlkrrTelts r@r r s"ug:  :5zz *U1Xu"="=   : : :01169 : : A (0 " "DAq!U## >Ia&&Ic!ffdHf==!U## >Ia&&Ic!ffdHf== HHQWq[ ! ! ! ! " 0 0DAq!U## >Ia&&Ic!ffdHf==!U## 0Ia&&S1%%%%As## 0Iax88S1%%%%0AA !00%c511N"+)C"6"6CC"+)CHHdHf"M"MCS3//// 0 !***! #a&&$&AAAHHQWq[)))))* 88A;;s*1A A8#A33A8 IAJJcXtjdtdt|S)Nz/urllib.parse.to_bytes() is deprecated as of 3.8rr])r_r`ra _to_bytesrs r@to_bytesrs/ MC$4444 S>>r?ct|trY |d}n0#t$r#t dt |zdzwxYw|S)zto_bytes(u"URL") --> 'URL'.ASCIIzURL z contains non-ASCII characters)r[r\rJrQ UnicodeErrorreprrs r@rrs #sA A**W%%,,..CC A A AvS 1? @AA A A Js '?-A,c t|}|dddkr*|dddkr|dd}|dddkr|dd}|S)zTransform a string like '' into 'scheme://host/path'. The string is returned unchanged if it's not a wrapped URL. NrZ 'type', 'opaquestring'.Nz ([^/:]+):(.*)) _typeprogrcompileDOTALLrgroupsr)rrrdatas r@rr8sdJ :: OOC E $||~~ ||~~t## 9r?cXtjdtdt|S)NzUurllib.parse.splithost() is deprecated as of 3.8, use urllib.parse.urlparse() insteadrr])r_r`ra _splithostrs r@ splithostrErr?cttjdtjat|}|r.|\}}|r|ddkrd|z}||fSd|fS)z;splithost('//host[:port]/path') --> 'host[:port]', '/path'.Nz//([^/#?]*)(.*)rr) _hostprogrrrrr)rr host_portr"s r@rrMsyJ0")<< OOC E ,,.. 4  DGsNN:D$ 9r?cXtjdtdt|S)NzUurllib.parse.splituser() is deprecated as of 3.8, use urllib.parse.urlparse() insteadrr])r_r`ra _splituserhosts r@ splituserr\5 M8$4444 d  r?cD|d\}}}|r|nd|fS)zJsplituser('user[:passwd]@host[:port]') --> 'user[:passwd]', 'host[:port]'.rNr)ruserrs r@rrcs.,,D% #DDtd **r?cXtjdtdt|S)NzWurllib.parse.splitpasswd() is deprecated as of 3.8, use urllib.parse.urlparse() insteadrr])r_r`ra _splitpasswd)rs r@ splitpasswdris5 M8$4444   r?cD|d\}}}||r|ndfS)z/splitpasswd('user:passwd') -> 'user', 'passwd'.rNr)rrpasswds r@rrps...--D% E+&&t ,,r?cXtjdtdt|S)NzUurllib.parse.splitport() is deprecated as of 3.8, use urllib.parse.urlparse() insteadrr])r_r`ra _splitportrs r@ splitportrvrr?cttjdtjat|}|r|\}}|r||fS|dfS)z*splitport('host:port') --> 'host', 'port'.Nz (.*):([0-9]*)) _portprogrrr fullmatchr)rrrs r@rrseJ ::    % %E \\^^ d  :  :r?rcZtjdtdt||S)NzVurllib.parse.splitnport() is deprecated as of 3.8, use urllib.parse.urlparse() insteadrr])r_r`ra _splitnport)rdefports r@ splitnportrs7 M8$4444 tW % %%r?c|d\}}}|s|}n@|r>|r$|rt|}nd}||fS||fS)zSplit host and port, returning numeric port. Return given default port if no ':' found; defaults to -1. Return numerical port if a valid number is found after ':'. Return None if ':' but not a valid number.rN)rrrr)rrrrnports r@rrsx ,,D%   <<>> dllnn IIEEEU{ =r?cXtjdtdt|S)NzVurllib.parse.splitquery() is deprecated as of 3.8, use urllib.parse.urlparse() insteadrr])r_r`ra _splitqueryrs r@ splitqueryrs5 M8$4444 s  r?cH|d\}}}|r||fS|dfS)z/splitquery('/path?query') --> '/path', 'query'.rNr)rr"rrs r@rrs6,,D% U{ 9r?cXtjdtdt|S)NzTurllib.parse.splittag() is deprecated as of 3.8, use urllib.parse.urlparse() insteadrr])r_r`ra _splittagrs r@splittagrs3 M8$4444 S>>r?cH|d\}}}|r||fS|dfS)z)splittag('/path#tag') --> '/path', 'tag'.rNr)rr"rtags r@rrs6~~c**D% Sy 9r?cXtjdtdt|S)NzUurllib.parse.splitattr() is deprecated as of 3.8, use urllib.parse.urlparse() insteadrr])r_r`ra _splitattrrs r@ splitattrrrr?cP|d}|d|ddfS)zksplitattr('/path;attr1=value1;attr2=value2;...') -> '/path', ['attr1=value1', 'attr2=value2', ...].rrrZN)r )rwordss r@rrs* IIcNNE 8U122Y r?cXtjdtdt|S)NzWurllib.parse.splitvalue() is deprecated as of 3.8, use urllib.parse.parse_qsl() insteadrr])r_r`ra _splitvalue)attrs r@ splitvaluers5 M9$4444 t  r?cD|d\}}}||r|ndfS)z-splitvalue('attr=value') --> 'attr', 'value'.rJNr)rrrHs r@rrs.,,D% 5*%%d ++r?)rT)r)T)r0r)FFr0rNr?)rNN)rNN)r)r)mrn collectionsr functoolsrsysrr_r__all__rrrnon_hierarchical uses_query uses_fragmentr rrrA_implicit_encoding_implicit_errorsrGrMrXr`objectrbrrrwrr_DefragResultBase_SplitResultBase_ParseResultBaserrrrr"rr ResultBaserrrrrrrrrrrrr lru_cacherrr rrr2r6rrr=rr r r frozensetrgr3rrdrmrbr rr=rr rrrrrrrrrrrrrrrrrrrrrrrrrrr>r?r@rsB#"""""  H H H000  --- FFFAAA %%%  \100'''"4/((((!3.HHHH222"VVVVVfVVVVVVVVVVV#8#8#8#8#8V#8#8#8L2O<46G<J~~>>:688:=??!K&" #N#!" %!  #3"9"A"2"9"A 0 5 =# "2!7!?$4$=$E! # $o     "$9        "$9   )+<     ')@        ')@   111""""<))))DDD$$$$&GGG4   555! 5n N N N&B:B:B:B:J666 #  < 2:& ' '8:?PS''''T;@QTG G G G R----y!"" U<((KKKd*4*4*4*4*l$$$$$ %%%2222(!rD"MMMM`                +++ ---      &&&&",,,,,r?__pycache__/robotparser.cpython-311.opt-2.pyc000064400000027351151026775530015003 0ustar00 !A?h$ ddlZddlZddlZdgZejddZGddZGddZGdd Z dS) NRobotFileParser RequestRatezrequests secondscZeZdZ ddZdZdZdZdZdZdZ d Z d Z d Z d Z d ZdS)rcg|_g|_d|_d|_d|_||d|_dS)NFr)entriessitemaps default_entry disallow_all allow_allset_url last_checkedselfurls +/usr/lib64/python3.11/urllib/robotparser.py__init__zRobotFileParser.__init__sG  !! Sc |jSN)rrs rmtimezRobotFileParser.mtime%s   rcB ddl}||_dS)Nr)timer)rrs rmodifiedzRobotFileParser.modified.s(    IIKKrc~ ||_tj|dd\|_|_dS)N)rurllibparseurlparsehostpathrs rr zRobotFileParser.set_url6s7:%|44S99!A#> 4999rc tj|j}|}||ddS#tjj $rK}|j dvrd|_ n)|j dkr|j dkrd|_ Yd}~dSYd}~dSYd}~dSYd}~dSd}~wwxYw)Nzutf-8)iiTii) rrequesturlopenrreadr decode splitlineserror HTTPErrorcoder r )rfrawerrs rr'zRobotFileParser.read;sB 9&&tx00A&&((C JJszz'**5577 8 8 8 8 8|% & & &x:%%$(!!SSX^^!%!"!!!!!%3^^^^^ &s$A77C .CCcpd|jvr|j ||_dSdS|j|dSN*) useragentsr rappend)rentrys r _add_entryzRobotFileParser._add_entryHsM %" " "!)%*"""*) L   & & & & &rc> d}t}||D]V}|sB|dkrt}d}n+|dkr%||t}d}|d}|dkr |d|}|}|s|dd}t |dkr|d|d<tj |d|d<|ddkrM|dkr#||t}|j |dd}o|ddkr8|dkr0|j t|ddd}|dd kr8|dkr0|j t|dd d}|dd krP|dkrH|drt!|d|_d}S|dd kr|dkr|dd }t |dkr|drg|dr;t%t!|dt!|d|_d}*|ddkr |j |dX|dkr||dSdS)Nrr#:z user-agentdisallowFallowTz crawl-delayz request-rate/sitemap)Entryrr6findstripsplitlenlowerrr unquoter3r4 rulelinesRuleLineisdigitintdelayrreq_rater )rlinesstater5lineinumberss rr zRobotFileParser.parseQsO  7 27 2D A::!GGEEEaZZOOE***!GGEE #AAvvBQBx::< 4   5\**6<+?+?+D+DEE l%%r"Z_  j. 0C'EFFl  %% C\ , ,E ** ,s+++++ ,   5%//44 4trc|sdS|jD] }||r |jcS!|jr |jjSdSr)rrrWrJr rrYr5s r crawl_delayzRobotFileParser.crawl_delaysmzz|| 4\ # #E ** #{""" #   ,%+ +trc|sdS|jD] }||r |jcS!|jr |jjSdSr)rrrWrKr r]s r request_ratezRobotFileParser.request_ratesmzz|| 4\ & &E ** &~%%% &   /%. .trc"|jsdS|jSr)r rs r site_mapszRobotFileParser.site_mapss} 4}rc|j}|j ||jgz}dtt|S)Nz )rr joinmapstr)rrs r__str__zRobotFileParser.__str__s>,   )!3 44G{{3sG,,---rN)r)__name__ __module__ __qualname__rrrr r'r6r r[r^r`rbrgrrrrs !!!(((??? 9 9 9'''G#G#G#R: .....rc"eZdZ dZdZdZdS)rGc|dkr|sd}tjtj|}tj||_||_dS)NrT)rr rRr!rVr#rX)rr#rXs rrzRuleLine.__init__s[ 2::i:I|&&v|'<'9zTADIMMrN)rhrirjrrWrgrkrrrGrGsN1###BBBNNNNNrrGc(eZdZ dZdZdZdZdS)r?c>g|_g|_d|_d|_dSr)r3rFrJrKrs rrzEntry.__init__s"  rc|g}|jD]}|d||j|d|j|j,|j}|d|jd|j|tt|j d |S)Nz User-agent: z Crawl-delay: zRequest-rate: r= ) r3r4rJrKrequestssecondsextendrerfrFrd)rretagentrates rrgz Entry.__str__s_ / /E JJ-e-- . . . . : ! JJ3tz33 4 4 4 = $=D JJF FF FF G G G 3sDN++,,,yy~~rc |dd}|jD]&}|dkrdS|}||vrdS'dS)Nr=rr2TF)rBrDr3)rrYr|s rrWzEntry.applies_tosq@OOC((+1133 _  E||ttKKMME !!tt"urcX |jD] }||r |jcS!dS)NT)rFrWrX)rrprNs rrXzEntry.allowance sF %N & &Dx(( &~%%% &trN)rhrirjrrgrWrXrkrrr?r?sSI      rr?) collections urllib.parserurllib.request__all__ namedtuplerrrGr?rkrrrs   $k$]4FGG ~.~.~.~.~.~.~.~.BNNNNNNNN$((((((((((r__pycache__/error.cpython-311.opt-1.pyc000064400000007454151026775530013573 0ustar00 !A?ho dZddlZddlZgdZGddeZGddeejjZ Gdd eZ dS) aException classes raised by urllib. The base exception class is URLError, which inherits from OSError. It doesn't define any behavior of its own, but is the base class for all exceptions defined in this package. HTTPError is an exception class that is also a valid HTTP response instance. It behaves this way because HTTP protocol errors are valid responses, with a status code, headers, and a body. In some contexts, an application may want to handle an exception like a regular response. N)URLError HTTPErrorContentTooShortErrorceZdZddZdZdS)rNc:|f|_||_| ||_dSdSN)argsreasonfilename)selfr r s %/usr/lib64/python3.11/urllib/error.py__init__zURLError.__init__s+G   $DMMM cd|jzS)Nz)r r s r __str__zURLError.__str__s#dk11rr)__name__ __module__ __qualname__rrrr rrs7 %%%% 22222rrceZdZdZejjjZdZdZ dZ e dZ e dZ e jdZ dS) rzBRaised when HTTP error occurs, but also acts like non-error returnc||_||_||_||_||_|t j}|||||dSr)codemsghdrsfpr ioBytesIO_HTTPError__super_init)r urlrrrrs r rzHTTPError.__init__'sU   :B "dC.....rc&d|jd|jS)Nz HTTP Error : rrrs r rzHTTPError.__str__1s&*iii::rc(d|jd|jdS)Nz r#rs r __repr__zHTTPError.__repr__4s'+yyy$(((;;rc|jSr)rrs r r zHTTPError.reason9s xrc|jSrrrs r headerszHTTPError.headers=s yrc||_dSrr))r r*s r r*zHTTPError.headersAs  rN)rrr__doc__urllibresponse addinfourlrrrr&propertyr r*setterrrr rr#sLL?-6L///;;;<<< XX ^^rrceZdZdZdZdS)rzDException raised when downloaded size does not match content-length.cJt||||_dSr)rrcontent)r messager4s r rzContentTooShortError.__init__Hs#$((( rN)rrrr,rrrr rrFs)NNrr) r,rurllib.responser-__all__OSErrorrr.r/rrrrr r9s    ; ; ; 2 2 2 2 2w 2 2 2     &/4   F8r__pycache__/error.cpython-311.opt-2.pyc000064400000006212151026775530013563 0ustar00 !A?ho  ddlZddlZgdZGddeZGddeejjZGddeZ dS) N)URLError HTTPErrorContentTooShortErrorceZdZddZdZdS)rNc:|f|_||_| ||_dSdSN)argsreasonfilename)selfr r s %/usr/lib64/python3.11/urllib/error.py__init__zURLError.__init__s+G   $DMMM cd|jzS)Nz)r r s r __str__zURLError.__str__s#dk11rr)__name__ __module__ __qualname__rrrr rrs7 %%%% 22222rrceZdZ ejjjZdZdZdZ e dZ e dZ e j dZ dS)rc||_||_||_||_||_|t j}|||||dSr)codemsghdrsfpr ioBytesIO_HTTPError__super_init)r urlrrrrs r rzHTTPError.__init__'sU   :B "dC.....rc&d|jd|jS)Nz HTTP Error : rrrs r rzHTTPError.__str__1s&*iii::rc(d|jd|jdS)Nz r#rs r __repr__zHTTPError.__repr__4s'+yyy$(((;;rc|jSr)rrs r r zHTTPError.reason9s xrc|jSrrrs r headerszHTTPError.headers=s yrc||_dSrr))r r*s r r*zHTTPError.headersAs  rN)rrrurllibresponse addinfourlrrrr&propertyr r*setterrrr rr#sL?-6L///;;;<<< XX ^^rrceZdZ dZdS)rcJt||||_dSr)rrcontent)r messager3s r rzContentTooShortError.__init__Hs#$((( rN)rrrrrrr rrFs&Nrr) rurllib.responser,__all__OSErrorrr-r.rrrrr r8s   ; ; ; 2 2 2 2 2w 2 2 2     &/4   F8r__pycache__/parse.cpython-311.opt-2.pyc000064400000127621151026775530013554 0ustar00 !A?h$0 ddlmZddlZddlZddlZddlZddlZddlZgdZgdZ gdZ gdZ gdZ gdZ gd Zd Zd Zgd Zd ZdZdZdZeefdZeefdZdZGddeZGddeZGddeZGddeeZGddeeZeddZed d!Z ed"d#Z!d$e_"d%ej#_"d&ej$_"d'e _"d(e j%_"d)e j&_"d*e j'_"d+e j(_"d,e j$_"d-e!_"e j%j"e!j%_"e j&j"e!j&_"e j'j"e!j'_"d.e!j)_"e j(j"e!j(_"e j$j"e!j$_"eZ*Gd/deeZ+Gd0d e eZ,Gd1d"e!eZ-Gd2d3eeZ.Gd4d5e eZ/Gd6d7e!eZ0d8Z1e1[1dtd;Z2d<Z3dud=Z4d>Z5d?Z6d@Z7ej8d:AdtdBZ9dCZ:dDZ;dvdEZda?dHZ@ejAdIZBdwdLZC dxdOZD dxdPZEdwdQZFeGdRZHeIeHZJdSZKGdTdUeLZMdydWZNdzdXZOej8dYZPd{dZZQdMd9ddeOfd[ZRd\ZSd]ZTd^ZUd_ZVdaWd`ZXdaZYdaZdbZ[dcZ\ddZ]deZ^dfZ_dgZ`daadhZbd|djZcd|dkZddlZedmZfdnZgdoZhdpZidqZjdrZkdsZldS)}) namedtupleN)urlparse urlunparseurljoin urldefragurlsplit urlunsplit urlencodeparse_qs parse_qslquote quote_plusquote_from_bytesunquote unquote_plusunquote_to_bytes DefragResult ParseResult SplitResultDefragResultBytesParseResultBytesSplitResultBytes)ftphttpgophernntpimapwaisfilehttpsshttpmmsprosperortsprtspsrtspusftpsvnsvn+sshwswss)rrrrrtelnetrrr r#r!r"snewsr$r%r&r'rsyncr)r*r(nfsgitzgit+sshr+r,)rrhdlr$rrr!r"r%r&r'sipsipsr#r(tel) rr2mailtonewsr-rrr.r3r4) rrrrr!r"r#rr%r&r'r3r4) rrr2rrr7rrr!r"r.r r$zAabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-.z!  )   cl ttdSN)r cache_clear_byte_quoter_factory%/usr/lib64/python3.11/urllib/parse.py clear_cacherB^s/N $$&&&&&r@asciistrictc|Sr<r?)objs rA_nooprGls Jr@c.|||Sr<encode)rFencodingerrorss rA_encode_resultrMos ::h ' ''r@c>tfd|DS)Nc3LK|]}|r|ndVdS)rNdecode.0xrKrLs rA z_decode_args..us;GGQq8(F+++bGGGGGGr@)tuple)argsrKrLs ``rA _decode_argsrXss* GGGGG$GGG G GGr@ct|dt}|ddD],}|r(t|t|krtd-|r |tfzSt |t fzS)Nrz$Cannot mix str and non-str arguments) isinstancestr TypeErrorrGrXrM)rW str_inputargs rA _coerce_argsr`ws 47C((IABBxDD  D:c3''944BCC Cuh    1 11r@ceZdZ dZddZdS)_ResultMixinStrr?rCrDc4|jfd|DS)Nc3DK|]}|VdSr<rIrRs rArUz)_ResultMixinStr.encode..1*T*T!188Hf+E+E*T*T*T*T*T*Tr@)_encoded_counterpartselfrKrLs ``rArJz_ResultMixinStr.encode,(t(*T*T*T*T*Tt*T*T*TUUr@NrCrD)__name__ __module__ __qualname__ __slots__rJr?r@rArbrb6HIVVVVVVr@rbceZdZ dZddZdS)_ResultMixinBytesr?rCrDc4|jfd|DS)Nc3DK|]}|VdSr<rPrRs rArUz+_ResultMixinBytes.decode..rer@)_decoded_counterpartrgs ``rArQz_ResultMixinBytes.decoderir@Nrj)rkrlrmrnrQr?r@rArqrqror@rqceZdZ dZedZedZedZedZe e j Z dS)_NetlocResultMixinBaser?c|jdS)Nr _userinforhs rAusernamez_NetlocResultMixinBase.username~a  r@c|jdS)NrZrxrzs rApasswordz_NetlocResultMixinBase.passwordr|r@c|jd}|sdSt|trdnd}||\}}}||z|zS)Nr%%) _hostinfor[r\ partitionlower)rhhostname separatorpercentzones rArz_NetlocResultMixinBase.hostnamesi>!$ 4&h44>CC$ "*"4"4Y"?"?'4~~')D00r@c|jd}|h|r$|rt|}nt d|d|cxkrdksnt d|S)NrZz+Port could not be cast to integer value as rizPort out of range 0-65535)risdigitisasciiint ValueError)rhports rArz_NetlocResultMixinBase.ports~a   ||~~ Y$,,.. Y4yy !Wt!W!WXXX&&&&&&&& !<=== r@N) rkrlrmrnpropertyr{r~rr classmethodtypes GenericAlias__class_getitem__r?r@rArvrvsRI !!X!!!X!11X1  X $ E$677r@rvc>eZdZdZedZedZdS)_NetlocResultMixinStrr?c|j}|d\}}}|r|d\}}}|sd}ndx}}||fS)N@:netloc rpartitionrrhruserinfo have_infohostinfor{ have_passwordr~s rAryz_NetlocResultMixinStr._userinfosh(.(9(9#(>(>%)X  '080B0B30G0G -HmX  "& &Hx!!r@c |j}|d\}}}|d\}}}|r3|d\}}}|d\}}}n|d\}}}|sd}||fS)Nr[]rrrhr_r have_open_br bracketedrrs rArz_NetlocResultMixinStr._hostinfos**3//1h%-%7%7%<%<"<  8 ) 3 3C 8 8 Ha,,JAq$$ ( 2 23 7 7 Ha D~r@Nrkrlrmrnrryrr?r@rArrMI  " "X "  X   r@rc>eZdZdZedZedZdS)_NetlocResultMixinBytesr?c|j}|d\}}}|r|d\}}}|sd}ndx}}||fS)N@:rrs rAryz!_NetlocResultMixinBytes._userinfosh(.(9(9$(?(?%)X  '080B0B40H0H -HmX  "& &Hx!!r@c |j}|d\}}}|d\}}}|r3|d\}}}|d\}}}n|d\}}}|sd}||fS)Nr[]rrrs rArz!_NetlocResultMixinBytes._hostinfos**4001h%-%7%7%=%="<  9 ) 3 3D 9 9 Ha--JAq$$ ( 2 24 8 8 Ha D~r@Nrr?r@rArrrr@rrz url fragmentrz!scheme netloc path query fragmentrz(scheme netloc path params query fragmentz DefragResult(url, fragment) A 2-tuple that contains the url without fragment identifier and the fragment identifier as a separate argument. z$The URL with no fragment identifier.z Fragment identifier separated from URL, that allows indirect identification of a secondary resource by reference to a primary resource and additional identifying information. z SplitResult(scheme, netloc, path, query, fragment) A 5-tuple that contains the different components of a URL. Similar to ParseResult, but does not split params. z%Specifies URL scheme for the request.z0 Network location where the request is made to. z@ The hierarchical path, such as the path to a file to download. z The query component, that contains non-hierarchical data, that along with data in path component, identifies a resource in the scope of URI's scheme and network location. z Fragment identifier, that allows indirect identification of a secondary resource by reference to a primary resource and additional identifying information. zq ParseResult(scheme, netloc, path, params, query, fragment) A 6-tuple that contains components of a parsed URL. z Parameters for last path element used to dereference the URI in order to provide access to perform some operation on the resource. ceZdZdZdZdS)rr?cB|jr|jdz|jzS|jSN#fragmenturlrzs rAgeturlzDefragResult.geturlEs& = 8c>DM1 18Or@Nrkrlrmrnrr?r@rArrC(Ir@ceZdZdZdZdS)rr?c t|Sr<r rzs rArzSplitResult.geturlM$r@Nrr?r@rArrK(I     r@ceZdZdZdZdS)rr?c t|Sr<rrzs rArzParseResult.geturlRrr@Nrr?r@rArrPrr@ceZdZdZdZdS)rr?cB|jr|jdz|jzS|jS)N#rrzs rArzDefragResultBytes.geturlXs& = 8d?T]2 28Or@Nrr?r@rArrVrr@rceZdZdZdZdS)rr?c t|Sr<rrzs rArzSplitResultBytes.geturl`rr@Nrr?r@rArr^rr@rceZdZdZdZdS)rr?c t|Sr<rrzs rArzParseResultBytes.geturlerr@Nrr?r@rArrcrr@rcttfttftt ff}|D]\}}||_||_dSr<)rrrrrrrfrt) _result_pairs_decoded_encodeds rA_fix_result_transcodingrisW () &' &'M ,11((0%(0%%11r@rTc t||\}}}t|||}|\}}}}}|tvrd|vrt|\}}nd}t ||||||} || S)N;r)r`r uses_params _splitparamsr) rschemeallow_fragments_coerce_result splitresultrqueryrparamsresults rArrvs&#/sF";";C388K+6(FFC "3'' VV feX F FF >& ! !!r@cd|vr4|d|d}|dkr|dfSn|d}|d|||dzdfS)N/rrrrZ)findrfind)ris rArrso s{{ HHS#))C.. ) ) q557N  HHSMM rr7C!I r@ct|}dD].}|||}|dkrt||}/|||||dfS)Nz/?#r)lenrmin)rstartdelimcwdelims rA _splitnetlocrsd HHE ''!U## Q;;v&&E uU{ S[ ((r@cl|r|rdSddl}|dd}|dd}|dd}|dd}|d|}||krdSdD]}||vrt d |zd zd zdS) Nrrrrr?NFKCz/?#@:znetloc 'z' contains invalid z#characters under NFKC normalization)r unicodedatareplace normalizer)rrnnetloc2rs rA _checknetlocrs V^^%%sBA #rA #rA #rA##FA..GG|| DD <<Z&03HHBCDD D DDr@cd|dd}|d\}}}|rQ|rtd|d\}}}|r$|dstdn|d\}}}t |dS)NrrInvalid IPv6 URLrr)rrr startswith_check_bracketed_host)rhostname_and_portbefore_bracketrrrrrs rA_check_bracketed_netlocrs))#..q1.?.I.I#.N.N+NL) =  1/00 0%//44!T  1,, 1/00 0-77<<!T(#####r@c|dr&tjd|stddSt j|}t |tjrtddS)Nvz\Av[a-fA-F0-9]+\..+\ZzIPvFuture address is invalidz%An IPv4 address cannot be in brackets)rrematchr ipaddress ip_addressr[ IPv4Address)rips rArrs3Gx0(;; ><== = > > !( + + b)/ 0 0 GEFF F G Gr@)typedc t||\}}}|t}|t}tD].}||d}||d}/t |}dx}x}}|d}|dkru|dr[|d rA|d|D] } | tvrn*|d| ||dzd}}|dddkrIt|d\}}d|vrd|vsd|vrd|vrtd d|vrd|vrt||rd |vr|d d\}}d |vr|d d\}}t!|t#|||||} || S) NrrrrZr//rrrrr)r`lstrip_WHATWG_C0_CONTROL_OR_SPACEstrip_UNSAFE_URL_BYTES_TO_REMOVErboolrrisalpha scheme_charsrrrrsplitrr) rrrrbrrrrrrs rArrs(#/sF";";C **0 1 1C \\5 6 6F (''kk!R  2&&?++O ""F"UX  A1uuQ!!uc!fnn&6&6uRaR 5 5A $$%bqb'--//3qstt9CF 2A2w$"3**  F]]s&003f#4#4/00 0 &==SF]] #F + + +*3#:: #q)) X czzYYsA&& UFFC99A >!  r@c r t|\}}}}}}}|r|d|}|t|||||fS)Nr)r`r ) componentsrrrrrrrs rArr s`5 3? 2KAFFC. &ff% >*ffc5(%KLL M MMr@c t|\}}}}}}|s|r |tvs|dddkr|r|dddkrd|z}d|pdz|z}|r|dz|z}|r|dz|z}|r|dz|z}||S) NrrrZrrrrr)r` uses_netloc)rrrrrrrs rAr r s? +7 *C9FFC. *&*V{22s2A2w$ 23rr7c>>s3fl#c) !slS   Ci%#Ci(" >#  r@c  |s|S|s|St||\}}}t|d|\}}}}}} t|||\} } } } }}| |ks | tvr ||S| tvr"| r|t | | | | ||fS|} | s(| s&|} |} |s|}|t | | | | ||fS|d}|ddkr|d=| dddkr| d}n5|| dz}t d|dd|dd<g}|D]J}|dkr& |#t$rY*wxYw|dkr5| |K|ddvr| d|t | | d |pd| ||fS)NrrrZ...)rr) r`r uses_relativerrr filterpop IndexErrorappendjoin)baserrrbschemebnetlocbpathbparamsbquery bfragmentrrpathrrr base_partssegments resolved_pathsegs rArr+s%   ,T3 7 7D#~ T2 / /8GWeWfi S'? 3 32FFD&%F-77~c"""   I!>*ffd.4eX.G#H#HII I EE E~j&&$*0%*CDDEE ES!!J"~ rN BQBx3::c?? 3/ hqtn552M & & $;; !!####    CZZ    % % % %|{"" R   >*ffchh777vuh&899 : ::sE E)(E)c t|\}}d|vr,t|\}}}}}}t|||||df}nd}|}|t||S)Nrr)r`rrr) rrsrpaqfragdefrags rArrps| 's++C czz&smm1aAtQ1aB/00 >,vt44 5 55r@0123456789ABCDEFabcdefc |s |jdSt|tr|d}|d}t |dkr|S|dg}|j}t dtDa|ddD]Z} |t |dd||dd5#t$r|d||YWwxYwd |S)Nr@utf-8rrZrci|]?}tD]5}||zt||z6@Sr?)_hexdigrJbytesfromhex)rSr*r s rA z$unquote_to_bytes..s\99999+,1unn&& a!e(<(<9999r@r) r r[r\rJrr _hextobyter2KeyErrorr)stringbitsresritems rArrs:6  s&#(w'' <<  D 4yyA~~ 7)C ZF99&999 QRR  F:d2A2h' ( ( ( F48        F4LLL F4LLLLL  88C==s1C C+*C+z([-]+)r0rc t|tr#t|||Sd|vr |j|S|d}|d}t |}|dg}|j}tdt|dD]H}|t|||||||dzId |S)Nrr0rrrZrr) r[r3rrQr _asciirerrangerr)r8rKrLr9r:rrs rArrs&%  A''..x@@@ &   ~ >>& ! !D 7)C ZF 1c$ii # #Q((//&AABBBtAE{ 773<<r@F&c  i}t|||||||}|D]+\} } | |vr|| | %| g|| <,|S)N)rKrLmax_num_fieldsr)r r) qskeep_blank_valuesstrict_parsingrKrLrAr parsed_resultpairsnamevalues rAr r s8M b+^'%3y J J JE** e = $  & &u - - - -#('M$   r@c |rt|ttfstdt|tr.t|tst|d}d}fd}nJ|sgStt |}t|trt|d}d}d}|sgS|-d||z} || krtdg} ||D]f} | s|r`| |\} } }| s|rtd | |s|r-|| } ||}| | |fg| S) Nz*Separator must be of type string or bytes.rC=c(t|S)N)rKrL)r)r(rKrLs rA_unquotezparse_qsl.._unquote sHVDDD Dr@=cHt|ddS)N+ )rr)r(s rArLzparse_qsl.._unquotes#AIIdD$9$9:: :r@rZzMax number of fields exceededzbad query field: ) r[r\r3r memoryviewcountr rr)rBrCrDrKrLrAreqrL num_fieldsr name_valuerGhas_eqrHs `` rAr r s8 GJy3,??GEFFF"c;)S)) 0Iw//I  E E E E E E E I:b>> " " i % % 2i11I  ; ; ;  !),,, J & &<== = Ahhy))((  ( (","6"6r":": D&% Hn H j**!FGGG () (x~~ $''' Hr@cR |dd}t|||S)N+ )rr)r8rKrLs rArr2s. ^^C % %F 68V , ,,r@sBABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.-~c|dkr#tjdtdtSt dt d|)NQuoterzoDeprecated in 3.11. urllib.parse.Quoter will be removed in Python 3.14. It was not intended to be a public API.r stacklevelzmodule z has no attribute )warningswarnDeprecationWarning_QuoterAttributeErrorrk)rGs rA __getattr__rdAsY x @)Q 8 8 8 8 I8IIII J JJr@c"eZdZ dZdZdZdS)rbcF t||_dSr<) _ALWAYS_SAFEunionsafe)rhris rA__init__z_Quoter.__init__Rs! &&t,, r@c(dt|dS)Nz)dictrzs rA__repr__z_Quoter.__repr__Vs)$t**))))r@cj||jvrt|nd|}|||<|S)Nz%{:02X})richrformat)rhr r:s rA __missing__z_Quoter.__missing__Ys7TYc!fffI,<,Fx00  JKK K  HII I FD ) ))r@c t|trd|vst|trd|vrt||||St|trd}nd}t|||z||}|ddS)NrZrPrY)r[r\r3r r)r8rirKrLspaces rArrs FC 5S%6%6 FE " "&7'+6'9'9VT8V444$ 64%<6 : :F >>#s # ##r@c*t|jSr<)rb __getitem__)ris rAr>r>s 4== $$r@c t|ttfstd|sdSt|tr|dd}ntd|D}|t|zs|St|d fd|DS)Nz!quote_from_bytes() expected bytesrrCignorecg|] }|dk| S)r?)rSrs rA z$quote_from_bytes..s111ASar@c&g|] }|Sr?r?)rScharquoters rAr|z$quote_from_bytes..s!000TFF4LL000r@) r[r3 bytearrayr]r\rJrstrip_ALWAYS_SAFE_BYTESrQr>r)bsrirs @rArrs b5), - -=;<<< r$3{{7H--1111122 99'$. / /yy{{ !$ ' 'F 770000R000 1 11r@cV t|dr|}nU t|r"t|dtst n"#t $r}t d|d}~wwxYwg}|s|D]\}} t|t r |||}n|t||||}t| t r || |} n|t| |||} ||dz| znw|D]s\}} t|t r |||}n|t||||}t| t r(|| |} ||dz| zt| tr*|| |||} ||dz| z t| } | D]Z} t| t r || |} n|t| |||} ||dz| z[.#t $r:|t| |||} ||dz| zYqwxYwd |S)Nitemsrz1not a valid non-string sequence or mapping objectrJr?) hasattrrrr[rVr]r3r\rr) rdoseqrirKrL quote_viaerrlkrrTelts rAr r s  ug:  :5zz *U1Xu"="=   : : :01169 : : A (0 " "DAq!U## >Ia&&Ic!ffdHf==!U## >Ia&&Ic!ffdHf== HHQWq[ ! ! ! ! " 0 0DAq!U## >Ia&&Ic!ffdHf==!U## 0Ia&&S1%%%%As## 0Iax88S1%%%%0AA !00%c511N"+)C"6"6CC"+)CHHdHf"M"MCS3//// 0 !***! #a&&$&AAAHHQWq[)))))* 88A;;s*1A A9$A44A9!IAJJcXtjdtdt|S)Nz/urllib.parse.to_bytes() is deprecated as of 3.8rr])r_r`ra _to_bytesrs rAto_bytesrs/ MC$4444 S>>r@c t|trY |d}n0#t$r#t dt |zdzwxYw|S)NASCIIzURL z contains non-ASCII characters)r[r\rJrQ UnicodeErrorreprrs rArrs%#sA A**W%%,,..CC A A AvS 1? @AA A A Js 'A-A-c t|}|dddkr*|dddkr|dd}|dddkr|dd}|S)NrZ|r$|rt|}nd}||fS||fSr)rrrr)rrrrnports rArrs}2,,D%   <<>> dllnn IIEEEU{ =r@cXtjdtdt|S)NzVurllib.parse.splitquery() is deprecated as of 3.8, use urllib.parse.urlparse() insteadrr])r_r`ra _splitqueryrs rA splitqueryrs5 M8$4444 s  r@cJ |d\}}}|r||fS|dfS)Nrr)rr"rrs rArrs99,,D% U{ 9r@cXtjdtdt|S)NzTurllib.parse.splittag() is deprecated as of 3.8, use urllib.parse.urlparse() insteadrr])r_r`ra _splittagrs rAsplittagrs3 M8$4444 S>>r@cJ |d\}}}|r||fS|dfSrr)rr"rtags rArrs93~~c**D% Sy 9r@cXtjdtdt|S)NzUurllib.parse.splitattr() is deprecated as of 3.8, use urllib.parse.urlparse() insteadrr])r_r`ra _splitattrrs rA splitattrrrr@cR |d}|d|ddfS)NrrrZ)r )rwordss rArrs-; IIcNNE 8U122Y r@cXtjdtdt|S)NzWurllib.parse.splitvalue() is deprecated as of 3.8, use urllib.parse.parse_qsl() insteadrr])r_r`ra _splitvalue)attrs rA splitvaluers5 M9$4444 t  r@cF |d\}}}||r|ndfS)NrJr)rrrHs rArrs17,,D% 5*%%d ++r@)rT)r)T)r0r)FFr0rNr?)rNN)rNN)r)r)m collectionsr functoolsrsysrr_r__all__rrrnon_hierarchical uses_query uses_fragmentr rrrB_implicit_encoding_implicit_errorsrGrMrXr`objectrbrqrvrr_DefragResultBase_SplitResultBase_ParseResultBase__doc__rrrrr"rr ResultBaserrrrrrrrrrrrr lru_cacherrr rrr2r6rrr=rr r r frozensetrgr3rrdrmrbr rr>rr rrrrrrrrrrrrrrrrrrrrrrrrrrr?r@rArsB#"""""  H H H000  --- FFFAAA %%%  \100'''"4/((((!3.HHHH222"VVVVVfVVVVVVVVVVV#8#8#8#8#8V#8#8#8L2O<46G<J~~>>:688:=??!K&" #N#!" %!  #3"9"A"2"9"A 0 5 =# "2!7!?$4$=$E! # $o     "$9        "$9   )+<     ')@        ')@   111""""<))))DDD$$$$&GGG4   555! 5n N N N&B:B:B:B:J666 #  < 2:& ' '8:?PS''''T;@QTG G G G R----y!"" U<((KKKd*4*4*4*4*l$$$$$ %%%2222(!rD"MMMM`                +++ ---      &&&&",,,,,r@__pycache__/response.cpython-311.opt-2.pyc000064400000011010151026775530014260 0ustar00 !A?h9  ddlZgdZGddejZGddeZGddeZGd d eZdS) N)addbase addclosehookaddinfo addinfourlc2eZdZ fdZdZdZdZxZS)rcltt||dd||_dS)NzF)delete)superr__init__fp)selfr __class__s (/usr/lib64/python3.11/urllib/response.pyr zaddbase.__init__s4 g&&r+>u&MMMcRd|jjdt|d|jdS)N)r__name__idfiler s r__repr__zaddbase.__repr__s3-1^-D-D-D-/XXXXtyyyB Brc<|jjrtd|S)NzI/O operation on closed file)r closed ValueErrorrs r __enter__zaddbase.__enter__s" 7> =;<< < rc.|dSN)close)r typevalue tracebacks r__exit__zaddbase.__exit__!s r)r __module__ __qualname__r rrr# __classcell__rs@rrrskY BBB rrc*eZdZ fdZfdZxZS)rcttt||||_||_dSr)r rr closehookhookargs)r r r*r+rs rr zaddclosehook.__init__(s3 lD!!**2..."  rc |j}|j}|rd|_d|_||tt|dS#tt|wxYwr)r*r+r rr)r r*r+rs rrzaddclosehook.close-s} .I}H %!% $  8$$ , % % + + - - - - -E, % % + + - - - -s #A)A8)rr$r%r rr&r's@rrr%sT4!!!!! . . . . . . . . .rrc&eZdZ fdZdZxZS)rcftt||||_dSr)r rr headers)r r r/rs rr zaddinfo.__init__<s, gt%%b))) rc|jSr)r/rs rinfoz addinfo.info@s |r)rr$r%r r1r&r's@rrr9sJ8rrcDeZdZ dfd ZedZdZdZxZS)rNcvtt|||||_||_dSr)r rr urlcode)r r r/r4r5rs rr zaddinfourl.__init__Gs5 j$((W555 rc|jSrr5rs rstatuszaddinfourl.statusLs yrc|jSrr7rs rgetcodezaddinfourl.getcodePs yrc|jSr)r4rs rgeturlzaddinfourl.geturlSs xrr) rr$r%r propertyr8r:r<r&r's@rrrDsyC Xrr)tempfile__all___TemporaryFileWrapperrrrrrrrBs > > >h,......7...(gr__pycache__/request.cpython-311.opt-2.pyc000064400000337237151026775530014140 0ustar00 !A?hw< ddlZddlZddlZddlZddlZddlZddlZddlZddl 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,n #e-$rdZ,YnwxYwgdZ.de j/dd zZ0da1de j2fddddd d Z3d Z4gZ5dfd Z6dZ7e j8de j9Z:dZ;GddZ<GddZ=dZ>GddZ?Gdde?Z@Gdde?ZAGdde?ZBdZCGdd e?ZDGd!d"ZEGd#d$eEZFGd%d&eFZGGd'd(ZHGd)d*eHe?ZIGd+d,eHe?ZJejKZLGd-d.ZMGd/d0e?eMZNGd1d2e?eMZOGd3d4e?ZPGd5d6ePZQeRejSd7r#Gd8d9ePZTe.Ud9Gd:d;e?ZVGd<d=e?ZWd>ZXd?ZYGd@dAe?ZZdBZ[GdCdDe?Z\GdEdFe\Z]GdGdHe?Z^dIZ_ej`dJkr ddKlambZbmcZcndLZbdMZciZdGdNdOZeGdPdQeeZfdagdRZhdaidSZjdakdTZldamdUZnGdVdWZodXZpdgdYZqdZZrd[Zse jtd\krdd]lumvZvmwZwd^Zxd_Zyd`ZzdaZ{dSej`dJkrdbZ|dcZ{ddZ}deZzdSepZ{eqZzdS)hN)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) NrzJcafile, 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 '/usr/lib64/python3.11/urllib/request.pyr1r1s40d9 01CQ H H H    :899 9,S[-D4:4:<<< ""J<000$W555 m,, $W555 m,, '>>)&& ;;sD' * **c |adSN)rL)rRs rSr2r2s GGGrTcN t|\}}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) NfilewbF)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==E9A E9 B E" E9"E& &E9)E& *E99E=E=c tD]'} tj|#t$rY$wxYwtdd=trdadSdSrV)rjrdunlinkOSErrorrL) temp_files rSr8r8su:#   Ii     D  qqqs ! ..z:\d+$c |j}t|d}|dkr|dd}td|d}|S)Nr_Host)full_urlr get_header _cut_port_resublower)requestrNhosts rS request_hostr-sf  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|_dSNr)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)NPOSTGETr)rOgetattr)rdefault_methods rS get_methodzRequest.get_method~s'A#'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)rr rOrvrs 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)NHTTPSConnection)rr r/r*rrr,r+r0r.rrclientrkrKsetrr issubclassaddremover)rrRdefault_classesskipklasscheckhs rSr3r39s|  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   88888rTrceZdZ dZdZeZdS)r0ic|j|j|}}}d|cxkrdks!n|jd|||||}|S)N,r)codemsgrcr)r)rrrr3r4rs 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) rr rsr3r4rtnewurlm 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) rr rsr3r4rtrIurlpartsnewvisiteds 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~2GGGrTrc t|\}}|dsd}|}n|dstd|zd|vr,|d}|d|}n|dd}|dkrd}|d|}t |\}}|t |\}} ndx}} ||| |fS)NrQ//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}||_|D]7\}}|}t |d|z|||jfd8dS)Nz%s_openc||||SrVr)rrhrrs rSz'ProxyHandler.__init__..#sQt,,rT)r6proxiesrrsetattrr)rrxrrNs rSrzProxyHandler.__init__s ? llG   . .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?;;('(( (zrTTc t|}|dr|d}|d}|dpd}nd}|}d}t|\}}|r%|#|!ddd|} | d|| fz}||fS) Nr_rr;rQPirz%s:%d)rrr) rrNrpartsrVrjrerportdports rSrzHTTPPasswordMgr.reduce_uri\sN  8 1XFaI8?sDDFID ** d  4DLV-?!s6{{  #tUm3 $rTc ||krdS|d|dkrdS|d}|dddkr|dz }|d|S)NTrFr_r\rQ)r)rbasetestprefixs rSrzHTTPPasswordMgr.is_suburissl  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) rauthreqrr rt 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{r~r|rU) rrrrrrr auth_headerrr)rMrP)rrr rropwrawauths 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)rr ror 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)Nrr1r2TF)rrr3rr)rr rs rSr5z&AbstractBasicAuthHandler.http_response sx 4; 2 3 3 Fhm))))c))))) 00tDDDD 00uEEErTrV)rrrrecompileIrrrrrrr5 https_requestr6rrTrSr$r$s 1D  B5555 !!!(***4      !M"NNNrTr$ceZdZdZdZdS)r%rcD|j}|d|||}|S)Nwww-authenticate)rr)rr rsr3r4rtrNrs rShttp_error_401z#HTTPBasicAuthHandler.http_error_401s-l--.@*-sG==rTN)rrrrrrrTrSr%r%s(!KrTr%ceZdZdZdZdS)r&r}cD|j}|d|||}|SNproxy-authenticate)rr)rr rsr3r4rtrjrs 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)rrrr rtrrVs 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 rSrwz?AbstractDigestAuthHandler.get_algorithm_impls..s('+ahhw&7&788BBDDrTSHActtj|dSr )rrrrr"s rSrwz?AbstractDigestAuthHandler.get_algorithm_impls..s(',qxx'8'899CCEErTz.Unsupported digest authentication algorithm %rc$|d|S)Nr{r)rdrs rSrwz?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'ceZdZ dZdZdZdS)r(rct|jd}|d|||}||S)Nr_r)rrrrrr rsr3r4rtrretrys rSrz$HTTPDigestAuthHandler.http_error_401sL %%a(**+=+/g??     rTN)rrrrr,rrrTrSr(r(s4 "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||_dSrVr4)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) rrrrOr4content_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) Nr?rPc$i|] \}}|v || Srr)rCrDrErts rSrGz/AbstractHTTPHandler.do_open..)s3---AG++1+++rTr Connectionc>i|]\}}||Sr)title)rCrirs rSrGz/AbstractHTTPHandler.do_open..6s&FFFs4::<<FFFrTr/rtrA)encode_chunked)rrrPset_debuglevelr5rrupdatertrr set_tunnelrrrrOrr} getresponsersockrrNreasonr4) r http_classr http_conn_argsrr%tunnel_headersproxy_auth_hdrerrrvrts @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 D98E/9 EEEE//FNr)rrrrr9r<rGrrrTrSr2r2sj&&&&!!!""" $$$L@@@@@rTr2c"eZdZdZejZdS)r*cL|tjj|SrV)rrrr;rr s rS http_openzHTTPHandler.http_open`s||DK6<< 2 2 2 2  L L L,7 rTrKc*eZdZddZdZdZeZeZdS)rNcRddl}||j}||_dSr)http.cookiejar cookiejar CookieJar)rrirs rSrzHTTPCookieProcessor.__init__ws2  0022I"rTc:|j||SrV)riadd_cookie_headerr=s rSrz HTTPCookieProcessor.http_request}s ((111rTc<|j|||SrV)riextract_cookies)rrrs rSr5z!HTTPCookieProcessor.http_responses &&x999rTrV)rrrrrr5rr6rrTrSrrvsL#### !M"NNNrTrceZdZdZdS)r/c4|j}td|z)Nzunknown url type: %s)rr)rr rs rSrzUnknownHandler.unknown_opensx-4555rTN)rrrrrrTrSr/r/s#66666rTr/c i}|D]B}|dd\}}|ddkr|ddkr |dd}|||<C|S)N=r_rrr\)r)lparsedeltrDrEs rSrrsfH Fyya  1 Q43;;1R5C<<!B$Aq MrTc g}d}dx}}|D]P}|r||z }d} |r|dkrd}|dkrd}||z }%|dkr||d}C|dkrd}||z }Q|r||d|DS)NrF\Trrc6g|]}|Sr)r)rCparts rS z#parse_http_list..s ) ) )TDJJLL ) ) )rT)rk)rresryescaper 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)rr rNs 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)rr emailrrrp 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)rr rrrrrorr4reattrsdirsrXfwrattrrrsretrlenrtrrs 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)rr rNrVrO 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|SrV)r pathnames rSr5r5s Cx   rTc" t|SrV)r rs rSr4r4s BXrTceZdZ dZdezZddZdZdZdZ dZ ddZ dd Z dd Z dd Zd Zdd ZddZdZerdZddZdZdZdZddZdS)r9Nrc ldd|jjiz}tj|td|t }||_|d|_|d|_ d|j fdg|_ g|_ tj|_d|_t"|_dS) NzW%(class)s style of invoking requests is deprecated. Use newer urlopen functions/methodsclassr) stacklevelkey_file cert_filez User-Agent)Acceptz*/*)rrrArBrCr6rxrrrversionr_URLopener__tempfilesrdr|_URLopener__unlink tempcacheftpcache)rrxx509r4s rSrzURLopener.__init__s47>@W6XY c-!<<<< ? llG ,, +..($,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|dSrV)rrk)rrs rS addheaderzURLopener.addheaders# 5 t$$$$$rTc0 tt|}t|d}|jr:||jvr1|j|\}}t |d}t |||St |\}}|sd}||jvr6|j|}t |\}} t| \} } | |f}nd}d|z} ||_ | dd} t|| r| dkr/|r| |||S| ||S |t|| |St|| ||S#tt f$rt"$r} t#d | | d} ~ wwxYw) Nz%/:=&?~#+!$,;'@()*[]|rSrrXopen_-rrz socket error)r rr rrMrr rxr rrHropen_unknown_proxy open_unknownrrrr})rrrOrprtrsurltyperNrh proxyhostrrrir4s rSrMzURLopener.opensD7++,,&=>>> > 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?FFcJ t|\}}tdd|)N 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 B99 CC C J BI1J 1JJ J6c> 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)Nrz://z http errorr?r|zBasic %sr/rrrrJr@z Content-TyperrrMz$http protocol error: bad status liner1r2http:)rrr rr r rrr}rrrrrrrRrr BadStatusLinerstatusrr4 http_errorrsrT)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$H:cP |tjj||SrV)rrrr;rrNrOs rS open_httpzURLopener.open_https" &&t{'A3MMMrTc d|z}t||r6t||}|||||||} n|||||||} | r| S||||||S)Nz http_error_%d)rrr) rrNrserrcodeerrmsgrtrOrirrvs rSr zURLopener.http_errors E ( 4   %T4((F|R&'BBR&'4HH $f}&&sBIIIrTcR |t||||drV)rrrrNrsrrrts rSrzURLopener.http_error_defaults(L  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 K3K..K3c  t|tstd |dd\}}n#t$rt ddwxYw|sd}|d}|dkr$d ||dvr||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)NzEdata error: proxy support for data protocol currently not implementedrr_z data errorz bad data URLr;rrrrzDate: %sz%a, %d %b %Y %H:%M:%S GMTzContent-type: %srr|zlatin-1zContent-Length: %d )rrrrrDr}rfindrkrstrftimegmtimerrrrr rnrrrrStringIOr) rrNrOrsemirRr4rtfs 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)rrrrrrrrrrrrMrrrrrr rrErrr!rr,r6rrTrSr9r9sK ;.G!!!!4 # # #%%% "8"8"8"8H==== IIII ====BZFZFZFxNNNNJJJJ === N E E E  N N N N--->>>@898989t'+'+'+'+'+'+rTr9ceZdZ dZdZddZdZddZddZddZ dd Z dd Z dd Z dd Z ddZddZddZddZdZdS)r:cZtj|g|Ri|i|_d|_d|_dS)Nrr;)r9r auth_cachetriesmaxtries)rrrs rSrzFancyURLopener.__init__^s<41$111&111  rTc. t||d|z|S)Nr)rrs rSrz!FancyURLopener.http_error_defaultdsA"gw}g>>>rTNc |xjdz c_ |jrE|j|jkr5t|dr|j}n|j}|||dd|d|_S|||||||}|d|_S#d|_wxYw)Nr_http_error_500r'z)Internal Server Error: Redirect Recursionr)r;r<rr?rredirect_internal) rrNrsrrrtrOrrvs rSr`zFancyURLopener.http_error_302hs3 a  } %t}! > >FG"FOP#R)) ) yy   rTc8 |||||||SrVr`rrNrsrrrtrOs rSrazFancyURLopener.http_error_301s#8""3GVWdKKKrTc8 |||||||SrVrCrDs rSrbzFancyURLopener.http_error_303s#I""3GVWdKKKrTcn ||||||||S||||||SrV)r`rrDs rSrczFancyURLopener.http_error_307D? <&&sB$OO O**3GVWMM MrTcn ||||||||S||||||SrV)rarrDs rSrdzFancyURLopener.http_error_308rGrTFc, d|vrt|||||||d}tjd|} | st||||||| \} } | dkrt|||||||st||||||d|jzdz} |t|| || St|| || |S)Nr![ ]*([^ ]+)[ ]+realm="([^"]*)"rretry_ _basic_authr9rrmatchrrrr rrNrsrrrtrOr-stuffrNrVrris rSrzFancyURLopener.http_error_401sQ = 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)NrrJr retry_proxy_rLrMrOs rSrzFancyURLopener.http_error_407sQ = 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 rxr 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{rUrWs 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{rTr rrVr 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[r^r_s 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 rSrVzFancyURLopener.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)NrzEnter username for z at z: zEnter password for z in r)getpassinputKeyboardInterruptprint)rrrrerors rSrcz!FancyURLopener.prompt_user_passwd) s1 5EEE444HIID___uuuddd&$%%F<      GGG:: s8AAArV)NFrZ)rrrrrr`r@rarbrcrdrrrYr\rrarVrcrrTrSr:r:[sgI ???$!!!8LLLLLLLLNNNNNNNNFJ88882FJ88882++++$++++$ + + + + + + + +         rTr:cH ttjdatS)Nr) _localhostrrrrTrSrr9 s!B)+66 rTc  tv ttjtjdan<#tj$r*ttjddaYnwxYwtS)Nr;r) _thishostrrrrrrrTrSr$r$A s6 Gf5f6H6J6JKKANOOII G G Gf5kBB1EFFIII G s8A6A<;A<c6 t ddl}|jatSr) _ftperrorsrr)rs rSr+r+L s"; & rTcH ttjdatSr) _noheadersrrrrTrS noheadersrqU s!/.r22 rTc@eZdZ d dZdZdZdZdZdZd Z dS) rNTc||_||_||_||_||_||_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 rSrvzftpwrapper.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 endtransferrPvoidcmdrrv ntransfercmd error_permrrpwdr|rxrmakefile file_closertr) rrXrrcmdisdirrrrTrftpobjs 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)rxrPvoidrespr+rs rSrzftpwrapper.endtransfer s]y  F   H       {{    DD s-AAcVd|_|jdkr|dSdS)NFr)rurt real_closers rSrzftpwrapper.close s4 =A   OO       rTc||xjdzc_|jdkr|js|dSdSdS)Nr_r)rrtrurrs rSrzftpwrapper.file_close s\   =A  dn  OO         rTc| |jdS#t$rYdSwxYwrV)rrPrr+rs rSrzftpwrapper.real_close sW   HNN     {{    DD s1AA)NT) rrrrrvrrrrrrrTrSrr_ sE?C  *!*!*!X  rTrc i}tjD]6\}}|}|r|dddkr |||dd<7dtjvr|ddtjD]U\}}|dddkrB|}|r|||dd<7||dddV|S)Ni_proxyREQUEST_METHODr)rdenvironrrr)rxrirs rSgetproxies_environmentr sGz''))'' ezz||  'T"##Y(**!&GD"I  2:%% FD!!!z''))-- e 9 ::<.ip2num s S!!Se__%% u::??\\\)2A2.EaB58r>2eAh!mDuQxOOrTrexclude_simpleT exceptionsrz(\d+(?:\.\d+)*)(/\d+)?r_r;r F) r ipaddressrrrrlrrrNgroupcount) rproxy_settingsrrrrrrhostIPrrJrmasks rS_proxy_bypass_macosx_sysconfr s  88888888%%NHdPPP $ * + 4 F [[**++       ##L"55h H. 6 6 =V/6!''!**%%D771::D|AGGAJJ,,S11A5648}}axx4"999D$DDL11tt2WT5 ! ! 44  5sAAAc ddlm}t|\}}|d}|D]3}|}|dkrd|vrdS$|||rdS4dS)Nrrr.zrTF)rrrr)roverriderrproxy_overriders rS_proxy_bypass_winreg_overriderG s GD!^^C((Nzz|| 9  $tt WT4  44  5rTdarwin)_get_proxy_settings _get_proxiesc>t}t||SrV)rr)rrs rSproxy_bypass_macosx_sysconfrb s,..+D.AAArTc tSrV)rrrTrSgetproxies_macosx_sysconfrf s ~~rTcb t}|rt||St|SrV)rrrrrxs rSrrp s: )**  5+D':: :.t44 4rTc:tp tSrV)rrrrTrSr6r6} 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)Nr;Software\Microsoft\Windows\CurrentVersion\Internet Settings ProxyEnable ProxyServerrrr.zhttp={0};https={0};ftp={0}r_z (?:[^/:]+)://)rrrPrTsockszsocks://z ^socks://z socks4://rr)winreg ImportErrorOpenKeyHKEY_CURRENT_USER QueryValueExrrrrrNrrCloser}rDr)rxrinternetSettings proxyEnable proxyServerpraddresss rSgetproxies_registryr 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 EE77FFc< tp tSrV)rrrrTrSr6r6 s! &''@+>+@+@@rTcB ddl}n#t$rYdSwxYw ||jd}||dd}t ||dd}n#t $rYdSwxYw|r|sdSt||S)NrFrr ProxyOverride)rrrrrrr}r)rrrr proxyOverrides rSproxy_bypass_registryr s  MMMM   55  %~~f.FN P P  --.>/<>>>?AK 3 34D5D!F!FFG!IJJMM   55  - 5,T=AAAs A A:: BBcb t}|rt||St|SrV)rrrrs rSrr s: )**  /+D':: :(.. .rTr7rV)~rrrr 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)r2r*rrrKrkrr/rrr+rr,r-r.r*ri nturl2pathr5r4rr9r:rjrrlr$rnr+rprqrrrrrplatform_scproxyrrrrrr6rrrrTrSrs Cf   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<<<@0<8::::::::BBB 5 5 5GGGGGW__///bAAABBB( / / / / /(J+LLLs=BB B__pycache__/response.cpython-311.pyc000064400000012110151026775530013322 0ustar00 !A?h9 dZddlZgdZGddejZGddeZGdd eZGd d eZdS) aResponse classes used by urllib. The base class, addbase, defines a minimal file-like interface, including read() and readline(). The typical response object is an addinfourl instance, which defines an info() method that returns headers and a geturl() method that returns the url. N)addbase addclosehookaddinfo addinfourlc4eZdZdZfdZdZdZdZxZS)rzOBase class for addinfo and addclosehook. Is a good idea for garbage collection.cltt||dd||_dS)NzF)delete)superr__init__fp)selfr __class__s (/usr/lib64/python3.11/urllib/response.pyr zaddbase.__init__s4 g&&r+>u&MMMcRd|jjdt|d|jdS)N)r__name__idfiler s r__repr__zaddbase.__repr__s3-1^-D-D-D-/XXXXtyyyB Brc<|jjrtd|S)NzI/O operation on closed file)r closed ValueErrorrs r __enter__zaddbase.__enter__s" 7> =;<< < rc.|dSN)close)r typevalue tracebacks r__exit__zaddbase.__exit__!s r) r __module__ __qualname____doc__r rrr# __classcell__rs@rrrsnYY BBB rrc,eZdZdZfdZfdZxZS)rz*Class to add a close hook to an open file.cttt||||_||_dSr)r rr closehookhookargs)r r r+r,rs rr zaddclosehook.__init__(s3 lD!!**2..."  rc |j}|j}|rd|_d|_||tt|dS#tt|wxYwr)r+r,r rr)r r+r,rs rrzaddclosehook.close-s} .I}H %!% $  8$$ , % % + + - - - - -E, % % + + - - - -s #A)A8)rr$r%r&r rr'r(s@rrr%sW44!!!!! . . . . . . . . .rrc(eZdZdZfdZdZxZS)rz.class to add an info() method to an open file.cftt||||_dSr)r rr headers)r r r0rs rr zaddinfo.__init__<s, gt%%b))) rc|jSr)r0rs rinfoz addinfo.info@s |r)rr$r%r&r r2r'r(s@rrr9sM88rrcFeZdZdZdfd ZedZdZdZxZ S)rz9class to add info() and geturl() methods to an open file.Ncvtt|||||_||_dSr)r rr urlcode)r r r0r5r6rs rr zaddinfourl.__init__Gs5 j$((W555 rc|jSrr6rs rstatuszaddinfourl.statusLs yrc|jSrr8rs rgetcodezaddinfourl.getcodePs yrc|jSr)r5rs rgeturlzaddinfourl.geturlSs xrr) rr$r%r&r propertyr9r;r=r'r(s@rrrDs|CC Xrr)r&tempfile__all___TemporaryFileWrapperrrrrrrrCs > > >h,......7...(gr__pycache__/robotparser.cpython-311.pyc000064400000032025151026775530014035 0ustar00 !A?h$dZddlZddlZddlZdgZejddZGddZGddZ Gd d Z dS) a% robotparser.py Copyright (C) 2000 Bastian Kleineidam You can choose between two licenses when using this package: 1) GNU GPLv2 2) PSF license for Python 2.2 The robots.txt Exclusion Protocol is implemented as specified in http://www.robotstxt.org/norobots-rfc.txt NRobotFileParser RequestRatezrequests secondsc\eZdZdZddZdZdZdZdZdZ d Z d Z d Z d Z d ZdZdS)rzs This class provides a set of methods to read, parse and answer questions about a single robots.txt file. cg|_g|_d|_d|_d|_||d|_dS)NFr)entriessitemaps default_entry disallow_all allow_allset_url last_checkedselfurls +/usr/lib64/python3.11/urllib/robotparser.py__init__zRobotFileParser.__init__sG  !! Sc|jS)zReturns the time the robots.txt file was last fetched. This is useful for long-running web spiders that need to check for new robots.txt files periodically. )rrs rmtimezRobotFileParser.mtime%s   rc@ddl}||_dS)zYSets the time the robots.txt file was last fetched to the current time. rN)timer)rrs rmodifiedzRobotFileParser.modified.s#   IIKKrc|||_tj|dd\|_|_dS)z,Sets the URL referring to a robots.txt file.N)rurllibparseurlparsehostpathrs rr zRobotFileParser.set_url6s4%|44S99!A#> 4999rc tj|j}|}||ddS#tjj $rK}|j dvrd|_ n)|j dkr|j dkrd|_ Yd}~dSYd}~dSYd}~dSYd}~dSd}~wwxYw)z4Reads the robots.txt URL and feeds it to the parser.zutf-8)iiTiiN) rrequesturlopenrreadrdecode splitlineserror HTTPErrorcoder r )rfrawerrs rr&zRobotFileParser.read;s 9&&tx00A&&((C JJszz'**5577 8 8 8 8 8|% & & &x:%%$(!!SSX^^!%!"!!!!!%3^^^^^ &s$A66C .CCcpd|jvr|j ||_dSdS|j|dSN*) useragentsr rappend)rentrys r _add_entryzRobotFileParser._add_entryHsM %" " "!)%*"""*) L   & & & & &rc<d}t}||D]V}|sB|dkrt}d}n+|dkr%||t}d}|d}|dkr |d|}|}|s|dd}t |dkr|d|d<tj |d|d<|ddkrM|dkr#||t}|j |dd}o|ddkr8|dkr0|j t|dd d}|dd kr8|dkr0|j t|dd d}|dd krP|dkrH|drt!|d|_d}S|dd kr|dkr|dd}t |dkr|drg|dr;t%t!|dt!|d|_d}*|ddkr |j |dX|dkr||dSdS)zParse the input lines from a robots.txt file. We allow that a user-agent: line is not preceded by one or more blank lines. rr#N:z user-agentdisallowFallowTz crawl-delayz request-rate/sitemap)Entryrr5findstripsplitlenlowerrrunquoter2r3 rulelinesRuleLineisdigitintdelayrreq_rater )rlinesstater4lineinumberss rrzRobotFileParser.parseQsJ 7 27 2D A::!GGEEEaZZOOE***!GGEE #AAvvBQBx::< 4   5\**6<+?+?+D+DEE l%%r"Z_  j. 0C'EFFl  %% C\ , ,E ** ,s+++++ ,   5%//44 4trc|sdS|jD] }||r |jcS!|jr |jjSdSN)rrrVrIr rrXr4s r crawl_delayzRobotFileParser.crawl_delaysmzz|| 4\ # #E ** #{""" #   ,%+ +trc|sdS|jD] }||r |jcS!|jr |jjSdSr\)rrrVrJr r]s r request_ratezRobotFileParser.request_ratesmzz|| 4\ & &E ** &~%%% &   /%. .trc"|jsdS|jSr\)r rs r site_mapszRobotFileParser.site_mapss} 4}rc|j}|j ||jgz}dtt|S)Nz )rr joinmapstr)rrs r__str__zRobotFileParser.__str__s>,   )!3 44G{{3sG,,---rN)r)__name__ __module__ __qualname____doc__rrrr r&r5rrZr^r`rbrgrrrrs !!!(((??? 9 9 9'''G#G#G#R: .....rc$eZdZdZdZdZdZdS)rFzoA rule line is a single "Allow:" (allowance==True) or "Disallow:" (allowance==False) followed by a path.c|dkr|sd}tjtj|}tj||_||_dS)NrT)rrrQr rUr"rW)rr"rWs rrzRuleLine.__init__s[ 2::i:I|&&v|'<'9zTADIMMrN)rhrirjrkrrVrgrlrrrFrFsS11###BBBNNNNNrrFc*eZdZdZdZdZdZdZdS)r>z?An entry has one or more user-agents and zero or more rulelinesc>g|_g|_d|_d|_dSr\)r2rErIrJrs rrzEntry.__init__s"  rc|g}|jD]}|d||j|d|j|j,|j}|d|jd|j|tt|j d |S)Nz User-agent: z Crawl-delay: zRequest-rate: r< ) r2r3rIrJrequestssecondsextendrerfrErd)rretagentrates rrgz Entry.__str__s_ / /E JJ-e-- . . . . : ! JJ3tz33 4 4 4 = $=D JJF FF FF G G G 3sDN++,,,yy~~rc|dd}|jD]&}|dkrdS|}||vrdS'dS)z2check if this entry applies to the specified agentr<rr1TF)rArCr2)rrXr}s rrVzEntry.applies_tospOOC((+1133 _  E||ttKKMME !!tt"urcV|jD] }||r |jcS!dS)zZPreconditions: - our agent applies to this entry - filename is URL decodedT)rErVrW)rrqrMs rrWzEntry.allowance sAN & &Dx(( &~%%% &trN)rhrirjrkrrgrVrWrlrrr>r>sVII      rr>) rk collections urllib.parserurllib.request__all__ namedtuplerrrFr>rlrrrs    $k$]4FGG ~.~.~.~.~.~.~.~.BNNNNNNNN$((((((((((r__pycache__/robotparser.cpython-311.opt-1.pyc000064400000032025151026775530014774 0ustar00 !A?h$dZddlZddlZddlZdgZejddZGddZGddZ Gd d Z dS) a% robotparser.py Copyright (C) 2000 Bastian Kleineidam You can choose between two licenses when using this package: 1) GNU GPLv2 2) PSF license for Python 2.2 The robots.txt Exclusion Protocol is implemented as specified in http://www.robotstxt.org/norobots-rfc.txt NRobotFileParser RequestRatezrequests secondsc\eZdZdZddZdZdZdZdZdZ d Z d Z d Z d Z d ZdZdS)rzs This class provides a set of methods to read, parse and answer questions about a single robots.txt file. cg|_g|_d|_d|_d|_||d|_dS)NFr)entriessitemaps default_entry disallow_all allow_allset_url last_checkedselfurls +/usr/lib64/python3.11/urllib/robotparser.py__init__zRobotFileParser.__init__sG  !! Sc|jS)zReturns the time the robots.txt file was last fetched. This is useful for long-running web spiders that need to check for new robots.txt files periodically. )rrs rmtimezRobotFileParser.mtime%s   rc@ddl}||_dS)zYSets the time the robots.txt file was last fetched to the current time. rN)timer)rrs rmodifiedzRobotFileParser.modified.s#   IIKKrc|||_tj|dd\|_|_dS)z,Sets the URL referring to a robots.txt file.N)rurllibparseurlparsehostpathrs rr zRobotFileParser.set_url6s4%|44S99!A#> 4999rc tj|j}|}||ddS#tjj $rK}|j dvrd|_ n)|j dkr|j dkrd|_ Yd}~dSYd}~dSYd}~dSYd}~dSd}~wwxYw)z4Reads the robots.txt URL and feeds it to the parser.zutf-8)iiTiiN) rrequesturlopenrreadrdecode splitlineserror HTTPErrorcoder r )rfrawerrs rr&zRobotFileParser.read;s 9&&tx00A&&((C JJszz'**5577 8 8 8 8 8|% & & &x:%%$(!!SSX^^!%!"!!!!!%3^^^^^ &s$A66C .CCcpd|jvr|j ||_dSdS|j|dSN*) useragentsr rappend)rentrys r _add_entryzRobotFileParser._add_entryHsM %" " "!)%*"""*) L   & & & & &rc<d}t}||D]V}|sB|dkrt}d}n+|dkr%||t}d}|d}|dkr |d|}|}|s|dd}t |dkr|d|d<tj |d|d<|ddkrM|dkr#||t}|j |dd}o|ddkr8|dkr0|j t|dd d}|dd kr8|dkr0|j t|dd d}|dd krP|dkrH|drt!|d|_d}S|dd kr|dkr|dd}t |dkr|drg|dr;t%t!|dt!|d|_d}*|ddkr |j |dX|dkr||dSdS)zParse the input lines from a robots.txt file. We allow that a user-agent: line is not preceded by one or more blank lines. rr#N:z user-agentdisallowFallowTz crawl-delayz request-rate/sitemap)Entryrr5findstripsplitlenlowerrrunquoter2r3 rulelinesRuleLineisdigitintdelayrreq_rater )rlinesstater4lineinumberss rrzRobotFileParser.parseQsJ 7 27 2D A::!GGEEEaZZOOE***!GGEE #AAvvBQBx::< 4   5\**6<+?+?+D+DEE l%%r"Z_  j. 0C'EFFl  %% C\ , ,E ** ,s+++++ ,   5%//44 4trc|sdS|jD] }||r |jcS!|jr |jjSdSN)rrrVrIr rrXr4s r crawl_delayzRobotFileParser.crawl_delaysmzz|| 4\ # #E ** #{""" #   ,%+ +trc|sdS|jD] }||r |jcS!|jr |jjSdSr\)rrrVrJr r]s r request_ratezRobotFileParser.request_ratesmzz|| 4\ & &E ** &~%%% &   /%. .trc"|jsdS|jSr\)r rs r site_mapszRobotFileParser.site_mapss} 4}rc|j}|j ||jgz}dtt|S)Nz )rr joinmapstr)rrs r__str__zRobotFileParser.__str__s>,   )!3 44G{{3sG,,---rN)r)__name__ __module__ __qualname____doc__rrrr r&r5rrZr^r`rbrgrrrrs !!!(((??? 9 9 9'''G#G#G#R: .....rc$eZdZdZdZdZdZdS)rFzoA rule line is a single "Allow:" (allowance==True) or "Disallow:" (allowance==False) followed by a path.c|dkr|sd}tjtj|}tj||_||_dS)NrT)rrrQr rUr"rW)rr"rWs rrzRuleLine.__init__s[ 2::i:I|&&v|'<'9zTADIMMrN)rhrirjrkrrVrgrlrrrFrFsS11###BBBNNNNNrrFc*eZdZdZdZdZdZdZdS)r>z?An entry has one or more user-agents and zero or more rulelinesc>g|_g|_d|_d|_dSr\)r2rErIrJrs rrzEntry.__init__s"  rc|g}|jD]}|d||j|d|j|j,|j}|d|jd|j|tt|j d |S)Nz User-agent: z Crawl-delay: zRequest-rate: r< ) r2r3rIrJrequestssecondsextendrerfrErd)rretagentrates rrgz Entry.__str__s_ / /E JJ-e-- . . . . : ! JJ3tz33 4 4 4 = $=D JJF FF FF G G G 3sDN++,,,yy~~rc|dd}|jD]&}|dkrdS|}||vrdS'dS)z2check if this entry applies to the specified agentr<rr1TF)rArCr2)rrXr}s rrVzEntry.applies_tospOOC((+1133 _  E||ttKKMME !!tt"urcV|jD] }||r |jcS!dS)zZPreconditions: - our agent applies to this entry - filename is URL decodedT)rErVrW)rrqrMs rrWzEntry.allowance sAN & &Dx(( &~%%% &trN)rhrirjrkrrgrVrWrlrrr>r>sVII      rr>) rk collections urllib.parserurllib.request__all__ namedtuplerrrFr>rlrrrs    $k$]4FGG ~.~.~.~.~.~.~.~.BNNNNNNNN$((((((((((r__pycache__/__init__.cpython-311.pyc000064400000000225151026775530013227 0ustar00 ehdS)Nr(/usr/lib64/python3.11/urllib/__init__.pyrsr__pycache__/__init__.cpython-311.opt-1.pyc000064400000000225151026775530014166 0ustar00 ehdS)Nr(/usr/lib64/python3.11/urllib/__init__.pyrsr__pycache__/error.cpython-311.pyc000064400000007454151026775530012634 0ustar00 !A?ho dZddlZddlZgdZGddeZGddeejjZ Gdd eZ dS) aException classes raised by urllib. The base exception class is URLError, which inherits from OSError. It doesn't define any behavior of its own, but is the base class for all exceptions defined in this package. HTTPError is an exception class that is also a valid HTTP response instance. It behaves this way because HTTP protocol errors are valid responses, with a status code, headers, and a body. In some contexts, an application may want to handle an exception like a regular response. N)URLError HTTPErrorContentTooShortErrorceZdZddZdZdS)rNc:|f|_||_| ||_dSdSN)argsreasonfilename)selfr r s %/usr/lib64/python3.11/urllib/error.py__init__zURLError.__init__s+G   $DMMM cd|jzS)Nz)r r s r __str__zURLError.__str__s#dk11rr)__name__ __module__ __qualname__rrrr rrs7 %%%% 22222rrceZdZdZejjjZdZdZ dZ e dZ e dZ e jdZ dS) rzBRaised when HTTP error occurs, but also acts like non-error returnc||_||_||_||_||_|t j}|||||dSr)codemsghdrsfpr ioBytesIO_HTTPError__super_init)r urlrrrrs r rzHTTPError.__init__'sU   :B "dC.....rc&d|jd|jS)Nz HTTP Error : rrrs r rzHTTPError.__str__1s&*iii::rc(d|jd|jdS)Nz r#rs r __repr__zHTTPError.__repr__4s'+yyy$(((;;rc|jSr)rrs r r zHTTPError.reason9s xrc|jSrrrs r headerszHTTPError.headers=s yrc||_dSrr))r r*s r r*zHTTPError.headersAs  rN)rrr__doc__urllibresponse addinfourlrrrr&propertyr r*setterrrr rr#sLL?-6L///;;;<<< XX ^^rrceZdZdZdZdS)rzDException raised when downloaded size does not match content-length.cJt||||_dSr)rrcontent)r messager4s r rzContentTooShortError.__init__Hs#$((( rN)rrrr,rrrr rrFs)NNrr) r,rurllib.responser-__all__OSErrorrr.r/rrrrr r9s    ; ; ; 2 2 2 2 2w 2 2 2     &/4   F8r__pycache__/__init__.cpython-311.opt-2.pyc000064400000000225151026775530014167 0ustar00 ehdS)Nr(/usr/lib64/python3.11/urllib/__init__.pyrsrerror.py000064400000004557151026775530006275 0ustar00"""Exception classes raised by urllib. The base exception class is URLError, which inherits from OSError. It doesn't define any behavior of its own, but is the base class for all exceptions defined in this package. HTTPError is an exception class that is also a valid HTTP response instance. It behaves this way because HTTP protocol errors are valid responses, with a status code, headers, and a body. In some contexts, an application may want to handle an exception like a regular response. """ import io import urllib.response __all__ = ['URLError', 'HTTPError', 'ContentTooShortError'] class URLError(OSError): # URLError is a sub-type of OSError, but it doesn't share any of # the implementation. need to override __init__ and __str__. # It sets self.args for compatibility with other OSError # subclasses, but args doesn't have the typical format with errno in # slot 0 and strerror in slot 1. This may be better than nothing. def __init__(self, reason, filename=None): self.args = reason, self.reason = reason if filename is not None: self.filename = filename def __str__(self): return '' % self.reason class HTTPError(URLError, urllib.response.addinfourl): """Raised when HTTP error occurs, but also acts like non-error return""" __super_init = urllib.response.addinfourl.__init__ def __init__(self, url, code, msg, hdrs, fp): self.code = code self.msg = msg self.hdrs = hdrs self.fp = fp self.filename = url if fp is None: fp = io.BytesIO() self.__super_init(fp, hdrs, url, code) def __str__(self): return 'HTTP Error %s: %s' % (self.code, self.msg) def __repr__(self): return '' % (self.code, self.msg) # since URLError specifies a .reason attribute, HTTPError should also # provide this attribute. See issue13211 for discussion. @property def reason(self): return self.msg @property def headers(self): return self.hdrs @headers.setter def headers(self, headers): self.hdrs = headers class ContentTooShortError(URLError): """Exception raised when downloaded size does not match content-length.""" def __init__(self, message, content): URLError.__init__(self, message) self.content = content __init__.py000064400000000000151026775530006656 0ustar00