[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/mail/ Fix the last
part of http://www.zope.org/Collectors/Zope3-dev/590:
Marius Gedminas
marius at pov.lt
Fri Apr 21 13:49:48 EDT 2006
Log message for revision 67241:
Fix the last part of http://www.zope.org/Collectors/Zope3-dev/590:
when you tried to send N emails with one HTTP request, that request used to
take N seconds, if you used QueuedMailDelivery.
Changed:
U Zope3/trunk/src/zope/app/mail/maildir.py
U Zope3/trunk/src/zope/app/mail/tests/test_maildir.py
-=-
Modified: Zope3/trunk/src/zope/app/mail/maildir.py
===================================================================
--- Zope3/trunk/src/zope/app/mail/maildir.py 2006-04-21 17:46:24 UTC (rev 67240)
+++ Zope3/trunk/src/zope/app/mail/maildir.py 2006-04-21 17:49:48 UTC (rev 67241)
@@ -20,6 +20,7 @@
import os
import socket
import time
+import random
from zope.interface import implements, classProvides
@@ -81,10 +82,12 @@
subdir_new = join(self.path, 'new')
pid = os.getpid()
host = socket.gethostname()
+ randmax = 0x7fffffff
counter = 0
while True:
timestamp = int(time.time())
- unique = '%d.%d.%s' % (timestamp, pid, host)
+ unique = '%d.%d.%s.%d' % (timestamp, pid, host,
+ random.randrange(randmax))
filename = join(subdir_tmp, unique)
try:
fd = os.open(filename, os.O_CREAT|os.O_EXCL|os.O_WRONLY, 0600)
@@ -96,8 +99,7 @@
" in %s, are we under a DoS attack?"
% subdir_tmp)
# NOTE: maildir.html (see above) says I should sleep for 2
- # seconds, not 1
- time.sleep(1)
+ time.sleep(0.1)
else:
break
return MaildirMessageWriter(os.fdopen(fd, 'w'), filename,
Modified: Zope3/trunk/src/zope/app/mail/tests/test_maildir.py
===================================================================
--- Zope3/trunk/src/zope/app/mail/tests/test_maildir.py 2006-04-21 17:46:24 UTC (rev 67240)
+++ Zope3/trunk/src/zope/app/mail/tests/test_maildir.py 2006-04-21 17:49:48 UTC (rev 67241)
@@ -69,8 +69,8 @@
'/path/to/maildir/tmp': stat.S_IFDIR,
'/path/to/maildir/tmp/1': stat.S_IFREG,
'/path/to/maildir/tmp/2': stat.S_IFREG,
- '/path/to/maildir/tmp/1234500000.4242.myhostname': stat.S_IFREG,
- '/path/to/maildir/tmp/1234500001.4242.myhostname': stat.S_IFREG,
+ '/path/to/maildir/tmp/1234500000.4242.myhostname.*': stat.S_IFREG,
+ '/path/to/maildir/tmp/1234500001.4242.myhostname.*': stat.S_IFREG,
'/path/to/regularfile': stat.S_IFREG,
'/path/to/emptydirectory': stat.S_IFDIR,
}
@@ -92,7 +92,13 @@
self._descriptors = {}
def access(self, path, mode):
- return path in self._stat_mode or self._all_files_exist
+ if self._all_files_exist:
+ return True
+ if path in self._stat_mode:
+ return True
+ if path.rsplit('.', 1)[0] + '.*' in self._stat_mode:
+ return True
+ return False
def stat(self, path):
if path in self._stat_mode:
@@ -228,8 +234,8 @@
m = Maildir('/path/to/maildir')
fd = m.newMessage()
verifyObject(IMaildirMessageWriter, fd)
- self.assertEquals(fd._filename,
- '/path/to/maildir/tmp/1234500002.4242.myhostname')
+ self.assert_(fd._filename.startswith(
+ '/path/to/maildir/tmp/1234500002.4242.myhostname.'))
def test_newMessage_never_loops(self):
from zope.app.mail.maildir import Maildir
More information about the Zope3-Checkins
mailing list