Commit dac57b6e by mike

move lettuce.django import into enable() method of plugin

parent 3891f7ea
...@@ -9,7 +9,6 @@ from smtpd import SMTPServer ...@@ -9,7 +9,6 @@ from smtpd import SMTPServer
from django.core.mail import EmailMessage, EmailMultiAlternatives from django.core.mail import EmailMessage, EmailMultiAlternatives
from lettuce import after, before from lettuce import after, before
from lettuce.django import mail
def _parse_header(val): def _parse_header(val):
...@@ -55,6 +54,8 @@ def _convert_to_django_msg(msg): ...@@ -55,6 +54,8 @@ def _convert_to_django_msg(msg):
def enable(): def enable():
from django.conf import settings from django.conf import settings
from lettuce.django import mail
smtp_queue_server = None smtp_queue_server = None
@before.each_scenario @before.each_scenario
...@@ -70,41 +71,40 @@ def enable(): ...@@ -70,41 +71,40 @@ def enable():
global smtp_queue_server global smtp_queue_server
smtp_queue_server.stop() smtp_queue_server.stop()
class QueueSMTPServer(SMTPServer, threading.Thread):
class QueueSMTPServer(SMTPServer, threading.Thread): """
""" Asyncore SMTP server wrapped into a thread.
Asyncore SMTP server wrapped into a thread. It pushes incoming email messages into lettuce email queue.
It pushes incoming email messages into lettuce email queue. Based on DummyFTPServer from:
Based on DummyFTPServer from: http://svn.python.org/view/python/branches/py3k/Lib/test/test_ftplib.py?revision=86061&view=markup
http://svn.python.org/view/python/branches/py3k/Lib/test/test_ftplib.py?revision=86061&view=markup """
""" def __init__(self, *args, **kwargs):
def __init__(self, *args, **kwargs): threading.Thread.__init__(self)
threading.Thread.__init__(self) SMTPServer.__init__(self, *args, **kwargs)
SMTPServer.__init__(self, *args, **kwargs) self.active_lock = threading.Lock()
self.active_lock = threading.Lock() self.active = False
self.active = False self.daemon = True
self.daemon = True
def process_message(self, peer, mailfrom, rcpttos, data):
def process_message(self, peer, mailfrom, rcpttos, data): msg = message_from_string(data)
msg = message_from_string(data) django_msg = _convert_to_django_msg(msg)
django_msg = _convert_to_django_msg(msg) mail.queue.put(django_msg)
mail.queue.put(django_msg)
def start(self):
def start(self): assert not self.active
assert not self.active self.__flag = threading.Event()
self.__flag = threading.Event() threading.Thread.start(self)
threading.Thread.start(self)
def run(self):
def run(self): self.active = True
self.active = True self.__flag.set()
self.__flag.set() while self.active and asyncore.socket_map:
while self.active and asyncore.socket_map: self.active_lock.acquire()
self.active_lock.acquire() asyncore.loop(timeout=0.1, count=1)
asyncore.loop(timeout=0.1, count=1) self.active_lock.release()
self.active_lock.release() asyncore.close_all()
asyncore.close_all()
def stop(self):
def stop(self): assert self.active
assert self.active self.active = False
self.active = False self.join()
self.join()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment