mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-29 22:29:24 +01:00
Automatically convert non-strings to strings with safeArgument.
This commit is contained in:
parent
aeb470750a
commit
2377a4a83c
@ -54,6 +54,10 @@ from cStringIO import StringIO as sio
|
||||
|
||||
import utils
|
||||
|
||||
def debug(s, *args):
|
||||
"""Prints a debug string. Most likely replaced by our logging debug."""
|
||||
print '***', s % args
|
||||
|
||||
def isUserHostmask(s):
|
||||
"""Returns whether or not the string s is a valid User hostmask."""
|
||||
p1 = s.find('!')
|
||||
@ -357,6 +361,9 @@ def safeArgument(s):
|
||||
"""If s is unsafe for IRC, returns a safe version."""
|
||||
if isinstance(s, unicode):
|
||||
s = s.encode('utf-8')
|
||||
elif not isinstance(s, basestring):
|
||||
debug('Got a non-string in safeArgument: %r', s)
|
||||
s = str(s)
|
||||
if isValidArgument(s):
|
||||
return s
|
||||
else:
|
||||
|
@ -47,6 +47,8 @@ import conf
|
||||
import utils
|
||||
import registry
|
||||
|
||||
import ircutils
|
||||
|
||||
deadlyExceptions = [KeyboardInterrupt, SystemExit]
|
||||
|
||||
class Formatter(logging.Formatter):
|
||||
@ -137,6 +139,8 @@ pluginFormatter = Formatter('%(levelname)s %(asctime)s %(name)s %(message)s')
|
||||
# These are not.
|
||||
logging.setLoggerClass(Logger)
|
||||
_logger = logging.getLogger('supybot')
|
||||
|
||||
# These just make things easier.
|
||||
debug = _logger.debug
|
||||
info = _logger.info
|
||||
warning = _logger.warning
|
||||
@ -148,6 +152,9 @@ setLevel = _logger.setLevel
|
||||
|
||||
atexit.register(logging.shutdown)
|
||||
|
||||
# ircutils will work without this, but it's useful.
|
||||
ircutils.debug = debug
|
||||
|
||||
def getPluginLogger(name):
|
||||
if not conf.supybot.log.individualPluginLogfiles():
|
||||
return _logger
|
||||
|
@ -165,6 +165,10 @@ class FunctionsTestCase(SupyTestCase):
|
||||
self.assertEqual(bolds, ircutils.safeArgument(bolds))
|
||||
self.assertEqual(colors, ircutils.safeArgument(colors))
|
||||
|
||||
def testSafeArgumentConvertsToString(self):
|
||||
self.assertEqual('1', ircutils.safeArgument(1))
|
||||
self.assertEqual(str(None), ircutils.safeArgument(None))
|
||||
|
||||
def testIsNick(self):
|
||||
try:
|
||||
original = conf.supybot.protocols.irc.strictRfc()
|
||||
|
Loading…
Reference in New Issue
Block a user