changeset 4164:0be4fb46e492

Moved even more attributes into (lazy) properties
author Florian Krupicka <florian.krupicka@googlemail.com>
date Wed, 11 Jun 2008 18:36:54 +0200
parents d45b0bb15d2f
children 435ae662416d
files MoinMoin/web/contexts.py MoinMoin/wsgiapp.py
diffstat 2 files changed, 40 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/web/contexts.py	Wed Jun 11 14:39:38 2008 +0200
+++ b/MoinMoin/web/contexts.py	Wed Jun 11 18:36:54 2008 +0200
@@ -10,10 +10,11 @@
 
 import re, time, inspect
 
-from werkzeug.utils import Headers, http_date
+from werkzeug.utils import Headers, http_date, cached_property
 from werkzeug.exceptions import Unauthorized, NotFound
 
-from MoinMoin import i18n
+from MoinMoin import i18n, error
+from MoinMoin.config import multiconfig
 from MoinMoin.formatter import text_html
 from MoinMoin.request import RequestBase
 from MoinMoin.web.request import Request
@@ -86,7 +87,7 @@
             return self._is_spideragent
         else:
             return False
-    is_spideragent = property(is_spideragent)
+    is_spideragent = cached_property(is_spideragent)
 
     # legacy compatibility
     isSpiderAgent = is_spideragent
@@ -222,7 +223,7 @@
         else:
             lang = 'en'
         return lang
-    lang = property(lang)
+    lang = cached_property(lang)
 
     def getText(self):
         lang = self.lang
@@ -230,7 +231,28 @@
         def _(text, i18n=i18n, request=self, lang=lang, **kw):
             return i18n.getText(text, request, lang, **kw)
         return _
-    getText = property(getText)
+    getText = cached_property(getText)
+
+    def action(self):
+        return self.values.get('action','show')
+    action = cached_property(action)
+
+    def rev(self):
+        try:
+            return int(self.values['rev'])
+        except:
+            return None
+    rev = cached_property(rev)
+
+    def cfg(self):
+        try:
+            self.clock.start('load_multicfg')
+            cfg = multiconfig.getConfig(self.url)
+            self.clock.stop('load_multi_cfg')
+            return cfg
+        except error.NoConfigMatchedError:
+            raise NotFound('<p>No wiki configuration matching the URL found!</p>')
+    cfg = cached_property(cfg)
 
 class RenderContext(Context):
     """ Context for rendering content
@@ -241,10 +263,8 @@
     * page
     * output redirection
     """
-    def __init__(self, parent,  page=None, user=None, lang=None):
+    def __init__(self, parent):
         Context.__init__(self, parent)
-        self.page = page
-        self.user = user
 
         self.pragma = {}
         self.mode_getpagelinks = 0
@@ -262,7 +282,12 @@
             return self.user.language
         else:
             return getattr(self._parent, 'lang')
-    lang = property(lang)
+    lang = cached_property(lang)
+
+    def rootpage(self):
+        from MoinMoin.Page import RootPage
+        return RootPage(self)
+    rootpage = cached_property(rootpage)
 
 # mangle in logging of function calls
 def _logfunc(func):
--- a/MoinMoin/wsgiapp.py	Wed Jun 11 14:39:38 2008 +0200
+++ b/MoinMoin/wsgiapp.py	Wed Jun 11 18:36:54 2008 +0200
@@ -10,7 +10,7 @@
 from werkzeug.wrappers import Response
 from werkzeug.exceptions import NotFound
 
-from MoinMoin.web.contexts import HTTPContext
+from MoinMoin.web.contexts import HTTPContext, RenderContext
 from MoinMoin.web.request import Request
 from MoinMoin.web.utils import check_spider, check_forbidden, check_setuid
 from MoinMoin.web.utils import check_surge_protect, handle_auth_form
@@ -29,27 +29,9 @@
     request.clock = Clock()
     request.clock.start('total')
     request.clock.start('base__init__')
-    try:
-        request.clock.start('load_multi_cfg')
-        request.cfg = multiconfig.getConfig(request.url)
-        request.clock.stop('load_multi_cfg')
-    except error.NoConfigMatchedError:
-        raise NotFound('<p>No wiki configuration matching the URL found!</p>')
-
-    request.action = request.form.get('action', 'show')
-    
-    try:
-        request.rev = int(request.form['rev'])
-    except:
-        request.rev = None
-
-    from MoinMoin.Page import RootPage
-    request.rootpage = RootPage(request)
 
     user_obj = request.cfg.session_handler.start(request, request.cfg.session_id_handler)
-    
-    request.user = None
-    request.user = handle_auth_form(user_obj, request.form)
+    request.user = handle_auth_form(user_obj, request)
 
     request.cfg.session_handler.after_auth(request, request.cfg.session_id_handler, request.user)
 
@@ -58,6 +40,8 @@
 
     check_setuid(request)
 
+    request = RenderContext(request)
+
     if request.action != 'xmlrpc':
         check_forbidden(request)
         check_surge_protect(request)
@@ -65,11 +49,12 @@
     request.reset()
 
     request.clock.stop('base__init__')
+    return request
 
 def application(environ, start_response):
     request = Request(environ)
     request = HTTPContext(request)
-    _request_init(request)
+    request = _request_init(request)
     request.run()
 
     response = Response(status=request.status,