From a80fab63036d43f71e971bbbe5c2aa1263da4ff0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 6 Nov 2012 14:37:51 +0100 Subject: [PATCH] [FIX] tools: mail: use beautifulsoup parser, if not present, html parser. bzr revid: tde@openerp.com-20121106133751-ds0g2c7k8pu4d6rl --- openerp/tools/mail.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/openerp/tools/mail.py b/openerp/tools/mail.py index b4e5754bfe4..2cbb094bf8e 100644 --- a/openerp/tools/mail.py +++ b/openerp/tools/mail.py @@ -19,8 +19,11 @@ # ############################################################################## -from lxml.html.soupparser import fromstring -from lxml.etree import tostring +from lxml.etree import tostring, Element +try: + from lxml.html.soupparser import fromstring as parser_fromstring +except ImportError: + from lxml.html import fromstring as parser_fromstring import logging import lxml.html import openerp.pooler as pooler @@ -124,10 +127,10 @@ def html_email_clean(html): modified_html += html[idx:] # 2. form a tree, handle (currently ?) pure-text by enclosing them in a pre - root = fromstring(modified_html) + root = parser_fromstring(modified_html) if not len(root) and root.text is None and root.tail is None: modified_html = '
%s
' % modified_html - root = fromstring(modified_html) + root = parser_fromstring(modified_html) # 3. remove blockquotes quotes = [el for el in root.iterchildren(tag='blockquote')]