class IncludeRegexpStrategyRule(StrategyRule):
  """Include symbols matching pattern."""

  def __init__(self, pattern):
    try:
      self.regexp = re.compile('^' + pattern + '$')
    except re.error:
      raise FatalError("%r is not a valid regexp." % (pattern,))
    
  def log(self, symbol):
    Log().verbose(
      'Excluding symbol %s because it doesn\'t match regexp "%s".'
      % (symbol, self.regexp.pattern,)
      )
    
  def get_symbol(self, symbol, stats):

    if ( hasattr( symbol, "name" ) ):

      if self.regexp.match( symbol.name ):
        return symbol
      else:
        self.log( symbol )
        return ExcludedSymbol(symbol)
    else:
      return symbol