changeset 4184:b4acdce23cfa

Group some functionality
author Florian Krupicka <florian.krupicka@googlemail.com>
date Sat, 21 Jun 2008 20:01:54 +0200
parents fc20a076aad0
children 68bcf39ae1d3
files MoinMoin/web/contexts.py
diffstat 1 files changed, 26 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/web/contexts.py	Sat Jun 21 16:57:20 2008 +0200
+++ b/MoinMoin/web/contexts.py	Sat Jun 21 20:01:54 2008 +0200
@@ -67,6 +67,8 @@
                                   self.full_name)
 
 class Context(object):
+    __slots__ = ['request', 'environ']
+
     def __init__(self, request):
         assert isinstance(request, Request)
         self.request = request
@@ -140,7 +142,6 @@
 
 class HTTPMixin(object):
     forbidden = EnvironProxy('old.forbidden', 0)
-
     
     _auth_redirected = EnvironProxy('old._auth_redirected', 0)
     _cache_disabled = EnvironProxy('old._cache_disabled', 0)
@@ -319,18 +320,35 @@
 class ClockMixin(object):
     clock = EnvironProxy('clock', lambda o: Clock())
 
-class HTTPContext(Context, HTTPMixin, ConfigMixin, UserMixin,
-                  LanguageMixin, RenamedMixin, ClockMixin):
+class _AuxilaryContext(Context, ConfigMixin, UserMixin,
+                      ClockMixin, LanguageMixin):
+    pass
+
+class HTTPContext(_AuxilaryContext, HTTPMixin):
     def __getattribute__(self, name):
          try:
              return super(HTTPContext, self).__getattribute__(name)
          except AttributeError:
-             return getattr(self.request, name)
+             try:
+                 return getattr(self.request, name)
+             except AttributeError:
+                 msg = "'%s' object has no attribute '%s'"
+                 msg = msg % (self.__class__.__name__,
+                              name)
+                 raise AttributeError(msg)
 
-class RenderContext(Context, RedirectMixin, ConfigMixin, UserMixin,
-                    LanguageMixin, PragmaMixin, ThemeMixin,
-                    AuxilaryMixin, DictsMixin, ActionMixin,
-                    ClockMixin): pass
+class RenderContext(_AuxilaryContext, RedirectMixin, PragmaMixin, ThemeMixin,
+                    AuxilaryMixin, DictsMixin, ActionMixin, PageMixin,
+                    RevisionMixin, FormatterMixin):
+    def write(self, *data):
+        if len(data) > 1:
+            logging.warning("Some code still uses write with multiple arguments, "
+                            "consider changing this soon")
+        self.request.stream.writelines(data)
 
 class XMLRPCContext(HTTPContext):
     pass
+
+class AllContext(HTTPContext, RenderContext):
+    pass
+