irc/py-limnoria: Backport Web plugin bugfixes
Backport fixes for the Web plugin [1][2][3]. [1] https://github.com/ProgVal/Limnoria/pull/1371 [2] https://github.com/ProgVal/Limnoria/issues/1362 [3] https://github.com/ProgVal/Limnoria/issues/1359 Submitted by: DanDare (GitHub: Rodrigo-NH, via IRC)
This commit is contained in:
parent
41e4b588f5
commit
4c6b47d49f
Notes:
svn2git
2021-03-31 03:12:20 +00:00
svn path=/head/; revision=513446
@ -3,7 +3,7 @@
|
||||
|
||||
PORTNAME= limnoria
|
||||
PORTVERSION= 2018.09.09
|
||||
PORTREVISION= 1
|
||||
PORTREVISION= 2
|
||||
CATEGORIES= irc python
|
||||
PKGNAMEPREFIX= ${PYTHON_PKGNAMEPREFIX}
|
||||
|
||||
|
62
irc/py-limnoria/files/patch-plugins_Web_plugin.py
Normal file
62
irc/py-limnoria/files/patch-plugins_Web_plugin.py
Normal file
@ -0,0 +1,62 @@
|
||||
# https://github.com/ProgVal/Limnoria/pull/1371
|
||||
# https://github.com/ProgVal/Limnoria/issues/1362
|
||||
# https://github.com/ProgVal/Limnoria/issues/1359
|
||||
|
||||
--- plugins/Web/plugin.py.orig 2019-09-29 03:00:58 UTC
|
||||
+++ plugins/Web/plugin.py
|
||||
@@ -149,32 +149,31 @@ class Web(callbacks.PluginRegexp):
|
||||
def getTitle(self, irc, url, raiseErrors):
|
||||
size = conf.supybot.protocols.http.peekSize()
|
||||
timeout = self.registryValue('timeout')
|
||||
- (target, text) = utils.web.getUrlTargetAndContent(url, size=size,
|
||||
- timeout=timeout)
|
||||
try:
|
||||
- text = text.decode(utils.web.getEncoding(text) or 'utf8',
|
||||
- 'replace')
|
||||
- except UnicodeDecodeError:
|
||||
- pass
|
||||
- parser = Title()
|
||||
- if minisix.PY3 and isinstance(text, bytes):
|
||||
- if raiseErrors:
|
||||
- irc.error(_('Could not guess the page\'s encoding. (Try '
|
||||
- 'installing python-charade.)'), Raise=True)
|
||||
+ (target, text) = utils.web.getUrlTargetAndContent(url, size=size,timeout=timeout)
|
||||
+ encoding = utils.web.getEncoding(text)
|
||||
+ if encoding is None: # Condition if charade not installed
|
||||
+ self.log.info('Web plugin TitleSnarfer: Could not guess the page\'s'
|
||||
+ ' encoding. (Try installing python-charade.)')
|
||||
+ encoding = 'utf-8' # Assume UTF-8 and replace unknown chars to the UTF-8 codec for U+FFFD in the next hop
|
||||
+ text = text.decode(utils.web.getEncoding(text) or 'utf-8','replace')
|
||||
+ parser = Title()
|
||||
+ try:
|
||||
+ parser.feed(text)
|
||||
+ except:
|
||||
+ parser = Title()
|
||||
+ parser.feed(bytes(text)) # Explicitly pack to bytes in encoding errors for (more) python2 compatibility
|
||||
+ parser.close()
|
||||
+ title = utils.str.normalizeWhitespace(''.join(parser.data).strip())
|
||||
+ if title:
|
||||
+ return (target, title)
|
||||
else:
|
||||
- return None
|
||||
- parser.feed(text)
|
||||
- parser.close()
|
||||
- title = utils.str.normalizeWhitespace(''.join(parser.data).strip())
|
||||
- if title:
|
||||
- return (target, title)
|
||||
- elif raiseErrors:
|
||||
- if len(text) < size:
|
||||
- irc.error(_('That URL appears to have no HTML title.'),
|
||||
- Raise=True)
|
||||
- else:
|
||||
- irc.error(format(_('That URL appears to have no HTML title '
|
||||
- 'within the first %S.'), size), Raise=True)
|
||||
+ if len(text) < size:
|
||||
+ self.log.info('Web plugin TitleSnarfer: <' + url + '> appears to have no HTML title.')
|
||||
+ else:
|
||||
+ self.log.info('Web plugin TitleSnarfer: Could not retrieve title of <' + url + '>')
|
||||
+ except Exception as e:
|
||||
+ self.log.info('Web plugin TitleSnarfer: <' + str(e) + '> while trying to process <' + url +'>')
|
||||
|
||||
@fetch_sandbox
|
||||
def titleSnarfer(self, irc, msg, match):
|
Loading…
Reference in New Issue
Block a user