Convert a path to a file: URL.  The path will be made absolute and have
    quoted path parts.
762628
def path_to_url2(path):
    
    path = os.path.normpath(os.path.abspath(path))
    drive, path = os.path.splitdrive(path)
    filepath = path.split(os.path.sep)
    url = '/'.join([urllib.quote(part) for part in filepath])
    if not drive:
        url = url.lstrip('/')
    return 'file:///' + drive + url
1257587
def download_file(save_path, file_url):
    

    r = requests.get(file_url)  # create HTTP response object

    with open(save_path, 'wb') as f:
        f.write(r.content)

    return save_path
943166
def path_to_url(path):
    # type: (Union[str, Text]) -> str
    
    path = os.path.normpath(os.path.abspath(path))
    url = urllib_parse.urljoin('file:', urllib_request.pathname2url(path))
    return url
324637
def path_to_url(path, relative_to = nil)

      # Find the parent path we're in
      path = Pathname.new(path).realpath
      base = self.load_paths.find{|lp| path.to_s =~ /\A#{Regexp.escape(lp.realpath.to_s)}/ }

      path = path.relative_path_from(base).cleanpath
      
      if relative_to
        if relative_to.to_s =~ /\A\//
          relative_to = Pathname.new(File.dirname(relative_to.to_s)).relative_path_from(base).cleanpath
        else
          relative_to = Pathname.new(File.dirname(relative_to.to_s))
        end
        path = Pathname.new("/" + path.to_s).relative_path_from(Pathname.new("/" + relative_to.to_s))
        path.to_s
      else
        "/" + path.to_s
      end
      
    end
285548
def _parse_url(path):
    """"""

    # path changes from bytes to Unicode in going from Python 2 to
    # Python 3.
    if sys.version_info[0] < 3:
        o = urlparse(urllib.parse.unquote_plus(path).decode('utf8'))
    else:
        o = urlparse(urllib.parse.unquote_plus(path))

    path = o.path
    args = {}

    # Convert parse_qs' str --> [str] dictionary to a str --> str
    # dictionary since we never use multi-value GET arguments
    # anyway.
    multiargs = parse_qs(o.query, keep_blank_values=True)
    for arg, value in list(multiargs.items()):
        args[arg] = value[0]

    return path, args
407124
def to_absolute(link)
      return nil if link.nil?

      # remove anchor
      link = URI.encode(URI.decode(link.to_s.gsub(/#[a-zA-Z0-9_-]*$/,'')))

      relative = URI(link)
      absolute = base ? base.merge(relative) : @url.merge(relative)

      absolute.path = '/' if absolute.path.empty?

      return absolute
    end
999062
def path_to_URL(path, escape=True):
    """"""
    # We do not use urllib's builtin pathname2url() function since:
    #  - it has been commented with 'not recommended for general use'
    #  - it does not seem to work the same on Windows and non-Windows platforms
    #    (result starts with /// on Windows but does not on others)
    #  - urllib implementation prior to Python 2.5 used to quote ':' characters
    #    as '|' which would confuse pip on Windows.
    url = os.path.abspath(path)
    for sep in (os.sep, os.altsep):
        if sep and sep != "/":
            url = url.replace(sep, "/")
    if escape:
        # Must not escape ':' or '/' or Python will not recognize those URLs
        # correctly. Detected on Windows 7 SP1 x64 with Python 3.4.0, but doing
        # this always does not hurt since both are valid ASCII characters.
        no_protocol_URL = url_quote(url, safe=":/")
    else:
        no_protocol_URL = url
    return "file:///%s" % (no_protocol_URL,)
1132601
def file_uri_from_path(path)
      path = path.to_s if path.is_a?(Pathname)
      path = path.tr('\\', '/') if windows?
      path = URI::DEFAULT_PARSER.escape(path)
      return path.start_with?('/') ? "file://" + path : path unless windows?
      return "file:///" + path.tr("\\", "/") if path =~ %r{^[a-zA-Z]:[/\\]}
      return "file:" + path.tr("\\", "/") if path =~ %r{\\\\[^\\]+\\[^\\/]+}
      path.tr("\\", "/")
    end
1249881
def string_to_file(path, input):
    
    mkdir_p(os.path.dirname(path))

    with codecs.open(path, "w+", "UTF-8") as file:
        file.write(input)
833536
def url_to_file_path(url, filecache):
    
    key = CacheController.cache_url(url)
    return filecache._fn(key)
636555
def path_to_url(path):
    
    path = os.path.normpath(os.path.abspath(path))
    url = urlparse.urljoin("file:", urllib2.pathname2url(path))
    return url
717992
def _make_path(*parts):
    
    # TODO: maybe only allow some parts to be lists/tuples ?
    return "/" + "/".join(
        # preserve ',' and '*' in url for nicer URLs in logs
        quote_plus(_escape(p), b",*")
        for p in parts
        if p not in SKIP_IN_PATH
    )
1259727
def url_to_parts(url):
    

    if not url:
        return None

    scheme, netloc, path, query, fragment = _urlsplit(url)

    if not path or path == '/':
        path = []
    else:
        path = path.strip('/').split('/')

    if not query:
        query = {}
    else:
        query = _parse_qs(query)

    return _urllib_parse.SplitResult(scheme, netloc, path, query, fragment)
398330
def _get_file_from_url(url):
        """"""
        path = urlparse(url).path
        if not path:
            raise ValueError("Could not extract path from URL '{0}'".format(url))
        name = os.path.basename(path)
        if not name:
            raise ValueError("Could not extract file name from path '{0}'".format(path))
        return name
15669
def _urlparse(path):
    
    url = urlparse.urlparse(path)
    _validate_url(url)
    if not url.scheme or url.scheme == 'file://':
        # Normalize path, and set scheme to "file" if missing
        path = os.path.abspath(
            os.path.expanduser(path))
        url = urlparse.urlparse('file://'+path)
    return url
1119099
def PathToComponents(path):
  
  precondition.AssertType(path, Text)
  if path and not path.startswith("/"):
    raise ValueError("Path '{}' is not absolute".format(path))

  if path:
    return tuple(path.split("/")[1:])
  else:
    return ()
174453
def save(self, path):
        
        for relative_path_and_filename, content in self.files.items():
            full_path_and_filename = os.path.join(path, relative_path_and_filename)
            full_path = os.path.dirname(full_path_and_filename)

            if not os.path.isdir(full_path):
                os.makedirs(full_path)

            with open(full_path_and_filename, 'wb') as handle:
                handle.write(b64decode(content))