checks if a file is stored securely
351609
def assert_secure_file(file):
    """"""
    if not is_secure_file(file):
        msg = """
        File {0} can be read by other users.
        This is not secure. Please run 'chmod 600 "{0}"'"""
        raise SecurityError(dedent(msg).replace('\n', ' ').format(file))
    return True
1326937
def isHeld(self):
        '''
            
        '''
        if not os.path.exists(self.lockPath):
            return False
        
        try:
            mtime = os.stat(self.lockPath).st_mtime
        except FileNotFoundError as e:
            return False
        
        if self.__checkExpiration(mtime):
            return False

        return True
1044606
function safeReadFileSync (fileName, options) {
    verifyFileName (fileName);
    
    // if fileName exists, verify it is a file
    var info = getFileInfo (fileName);
    if ((info.exists) && (info.isFile === false)) {
        var message = format (cc.MSG_IS_NOT_A_FILE, fileName);
        throw new SafeFileError (cc.IS_NOT_A_FILE, message);
    }

    // get state, if auto-recovery required, perform recovery
    var state = getState (fileName);
    if (state.status === cc.SAFE_RECOVERABLE) {
        performRecovery (state, true);
    }

    // perform read on file
    return (readFileSync (fileName, options));
}
892259
def verify_file_private(filename):
    
    if platform.system().upper() != 'WINDOWS':
        filename = os.path.expanduser(filename)
        if os.path.exists(filename):
            file_stat = os.stat(filename)
            if mode_allows_group_or_other(file_stat.st_mode):
                raise ValueError(CONFIG_FILE_PERMISSIONS_ERROR)
784497
def is_file(self):
        
        try:
            return S_ISREG(self.stat().st_mode)
        except OSError as e:
            if e.errno not in (ENOENT, ENOTDIR):
                raise
            # Path doesn't exist or is a broken symlink
            # (see https://bitbucket.org/pitrou/pathlib/issue/12/)
            return False
644215
def file_verified?(path, expected_digest, digest_type=:md5)
      return false unless file_exists?(path)
      raise "Unknown disgest type: #{digest_type}" unless can?("digest_#{digest_type}")
      digest = self.send("digest_#{digest_type}", path).first
      info "#{digest_type} (#{path}) = #{digest}"
      digest.to_s == expected_digest.to_s
    end
103558
def __check_file_status(self, index):
        """"""
        if self.__file_status_flag:
            # Avoid infinite loop: when the QMessageBox.question pops, it
            # gets focus and then give it back to the CodeEditor instance,
            # triggering a refresh cycle which calls this method
            return
        self.__file_status_flag = True

        finfo = self.data[index]
        name = osp.basename(finfo.filename)

        if finfo.newly_created:
            # File was just created (not yet saved): do nothing
            # (do not return because of the clean-up at the end of the method)
            pass

        elif not osp.isfile(finfo.filename):
            # File doesn't exist (removed, moved or offline):
            self.msgbox = QMessageBox(
                    QMessageBox.Warning,
                    self.title,
                    _("<b>%s</b> is unavailable "
                      "(this file may have been removed, moved "
                      "or renamed outside Spyder)."
                      "<br>Do you want to close it?") % name,
                    QMessageBox.Yes | QMessageBox.No,
                    self)
            answer = self.msgbox.exec_()
            if answer == QMessageBox.Yes:
                self.close_file(index)
            else:
                finfo.newly_created = True
                finfo.editor.document().setModified(True)
                self.modification_changed(index=index)

        else:
            # Else, testing if it has been modified elsewhere:
            lastm = QFileInfo(finfo.filename).lastModified()
            if to_text_string(lastm.toString()) \
               != to_text_string(finfo.lastmodified.toString()):
                if finfo.editor.document().isModified():
                    self.msgbox = QMessageBox(
                        QMessageBox.Question,
                        self.title,
                        _("<b>%s</b> has been modified outside Spyder."
                          "<br>Do you want to reload it and lose all "
                          "your changes?") % name,
                        QMessageBox.Yes | QMessageBox.No,
                        self)
                    answer = self.msgbox.exec_()
                    if answer == QMessageBox.Yes:
                        self.reload(index)
                    else:
                        finfo.lastmodified = lastm
                else:
                    self.reload(index)

        # Finally, resetting temporary flag:
        self.__file_status_flag = False
844897
function ensureDir(filename) {
    var fs = require('fs');
    var path = require('path');
    var dir = path.dirname(filename);
    if (!fs.existsSync(dir)) {
        var mkdirp = require('mkdirp').sync;
        mkdirp(dir);
    }
}
374191
def isPythonFile(filename):
    """"""
    if filename.endswith('.py'):
        return True

    # Avoid obvious Emacs backup files
    if filename.endswith("~"):
        return False

    max_bytes = 128

    try:
        with open(filename, 'rb') as f:
            text = f.read(max_bytes)
            if not text:
                return False
    except IOError:
        return False

    first_line = text.splitlines()[0]
    return PYTHON_SHEBANG_REGEX.match(first_line)
209580
def isvalid(path, access=None, extensions=None, filetype=None, minsize=None):
    """"""
    return ((access is None or os.access(path, access)) and
            (extensions is None or checkext(path, extensions)) and
            (((filetype == 'all' and os.path.exists(path)) or
              (filetype == 'dir' and os.path.isdir(path)) or
              (filetype == 'file' and os.path.isfile(path))) or
             filetype is None) and
            (minsize is None or (not os.path.isfile(path) or
                                 os.path.getsize(path) > minsize)))
775391
function safeWriteFileSync (fileName, data, options) {
    verifyFileName (fileName);
    
    // if fileName exists, verify it is a file
    var info = getFileInfo (fileName);
    if ((info.exists) && (info.isFile === false)) {
        var message = format (cc.MSG_IS_NOT_A_FILE, fileName);
        throw new SafeFileError (cc.IS_NOT_A_FILE, message);
    }

    // get current file system state, and auto-recover if necessary
    var state = getState (fileName);

    // store data in well defined ephemeral file to allow manual recovery
    // If file already exists, remove it (failed prior recovery).
    if (state.ephemeral.exists) {
        fs.unlinkSync (state.ephemeral.name);
    }

    writeFileSync (state.ephemeral.name, data, options);
    state.ephemeral.exists = true;

    // if ready state file already exists, recover prior state
    if (state.ready.exists) {
        performRecovery (state, false);
    }
    
    fs.renameSync (state.ephemeral.name, state.ready.name);

    // refresh state and process recovery to set file system state
    state = getState (fileName);
    performRecovery (state, true);
}
1095803
def has_data_file(self, sha1hash):  # type: (str) -> bool
        """"""
        folder = os.path.join(self.folder, DATA, sha1hash[0:2])
        hash_path = os.path.join(folder, sha1hash)
        return os.path.isfile(hash_path)
259197
function fileExists(file_path) {
  try {
    var stats = fs.statSync(file_path);
    if (stats.isFile()) {
      return true;
    }
  } catch (e) {
  }
  return false;
}
282114
def check_if_committed(self, filename: str) -> bool:
        
        if os.path.isfile(filename + '.json.xz'):
            filename += '.json.xz'
        elif os.path.isfile(filename + '.json'):
            filename += '.json'
        else:
            return False
        try:
            load_structure_from_file(self.context, filename)
            return True
        except (FileNotFoundError, lzma.LZMAError, json.decoder.JSONDecodeError):
            return False
804028
def is_files(self, path):
        """"""
        return self._getReturnCodeCmd([self._hadoop_cmd, 'fs', '-test', '-f', self._full_hdfs_path(path)]) == 0
342303
def has_file(self, name: str):
        '''
        
        '''
        return os.path.isfile(self._path / name)
1048638
def is_readable(filename):
    """"""
    return os.path.isfile(filename) and os.access(filename, os.R_OK)