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

  1. #
  2. #  GlobalObjects.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. def loadSafeSitesPattern ():
  30.     lines = openFile('%ssafeSites' % CONF_PATH).readlines()
  31.     if len(lines):
  32.         return re.compile(r'|'.join([r'(?:%s)'%l.strip() for l in lines]), re.IGNORECASE)
  33.     else: return None    
  34.  
  35.  
  36. class GlobalObjects (object):
  37.     """Storing all global objects that need to be reloaded at some point, and
  38.     do lazy initialization."""
  39.     def __init__ (self):
  40.         self.emailDBReadFlag = False
  41.     
  42.     def emailAddrPat (self):
  43.         # Email address/comment pattern according to RFC 2822
  44.         return re.compile(''.join(map(lambda l:l.rstrip(), open('%setc/rfc2822' % ENGINE_PATH))))
  45.     emailAddrPat = Lazy(emailAddrPat)
  46.  
  47.     def emailAddrCommentPat (self):
  48.         return re.compile('[\040\t]*(?:\([^\\\x80-\xff\n\015()]*(?:(?:\\[^\x80-\xff]|\([^\\\x80-\xff\n\015()]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015()]*)*\))[^\\\x80-\xff\n\015()]*)*\)[\040\t]*)*')
  49.     emailAddrCommentPat = Lazy(emailAddrCommentPat)
  50.     
  51.     def prefs (self):
  52.         return __import__('Preferences').Preferences('%sprefs' % CONF_PATH)
  53.     prefs = Lazy(prefs)
  54.  
  55.     def htmlTags (self):
  56.         return __import__('HTMLTagDict').HTMLTagDict('%shtmlTags' % CONF_PATH)
  57.     htmlTags = Lazy(htmlTags)
  58.  
  59.     def safeSitesPattern (self):
  60.         return loadSafeSitesPattern()
  61.     safeSitesPattern = Lazy(safeSitesPattern)
  62.  
  63.     def siteDB (self):
  64.         return __import__('SiteDB').SiteDB('%ssiteDB' % CONF_PATH, self.prefs.siteLimit)
  65.     siteDB = Lazy(siteDB)
  66.  
  67.     def recipientPatterns (self):
  68.         return __import__('SimplePatterns').SimplePatterns('%srecipientPatterns' % CONF_PATH)
  69.     recipientPatterns = Lazy(recipientPatterns)
  70.     
  71.     def safeIPs (self):
  72.         return __import__('SimplePatterns').SimplePatterns('%ssafeIPs' % CONF_PATH)
  73.     safeIPs = Lazy(safeIPs)
  74.     
  75.     def whitelist (self):
  76.         return __import__('SimplePatterns').SimplePatterns('%swhitelist' % CONF_PATH, True)
  77.     whitelist = Lazy(whitelist)
  78.  
  79.     def metaPatterns (self):
  80.         return __import__('MetaPatterns').MetaPatterns('%smetaPatterns' % CONF_PATH)
  81.     metaPatterns = Lazy(metaPatterns)
  82.  
  83.     def addressSet (self):
  84.         return __import__('addressBook').getAddressesFromABook()
  85.     addressSet = Lazy(addressSet)
  86.  
  87.     def logger (self):
  88.         return __import__('Logger').Logger('%sjm.log' % CONF_PATH)
  89.     logger = Lazy(logger)
  90.  
  91.     def emailDB (self):
  92.         return __import__('EmailDB').EmailDB('%semailDB.dat' % CONF_PATH, self.emailDBReadFlag)
  93.     emailDB = Lazy(emailDB)
  94.  
  95.  
  96. globalObjects = GlobalObjects()
  97.  
  98.  
  99. if __name__ == '__main__':
  100.     print globalObjects.addressSet
  101.