Protected From File Type
14754
protected function fromFileType($path)
    {
        switch( Filesystem::getExtension($path) )
        {
            case 'png' : return imagecreatefrompng($path);
            case 'gif' : return imagecreatefromgif($path);
            case 'jpg' :
            case 'jpeg':
            default    : return imagecreatefromjpeg($path);
        }
    }
500940
def choose_type(cls, content_type):
        """"""
        return cls.type_cls.SUBDIR if content_type in cls.subdir_types \
            else cls.type_cls.FILE
818202
def __check_to_permit(self, entry_type, entry_filename):
        """"""

        rules = self.__filter_rules[entry_type]

        # Should explicitly include?
        for pattern in rules[fss.constants.FILTER_INCLUDE]:
            if fnmatch.fnmatch(entry_filename, pattern):
                _LOGGER_FILTER.debug("Entry explicitly INCLUDED: [%s] [%s] "
                                     "[%s]", 
                                     entry_type, pattern, entry_filename)

                return True

        # Should explicitly exclude?
        for pattern in rules[fss.constants.FILTER_EXCLUDE]:
            if fnmatch.fnmatch(entry_filename, pattern):
                _LOGGER_FILTER.debug("Entry explicitly EXCLUDED: [%s] [%s] "
                                     "[%s]", 
                                     entry_type, pattern, entry_filename)

                return False

        # Implicitly include.

        _LOGGER_FILTER.debug("Entry IMPLICITLY included: [%s] [%s]", 
                             entry_type, entry_filename)

        return True
540518
function readable(file) {
  if (!exists(file)) {
    return false;
  } else {
    try {
      fs.accessSync(file, fs.R_OK);
    } catch (e) {
      return false;
    }
    return true;
  }
}
521817
def safe_mkstemp(suffix, prefix='filedownloadutils_'):
    """"""
    tmpfd, tmppath = tempfile.mkstemp(
        suffix=suffix,
        prefix=prefix,
        dir=current_app.config['CFG_TMPSHAREDDIR']
    )
    # Close the file and leave the responsability to the client code to
    # correctly open/close it.
    os.close(tmpfd)

    if '.' not in suffix:
        # Just in case format is empty
        return tmppath
    while '.' in os.path.basename(tmppath)[:-len(suffix)]:
        os.remove(tmppath)
        tmpfd, tmppath = tempfile.mkstemp(
            suffix=suffix,
            prefix=prefix,
            dir=current_app.config['CFG_TMPSHAREDDIR']
        )
        os.close(tmpfd)
    return tmppath
569136
function getFileTypeReg(type) {
    var map = [],
        ext = ""; // fis.config.get('project.fileType.' + type);
    if (type === 'text') {
        map = TEXT_FILE_EXTS;
    } else if (type === 'image') {
        map = IMAGE_FILE_EXTS;
    } else {
        xgulp.log.error('invalid file type [%s]', type);
    }
    if (ext && ext.length) {
        if (typeof ext === 'string') {
            ext = ext.split(/\s*,\s*/);
        }
        map = map.concat(ext);
    }
    map = map.join('|');
    return new RegExp('\\.(?:' + map + ')$', 'i');
}
538440
private function protect()
    {
        if (!in_array($this->type, self::allAsString(), true)) {
            throw new \InvalidArgumentException(sprintf('Invalid token type "%s"', $this->type));
        }
    }
431963
def is_protected_type(obj):
    
    return isinstance(obj, six.integer_types + (type(None), float, Decimal,
        datetime.datetime, datetime.date, datetime.time))
1048638
def is_readable(filename):
    """"""
    return os.path.isfile(filename) and os.access(filename, os.R_OK)
1264883
def _detect_content_type(self, filename):
        '''
        '''
        name, ext = os.path.splitext(filename)
        if not ext:
            raise MessageError('File requires an extension.')
        ext = ext.lower()
        if ext.lstrip('.') in self._banned_extensions:
            err = 'Extension "{0}" is not allowed.'
            raise MessageError(err.format(ext))
        if not mimetypes.inited:
            mimetypes.init()
        return mimetypes.types_map.get(ext, self._default_content_type)
948336
def prompt_filetype(args):
    """"""
    valid_types = ('print', 'text', 'csv', 'pdf', 'html')
    if not any(args[x] for x in valid_types):
        try:
            filetype = input('Print or save output as ({0}): '
                             .format(', '.join(valid_types))).lower()
            while filetype not in valid_types:
                filetype = input('Invalid entry. Choose from ({0}): '
                                 .format(', '.join(valid_types))).lower()
        except (KeyboardInterrupt, EOFError):
            return
        args[filetype] = True
437310
private static function lock()
	{
		if (self::$currentlylocked === false) {
			self::$authFileP = fopen( self::$authFile , "a+" );
			if ( flock( self::$authFileP , LOCK_EX ) ) {
				self::$currentlylocked = true;
			} else {
				throw new Exception( 'Unable to lock file' );
			}
		}

		return true;
	}
1065280
public static final void checkFileType(Path path, String perms)
    {
        if (perms.length() != 10)
        {
            throw new IllegalArgumentException(perms+" not permission. E.g. -rwxr--r--");
        }
        switch (perms.charAt(0))
        {
            case '-':
                if (!Files.isRegularFile(path))
                {
                    throw new IllegalArgumentException("file is not regular file");
                }
                break;
            case 'd':
                if (!Files.isDirectory(path))
                {
                    throw new IllegalArgumentException("file is not directory");
                }
                break;
            case 'l':
                if (!Files.isSymbolicLink(path))
                {
                    throw new IllegalArgumentException("file is not symbolic link");
                }
                break;
            default:
                throw new UnsupportedOperationException(perms+" not supported");
        }
    }
647530
function dirtyFileSaveCancelled() {
        UpdateInfoBar.showUpdateBar({
            type: "warning",
            title: Strings.WARNING_TYPE,
            description: Strings.UPDATE_ON_NEXT_LAUNCH
        });
    }
513775
def files_type(fs0, fs1, files):
    """"""
    for file_meta in files['deleted_files']:
        file_meta['type'] = fs0.file(file_meta['path'])
    for file_meta in files['created_files'] + files['modified_files']:
        file_meta['type'] = fs1.file(file_meta['path'])

    return files
744833
function getFileExcerptIfPossible(err) {
  try {
    const content = fs.readFileSync(err.file, 'utf8');

    return `${os.EOL +
      content.split(os.EOL)[err.line - 1] +
      os.EOL +
      new Array(err.column - 1).join(' ')}^${os.EOL}      `;
  } catch (ignoreErr) {
    // If anything goes wrong here, we don't want any errors to be reported to the user
    return '';
  }
}
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