00001 __copyright__ = """ 00002 Copyright 2008 Sean Ross-Ross 00003 """ 00004 __license__ = """ 00005 This file is part of SLIMpy . 00006 00007 SLIMpy is free software: you can redistribute it and/or modify 00008 it under the terms of the GNU Lesser General Public License as published by 00009 the Free Software Foundation, either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 SLIMpy is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public License 00018 along with SLIMpy . If not, see <http://www.gnu.org/licenses/>. 00019 """ 00020 00021 00022 00023 class Filter( object): 00024 00025 def gen_index_set( self, record_list ): 00026 00027 index_list = range( len(record_list) ) 00028 return set( index_list ) 00029 00030 00031 class VerbosityFilter( Filter ): 00032 00033 def __init__(self,verb): 00034 self._verb = verb 00035 return 00036 00037 def gen_index_set( self, record_list ): 00038 index_set = set( ) 00039 for i,item in enumerate( record_list ): 00040 if item['verb'] <= self._verb: 00041 index_set.add( i ) 00042 00043 return index_set 00044 00045 class DebugFilter( Filter ): 00046 00047 def __init__(self, db_list): 00048 self._db = set( db_list ) 00049 00050 00051 def gen_index_set( self, record_list ): 00052 00053 index_set = set( ) 00054 00055 for i, item in enumerate( record_list ): 00056 00057 if self._db.intersection( item['debug'] ): 00058 index_set.add( i ) 00059 00060 return index_set 00061