diff options
| author | Jacob Kaplan-Moss <jacob@jacobian.org> | 2008-08-06 15:32:46 +0000 |
|---|---|---|
| committer | Jacob Kaplan-Moss <jacob@jacobian.org> | 2008-08-06 15:32:46 +0000 |
| commit | 34a3bd52255a2253696b74b2d76133aace839fd2 (patch) | |
| tree | 73bc39cc2e0a93925b1e8796b18224192e19e4a3 /django/test | |
| parent | d06b474251c979c512a966a7fb41cd8a06487c14 (diff) | |
Major refactoring of django.dispatch with an eye towards speed. The net result is that signals are up to 90% faster.
Though some attempts and backwards-compatibility were made, speed trumped compatibility. Thus, as usual, check BackwardsIncompatibleChanges for the complete list of backwards-incompatible changes.
Thanks to Jeremy Dunck and Keith Busell for the bulk of the work; some ideas from Brian Herring's previous work (refs #4561) were incorporated.
Documentation is, sigh, still forthcoming.
Fixes #6814 and #3951 (with the new dispatch_uid argument to connect).
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8223 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/test')
| -rw-r--r-- | django/test/client.py | 13 | ||||
| -rw-r--r-- | django/test/signals.py | 4 | ||||
| -rw-r--r-- | django/test/utils.py | 3 |
3 files changed, 10 insertions, 10 deletions
diff --git a/django/test/client.py b/django/test/client.py index 7d621449ea..060fabd238 100644 --- a/django/test/client.py +++ b/django/test/client.py @@ -11,7 +11,6 @@ from django.contrib.auth import authenticate, login from django.core.handlers.base import BaseHandler from django.core.handlers.wsgi import WSGIRequest from django.core.signals import got_request_exception -from django.dispatch import dispatcher from django.http import SimpleCookie, HttpRequest from django.template import TemplateDoesNotExist from django.test import signals @@ -59,7 +58,7 @@ class ClientHandler(BaseHandler): if self._request_middleware is None: self.load_middleware() - dispatcher.send(signal=signals.request_started) + signals.request_started.send(sender=self.__class__) try: request = WSGIRequest(environ) response = self.get_response(request) @@ -69,11 +68,11 @@ class ClientHandler(BaseHandler): response = middleware_method(request, response) response = self.apply_response_fixes(request, response) finally: - dispatcher.send(signal=signals.request_finished) + signals.request_finished.send(sender=self.__class__) return response -def store_rendered_templates(store, signal, sender, template, context): +def store_rendered_templates(store, signal, sender, template, context, **kwargs): """ Stores templates and contexts that are rendered. """ @@ -160,7 +159,7 @@ class Client: self.cookies = SimpleCookie() self.exc_info = None - def store_exc_info(self, *args, **kwargs): + def store_exc_info(self, **kwargs): """ Stores exceptions when they are generated by a view. """ @@ -202,10 +201,10 @@ class Client: # callback function. data = {} on_template_render = curry(store_rendered_templates, data) - dispatcher.connect(on_template_render, signal=signals.template_rendered) + signals.template_rendered.connect(on_template_render) # Capture exceptions created by the handler. - dispatcher.connect(self.store_exc_info, signal=got_request_exception) + got_request_exception.connect(self.store_exc_info) try: response = self.handler(environ) diff --git a/django/test/signals.py b/django/test/signals.py index 40748ff4fe..a328a7782e 100644 --- a/django/test/signals.py +++ b/django/test/signals.py @@ -1 +1,3 @@ -template_rendered = object()
\ No newline at end of file +from django.dispatch import Signal + +template_rendered = Signal(providing_args=["template", "context"]) diff --git a/django/test/utils.py b/django/test/utils.py index 03f40a8df7..733307a1c0 100644 --- a/django/test/utils.py +++ b/django/test/utils.py @@ -3,7 +3,6 @@ from django.conf import settings from django.db import connection, get_creation_module from django.core import mail from django.core.management import call_command -from django.dispatch import dispatcher from django.test import signals from django.template import Template from django.utils.translation import deactivate @@ -17,7 +16,7 @@ def instrumented_test_render(self, context): An instrumented Template render method, providing a signal that can be intercepted by the test system Client """ - dispatcher.send(signal=signals.template_rendered, sender=self, template=self, context=context) + signals.template_rendered.send(sender=self, template=self, context=context) return self.nodelist.render(context) class TestSMTPConnection(object): |
