Convert a URL or file name to a string
768027
def _to_string(inp: str) -> str:
        
        if '://' in inp:
            req = requests.get(inp)
            if not req.ok:
                raise ValueError(f"Unable to read {inp}")
            return req.text
        else:
            with open(inp) as infile:
                return infile.read()
283902
def url_to_fn(url):
    
    url = url.replace("http://", "").replace("https://", "")
    url = url.split("?")[0]

    return url.replace("%", "_").replace("/", "_")
945975
private static function get_filename_from_url( $url ) {
		$url_parts   = explode( '/', $url );
		$parts_count = count( $url_parts );
		if ( 1 < $parts_count ) {
			return $url_parts[ count( $url_parts ) - 1 ];
		}
		return $url;
	}
1329035
function stripFileProtocol (url) {
  var isFileUrl = url.substr(0, 7).toLowerCase() === 'file://';

  if (isFileUrl) {
    // Strip-off the protocol, and the initial "/", if there is one
    url = url[7] === '/' ? url.substr(8) : url.substr(7);

    if (isWindows) {
      // Insert a colon (":") after the drive letter, if necessary
      if (url[1] === '/') {
        url = url[0] + ':' + url.substr(1);
      }
    }
    else {
      // It's a Posix path, so start at root
      url = '/' + url;
    }
  }

  return url;
}
581369
def get_file_string(filepath):
    """"""
    with open(os.path.abspath(filepath)) as f:
        return f.read()
529920
function createFilenameForScript(url) {
    // TODO make this much more robust
    console.log("url:" + url);
    var parsed = urlParser.parse(url);
    if (inlineRegexp.test(url)) {
        return parsed.hash.substring(1) + ".js";
    } else {
        return parsed.pathname.substring(parsed.pathname.lastIndexOf("/") + 1);
    }
}
651385
def get_single_outfilename(args):
    """"""
    for arg in args['query']:
        if arg in args['files']:
            return ('.'.join(arg.split('.')[:-1])).lower()
        for url in args['urls']:
            if arg.strip('/') in url:
                domain = get_domain(url)
                return get_outfilename(url, domain)
    sys.stderr.write('Failed to construct a single out filename.\n')
    return ''
539767
function translateUrl (url) {
  const RE = new RegExp('^[./]');
  if (RE.test(url)) {
    const fileUrl = 'file://' + path.join(process.cwd(), url);
    console.log('Relative filename detected -- translating to ' + fileUrl);
    return fileUrl;
  } else {
    return url;
  }
}
928239
def convert_filename(txtfilename, outdir='.'):
    """"""
    return os.path.join(outdir, os.path.basename(txtfilename)).rsplit('.', 1)[0] + '.th'
74412
def filename(value):
        '''
        
        '''
        return re.sub('[^a-zA-Z0-9.-_ ]', '', os.path.basename(InputSanitizer.trim(value)))
314319
def format_file_url_params(file_urls):
        '''
            
        '''
        file_urls_payload = {}
        if file_urls:
            for idx, fileurl in enumerate(file_urls):
                file_urls_payload["file_url[" + str(idx) + "]"] = fileurl
        return file_urls_payload
885628
public String convertString(String string)
    {
        if (string.indexOf("<referral") != -1)
        {
            int iStart = string.indexOf("url=\"") + 5;
            int iEnd = string.indexOf('\"', iStart);
            if ((iStart != 4) && (iEnd != -1))
            {
                String filename = string.substring(iStart, iEnd);
                if (filename.indexOf(":/") == -1)
                {
                    String stringFile = readFile(filename);
                    
                    if (stringFile != null)
                        string = "<!-- " + "Repository inlined from: " + filename  + " -->"
                            + "\n" + stringFile + "\n";
                }        
            }
        }
        return string;
    }
701642
def get_filename(self, prefix, url):
        
        return '{}.txt'.format(os.path.join(os.getcwd(), prefix, self.clean_url(url)))
1205451
def _get_url(self, url):
        
        url = str(url)
        if url != 'default' and not '://' in url:
            url = ':///'.join(('file', url))
        return url
286217
def get_outfilename(url, domain=None):
    """"""
    if domain is None:
        domain = get_domain(url)

    path = '{url.path}'.format(url=urlparse(url))
    if '.' in path:
        tail_url = path.split('.')[-2]
    else:
        tail_url = path

    if tail_url:
        if '/' in tail_url:
            tail_pieces = [x for x in tail_url.split('/') if x]
            tail_url = tail_pieces[-1]

        # Keep length of return string below or equal to max_len
        max_len = 24
        if domain:
            max_len -= (len(domain) + 1)
        if len(tail_url) > max_len:
            if '-' in tail_url:
                tail_pieces = [x for x in tail_url.split('-') if x]
                tail_url = tail_pieces.pop(0)
                if len(tail_url) > max_len:
                    tail_url = tail_url[:max_len]
                else:
                    # Add as many tail pieces that can fit
                    tail_len = 0
                    for piece in tail_pieces:
                        tail_len += len(piece)
                        if tail_len <= max_len:
                            tail_url += '-' + piece
                        else:
                            break
            else:
                tail_url = tail_url[:max_len]

        if domain:
            return '{0}-{1}'.format(domain, tail_url).lower()
        return tail_url
    return domain.lower()
41817
def _get_filename_from_url(url):
    
    parse = urlparse(url)
    return os.path.basename(parse.path)
814319
static String getFilenameFromUrl(String url) {
    String filename = md5(url) + ".down";

    int index = url.lastIndexOf("/");
    if (index > 0) {
      String tmpFilename = url.substring(index + 1);
      int qmarkIndex = tmpFilename.indexOf("?");
      if (qmarkIndex > 0) {
        tmpFilename = tmpFilename.substring(0, qmarkIndex - 1);
      }

      /* if filename contains '.', then the filename has file extension */
      if (tmpFilename.contains(".")) {
        filename = tmpFilename;
      }
    }

    return filename;
  }