31 | | for middleware_path in settings.MIDDLEWARE_CLASSES: |
32 | | try: |
33 | | dot = middleware_path.rindex('.') |
34 | | except ValueError: |
35 | | raise exceptions.ImproperlyConfigured, '%s isn\'t a middleware module' % middleware_path |
36 | | mw_module, mw_classname = middleware_path[:dot], middleware_path[dot+1:] |
37 | | try: |
38 | | mod = __import__(mw_module, {}, {}, ['']) |
39 | | except ImportError, e: |
40 | | raise exceptions.ImproperlyConfigured, 'Error importing middleware %s: "%s"' % (mw_module, e) |
41 | | try: |
42 | | mw_class = getattr(mod, mw_classname) |
43 | | except AttributeError: |
44 | | raise exceptions.ImproperlyConfigured, 'Middleware module "%s" does not define a "%s" class' % (mw_module, mw_classname) |
| 31 | try: |
| 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) |
| 47 | try: |
| 48 | mw_instance = mw_class() |
| 49 | except exceptions.MiddlewareNotUsed: |
| 50 | continue |
| 51 | |
| 52 | if hasattr(mw_instance, 'process_request'): |
| 53 | self._request_middleware.append(mw_instance.process_request) |
| 54 | if hasattr(mw_instance, 'process_view'): |
| 55 | self._view_middleware.append(mw_instance.process_view) |
| 56 | if hasattr(mw_instance, 'process_response'): |
| 57 | self._response_middleware.insert(0, mw_instance.process_response) |
| 58 | if hasattr(mw_instance, 'process_exception'): |
| 59 | self._exception_middleware.insert(0, mw_instance.process_exception) |
| 60 | |
| 61 | except: |
51 | | if hasattr(mw_instance, 'process_request'): |
52 | | self._request_middleware.append(mw_instance.process_request) |
53 | | if hasattr(mw_instance, 'process_view'): |
54 | | self._view_middleware.append(mw_instance.process_view) |
55 | | if hasattr(mw_instance, 'process_response'): |
56 | | self._response_middleware.insert(0, mw_instance.process_response) |
57 | | if hasattr(mw_instance, 'process_exception'): |
58 | | self._exception_middleware.insert(0, mw_instance.process_exception) |