Ticket #730: middleware_dict__ticket_730__rev_8168.patch
File middleware_dict__ticket_730__rev_8168.patch, 7.5 KB (added by , 16 years ago) |
---|
-
django/conf/project_template/settings.py
57 57 # 'django.template.loaders.eggs.load_template_source', 58 58 ) 59 59 60 MIDDLEWARE_CLASSES = ( 61 'django.middleware.common.CommonMiddleware', 62 'django.contrib.sessions.middleware.SessionMiddleware', 63 'django.contrib.auth.middleware.AuthenticationMiddleware', 64 'django.middleware.doc.XViewMiddleware', 65 ) 60 MIDDLEWARE_CLASSES = { 61 'request': ( 62 'django.middleware.common.CommonMiddleware', 63 'django.contrib.sessions.middleware.SessionMiddleware', 64 'django.contrib.auth.middleware.AuthenticationMiddleware', 65 ), 66 'response': ( 67 'django.contrib.sessions.middleware.SessionMiddleware', 68 # 'django.middleware.http.ConditionalGetMiddleware', 69 # 'django.middleware.gzip.GZipMiddleware', 70 'django.middleware.common.CommonMiddleware', 71 ), 72 'view': ( 73 'django.middleware.doc.XViewMiddleware', 74 ), 75 } 66 76 67 77 ROOT_URLCONF = '{{ project_name }}.urls' 68 78 -
django/conf/global_settings.py
288 288 # MIDDLEWARE # 289 289 ############## 290 290 291 # List of middleware classes to use. Order is important; in the request phase, 292 # this middleware classes will be applied in the order given, and in the 293 # response phase the middleware will be applied in reverse order. 294 MIDDLEWARE_CLASSES = ( 295 'django.contrib.sessions.middleware.SessionMiddleware', 296 'django.contrib.auth.middleware.AuthenticationMiddleware', 297 # 'django.middleware.http.ConditionalGetMiddleware', 298 # 'django.middleware.gzip.GZipMiddleware', 299 'django.middleware.common.CommonMiddleware', 300 'django.middleware.doc.XViewMiddleware', 301 ) 291 # List of middleware classes to use. Order is important; all middleware types 292 # will be applied in the order given. 293 MIDDLEWARE_CLASSES = { 294 'request': ( 295 'django.middleware.common.CommonMiddleware', 296 'django.contrib.sessions.middleware.SessionMiddleware', 297 'django.contrib.auth.middleware.AuthenticationMiddleware', 298 ), 299 'response': ( 300 'django.contrib.sessions.middleware.SessionMiddleware', 301 # 'django.middleware.http.ConditionalGetMiddleware', 302 # 'django.middleware.gzip.GZipMiddleware', 303 'django.middleware.common.CommonMiddleware', 304 ), 305 'view': ( 306 'django.middleware.doc.XViewMiddleware', 307 ), 308 } 302 309 303 310 ############ 304 311 # SESSIONS # -
django/core/handlers/base.py
1 1 import sys 2 2 3 3 from django import http 4 from django.core import exceptions 4 5 from django.core import signals 5 6 from django.dispatch import dispatcher 6 7 from django.utils.encoding import force_unicode … … 17 18 def __init__(self): 18 19 self._request_middleware = self._view_middleware = self._response_middleware = self._exception_middleware = None 19 20 20 def load_middleware(self): 21 """ 22 Populate middleware lists from settings.MIDDLEWARE_CLASSES. 21 def middleware_class_from_path(self, middleware_path): 22 try: 23 dot = middleware_path.rindex('.') 24 except ValueError: 25 raise exceptions.ImproperlyConfigured, '%s isn\'t a middleware module' % middleware_path 26 mw_module, mw_classname = middleware_path[:dot], middleware_path[dot+1:] 27 try: 28 mod = __import__(mw_module, {}, {}, ['']) 29 except ImportError, e: 30 raise exceptions.ImproperlyConfigured, 'Error importing middleware %s: "%s"' % (mw_module, e) 31 try: 32 mw_class = getattr(mod, mw_classname) 33 except AttributeError: 34 raise exceptions.ImproperlyConfigured, 'Middleware module "%s" does not define a "%s" class' % (mw_module, mw_classname) 35 return mw_class 23 36 24 Must be called after the environment is fixed (see __call__). 25 """ 26 from django.conf import settings 27 from django.core import exceptions 28 self._request_middleware = [] 29 self._view_middleware = [] 30 self._response_middleware = [] 31 self._exception_middleware = [] 32 for middleware_path in settings.MIDDLEWARE_CLASSES: 33 try: 34 dot = middleware_path.rindex('.') 35 except ValueError: 36 raise exceptions.ImproperlyConfigured, '%s isn\'t a middleware module' % middleware_path 37 mw_module, mw_classname = middleware_path[:dot], middleware_path[dot+1:] 38 try: 39 mod = __import__(mw_module, {}, {}, ['']) 40 except ImportError, e: 41 raise exceptions.ImproperlyConfigured, 'Error importing middleware %s: "%s"' % (mw_module, e) 42 try: 43 mw_class = getattr(mod, mw_classname) 44 except AttributeError: 45 raise exceptions.ImproperlyConfigured, 'Middleware module "%s" does not define a "%s" class' % (mw_module, mw_classname) 37 def middleware_from_list(self, middleware_classes): 38 mw_list = [] 39 for middleware_path in middleware_classes: 40 mw_class = self.middleware_class_from_path(middleware_path) 46 41 47 42 try: 48 43 mw_instance = mw_class() 49 44 except exceptions.MiddlewareNotUsed: 50 45 continue 46 else: 47 mw_list.append(mw_instance) 48 return mw_list 51 49 50 def _load_middleware_legacy(self, mw_class_list): 51 mw_list = self.middleware_from_list(mw_class_list) 52 53 for mw_instance in mw_list: 52 54 if hasattr(mw_instance, 'process_request'): 53 55 self._request_middleware.append(mw_instance.process_request) 54 56 if hasattr(mw_instance, 'process_view'): … … 58 60 if hasattr(mw_instance, 'process_exception'): 59 61 self._exception_middleware.insert(0, mw_instance.process_exception) 60 62 63 def load_middleware(self): 64 """ 65 Populate middleware lists from settings.MIDDLEWARE_CLASSES. 66 67 Must be called after the environment is fixed (see __call__). 68 """ 69 from django.conf import settings 70 self._request_middleware = [] 71 self._view_middleware = [] 72 self._response_middleware = [] 73 self._exception_middleware = [] 74 75 MIDDLEWARE_CLASSES = settings.MIDDLEWARE_CLASSES 76 77 if isinstance(MIDDLEWARE_CLASSES, (tuple, list)): 78 self._load_middleware_legacy(MIDDLEWARE_CLASSES) 79 else: 80 self._request_middleware = self.middleware_from_list(MIDDLEWARE_CLASSES.get('request', [])) 81 self._view_middleware = self.middleware_from_list(MIDDLEWARE_CLASSES.get('view', [])) 82 self._response_middleware = self.middleware_from_list(MIDDLEWARE_CLASSES.get('response', [])) 83 self._exception_middleware = self.middleware_from_list(MIDDLEWARE_CLASSES.get('exception', [])) 84 61 85 def get_response(self, request): 62 86 "Returns an HttpResponse object for the given HttpRequest" 63 from django.core import exceptions,urlresolvers87 from django.core import urlresolvers 64 88 from django.conf import settings 65 89 66 90 # Apply request middleware