Return an open file.

        Args:
            file_des: File descriptor of the open file.

        Raises:
            OSError: an invalid file descriptor.
            TypeError: filedes is not an integer.

        Returns:
            Open file object.
501116
def get_open_file(self, file_des):
        
        if not is_int_type(file_des):
            raise TypeError('an integer is required')
        if (file_des >= len(self.open_files) or
                self.open_files[file_des] is None):
            self.raise_os_error(errno.EBADF, str(file_des))
        return self.open_files[file_des][0]
602612
def open(cls, fp):
        
        if hasattr(fp, 'read'):
            self = cls(PSD.read(fp))
        else:
            with open(fp, 'rb') as f:
                self = cls(PSD.read(f))
        return self
588880
def _openFile(self):
        
        if self.filename is not None:
            self.h5 = h5py.File(self.filename)
        else:
            return

        if 'bp' not in self.h5:
            self.h5.create_group('bp')

        if 'bps' not in self.h5:
            self.h5.create_group('bps')

        for bp_type in ['bp', 'bps']:
            for bp_num in self.data[bp_type]:

                # Create group in case if new hdf5 file is opened
                if bp_num not in self.h5[bp_type]:
                    self.h5[bp_type].create_group(bp_num)

                # Sync data if old file is opened
                for parameters in self.h5[bp_type][bp_num]:
                    self.data[bp_type][bp_num][parameters] = self.h5[bp_type][bp_num][parameters]

        if 'mask' in self.h5:
            self.mask = self.h5['mask'][:]

        if 'time' in self.h5:
            self.time = self.h5['time'][:]

        if 'num_bp' in self.h5.attrs:
            self.num_bp = self.h5.attrs['num_bp']
        else:
            self.h5.attrs['num_bp'] = self.num_bp

        if 'num_step' in self.h5.attrs:
            self.num_step = self.h5.attrs['num_step']
        else:
            self.h5.attrs['num_step'] = self.num_step

        if 'startBP' in self.h5.attrs:
            self.startBP = self.h5.attrs['startBP']
        else:
            self.h5.attrs['startBP'] = self.startBP
515494
def read_file(file):
	
	if hasattr(file, "read"):
		return file.read()
	if hasattr(file, "read_bytes"):
		return file.read_bytes()
	with open(file, "rb") as f:
		return f.read()
1358042
def ParseFileObject(self, parser_mediator, file_object):
    
    esedb_file = pyesedb.file()

    try:
      esedb_file.open_file_object(file_object)
    except IOError as exception:
      parser_mediator.ProduceExtractionWarning(
          'unable to open file with error: {0!s}'.format(exception))
      return

    # Compare the list of available plugin objects.
    cache = ESEDBCache()
    try:
      table_names = frozenset(self._GetTableNames(esedb_file))

      for plugin in self._plugins:
        if parser_mediator.abort:
          break

        if not plugin.required_tables.issubset(table_names):
          continue

        try:
          plugin.UpdateChainAndProcess(
              parser_mediator, cache=cache, database=esedb_file)

        except Exception as exception:  # pylint: disable=broad-except
          parser_mediator.ProduceExtractionWarning((
              'plugin: {0:s} unable to parse ESE database with error: '
              '{1!s}').format(plugin.NAME, exception))

    finally:
      # TODO: explicitly clean up cache.

      esedb_file.close()
1059890
def fileish_open(fileish, mode):
    
    if mode is not None and any(m in mode for m in ['+', 'w', 'a', 'x']):
        attr = 'write'
    else:
        attr = 'read'
    if hasattr(fileish, attr) and hasattr(fileish, 'seek'):
        # BytesIO-like object
        return fileish
    elif isinstance(fileish, str):
        # Python2 - file path, file contents in the case of a TypeError
        # Python3 - file path
        try:
            return open(fileish, mode)
        except TypeError:
            return io.BytesIO(fileish)
    else:
        # Python 3 - file contents
        return io.BytesIO(fileish)
389907
def _fileobj_to_fd(fileobj):
    
    if isinstance(fileobj, int):
        fd = fileobj
    else:
        try:
            fd = int(fileobj.fileno())
        except (AttributeError, TypeError, ValueError):
            raise ValueError("Invalid file object: {0!r}".format(fileobj))
    if fd < 0:
        raise ValueError("Invalid file descriptor: {0}".format(fd))
    return fd
1364172
def _read_fd(file_descr):
        
        try:
            line = os.read(file_descr, 1024 * 1024)
        except OSError:
            stream_desc = NonBlockingStreamReader._get_sd(file_descr)
            if stream_desc is not None:
                stream_desc.has_error = True
                if stream_desc.callback is not None:
                    stream_desc.callback()
            return 0

        if line:
            stream_desc = NonBlockingStreamReader._get_sd(file_descr)
            if stream_desc is None:
                return 0 # Process closing

            if IS_PYTHON3:
                try:
                    # @TODO: further develop for not ascii/unicode binary content
                    line = line.decode("ascii")
                except UnicodeDecodeError:
                    line = repr(line)
            stream_desc.buf += line
            # Break lines
            split = stream_desc.buf.split(os.linesep)
            for line in split[:-1]:
                stream_desc.read_queue.appendleft(strip_escape(line.strip()))
                if stream_desc.callback is not None:
                    stream_desc.callback()
            # Store the remainded, its either '' if last char was '\n'
            # or remaining buffer before line end
            stream_desc.buf = split[-1]
            return len(line)
        return 0
373587
def _open_file(filename):
        
        if filename is None:
            raise DataSourceError("Trace filename is not defined")

        try:
            trace_file = open(filename, "r")
        except IOError as e:
            raise DataSourceError("Unable to open trace file %s" % filename, e)
        else:
            LOG.debug("Opened trace file %s", filename)
            return trace_file
565314
def _fileobj_to_fd(fileobj):
    
    if isinstance(fileobj, _INTEGER_TYPES):
        fd = fileobj
    else:
        for _integer_type in _INTEGER_TYPES:
            try:
                fd = _integer_type(fileobj.fileno())
                break
            except (AttributeError, TypeError, ValueError):
                continue
        else:
            raise ValueError("Invalid file object: {0!r}".format(fileobj))
    if fd < 0:
        raise ValueError("Invalid file descriptor: {0}".format(fd))
    return fd
763031
def from_file(cls, path):

        

        with open(path, 'r', errors='replace') as f:
            return cls(f.read())
538389
def open(filename):
        """"""
        if isinstance(filename, six.string_types):
            try:
                fdesc = gzip.open(filename, "rb")
                magic = fdesc.read(4)
            except IOError:
                fdesc = open(filename, "rb")
                magic = fdesc.read(4)
        else:
            fdesc = filename
            filename = getattr(fdesc, "name", "No name")
            magic = fdesc.read(4)
        return filename, fdesc, magic
437964
def Open(self, file_object, ascii_codepage='cp1252'):
    
    registry_file = dfwinreg_regf.REGFWinRegistryFile(
        ascii_codepage=ascii_codepage)

    # We don't catch any IOErrors here since we want to produce a parse error
    # from the parser if this happens.
    registry_file.Open(file_object)

    return registry_file
387741
def open_file(self, file_):
        
        with open(file_, 'r', encoding='utf-8') as file:
            text = ''
            for line in file:
                text += line
        return text
125610
def download_file(self, file_id, dest):
        
        f = self.getFile(file_id)
        try:
            d = dest if _isfile(dest) else open(dest, 'wb')

            r = api.download((self._token, f['file_path']), preload_content=False)

            while 1:
                data = r.read(self._file_chunk_size)
                if not data:
                    break
                d.write(data)
        finally:
            if not _isfile(dest) and 'd' in locals():
                d.close()

            if 'r' in locals():
                r.release_conn()
786639
def open(self, fp, mode='r'):
        
        self._file = open(fp, mode=mode)
        return self._file
507563
def ParseFileObject(self, parser_mediator, file_object):
    
    evt_file = pyevt.file()
    evt_file.set_ascii_codepage(parser_mediator.codepage)

    try:
      evt_file.open_file_object(file_object)
    except IOError as exception:
      parser_mediator.ProduceExtractionWarning(
          'unable to open file with error: {0!s}'.format(exception))
      return

    try:
      self._ParseRecords(parser_mediator, evt_file)
    finally:
      evt_file.close()