Pass `file` to `func` and ensure the file is closed afterwards. If
       `file` is a string, open according to `mode`; if `expand` is true also
       expand user and vars.
776801
def withFile(file, func, mode='r', expand=False):
    
    file = _normalizeToFile(file, mode=mode, expand=expand)
    try:      return func(file)
    finally:  file.close()
1372115
function processFile(extension) {
  return (file, callback) => {
    let filePath;
    if (file.meta !== undefined && file.meta.filePath !== undefined) {
      const ext = extension === null
        ? file.meta.filePath.ext
        : extension;
      filePath = path.format(Object.assign({}, file.meta.filePath, { ext }));
    } else {
      filePath = extension === undefined
        ? file.path
        : `${trimExtension(file.path)}${extension}`;
    }

    async.nextTick(callback, null, Object.assign({}, file, { path: filePath }));
  };
}
257479
function (fp, opts, cb) {
    if (typeof fp !== 'string') {
      cb = opts;
      opts = fp;
      fp = null;
    }
    if (typeof opts === 'function') {
      cb = opts;
      opts = {};
    }
    if (typeof cb !== 'function') {
      throw new Error('expected a callback function.');
    }

    var dest = this.dest(fp || this.path, opts);
    var file = { contents: this.content, path: dest };
    opts = extend({ ask: true }, this.options, opts);
    utils.detect(file, opts, function (err) {
      if (file.contents) {
        utils.write(dest, file.contents, cb);
      } else {
        this.copy(dest, cb);
      }
      return this;
    }.bind(this));
    return this;
  }
376171
def auto(func, filename, *args, **kwargs):
    
    dev, dev_filename = get_dev_and_path(filename)
    if dev is None:
        if len(dev_filename) > 0 and dev_filename[0] == '~':
            dev_filename = os.path.expanduser(dev_filename)
        return func(dev_filename, *args, **kwargs)
    return dev.remote_eval(func, dev_filename, *args, **kwargs)
89334
def loadFromFile(self, path):
        
        if '~' in path:
            path = os.path.expanduser(path)
        f = open(path)
        body = f.read()
        f.close()
        self._path = path
        self.loadFromString(body)
442008
function getExtension(file) {
        var ret;
        if (file) {
            var fileTypes = file.split('.');
            var len = fileTypes.length;
            if (0 === len) {
                return ret;
            }
            ret = fileTypes[len - 1];
            return ret;
        }
    }
164665
def insert_file(self, file):
        

        if type(file) is bytes:
            file = open(file, 'r')

        self.insert_string(file.read())
816660
def bind(self, func: Callable[[Any], IO]) -> IO:
        """"""

        filename, g = self._get_value()
        return ReadFile(filename, lambda s: g(s).bind(func))
1311919
def ensure_obj(f):
    
    @click.pass_context
    def new_func(ctx, *args, **kwargs):
        if ctx.obj is None:
            ctx.obj = {}
        return ctx.invoke(f, *args, **kwargs)
    return update_wrapper(new_func, f)
695639
def file(self, name, *args, **kwargs):
        
        return open(self(name), *args, **kwargs)
767019
function(file) {
    var filePath = path.resolve(file);

    if (filePath) {
      if (!fs.existsSync(filePath)) {
        fse.ensureFileSync(filePath);
      }
      return filePath;
    }

    return false;
  }
113802
def watch_file(path, func, *args, **kwargs):
    
    if not path:
        raise ValueError('Please specify a file to watch')
    print('Watching "{}" for changes'.format(path))
    last_modification_time = os.path.getmtime(path)
    try:
        while True:
            time.sleep(1)
            new_modification_time = os.path.getmtime(path)
            if new_modification_time == last_modification_time:
                continue
            func(*args, **kwargs)
            last_modification_time = new_modification_time
    except KeyboardInterrupt:
        pass
502281
def validate(self, instance, value):
        
        if isinstance(value, string_types) and self.mode is not None:
            try:
                value = open(value, self.mode)
            except (IOError, TypeError):
                self.error(instance, value,
                           extra='Cannot open file: {}'.format(value))
        if not all([hasattr(value, attr) for attr in ('read', 'seek')]):
            self.error(instance, value, extra='Not a file-like object')
        if not hasattr(value, 'mode') or self.valid_modes is None:
            pass
        elif value.mode not in self.valid_modes:
            self.error(instance, value,
                       extra='Invalid mode: {}'.format(value.mode))
        if getattr(value, 'closed', False):
            self.error(instance, value, extra='File is closed.')
        return value
212796
def _expand_possible_file_value(self, value):
    """"""
    if value and os.path.isfile(str(value)):
      with open(value, 'r') as f:
        return f.read()
    return value
639588
def open(self):
        
        if self._f is not None:
            return self._f
        try:
            rv, self.should_close = open_stream(self.name, self.mode,
                                                self.encoding,
                                                self.errors,
                                                atomic=self.atomic)
        except (IOError, OSError) as e:
            from .exceptions import FileError
            raise FileError(self.name, hint=get_streerror(e))
        self._f = rv
        return rv
964333
function(file) {
    return fs.openAsync(file, 'r').then((fileDescriptor) => {
      return lzma.parseFileIndexFDAsync(fileDescriptor).tap(() => {
        return fs.closeAsync(fileDescriptor);
      });
    }).then((metadata) => {
      return {
        stream: fs.createReadStream(file)
          .pipe(lzma.createDecompressor()),
        size: metadata.uncompressedSize,
        transform: new PassThroughStream()
      };
    });
  }
816219
def execute_from_file(self, url, file_var):
        '''
        

        '''
        if isinstance(file_var, file):
            f = file_var
        elif isinstance(file_var, str):
            try:
                f = open(file_var)
            except IOError, e:
                raise e
        else:
            raise TypeError("This function only accepts a 'file' type  or file path")

        inputs = json.loads(f.read())
        resp = self.execute(url, inputs)
        return resp