From df7689cc2ee96237008182a7f431a73cd7013c2c Mon Sep 17 00:00:00 2001 From: Jussi Timperi Date: Thu, 22 Oct 2015 16:56:53 +0300 Subject: [PATCH 1/3] Web & utils.web: Force HTMLParser to process all buffered data. Python issue 23144. --- plugins/Web/plugin.py | 1 + src/utils/web.py | 1 + 2 files changed, 2 insertions(+) diff --git a/plugins/Web/plugin.py b/plugins/Web/plugin.py index 378275575..29810bdb0 100644 --- a/plugins/Web/plugin.py +++ b/plugins/Web/plugin.py @@ -155,6 +155,7 @@ class Web(callbacks.PluginRegexp): else: return None parser.feed(text) + parser.close() title = parser.title if title: title = utils.web.htmlToText(parser.title.strip()) diff --git a/src/utils/web.py b/src/utils/web.py index 8bc280a2d..31adac7e1 100644 --- a/src/utils/web.py +++ b/src/utils/web.py @@ -254,6 +254,7 @@ def htmlToText(s, tagReplace=' '): pass x = HtmlToText(tagReplace) x.feed(s) + x.close() return x.getText() def mungeEmail(s): From 5cf1b34f558ce4e36b8972ce3a3d5f4a729be67e Mon Sep 17 00:00:00 2001 From: Jussi Timperi Date: Thu, 22 Oct 2015 17:13:47 +0300 Subject: [PATCH 2/3] Web: Use title instead of parser.title. --- plugins/Web/plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/Web/plugin.py b/plugins/Web/plugin.py index 29810bdb0..1117d0208 100644 --- a/plugins/Web/plugin.py +++ b/plugins/Web/plugin.py @@ -158,7 +158,7 @@ class Web(callbacks.PluginRegexp): parser.close() title = parser.title if title: - title = utils.web.htmlToText(parser.title.strip()) + title = utils.web.htmlToText(title.strip()) elif raiseErrors: if len(text) < size: irc.reply(_('That URL appears to have no HTML title.')) From 1f96471d9354d3e2c6bf847e39e7d8e19344a2b9 Mon Sep 17 00:00:00 2001 From: Jussi Timperi Date: Thu, 22 Oct 2015 17:19:03 +0300 Subject: [PATCH 3/3] Web: Correct capitalization in testTitle. --- plugins/Web/test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/Web/test.py b/plugins/Web/test.py index c78bc7c35..1de573410 100644 --- a/plugins/Web/test.py +++ b/plugins/Web/test.py @@ -67,7 +67,7 @@ class WebTestCase(ChannelPluginTestCase): 'title http://www.youtube.com/watch?v=x4BtiqPN4u8') self.assertResponse( 'title http://www.thefreedictionary.com/don%27t', - "don't - definition of don't by The Free Dictionary") + "Don't - definition of don't by The Free Dictionary") def testTitleSnarfer(self): try: