def fetch(config, source, target): """Fetch a file from a remote system.""" if not source: raise FetchError("empty source URL (downloading to %s)" % target) if source.startswith("/"): os.link(source, target) return # Match lazr.restfulclient, for convenience when working with # development instances of Launchpad. no_check_certificate = bool( os.environ.get('LP_DISABLE_SSL_CERTIFICATE_VALIDATION', False)) # This should arguably use urllib2/urllib.request or similar instead. command = ["wget", "-nv"] if no_check_certificate: command.append("--no-check-certificate") command.extend([source, "-O", target]) ret = proxy_call(config, "fetch", command) if ret != 0: unlink_force(target) command_str = "wget -nv" if no_check_certificate: command_str += " --no-check-certificate" command_str += " '%s' -O '%s'" % (source, target) raise FetchError("%s returned %d" % (command_str, ret))
def test_call_unset_proxy(self): os.environ["http_proxy"] = "http://set.example.org:3128/" with mkfile(self.config_path) as f: print("caller\tunset", file=f) path = os.path.join(self.temp_dir, "proxy") with mkfile(path) as fp: self.assertEqual( 0, proxy_call(self.config, "caller", "echo \"$http_proxy\"", stdout=fp, shell=True)) with open(path) as fp: self.assertEqual("", fp.read().rstrip("\n"))