Ticket #5685: ticket_5685__revision_6809.diff
File ticket_5685__revision_6809.diff, 7.9 KB (added by , 17 years ago) |
---|
-
django/test/client.py
29 29 from django.conf import settings 30 30 from django.core import signals 31 31 32 # Set up middleware if needed. We couldn't do this earlier, because 33 # settings weren't available. 34 if self._request_middleware is None: 35 self.load_middleware() 32 # Perform state setup to ensure middleware is registered, among 33 # other things. 34 self.state.ensure_state() 36 35 37 36 dispatcher.send(signal=signals.request_started) 38 37 try: -
django/conf/global_settings.py
131 131 EMAIL_HOST_PASSWORD = '' 132 132 EMAIL_USE_TLS = False 133 133 134 # List of functions to be called to setup the runtime environment 135 RUNTIME_SETUP_FUNCTIONS = () 136 134 137 # List of strings representing installed apps. 135 138 INSTALLED_APPS = () 136 139 -
django/core/handlers/wsgi.py
180 180 raw_post_data = property(_get_raw_post_data) 181 181 182 182 class WSGIHandler(BaseHandler): 183 initLock = Lock()184 183 request_class = WSGIRequest 185 184 186 185 def __call__(self, environ, start_response): 187 186 from django.conf import settings 188 187 189 # Set up middleware if needed. We couldn't do this earlier, because 190 # settings weren't available. 191 if self._request_middleware is None: 192 self.initLock.acquire() 193 # Check that middleware is still uninitialised. 194 if self._request_middleware is None: 195 self.load_middleware() 196 self.initLock.release() 188 # Perform state setup to ensure middleware is registered, among 189 # other things. 190 self.state.ensure_state() 197 191 198 192 dispatcher.send(signal=signals.request_started) 199 193 try: -
django/core/handlers/base.py
1 1 from django.core import signals 2 2 from django.dispatch import dispatcher 3 from django.utils.setup import setup_runtime 3 4 from django import http 4 5 import sys 6 import threading 7 import logging 5 8 6 class BaseHandler(object): 7 # Changes that are always applied to a response (in this order). 8 response_fixes = [http.fix_location_header, 9 http.conditional_content_removal] 9 class HandlerState(object): 10 """ 11 A cache that stores/ensures state required for handling requests. 12 This includes loading the middleware and performing runtime setup. 13 """ 14 # Use the Borg pattern to share state between all instances. Details at 15 # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531. 16 __shared_state = dict( 17 request_middleware = [], 18 view_middleware = [], 19 response_middleware = [], 20 exception_middleware = [], 21 runtime_setup = False, # Flag to monitor whether generic runtime environment setup has occured 10 22 23 # -- Variables used to setup the state -- 24 loaded = False, # Flag to monitor the state of the cache 25 write_lock = threading.RLock(), 26 ) 27 11 28 def __init__(self): 12 self._request_middleware = self._view_middleware = self._response_middleware = self._exception_middleware = None 29 self.__dict__ = self.__shared_state 30 31 def ensure_state(self): 32 """ 33 Fill in all the cache information, and perform any setup that is 34 necessary. This method is threadsafe, in the sense that every caller 35 will see the same state upon return, and if the cache is already 36 initialised, it does no work. 37 """ 38 if self.loaded: 39 return 40 self.write_lock.acquire() 41 try: 42 if self.loaded: 43 return 13 44 45 setup_runtime() 46 self.runtime_setup = True 47 48 self.load_middleware() 49 50 self.loaded = True 51 finally: 52 self.write_lock.release() 53 14 54 def load_middleware(self): 15 55 """ 16 56 Populate middleware lists from settings.MIDDLEWARE_CLASSES. … … 19 59 """ 20 60 from django.conf import settings 21 61 from django.core import exceptions 22 self._request_middleware = [] 23 self._view_middleware = [] 24 self._response_middleware = [] 25 self._exception_middleware = [] 62 26 63 for middleware_path in settings.MIDDLEWARE_CLASSES: 27 64 try: 28 65 dot = middleware_path.rindex('.') … … 44 81 continue 45 82 46 83 if hasattr(mw_instance, 'process_request'): 47 self. _request_middleware.append(mw_instance.process_request)84 self.request_middleware.append(mw_instance.process_request) 48 85 if hasattr(mw_instance, 'process_view'): 49 self. _view_middleware.append(mw_instance.process_view)86 self.view_middleware.append(mw_instance.process_view) 50 87 if hasattr(mw_instance, 'process_response'): 51 self. _response_middleware.insert(0, mw_instance.process_response)88 self.response_middleware.insert(0, mw_instance.process_response) 52 89 if hasattr(mw_instance, 'process_exception'): 53 self. _exception_middleware.insert(0, mw_instance.process_exception)90 self.exception_middleware.insert(0, mw_instance.process_exception) 54 91 92 handler_state = HandlerState() 93 94 class BaseHandler(object): 95 state = handler_state 96 _request_middleware = handler_state.request_middleware 97 _view_middleware = handler_state.view_middleware 98 _response_middleware = handler_state.response_middleware 99 _exception_middleware = handler_state.exception_middleware 100 101 # Changes that are always applied to a response (in this order). 102 response_fixes = [http.fix_location_header, 103 http.conditional_content_removal] 104 55 105 def get_response(self, request): 56 106 "Returns an HttpResponse object for the given HttpRequest" 57 107 from django.core import exceptions, urlresolvers -
django/core/handlers/modpython.py
146 146 # that use settings now can work 147 147 from django.conf import settings 148 148 149 # if we need to set up middleware, now that settings works we can do it now.150 if self._request_middleware is None:151 self.load_middleware()149 # Perform state setup to ensure middleware is registered, among 150 # other things. 151 self.state.ensure_state() 152 152 153 153 dispatcher.send(signal=signals.request_started) 154 154 try: -
django/core/management/commands/shell.py
1 1 import os 2 2 from django.core.management.base import NoArgsCommand 3 from django.utils.setup import setup_runtime 3 4 from optparse import make_option 4 5 5 6 class Command(NoArgsCommand): … … 12 13 requires_model_validation = False 13 14 14 15 def handle_noargs(self, **options): 16 setup_runtime() # Perform some setup that may be necessary to get the runtime environment ready 17 15 18 # XXX: (Temporary) workaround for ticket #1796: force early loading of all 16 19 # models from installed apps. 17 20 from django.db.models.loading import get_models