home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 108 / MacAddict108.iso / Software / Internet & Communication / JunkMatcher 1.5.5.dmg / JunkMatcher.app / Contents / Resources / Engine / MatchResult.py < prev    next >
Encoding:
Python Source  |  2005-06-01  |  2.1 KB  |  58 lines

  1. #
  2. #  MatchResult.py
  3. #  JunkMatcher
  4. #
  5. #  Created by Benjamin Han on 2/1/05.
  6. #  Copyright (c) 2005 Benjamin Han. All rights reserved.
  7. #
  8.  
  9. # This program is free software; you can redistribute it and/or
  10. # modify it under the terms of the GNU General Public License
  11. # as published by the Free Software Foundation; either version 2
  12. # of the License, or (at your option) any later version.
  13.  
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. # GNU General Public License for more details.
  18.  
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program; if not, write to the Free Software
  21. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  22.  
  23. #!/usr/bin/env python
  24.  
  25. from consts import *
  26. from utilities import *
  27.  
  28.  
  29. class MatchResultEntry (object):
  30.     __slots__ = ('isProperty', 'idStr', 'view', 'isPositive', 'info', 'testIdx')
  31.  
  32.     def __init__ (self, isProperty, idStr, isPositive, view = None, info = None, testIdx = -1):
  33.         self.isProperty = isProperty
  34.         self.idStr = idStr
  35.         self.isPositive = isPositive
  36.         if view: self.view = view
  37.         if info: self.info = info
  38.         self.testIdx = testIdx
  39.  
  40.  
  41. class MatchResult (list):
  42.     """Recording the verdict, each test (property/pattern) and its result
  43.        ------------------------------------------------------------------
  44.        verdict: True iff the message is junk; False iff it's clean; a string if it's whitelisted
  45.          (the pattern name being matched).
  46.        """
  47.     # improving performance by not having __dict__
  48.     __slots__ = 'verdict'
  49.  
  50.     def setVerdict (self, verdict):
  51.         self.verdict = verdict
  52.     
  53.     def addProperty (self, propertyID, isPositive, info = None, testIdx = -1):
  54.         self.append(MatchResultEntry(True, propertyID, isPositive, info = info, testIdx = testIdx))
  55.         
  56.     def addPattern (self, patternStr, view, isPositive, info = None, testIdx = -1):
  57.         self.append(MatchResultEntry(False, patternStr, isPositive, view = view, info = info, testIdx = testIdx))
  58.