mirror of https://github.com/Mikaela/Limnoria.git
Merge pull request #506 from kytvi2p/unicode2.x
Unicode fixes for python 2.x
This commit is contained in:
commit
dfdc7f1cd1
|
@ -33,6 +33,7 @@ import types
|
||||||
import socket
|
import socket
|
||||||
import threading
|
import threading
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
import supybot.conf as conf
|
import supybot.conf as conf
|
||||||
import supybot.utils as utils
|
import supybot.utils as utils
|
||||||
|
@ -155,15 +156,20 @@ class RSS(callbacks.Plugin):
|
||||||
if self.registryValue(dateconfig, channel):
|
if self.registryValue(dateconfig, channel):
|
||||||
if headline[2]:
|
if headline[2]:
|
||||||
pubDate = ' [%s]' % (headline[2],)
|
pubDate = ' [%s]' % (headline[2],)
|
||||||
try:
|
if sys.version_info[0] < 3:
|
||||||
|
if isinstance(headline[0], unicode):
|
||||||
newheadlines.append(format('%s %u%s',
|
newheadlines.append(format('%s %u%s',
|
||||||
headline[0],
|
headline[0].encode('utf-8','replace'),
|
||||||
link,
|
link,
|
||||||
pubDate))
|
pubDate))
|
||||||
except UnicodeDecodeError:
|
else:
|
||||||
newheadlines.append(format('%s %u%s',
|
newheadlines.append(format('%s %u%s',
|
||||||
headline[0].decode('utf8',
|
headline[0].decode('utf-8','replace'),
|
||||||
'replace'),
|
link,
|
||||||
|
pubDate))
|
||||||
|
else:
|
||||||
|
newheadlines.append(format('%s %u%s',
|
||||||
|
headline[0],
|
||||||
link,
|
link,
|
||||||
pubDate))
|
pubDate))
|
||||||
return newheadlines
|
return newheadlines
|
||||||
|
|
|
@ -153,10 +153,8 @@ class Web(callbacks.PluginRegexp):
|
||||||
domain = utils.web.getDomain(url)
|
domain = utils.web.getDomain(url)
|
||||||
title = utils.web.htmlToText(parser.title.strip())
|
title = utils.web.htmlToText(parser.title.strip())
|
||||||
if sys.version_info[0] < 3:
|
if sys.version_info[0] < 3:
|
||||||
try:
|
if isinstance(title, unicode):
|
||||||
title = title.encode('utf8', 'replace')
|
title = title.encode('utf8', 'replace')
|
||||||
except UnicodeDecodeError:
|
|
||||||
pass
|
|
||||||
s = format(_('Title: %s (at %s)'), title, domain)
|
s = format(_('Title: %s (at %s)'), title, domain)
|
||||||
irc.reply(s, prefixNick=False)
|
irc.reply(s, prefixNick=False)
|
||||||
titleSnarfer = urlSnarfer(titleSnarfer)
|
titleSnarfer = urlSnarfer(titleSnarfer)
|
||||||
|
|
|
@ -450,9 +450,15 @@ def format(s, *args, **kwargs):
|
||||||
if char == 's':
|
if char == 's':
|
||||||
token = args.pop()
|
token = args.pop()
|
||||||
if isinstance(token, str):
|
if isinstance(token, str):
|
||||||
|
if sys.version_info[0] < 3:
|
||||||
|
return token.decode('utf-8','replace')
|
||||||
|
else:
|
||||||
return token
|
return token
|
||||||
elif sys.version_info[0] < 3 and isinstance(token, unicode):
|
elif sys.version_info[0] < 3 and isinstance(token, unicode):
|
||||||
return token.encode('utf8')
|
return token.encode('utf8', 'replace')
|
||||||
|
else:
|
||||||
|
if sys.version_info[0] < 3:
|
||||||
|
return str(token).decode('utf-8','replace')
|
||||||
else:
|
else:
|
||||||
return str(token)
|
return str(token)
|
||||||
elif char == 'i':
|
elif char == 'i':
|
||||||
|
|
Loading…
Reference in New Issue