#!/usr/bin/env python
"""Library for processing of artifacts.

This file contains non-GRR specific pieces of artifact processing and is
intended to end up as an independent library.
"""


import re
from typing import Iterable
from typing import Text


from grr_response_core.lib import interpolation
from grr_response_core.lib import objectfilter
from grr_response_core.lib.rdfvalues import structs as rdf_structs


class Error(Exception):
  """Base exception."""


class ConditionError(Error):
  """An invalid artifact condition was specified."""


class ArtifactProcessingError(Error):
  """Unable to process artifact."""


class KbInterpolationMissingAttributesError(Error):
  """An exception class for missing knowledgebase attributes."""

  def __init__(self, attrs: Iterable[Text]) -> None:
    message = "Some attributes could not be located in the knowledgebase: {}"
    message = message.format(", ".join(attrs))
    super().__init__(message)

    self.attrs = list(attrs)


class KbInterpolationUnknownAttributesError(Error):
  """An exception class for non-existing knowledgebase attributes."""

  def __init__(self, attrs: Iterable[Text]) -> None:
    message = "Some attributes are not part of the knowledgebase: {}"
    message = message.format(", ".join(attrs))
    super().__init__(message)