Initializes the backend with common defaults.
 Downloads a remote file to disk using open-uri. Accepts any open-uri
 options, and a few more.
179358
def download(url, options = {})
      options = @options.merge(options)

      max_size            = options.delete(:max_size)
      max_redirects       = options.delete(:max_redirects)
      progress_proc       = options.delete(:progress_proc)
      content_length_proc = options.delete(:content_length_proc)
      destination         = options.delete(:destination)
      headers             = options.delete(:headers) || {}

      # Use open-uri's :content_lenth_proc or :progress_proc to raise an
      # exception early if the file is too large.
      #
      # Also disable following redirects, as we'll provide our own
      # implementation that has the ability to limit the number of redirects.
      open_uri_options = {
        content_length_proc: proc { |size|
          if size && max_size && size > max_size
            raise Down::TooLarge, "file is too large (max is #{max_size/1024/1024}MB)"
          end
          content_length_proc.call(size) if content_length_proc
        },
        progress_proc: proc { |current_size|
          if max_size && current_size > max_size
            raise Down::TooLarge, "file is too large (max is #{max_size/1024/1024}MB)"
          end
          progress_proc.call(current_size) if progress_proc
        },
        redirect: false,
      }

      # Handle basic authentication in the :proxy option.
      if options[:proxy]
        proxy    = URI(options.delete(:proxy))
        user     = proxy.user
        password = proxy.password

        if user || password
          proxy.user     = nil
          proxy.password = nil

          open_uri_options[:proxy_http_basic_authentication] = [proxy.to_s, user, password]
        else
          open_uri_options[:proxy] = proxy.to_s
        end
      end

      open_uri_options.merge!(options)
      open_uri_options.merge!(headers)

      uri = ensure_uri(addressable_normalize(url))

      # Handle basic authentication in the remote URL.
      if uri.user || uri.password
        open_uri_options[:http_basic_authentication] ||= [uri.user, uri.password]
        uri.user = nil
        uri.password = nil
      end

      open_uri_file = open_uri(uri, open_uri_options, follows_remaining: max_redirects)

      # Handle the fact that open-uri returns StringIOs for small files.
      tempfile = ensure_tempfile(open_uri_file, File.extname(open_uri_file.base_uri.path))
      OpenURI::Meta.init tempfile, open_uri_file # add back open-uri methods
      tempfile.extend Down::NetHttp::DownloadedFile

      download_result(tempfile, destination)
    end
760568
def putbinaryfile(localfile, remotefile = File.basename(localfile),
		      blocksize = DEFAULT_BLOCKSIZE, &block) # :yield: data
      if @resume
        begin
          rest_offset = size(remotefile)
        rescue Net::FTPPermError
          rest_offset = nil
        end
      else
	rest_offset = nil
      end
      f = open(localfile)
      begin
	f.binmode
	storbinary("STOR " + remotefile, f, blocksize, rest_offset, &block)
      ensure
	f.close
      end
    end
216083
def init_db(uri, base, **kwargs):
    
    engine = create_engine(uri, **kwargs)
    base.metadata.create_all(engine)
    return engine
431165
def create_shared_link(opts={})
      raise UnshareableResource unless ['folder', 'file'].include?(type)

      opts = {
        access: 'open'
      }.merge(opts) if opts

      url = "#{RubyBox::API_URL}/#{resource_name}/#{id}"
      uri = URI.parse(url)

      request = Net::HTTP::Put.new(uri.path, {
        "Content-Type" => 'application/json'
      })

      request.body = JSON.dump({
        shared_link: opts
      })

      @raw_item = @session.request(uri, request)
      self
    end
1026334
public void initialize(URI name, Configuration conf) throws IOException {
    statistics = getStatistics(name.getScheme(), getClass());    
  }
665465
def init():
    '''
    
    '''
    bp_ = os.path.join(__opts__['cachedir'], 'hgfs')
    new_remote = False
    repos = []

    per_remote_defaults = {}
    for param in PER_REMOTE_OVERRIDES:
        per_remote_defaults[param] = \
            six.text_type(__opts__['hgfs_{0}'.format(param)])

    for remote in __opts__['hgfs_remotes']:
        repo_conf = copy.deepcopy(per_remote_defaults)
        if isinstance(remote, dict):
            repo_url = next(iter(remote))
            per_remote_conf = dict(
                [(key, six.text_type(val)) for key, val in
                 six.iteritems(salt.utils.data.repack_dictlist(remote[repo_url]))]
            )
            if not per_remote_conf:
                log.error(
                    'Invalid per-remote configuration for hgfs remote %s. If '
                    'no per-remote parameters are being specified, there may '
                    'be a trailing colon after the URL, which should be '
                    'removed. Check the master configuration file.', repo_url
                )
                _failhard()

            branch_method = \
                per_remote_conf.get('branch_method',
                                    per_remote_defaults['branch_method'])
            if branch_method not in VALID_BRANCH_METHODS:
                log.error(
                    'Invalid branch_method \'%s\' for remote %s. Valid '
                    'branch methods are: %s. This remote will be ignored.',
                    branch_method, repo_url, ', '.join(VALID_BRANCH_METHODS)
                )
                _failhard()

            per_remote_errors = False
            for param in (x for x in per_remote_conf
                          if x not in PER_REMOTE_OVERRIDES):
                log.error(
                    'Invalid configuration parameter \'%s\' for remote %s. '
                    'Valid parameters are: %s. See the documentation for '
                    'further information.',
                    param, repo_url, ', '.join(PER_REMOTE_OVERRIDES)
                )
                per_remote_errors = True
            if per_remote_errors:
                _failhard()

            repo_conf.update(per_remote_conf)
        else:
            repo_url = remote

        if not isinstance(repo_url, six.string_types):
            log.error(
                'Invalid hgfs remote %s. Remotes must be strings, you may '
                'need to enclose the URL in quotes', repo_url
            )
            _failhard()

        try:
            repo_conf['mountpoint'] = salt.utils.url.strip_proto(
                repo_conf['mountpoint']
            )
        except TypeError:
            # mountpoint not specified
            pass

        hash_type = getattr(hashlib, __opts__.get('hash_type', 'md5'))
        repo_hash = hash_type(repo_url).hexdigest()
        rp_ = os.path.join(bp_, repo_hash)
        if not os.path.isdir(rp_):
            os.makedirs(rp_)

        if not os.listdir(rp_):
            # Only init if the directory is empty.
            hglib.init(rp_)
            new_remote = True
        try:
            repo = hglib.open(rp_)
        except hglib.error.ServerError:
            log.error(
                'Cache path %s (corresponding remote: %s) exists but is not '
                'a valid mercurial repository. You will need to manually '
                'delete this directory on the master to continue to use this '
                'hgfs remote.', rp_, repo_url
            )
            _failhard()
        except Exception as exc:
            log.error(
                'Exception \'%s\' encountered while initializing hgfs '
                'remote %s', exc, repo_url
            )
            _failhard()

        try:
            refs = repo.config(names='paths')
        except hglib.error.CommandError:
            refs = None

        # Do NOT put this if statement inside the except block above. Earlier
        # versions of hglib did not raise an exception, so we need to do it
        # this way to support both older and newer hglib.
        if not refs:
            # Write an hgrc defining the remote URL
            hgconfpath = os.path.join(rp_, '.hg', 'hgrc')
            with salt.utils.files.fopen(hgconfpath, 'w+') as hgconfig:
                hgconfig.write('[paths]\n')
                hgconfig.write(
                    salt.utils.stringutils.to_str(
                        'default = {0}\n'.format(repo_url)
                    )
                )

        repo_conf.update({
            'repo': repo,
            'url': repo_url,
            'hash': repo_hash,
            'cachedir': rp_,
            'lockfile': os.path.join(__opts__['cachedir'],
                                     'hgfs',
                                     '{0}.update.lk'.format(repo_hash))
        })
        repos.append(repo_conf)
        repo.close()

    if new_remote:
        remote_map = os.path.join(__opts__['cachedir'], 'hgfs/remote_map.txt')
        try:
            with salt.utils.files.fopen(remote_map, 'w+') as fp_:
                timestamp = datetime.now().strftime('%d %b %Y %H:%M:%S.%f')
                fp_.write('# hgfs_remote map as of {0}\n'.format(timestamp))
                for repo in repos:
                    fp_.write(
                        salt.utils.stringutils.to_str(
                            '{0} = {1}\n'.format(repo['hash'], repo['url'])
                        )
                    )
        except OSError:
            pass
        else:
            log.info('Wrote new hgfs_remote map to %s', remote_map)

    return repos
200767
private void initializeRetireJsRepo(Settings settings, URL repoUrl) throws UpdateException {
        try {
            final File dataDir = settings.getDataDirectory();
            final File tmpDir = settings.getTempDirectory();
            boolean useProxy = false;
            if (null != settings.getString(Settings.KEYS.PROXY_SERVER)) {
                useProxy = true;
                LOGGER.debug("Using proxy");
            }
            LOGGER.debug("RetireJS Repo URL: {}", repoUrl.toExternalForm());
            final URLConnectionFactory factory = new URLConnectionFactory(settings);
            final HttpURLConnection conn = factory.createHttpURLConnection(repoUrl, useProxy);
            final String filename = repoUrl.getFile().substring(repoUrl.getFile().lastIndexOf("/") + 1, repoUrl.getFile().length());
            if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
                final File tmpFile = new File(tmpDir, filename);
                final File repoFile = new File(dataDir, filename);
                try (InputStream inputStream = conn.getInputStream();
                        FileOutputStream outputStream = new FileOutputStream(tmpFile)) {
                    IOUtils.copy(inputStream, outputStream);
                }
                //using move fails if target and destination are on different disks which does happen (see #1394 and #1404)
                Files.copy(tmpFile.toPath(), repoFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
                if (!tmpFile.delete()) {
                    tmpFile.deleteOnExit();
                }
            }
        } catch (IOException e) {
            throw new UpdateException("Failed to initialize the RetireJS repo", e);
        }
    }
947500
function(dataUri, fileName) {

            var blob = joint.util.dataUriToBlob(dataUri);
            joint.util.downloadBlob(blob, fileName);
        }
989388
def init_resource(self, request, res):
        
        res.location_query = request.uri_query
        res.payload = (request.content_type, request.payload)
        return res
1301084
function () {
    // Create request options from parsed source URL
    var options = url.parse(this.source, false);

    // Add on some defaults
    extend(options, {
      method: 'get',
      headers: {
        host: options.host,
        accept: 'image/*'
      }
    });

    // Determine https/http from source URL
    var library = options.protocol === 'https:' ? https : http;

    // Setup the request and its event binds
    this.request = library.request(options);
    this.request.on('response', this.onResponse.bind(this));
    this.request.on('error', this.onError.bind(this));
    this.request.setTimeout(5000, this.onTimeout.bind(this));

    // Start the download
    this.startTime = new Date().getTime();
    this.request.end();
  }
319362
def retrieve_file(options)
        file_uri = options.fetch(:url)
        file_size = options.fetch(:file_size)

        retrieved = 0
        File.open(file_uri.path, 'rb') do |f|
          until f.eof?
            chunk = f.read(chunk_size)
            retrieved += chunk.length
            yield(chunk, retrieved, file_size)
          end
        end
      end
1134279
def default_backends(cls):
        
        paths = []
        paths.append(os.path.expanduser("~/.gitconfig"))
        paths.append("/etc/gitconfig")
        backends = []
        for path in paths:
            try:
                cf = ConfigFile.from_path(path)
            except (IOError, OSError), e:
                if e.errno != errno.ENOENT:
                    raise
                else:
                    continue
            backends.append(cf)
        return backends
193840
def download(self, request, **kwargs):
        

        # method check to avoid bad requests
        self.method_check(request, allowed=['get'])

        # create a basic bundle object for self.get_cached_obj_get.
        basic_bundle = self.build_bundle(request=request)

        # using the primary key defined in the url, obtain the tileset
        tileset = self.cached_obj_get(
            bundle=basic_bundle,
            **self.remove_api_resource_names(kwargs))

        filename = helpers.get_tileset_filename(tileset)
        filename = os.path.abspath(filename)
        if os.path.isfile(filename):
            response = serve(request, os.path.basename(filename), os.path.dirname(filename))
            response['Content-Disposition'] = 'attachment; filename="{}"'.format(os.path.basename(filename))
        else:
            response = self.create_response(request, {'status': 'not generated'})
        return response
409606
def open_remote_url(urls, **kwargs):
    
    if isinstance(urls, str):
        urls = [urls]
    for url in urls:
        try:
            web_file = requests.get(url, stream=True, **kwargs)
            if 'html' in web_file.headers['content-type']:
                raise ValueError("HTML source file retrieved.")
            return web_file
        except Exception as ex:
            logger.error('Fail to open remote url - {}'.format(ex))
            continue
1371606
def init(self):
        
        if os.path.isdir(self.path):
            self.fetch()
        else:
            self.clone()
546766
def _add_remote_resources(resources):
    
    out = copy.deepcopy(resources)
    for prog, info in resources.items():
        for key, val in info.items():
            if key == "jar" and objectstore.is_remote(val):
                store_dir = utils.safe_makedir(os.path.join(os.getcwd(), "inputs", "jars", prog))
                fname = objectstore.download(val, store_dir, store_dir)
                version_file = os.path.join(store_dir, "version.txt")
                if not utils.file_exists(version_file):
                    version = install.get_gatk_jar_version(prog, fname)
                    with open(version_file, "w") as out_handle:
                        out_handle.write(version)
                else:
                    with open(version_file) as in_handle:
                        version = in_handle.read().strip()
                del out[prog][key]
                out[prog]["dir"] = store_dir
                out[prog]["version"] = version
    return out
535246
def post_init(*args)
      logger.info "got connection from #{remote_ip}"

      # initialize the line-based protocol: IRC is \r\n
      @lt2_delimiter = "\r\n"

      # start up the IRCD for this connection
      @ircd = IRCD.new(self, options)

      if options[:ssl]
        logger.info "starting TLS for #{remote_ip}"
        start_tls(:cert_chain_file => options[:ssl_cert], :private_key_file => options[:ssl_private_key], :verify_peer => options[:ssl_verify_peer])
      end
    end