From cd1ca26702005c51dbcbeea593650b939cb2d3eb Mon Sep 17 00:00:00 2001 From: Brendon Crawford Date: Wed, 3 Apr 2013 19:42:31 -0700 Subject: [PATCH] Adds generators support for email backends that do not support it. --- django/core/mail/backends/console.py | 4 +++- django/core/mail/backends/dummy.py | 2 +- django/core/mail/backends/locmem.py | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/django/core/mail/backends/console.py b/django/core/mail/backends/console.py index ea0cb5d9ad..389e06b37f 100644 --- a/django/core/mail/backends/console.py +++ b/django/core/mail/backends/console.py @@ -16,6 +16,7 @@ class EmailBackend(BaseEmailBackend): """Write all messages to the stream in a thread-safe way.""" if not email_messages: return + msg_count = 0 with self._lock: try: stream_created = self.open() @@ -24,9 +25,10 @@ class EmailBackend(BaseEmailBackend): self.stream.write('-' * 79) self.stream.write('\n') self.stream.flush() # flush after each message + msg_count += 1 if stream_created: self.close() except: if not self.fail_silently: raise - return len(email_messages) + return msg_count diff --git a/django/core/mail/backends/dummy.py b/django/core/mail/backends/dummy.py index 273aa0d88e..7ae4878f13 100644 --- a/django/core/mail/backends/dummy.py +++ b/django/core/mail/backends/dummy.py @@ -6,4 +6,4 @@ from django.core.mail.backends.base import BaseEmailBackend class EmailBackend(BaseEmailBackend): def send_messages(self, email_messages): - return len(email_messages) + return len(list(email_messages)) diff --git a/django/core/mail/backends/locmem.py b/django/core/mail/backends/locmem.py index 6826d09ee5..8e893af358 100644 --- a/django/core/mail/backends/locmem.py +++ b/django/core/mail/backends/locmem.py @@ -20,7 +20,9 @@ class EmailBackend(BaseEmailBackend): def send_messages(self, messages): """Redirect messages to the dummy outbox""" + msg_count = 0 for message in messages: # .message() triggers header validation message.message() + msg_count += 1 mail.outbox.extend(messages) - return len(messages) + return msg_count