* looking for arch@arch.thinkmo.de--2003-archives/moin--main--1.3--patch-633 to compare with
* comparing to arch@arch.thinkmo.de--2003-archives/moin--main--1.3--patch-633
M  MoinMoin/util/antispam.py

* modified files

--- orig/MoinMoin/util/antispam.py
+++ mod/MoinMoin/util/antispam.py
@@ -21,6 +21,8 @@
 from MoinMoin.security import Permissions
 from MoinMoin import caching, wikiutil
 
+BLACKLISTPAGES = ["BadContent", "LocalBadContent"]
+_cache = {}
 
 # Errors ---------------------------------------------------------------
 
@@ -53,14 +55,22 @@
 
 
 def makelist(text):
-    """ Split text into lines, strip them, skip # comments """
+    """ Split text into lines, strip them, skip # comments
+
+    Retunr list of re objects.
+    """
     lines = text.splitlines()
     list = []
     for line in lines:
         line = line.split(' # ', 1)[0] # rest of line comment
         line = line.strip()
         if line and not line.startswith('#'):
-            list.append(line)
+            try:
+                scanner = re.compile(line, re.I)
+                list.append(scanner)
+            except re.error, err:
+                dprint("Error in regex '%s': %s. Please check the pages %s." % (
+                    line, str(err), ', '.join(BLACKLISTPAGES)))
     return list
 
 
@@ -72,6 +82,8 @@
     @rtype: list
     @return: list of blacklisted regular expressions
     """
+    global _cache
+    
     from MoinMoin.PageEditor import PageEditor
     p = PageEditor(request, pagename, uid_override="Antispam subsystem")
     if do_update:
@@ -122,6 +134,8 @@
                         raise WikirpcError("failed to get BadContent data",
                                            response)
                     p._write_file(response)
+                    # Delete cache for this page
+                    _cache[pagename] = None
 
             except (timeoutsocket.Timeout, timeoutsocket.error), err:
                 # Log the error
@@ -138,34 +152,37 @@
 
             # set back socket timeout
             timeoutsocket.setDefaultSocketTimeout(old_timeout)
-                
-    blacklist = p.get_raw_body()
-    return makelist(blacklist)
+            
+    # Return cached blacklist or create new
+    if not pagename in _cache:
+        blacklist = p.get_raw_body()
+        _cache[pagename] = makelist(blacklist)
+
+    return _cache[pagename]
 
 
 class SecurityPolicy(Permissions):
     """ Extend the default security policy with antispam feature """
     
     def save(self, editor, newtext, rev, **kw):
-        BLACKLISTPAGES = ["BadContent", "LocalBadContent"]
         if not editor.page_name in BLACKLISTPAGES:
             request = editor.request
 
             # Start timing of antispam operation
             request.clock.start('antispam')
-            
+
+            request.clock.start('antispam-get-blacklist')
             blacklist = []
             for pn in BLACKLISTPAGES:
                 do_update = (pn != "LocalBadContent")
                 blacklist += getblacklist(request, pn, do_update)
+            request.clock.stop('antispam-get-blacklist')
             if blacklist:
-                for blacklist_re in blacklist:
-                    try:
-                        match = re.search(blacklist_re, newtext, re.I)
-                    except re.error, err:
-                        dprint("Error in regex '%s': %s. Please check the pages %s." % (blacklist_re, str(err), ', '.join(BLACKLISTPAGES)))
-                        continue
+                request.clock.start('antispam-match')
+                for scanner in blacklist:
+                    match = scanner.search(newtext)
                     if match:
+                        request.clock.stop('antispam-match')
                         # Log error and raise SaveError, PageEditor
                         # should handle this.
                         _ = editor.request.getText
@@ -175,6 +192,7 @@
                             }
                         dprint(msg)
                         raise editor.SaveError(msg)
+                request.clock.stop('antispam-match')
             request.clock.stop('antispam')
             
         # No problem to save if my base class agree



