Fixed issue introduced by lxml 4.7+

Looks like the html.tostring() function does not respect the encoding
setting anymore, the ascii value in particular...
This commit is contained in:
Antoine Nguyen
2022-01-13 10:45:00 +01:00
parent bc829abb6e
commit f7c59390c6
3 changed files with 14 additions and 11 deletions
+4 -1
View File
@@ -251,7 +251,10 @@ class Email(object):
add_nofollow=True,
safe_attrs=safe_attrs
)
mail_text = lxml.html.tostring(cleaner.clean_html(html))
mail_text = lxml.html.tostring(
cleaner.clean_html(html), encoding="unicode")
with open("/tmp/output.txt", "w") as fp:
fp.write(mail_text)
return smart_text(mail_text)
def _map_cid(self, url):
@@ -12,9 +12,9 @@
someone
<a class="moz-txt-link-abbreviated" href="mailto:someone@example.net" target="_blank" rel="nofollow">someone@example.net</a></pre>
</body>
<span><b>Some <i>HTML</i> text</b>, a <a href="http://example.net" target="_blank" rel="nofollow">link</a>, an&#13;&#13;
embedded image and an external image.<br>&#13;&#13;
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAF0lEQVQY02NgYGD4//8/ThKfHASMRN0AfaqVa6MQxIQAAAAASUVORK5CYII=" target="_blank"><br>&#13;&#13;
<img src="http://example.net/image.png" target="_blank"><br>&#13;&#13;
Nifty!</span>&#13;
<span><b>Some <i>HTML</i> text</b>, a <a href="http://example.net" target="_blank" rel="nofollow">link</a>, an␍
embedded image and an external image.<br>␍
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAF0lEQVQY02NgYGD4//8/ThKfHASMRN0AfaqVa6MQxIQAAAAASUVORK5CYII=" target="_blank"><br>␍
<img src="http://example.net/image.png" target="_blank"><br>␍
Nifty!</span>
</div>
@@ -12,9 +12,9 @@
someone
<a class="moz-txt-link-abbreviated">someone@example.net</a></pre>
</body>
<span><b>Some <i>HTML</i> text</b>, a <a target="_blank" rel="nofollow">link</a>, an&#13;&#13;
embedded image and an external image.<br>&#13;&#13;
<img target="_blank"><br>&#13;&#13;
<img target="_blank"><br>&#13;&#13;
Nifty!</span>&#13;
<span><b>Some <i>HTML</i> text</b>, a <a target="_blank" rel="nofollow">link</a>, an␍
embedded image and an external image.<br>␍
<img target="_blank"><br>␍
<img target="_blank"><br>␍
Nifty!</span>
</div>