changeset 1549:e36313297589

introduce request.cfg.cache object, start using it for some precompiled regexes
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 14 Sep 2006 22:08:45 +0200
parents 2eb5117aa7de
children a4f0632414da
files MoinMoin/PageEditor.py MoinMoin/PageGraphicalEditor.py MoinMoin/config/multiconfig.py MoinMoin/macro/EditTemplates.py MoinMoin/request/__init__.py MoinMoin/security/__init__.py MoinMoin/wikidicts.py MoinMoin/wikiutil.py MoinMoin/xmlrpc/UpdateGroup.py
diffstat 9 files changed, 29 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/PageEditor.py	Thu Sep 14 18:37:05 2006 +0200
+++ b/MoinMoin/PageEditor.py	Thu Sep 14 22:08:45 2006 +0200
@@ -372,7 +372,7 @@
         self.request.write("</p>")
 
         # Category selection
-        filter = re.compile(self.cfg.page_category_regex, re.UNICODE).search
+        filter = self.cfg.cache.page_category_regex.search
         cat_pages = self.request.rootpage.getPageList(filter=filter)
         cat_pages.sort()
         cat_pages = [wikiutil.pagelinkmarkup(p) for p in cat_pages]
--- a/MoinMoin/PageGraphicalEditor.py	Thu Sep 14 18:37:05 2006 +0200
+++ b/MoinMoin/PageGraphicalEditor.py	Thu Sep 14 22:08:45 2006 +0200
@@ -300,7 +300,7 @@
         self.request.write("</p>")
 
         # Category selection
-        filter = re.compile(self.cfg.page_category_regex, re.UNICODE).search
+        filter = self.cfg.cache.page_category_regex.search
         cat_pages = self.request.rootpage.getPageList(filter=filter)
         cat_pages.sort()
         cat_pages = [wikiutil.pagelinkmarkup(p) for p in cat_pages]
--- a/MoinMoin/config/multiconfig.py	Thu Sep 14 18:37:05 2006 +0200
+++ b/MoinMoin/config/multiconfig.py	Thu Sep 14 22:08:45 2006 +0200
@@ -184,6 +184,11 @@
 def _(text): return text
 
 
+class CacheClass:
+    """ just a container for stuff we cache """
+    pass
+
+
 class DefaultConfig:
     """ default config values """
 
@@ -523,6 +528,8 @@
     def __init__(self, siteid):
         """ Init Config instance """
         self.siteid = siteid
+        self.cache = CacheClass()
+
         if self.config_check_enabled:
             self._config_check()
 
@@ -538,6 +545,13 @@
         # Try to decode certain names which allow unicode
         self._decode()
 
+        # After that, pre-compile some regexes
+        self.cache.page_category_regex = re.compile(self.page_category_regex, re.UNICODE)
+        self.cache.page_dict_regex = re.compile(self.page_dict_regex, re.UNICODE)
+        self.cache.page_group_regex = re.compile(self.page_group_regex, re.UNICODE)
+        self.cache.page_template_regex = re.compile(self.page_template_regex, re.UNICODE)
+        self.cache.ua_spiders = re.compile(self.ua_spiders, re.I)
+
         self._check_directories()
 
         if not isinstance(self.superuser, list):
--- a/MoinMoin/macro/EditTemplates.py	Thu Sep 14 18:37:05 2006 +0200
+++ b/MoinMoin/macro/EditTemplates.py	Thu Sep 14 22:08:45 2006 +0200
@@ -13,7 +13,7 @@
 
 def execute(self, args):
     # Get list of template pages readable by current user
-    filter = re.compile(self.request.cfg.page_template_regex, re.UNICODE).search
+    filter = self.request.cfg.cache.page_template_regex.search
     templates = self.request.rootpage.getPageList(filter=filter)
     result = []
     if templates:
--- a/MoinMoin/request/__init__.py	Thu Sep 14 18:37:05 2006 +0200
+++ b/MoinMoin/request/__init__.py	Thu Sep 14 22:08:45 2006 +0200
@@ -877,11 +877,9 @@
     def check_spider(self):
         """ check if the user agent for current request is a spider/bot """
         isSpider = False
-        spiders = self.cfg.ua_spiders
-        if spiders:
-            ua = self.getUserAgent()
-            if ua:
-                isSpider = re.search(spiders, ua, re.I) is not None
+        ua = self.getUserAgent()
+        if ua:
+            isSpider = self.cfg.cache.ua_spiders.search(ua) is not None
         return isSpider
 
     def isForbidden(self):
--- a/MoinMoin/security/__init__.py	Thu Sep 14 18:37:05 2006 +0200
+++ b/MoinMoin/security/__init__.py	Thu Sep 14 22:08:45 2006 +0200
@@ -172,7 +172,6 @@
     def __init__(self, cfg, lines=[]):
         """Initialize an ACL, starting from <nothing>.
         """
-        self._group_re = re.compile(cfg.page_group_regex, re.UNICODE)
         if lines:
             self.acl = [] # [ ('User', {"read": 0, ...}), ... ]
             self.acl_lines = []
@@ -222,19 +221,19 @@
         """May <name> <dowhat>?
            Returns boolean answer.
         """
-        is_group_member = request.dicts.has_member
-
         if self.acl is None: # no #acl used on Page
             acl_page = request.cfg._acl_rights_default.acl
         else: # we have a #acl on the page (self.acl can be [] if #acl is empty!)
             acl_page = self.acl
         acl = request.cfg._acl_rights_before.acl + acl_page + request.cfg._acl_rights_after.acl
+        is_group_member = request.dicts.has_member
+        group_re = request.cfg.cache.page_group_regex
         allowed = None
         for entry, rightsdict in acl:
             if entry in self.special_users:
                 handler = getattr(self, "_special_"+entry, None)
                 allowed = handler(request, name, dowhat, rightsdict)
-            elif self._group_re.search(entry):
+            elif group_re.search(entry):
                 if is_group_member(entry, name):
                     allowed = rightsdict.get(dowhat)
                 else:
--- a/MoinMoin/wikidicts.py	Thu Sep 14 18:37:05 2006 +0200
+++ b/MoinMoin/wikidicts.py	Thu Sep 14 22:08:45 2006 +0200
@@ -338,8 +338,8 @@
                 dump = 1
 
         if lastchange >= self.namespace_timestamp or dump:
-            isdict = re.compile(self.cfg.page_dict_regex, re.UNICODE).search
-            isgroup = re.compile(self.cfg.page_group_regex, re.UNICODE).search
+            isdict = self.cfg.cache.page_dict_regex.search
+            isgroup = self.cfg.cache.page_group_regex.search
 
             # check for new groups / dicts from time to time...
             if now - self.namespace_timestamp >= wikiutil.timestamp2version(60): # 60s
--- a/MoinMoin/wikiutil.py	Thu Sep 14 18:37:05 2006 +0200
+++ b/MoinMoin/wikiutil.py	Thu Sep 14 22:08:45 2006 +0200
@@ -682,8 +682,7 @@
     @rtype: bool
     @return: true if page is a template page
     """
-    filter = re.compile(request.cfg.page_template_regex, re.UNICODE)
-    return filter.search(pagename) is not None
+    return request.cfg.cache.page_template_regex.search(pagename) is not None
 
 
 def isGroupPage(request, pagename):
@@ -693,8 +692,7 @@
     @rtype: bool
     @return: true if page is a form page
     """
-    filter = re.compile(request.cfg.page_group_regex, re.UNICODE)
-    return filter.search(pagename) is not None
+    return request.cfg.cache.page_group_regex.search(pagename) is not None
 
 
 def filterCategoryPages(request, pagelist):
@@ -711,7 +709,7 @@
     @rtype: list
     @return: only the category pages of pagelist
     """
-    func = re.compile(request.cfg.page_category_regex, re.UNICODE).search
+    func = request.cfg.cache.page_category_regex.search
     return filter(func, pagelist)
 
 
--- a/MoinMoin/xmlrpc/UpdateGroup.py	Thu Sep 14 18:37:05 2006 +0200
+++ b/MoinMoin/xmlrpc/UpdateGroup.py	Thu Sep 14 22:08:45 2006 +0200
@@ -43,7 +43,7 @@
         return xmlrpclib.Fault(1, "You are not allowed to edit this page")
 
     # check if groupname matches page_group_regex
-    if not re.match(self.request.cfg.page_group_regex, groupname):
+    if not self.request.cfg.cache.page_group_regex.match(groupname):
         return xmlrpclib.Fault(2, "The groupname %s does not match your page_group_regex (%s)" % (
                                groupname, self.request.cfg.page_group_regex))