Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cubicweb
cubes
email
Commits
eec03b3568f9
Commit
3d3ebec7
authored
Apr 23, 2013
by
Sylvain Thénault
Browse files
we depend on python 2.6, use itertools.combinations instead of our own implementation
parent
2c8bceb8e9bf
Changes
1
Show whitespace changes
Inline
Side-by-side
mboximport.py
View file @
eec03b35
...
...
@@ -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
combinai
s
on
(
alternatives
):
for
eid1
,
eid2
in
combina
t
ion
s
(
alternatives
,
2
):
self
.
execute
(
'SET X alternative Y WHERE X eid %(x)s, Y eid %(y)s'
,
{
'x'
:
eid1
,
'y'
:
eid2
})
self
.
_context
=
None
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment