Convert a disk path on file to an 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
1138104
def file(cls, uri_or_path):
        
        uri = urlparse(uri_or_path)
        if not uri.scheme:
            # Just a normal path
            return open(uri_or_path, 'rb')
        else:
            it = cls(uri_or_path).download_iter(uri.path.lstrip('/'), skip_hash=True)
            if not it:
                raise ValueError('{0} not found'.format(uri_or_path))
            tmp = tempfile.TemporaryFile()
            for chunk in it:
                tmp.write(chunk)
            tmp.seek(0, 0)
            return tmp
836036
def upload_path(instance, filename):
    '''
        
    '''

    filename = filename.replace(" ", "_")
    filename = unicodedata.normalize('NFKD', filename).lower()
    return os.path.join(str(timezone.now().date().isoformat()), filename)
752361
def url_to_path(url):
    # type: (str) -> ByteString
    
    from .misc import to_bytes

    assert is_file_url(url), "Only file: urls can be converted to local paths"
    _, netloc, path, _, _ = urllib_parse.urlsplit(url)
    # Netlocs are UNC paths
    if netloc:
        netloc = "\\\\" + netloc

    path = urllib_request.url2pathname(netloc + path)
    return to_bytes(path, encoding="utf-8")
1199530
def _extrn_path(self, url, saltenv, cachedir=None):
        '''
        
        '''
        url_data = urlparse(url)
        if salt.utils.platform.is_windows():
            netloc = salt.utils.path.sanitize_win_path(url_data.netloc)
        else:
            netloc = url_data.netloc

        # Strip user:pass from URLs
        netloc = netloc.split('@')[-1]

        if cachedir is None:
            cachedir = self.opts['cachedir']
        elif not os.path.isabs(cachedir):
            cachedir = os.path.join(self.opts['cachedir'], cachedir)

        if url_data.query:
            file_name = '-'.join([url_data.path, url_data.query])
        else:
            file_name = url_data.path

        if len(file_name) > MAX_FILENAME_LENGTH:
            file_name = salt.utils.hashutils.sha256_digest(file_name)

        return salt.utils.path.join(
            cachedir,
            'extrn_files',
            saltenv,
            netloc,
            file_name
        )
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
914552
def pathencode (path):
    """"""
    if isinstance(path, unicode) and not os.path.supports_unicode_filenames:
        path = path.encode(FSCODING, "replace")
    return path
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
1346887
function getFileUrl (repo, path, sha, line) {
  return HOST + "/" + repo + "/src/" + sha + "/" + path + "#cl-" + line;
}
613275
def _extractPathFromUrl(url):
        
        if url.netloc != '' and url.netloc != 'localhost':
            raise RuntimeError("The URL '%s' is invalid" % url.geturl())
        return url.netloc + url.path
548982
def link(src, path):
    '''
    
    '''
    src = os.path.expanduser(src)

    if not os.path.isabs(src):
        raise SaltInvocationError('File path must be absolute.')

    try:
        os.link(src, path)
        return True
    except (OSError, IOError):
        raise CommandExecutionError('Could not create \'{0}\''.format(path))
    return False
1153220
def __get_pretty_filepath(path, article):
    
    short_filename = hashlib.sha256(article.filename.encode()).hexdigest()
    sub_dir = article.source_domain
    final_path = path + sub_dir + '/'
    if not os.path.exists(final_path):
        os.makedirs(final_path)
    return final_path + short_filename + '.json'
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
1039512
public static URL convertFileToURL( String filePath ) throws MalformedURLException {
        CheckArg.isNotEmpty(filePath, "filePath");
        File file = new File(filePath.trim());
        return file.toURI().toURL();
    }
683093
function file_path_to_web_path( file_path, root ) {
    return slash( path.join( '/', path.relative( root, file_path ) ) );
  }
1059860
def get_file_url(path, config):
    
    file_url_regex = re.compile(config['file_url_regex'])
    new_path = re.sub(file_url_regex, config['file_url_base'], path)
    return new_path
475661
def join_path(base, *parts: str):
    """"""
    _parts = "/".join((_part.strip("/") for _part in parts))
    # _parts = '/'.join(parts)
    if base.endswith("/"):
        url = base + _parts
    else:
        url = base + "/" + _parts
    return url