def get_opener(self, *args, **kwargs): """ Build an OpenerDirector instance based on the scheme, whether ssl is importable and the --insecure parameter. """ args = list(args) if self.proxy_handler: args.extend([self.proxy_handler, urllib2.CacheFTPHandler]) if kwargs.get('scheme') == 'https': if ssl: https_handler = VerifiedHTTPSHandler() director = urllib2.build_opener(https_handler, *args) #strip out HTTPHandler to prevent MITM spoof for handler in director.handlers: if isinstance(handler, urllib2.HTTPHandler): director.handlers.remove(handler) return director elif os.environ.get('PIP_INSECURE', '') == '1': return urllib2.build_opener(*args) else: raise NoSSLError() else: return urllib2.build_opener(*args)
def get_opener(self, *args, **kwargs): """ Build an OpenerDirector instance based on the scheme and proxy option """ args = list(args) if self.proxy_handler: args.extend([self.proxy_handler, urllib2.CacheFTPHandler]) if kwargs.get('scheme') == 'https': https_handler = VerifiedHTTPSHandler() director = urllib2.build_opener(https_handler, *args) #strip out HTTPHandler to prevent MITM spoof for handler in director.handlers: if isinstance(handler, urllib2.HTTPHandler): director.handlers.remove(handler) else: director = urllib2.build_opener(*args) # Add our new headers to the opener headers = [ x for x in director.addheaders if x[0].lower() != "user-agent" ] headers.append(("User-agent", build_user_agent())) director.addheaders = headers return director
def get_opener(self, *args, **kwargs): """ Build an OpenerDirector instance based on the scheme and proxy option """ args = list(args) if self.proxy_handler: args.extend([self.proxy_handler, urllib2.CacheFTPHandler]) if kwargs.get('scheme') == 'https': https_handler = VerifiedHTTPSHandler() director = urllib2.build_opener(https_handler, *args) #strip out HTTPHandler to prevent MITM spoof for handler in director.handlers: if isinstance(handler, urllib2.HTTPHandler): director.handlers.remove(handler) else: director = urllib2.build_opener(*args) # Add our new headers to the opener headers = [x for x in director.addheaders if x[0].lower() != "user-agent"] headers.append(("User-agent", build_user_agent())) director.addheaders = headers return director
def get_opener(self, *args, **kwargs): """ Build an OpenerDirector instance based on the scheme, whether ssl is importable and the --insecure parameter. """ if kwargs.get("scheme") == "https": if ssl: https_handler = VerifiedHTTPSHandler() director = urllib2.build_opener(https_handler, *args) # strip out HTTPHandler to prevent MITM spoof for handler in director.handlers: if isinstance(handler, urllib2.HTTPHandler): director.handlers.remove(handler) return director elif os.environ.get("PIP_INSECURE", "") == "1": return urllib2.build_opener(*args) else: raise NoSSLError() else: return urllib2.build_opener(*args)
def get_opener(self, *args, **kwargs): """ Build an OpenerDirector instance based on the scheme, whether ssl is importable and the --insecure parameter. """ if kwargs.get('scheme') == 'https': if ssl: https_handler = VerifiedHTTPSHandler() director = urllib2.build_opener(https_handler, *args) #strip out HTTPHandler to prevent MITM spoof for handler in director.handlers: if isinstance(handler, urllib2.HTTPHandler): director.handlers.remove(handler) return director elif os.environ.get('PIP_INSECURE', '') == '1': return urllib2.build_opener(*args) else: raise NoSSLError() else: return urllib2.build_opener(*args)
def setup(self, proxystr='', prompting=True): """ Sets the proxy handler given the option passed on the command line. If an empty string is passed it looks at the HTTP_PROXY environment variable. """ self.prompting = prompting proxy = self.get_proxy(proxystr) if proxy: proxy_support = urllib2.ProxyHandler({"http": proxy, "ftp": proxy}) opener = urllib2.build_opener(proxy_support, urllib2.CacheFTPHandler) urllib2.install_opener(opener)
def setup(self, proxystr='', prompting=True): """ Sets the proxy handler given the option passed on the command line. If an empty string is passed it looks at the HTTP_PROXY environment variable. """ self.prompting = prompting proxy = self.get_proxy(proxystr) if proxy: proxy_support = urllib2.ProxyHandler({"http": proxy, "ftp": proxy, "https": proxy}) opener = urllib2.build_opener(proxy_support, urllib2.CacheFTPHandler) urllib2.install_opener(opener)
def get_response(self, url, username=None, password=None): """ does the dirty work of actually getting the rsponse object using urllib2 and its HTTP auth builtins. """ scheme, netloc, path, query, frag = urlparse.urlsplit(url) req = self.get_request(url) stored_username, stored_password = self.passman.find_user_password(None, netloc) # see if we have a password stored if stored_username is None: if username is None and self.prompting: username = urllib.quote(raw_input('User for %s: ' % netloc)) password = urllib.quote(getpass.getpass('Password: ')) if username and password: self.passman.add_password(None, netloc, username, password) stored_username, stored_password = self.passman.find_user_password(None, netloc) authhandler = urllib2.HTTPBasicAuthHandler(self.passman) opener = urllib2.build_opener(authhandler) # FIXME: should catch a 401 and offer to let the user reenter credentials return opener.open(req)