diff options
| author | xmo-odoo <xmo@odoo.com> | 2017-05-10 09:39:55 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-05-10 09:39:55 +0200 |
| commit | fffaf735f58f1ac57781c095eb552de6d1fcdc47 (patch) | |
| tree | 88ab0ab65430d871862a836524e0ecc890d1674d /odoo/tools/mail.py | |
| parent | 10eee18a047d35305dc46282e610e88936d81ffc (diff) | |
[FIX] P3: list -> iterable builtins (#16811)
In Python 3:
* various builtins and dict methods were changed to return
view/iterable objects rather than lists
* and the separate Python 2 view/iterable builtins and methods were
removed altogether
This is problematic when using these items as list (which the happens
repeatedly in Odoo), but more viciously when iterating *multiple times*
over them (which also happens, which I've messed up multiple times while
writing this, and which is a pain to debug even when you've just created
the issue).
Convert all code using these to semantics-matching cross-version
helper functions to get the LCD behaviour between P2 and P3, and
forbid the builtins via lint.
issue #8530
Diffstat (limited to 'odoo/tools/mail.py')
| -rw-r--r-- | odoo/tools/mail.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/odoo/tools/mail.py b/odoo/tools/mail.py index 490006082d5..9689512df00 100644 --- a/odoo/tools/mail.py +++ b/odoo/tools/mail.py @@ -16,6 +16,7 @@ from lxml import etree import odoo from odoo.loglevels import ustr +from odoo.tools import pycompat _logger = logging.getLogger(__name__) @@ -84,7 +85,7 @@ class _Cleaner(clean.Cleaner): new_node.text = text new_node.tail = tail if attrs: - for key, val in attrs.iteritems(): + for key, val in pycompat.items(attrs): new_node.set(key, val) return new_node @@ -153,7 +154,7 @@ class _Cleaner(clean.Cleaner): if style[0].lower() in self._style_whitelist: valid_styles[style[0].lower()] = style[1] if valid_styles: - el.attrib['style'] = '; '.join('%s: %s' % (key, val) for (key, val) in valid_styles.iteritems()) + el.attrib['style'] = '; '.join('%s: %s' % (key, val) for (key, val) in pycompat.items(valid_styles)) else: del el.attrib['style'] @@ -530,4 +531,4 @@ def decode_smtp_header(smtp_header): # was mail_thread.decode_header() def decode_message_header(message, header, separator=' '): - return separator.join(map(decode_smtp_header, filter(None, message.get_all(header, [])))) + return separator.join(decode_smtp_header(h) for h in message.get_all(header, []) if h) |
