'''
Store/Restore interscanners for sagator, version 0.1

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.
                                                                                
'''
                                                                                
from avlib import *
from match import match_any
                                                                                
__all__=['store','restore']

class store(match_any):
  '''
  Store scanner return value.
  
  Usage: store('VAR',scanners...)
  
  Where: 'VAR' is a string, which defines variable name to store return value

  Example: store('var1', scanner1())
  
  This scanner return's return value for a scanner included into
  and stores it's value into a variable.
  '''
  name='store()'
  VARA={}
  def __init__(self,var,*scanners):
      self.var=var
      match_any.__init__(self,scanners)
  def scanstream(self,stream):
      level,detected,virlist=match_any.scanstream(self,stream)
      store.VARA[self.var]=level,detected,virlist
      return level,detected,virlist

class restore(match_any):
  '''
  Restore scanner return value.
  
  Usage: restore('VAR')
  
  Where: 'VAR' is a string, which defines variable name to store return value

  Example: store('var1')
  
  This scanner return's return value for previously stored variable.
  '''
  name='restore()'
  def __init__(self,var):
      self.var=var
  def scanstream(self,stream):
      return store.VARA[self.var]
