Commit 3d3ebec7 authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

we depend on python 2.6, use itertools.combinations instead of our own implementation

parent 2c8bceb8e9bf
......@@ -8,6 +8,7 @@ __docformat__ = "restructuredtext en"
import re
import mailbox
from itertools import combinations
from rfc822 import parsedate
from logilab.common.umessage import message_from_file
......@@ -18,25 +19,6 @@ CLEANUP_RGX = re.compile(r'\bre\s*:', re.I|re.U)
def cleanup_subject(string):
return CLEANUP_RGX.sub('', string).strip()
def combinaison(list):
"""given a list return an iterator on possible combinaisons between all the
elements in the list but without identity:
>>> list(combinaison([1,2,3]))
[(1, 2), (2, 3), (1, 3)]
>>> list(combinaison([1,2,3,4]))
[(1, 2), (2, 3), (3, 4), (1,3), (1,4), (2,4)]
note: in python 2.6, this can be written:
>>> import itertools
>>> itertools.combinations([1,2,3], 2)
"""
list = list[:]
while len(list) > 1:
first = list.pop()
for i in list:
yield (first, i)
class StreamMailbox(mailbox.mbox):
"""A read-only mbox format mailbox from stream."""
......@@ -174,7 +156,7 @@ class MBOXImporter(object):
self.import_message_parts(part, emaileid)
if self._context == 'alternative':
alternatives = self._alternatives.pop()
for eid1, eid2 in combinaison(alternatives):
for eid1, eid2 in combinations(alternatives, 2):
self.execute('SET X alternative Y WHERE X eid %(x)s, Y eid %(y)s',
{'x': eid1, 'y': eid2})
self._context = None
......
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