def __init__(self, base_fd, pathspec=None, progress_callback=None,
               full_pathspec=None):
    super(RegistryFile, self).__init__(base_fd, pathspec=pathspec,
                                       full_pathspec=full_pathspec,
                                       progress_callback=progress_callback)

    if base_fd is None:
      self.pathspec.Append(pathspec)
    elif base_fd.IsDirectory():
      self.pathspec.last.path = utils.JoinPath(self.pathspec.last.path,
                                               pathspec.path)
    else:
      raise IOError("Registry handler can not be stacked on another handler.")

    path_components = filter(None, self.pathspec.last.path.split("/"))
    try:
      # The first component MUST be a hive
      self.hive = getattr(_winreg, path_components[0])
      self.hive = KeyHandle(self.hive)
    except AttributeError:
      raise IOError("Unknown hive name %s" % path_components[0])
    except IndexError:
      # A hive is not specified, we just list all the hives.
      return

    # Normalize the path casing if needed
    self.key_name = "/".join(path_components[1:])
    self.local_path = CanonicalPathToLocalPath(self.key_name)

    try:
      # Maybe its a value
      key_name, value_name = os.path.split(self.local_path)
      with OpenKey(self.hive, key_name) as key:
        self.value, self.value_type = QueryValueEx(key, value_name)

      # We are a value and therefore not a directory.
      self.is_directory = False
    except exceptions.WindowsError:
      try:
        # Try to get the default value for this key
        with OpenKey(self.hive, self.local_path) as key:

          # Check for default value.
          try:
            self.value, self.value_type = QueryValueEx(key, "")
          except exceptions.WindowsError:
            # Empty default value
            self.value = ""
            self.value_type = _winreg.REG_NONE

      except exceptions.WindowsError:
        raise IOError("Unable to open key %s" % self.key_name)
dataset/ETHPy150Open google/grr/grr/client/vfs_handlers/registry.py/RegistryFile.__init__/original