def _Open(self, path_spec=None, mode='rb'):
    """Opens the file-like object defined by path specification.

    Args:
      path_spec: optional path specification (instance of PathSpec).
      mode: optional file access mode. The default is 'rb' read-only binary.

    Raises:
      AccessError: if the access to open the file was denied.
      IOError: if the file-like object could not be opened.
      PathSpecError: if the path specification is incorrect.
      ValueError: if the path specification is invalid.
    """
    if not path_spec:
      raise ValueError(u'Missing path specification.')

    if path_spec.HasParent():
      raise errors.PathSpecError(u'Unsupported path specification with parent.')

    location = getattr(path_spec, u'location', None)

    if location is None:
      raise errors.PathSpecError(u'Path specification missing location.')

    # Windows does not support running os.stat on device files so we use
    # libsmdev to do an initial check.
    try:
      is_device = pysmdev.check_device(location)
    except IOError as exception:
      # Since os.stat() will not recognize Windows device file names and
      # will return '[Error 87] The parameter is incorrect' we check here
      # if pysmdev exception message contains ' access denied ' and raise
      # AccessError instead.

      # Note that exception.message no longer works in Python 3.
      exception_string = str(exception)
      if not isinstance(exception_string, py2to3.UNICODE_TYPE):
        exception_string = py2to3.UNICODE_TYPE(
            exception_string, errors=u'replace')

      if u' access denied ' in exception_string:
        raise errors.AccessError(
            u'Access denied to file: {0:s} with error: {1:s}'.format(
                location, exception_string))
      is_device = False

    if not is_device:
      try:
        stat_info = os.stat(location)
      except __HOLE__ as exception:
        raise IOError(u'Unable to open file with error: {0:s}.'.format(
            exception))

      # In case the libsmdev check is not able to detect the device also use
      # the stat information.
      if stat.S_ISCHR(stat_info.st_mode) or stat.S_ISBLK(stat_info.st_mode):
        is_device = True

    if is_device:
      self._file_object = pysmdev.handle()
      self._file_object.open(location, mode=mode)
      self._size = self._file_object.media_size

    else:
      self._file_object = open(location, mode=mode)
      self._size = stat_info.st_size

  # Note: that the following functions do not follow the style guide
  # because they are part of the file-like object interface.
dataset/ETHPy150Open log2timeline/dfvfs/dfvfs/file_io/os_file_io.py/OSFile._Open