tOn empty headers, do not barf when normalize. - zs - Zeitungsschau rss to email converter
(HTM) git clone git://r-36.net/zs
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) LICENSE
---
(DIR) commit 7274f9076d9a7d9e65417808677a98277f3fd10e
(DIR) parent dfe52be165706983713f2b886988bfdc628f769a
(HTM) Author: Christoph Lohmann <20h@r-36.net>
Date: Wed, 24 Jul 2019 08:03:50 +0200
On empty headers, do not barf when normalize.
Diffstat:
zeitungsschau/feedemail.py | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
---
(DIR) diff --git a/zeitungsschau/feedemail.py b/zeitungsschau/feedemail.py
t@@ -13,6 +13,7 @@ from email.header import Header
import time
import subprocess
import lxml.html
+import lxml.etree
import urllib.parse
import html2text
t@@ -20,10 +21,13 @@ import html2text
def normalizeheader(hstr):
if len(hstr) == 0:
return ""
+ try:
+ return lxml.html.fromstring(hstr).text_content().\
+ replace(u"\xa0", "").\
+ replace("\n", " ").strip()
+ except lxml.etree.ParserError:
+ return ""
- return lxml.html.fromstring(hstr).text_content().\
- replace(u"\xa0", "").\
- replace("\n", " ").strip()
class LocalSendmail(object):
cmd="/usr/sbin/sendmail -f \"%s\" \"%s\""