Check if a file exists (and don't error out on unicode inputs)
5408
def file_exists(filename):
    
    try:
        return os.path.isfile(filename)
    except (UnicodeDecodeError, UnicodeEncodeError, ValueError):
        return False
1327333
def exists(self, filepath):
        """"""
        if self.is_ssh(filepath):
            self._check_ftp()
            remotepath = self._get_remote(filepath)
            try:
                self.ftp.stat(remotepath)
            except IOError as e:
                if e.errno == errno.ENOENT:
                    return False
            else:
                return True
        else:
            return os.path.exists(filepath)
53560
def _guess(self, filename):
        """"""

        encoding = None

        file_size = os.path.getsize(filename)
        # If the file is really big, lets just call it binary.
        # We don't have time to let Python chug through a massive file.
        if not self._is_very_large(file_size):
            with open(filename, "rb") as f:
                if file_size == 0:
                    encoding = 'ascii'
                else:
                    encoding = self._detect_buffer_encoding(f)
                    if encoding is None:
                        raise UnicodeDecodeError('None', b'', 0, 0, 'Unicode cannot be detected.')
                    if encoding != BINARY_ENCODE:
                        encoding = self._verify_encoding(encoding)
        else:  # pragma: no cover
            raise UnicodeDecodeError('None', b'', 0, 0, 'Unicode detection is not applied to very large files!')

        return encoding
224432
function fileExists(file) {
    var fileExists = true;

    try {
        fs.statSync(file, function(err, stat) {
            if (err == null) {
                fileExists = true;
            } else {
                fileExists = false;
            }
        });
    } catch (e) {
        fileExists = false;
    }

    return fileExists;
}
504505
function isExistingFile(filename) {
    try {
        return fs.statSync(filename).isFile();
    } catch (err) {
        if (err.code === "ENOENT") {
            return false;
        }
        throw err;
    }
}
675130
def check_existing_filename (filename, onlyfiles=True):
    """"""
    if not os.path.exists(filename):
        raise PatoolError("file `%s' was not found" % filename)
    if not os.access(filename, os.R_OK):
        raise PatoolError("file `%s' is not readable" % filename)
    if onlyfiles and not os.path.isfile(filename):
        raise PatoolError("`%s' is not a file" % filename)
673923
def file_name_error(file_name):
    

    if file_name == '' or file_name[0][0] == '-':
        raise IOError('Input file name not specified.')

    elif not os.path.isfile(file_name):
        raise IOError('Input file name [%s] not found!' % file_name)
194859
def load_file(path, encoding, encoding_errors):
    
    abs_path = abspath(path)
    if exists(abs_path):
        return read_unicode(abs_path, encoding, encoding_errors)
    raise IOError('File %s does not exist' % (abs_path))
247119
def check(self):
    
    errors = []
    results = []
    for fn in self._files:
      if not os.path.isdir(fn):
        try:
          with open(fn, 'r') as f:
            line_ct = 1
            for line in f:
              for word in split_words(line):
                if (word in self._misspelling_dict or
                    word.lower() in self._misspelling_dict):
                  results.append([fn, line_ct, word])
              line_ct += 1
        except UnicodeDecodeError:
          pass
        except IOError:
          errors.append('%s' % sys.exc_info()[1])
    return errors, results
867476
def fileExists(fName, dire=pDir()):
    
    if os.path.isfile(os.path.join(dire, fName)):
        return True
    return False
389428
def check_existance(f):
    """"""
    if not opath.isfile(f):
        logging.error("Nanoget: File provided doesn't exist or the path is incorrect: {}".format(f))
        sys.exit("File provided doesn't exist or the path is incorrect: {}".format(f))
487494
def check_file_existence(path):
    

    pathvalidate.validate_file_path(path)

    if not os.path.lexists(path):
        raise FileNotFoundError(path)

    if os.path.isfile(path):
        logger.debug("file found: " + path)
        return FileType.FILE

    if os.path.isdir(path):
        logger.debug("directory found: " + path)
        return FileType.DIRECTORY

    if os.path.islink(path):
        logger.debug("link found: " + path)
        return FileType.LINK

    raise RuntimeError()
1150540
def _check_file(parameters):
    """"""
    (filename, args) = parameters

    if filename == '-':
        contents = sys.stdin.read()
    else:
        with contextlib.closing(
            docutils.io.FileInput(source_path=filename)
        ) as input_file:
            contents = input_file.read()

    args = load_configuration_from_file(
        os.path.dirname(os.path.realpath(filename)), args)

    ignore_directives_and_roles(args.ignore_directives, args.ignore_roles)

    for substitution in args.ignore_substitutions:
        contents = contents.replace('|{}|'.format(substitution), 'None')

    ignore = {
        'languages': args.ignore_language,
        'messages': args.ignore_messages,
    }
    all_errors = []
    for error in check(contents,
                       filename=filename,
                       report_level=args.report,
                       ignore=ignore,
                       debug=args.debug):
        all_errors.append(error)
    return (filename, all_errors)
1091134
def check(args, source_code, filename=None, options=None):
    """"""
    if args is None:
        return []
    if options is not None:
        args += options
    if any(['pyflakes' in arg for arg in args]):
        #  Pyflakes requires an ending new line (pycodestyle don't! -- see Issue 1123)
        #  Note: this code is not used right now as it is faster to invoke 
        #  pyflakes in current Python interpreter (see `check_with_pyflakes` 
        #  function above) than calling it through a subprocess
        source_code += '\n'
    if filename is None:
        # Creating a temporary file because file does not exist yet 
        # or is not up-to-date
        tempfd = tempfile.NamedTemporaryFile(suffix=".py", delete=False)
        tempfd.write(source_code)
        tempfd.close()
        args.append(tempfd.name)
    else:
        args.append(filename)
    cmd = args[0]
    cmdargs = args[1:]
    proc = programs.run_program(cmd, cmdargs)
    output = proc.communicate()[0].strip().decode().splitlines()
    if filename is None:
        os.unlink(tempfd.name)
    results = []
    coding = encoding.get_coding(source_code)
    lines = source_code.splitlines()
    for line in output:
        lineno = int(re.search(r'(\:[\d]+\:)', line).group()[1:-1])
        try:
            text = to_text_string(lines[lineno-1], coding)
        except TypeError:
            text = to_text_string(lines[lineno-1])
        except UnicodeDecodeError:
            # Needed to handle UnicodeDecodeError and force the use
            # of chardet to detect enconding. See issue 6970
            coding = encoding.get_coding(source_code, force_chardet=True)
            text = to_text_string(lines[lineno-1], coding)
        if 'analysis:ignore' not in text:
            message = line[line.find(': ')+2:]
            results.append((message, lineno))
    return results
526696
def file_or_token(value):
    
    if isfile(value):
        with open(value) as fd:
            return fd.read().strip()

    if any(char in value for char in '/\\.'):
        # This chars will never be in a token value, but may be in a path
        # The error message will be handled by the parser
        raise ValueError()

    return value
660502
def is_valid_file(parser,arg):
	""""""
	if not os.path.exists(arg):
       		parser.error("File %s not found"%arg)
	else:
	       	return arg
202769
async function fileExists(f) {
  debug(`fileExists called with: ${JSON.stringify(arguments)}`);
  try {
    await fs.statAsync(f);
    return f;
  } catch (e) {
    throw e;
  }
}