mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-26 12:49: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
|
import utils
|
||||||
|
|
||||||
|
def debug(s, *args):
|
||||||
|
"""Prints a debug string. Most likely replaced by our logging debug."""
|
||||||
|
print '***', s % args
|
||||||
|
|
||||||
def isUserHostmask(s):
|
def isUserHostmask(s):
|
||||||
"""Returns whether or not the string s is a valid User hostmask."""
|
"""Returns whether or not the string s is a valid User hostmask."""
|
||||||
p1 = s.find('!')
|
p1 = s.find('!')
|
||||||
@ -357,6 +361,9 @@ def safeArgument(s):
|
|||||||
"""If s is unsafe for IRC, returns a safe version."""
|
"""If s is unsafe for IRC, returns a safe version."""
|
||||||
if isinstance(s, unicode):
|
if isinstance(s, unicode):
|
||||||
s = s.encode('utf-8')
|
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):
|
if isValidArgument(s):
|
||||||
return s
|
return s
|
||||||
else:
|
else:
|
||||||
|
@ -47,6 +47,8 @@ import conf
|
|||||||
import utils
|
import utils
|
||||||
import registry
|
import registry
|
||||||
|
|
||||||
|
import ircutils
|
||||||
|
|
||||||
deadlyExceptions = [KeyboardInterrupt, SystemExit]
|
deadlyExceptions = [KeyboardInterrupt, SystemExit]
|
||||||
|
|
||||||
class Formatter(logging.Formatter):
|
class Formatter(logging.Formatter):
|
||||||
@ -137,6 +139,8 @@ pluginFormatter = Formatter('%(levelname)s %(asctime)s %(name)s %(message)s')
|
|||||||
# These are not.
|
# These are not.
|
||||||
logging.setLoggerClass(Logger)
|
logging.setLoggerClass(Logger)
|
||||||
_logger = logging.getLogger('supybot')
|
_logger = logging.getLogger('supybot')
|
||||||
|
|
||||||
|
# These just make things easier.
|
||||||
debug = _logger.debug
|
debug = _logger.debug
|
||||||
info = _logger.info
|
info = _logger.info
|
||||||
warning = _logger.warning
|
warning = _logger.warning
|
||||||
@ -148,6 +152,9 @@ setLevel = _logger.setLevel
|
|||||||
|
|
||||||
atexit.register(logging.shutdown)
|
atexit.register(logging.shutdown)
|
||||||
|
|
||||||
|
# ircutils will work without this, but it's useful.
|
||||||
|
ircutils.debug = debug
|
||||||
|
|
||||||
def getPluginLogger(name):
|
def getPluginLogger(name):
|
||||||
if not conf.supybot.log.individualPluginLogfiles():
|
if not conf.supybot.log.individualPluginLogfiles():
|
||||||
return _logger
|
return _logger
|
||||||
|
@ -165,6 +165,10 @@ class FunctionsTestCase(SupyTestCase):
|
|||||||
self.assertEqual(bolds, ircutils.safeArgument(bolds))
|
self.assertEqual(bolds, ircutils.safeArgument(bolds))
|
||||||
self.assertEqual(colors, ircutils.safeArgument(colors))
|
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):
|
def testIsNick(self):
|
||||||
try:
|
try:
|
||||||
original = conf.supybot.protocols.irc.strictRfc()
|
original = conf.supybot.protocols.irc.strictRfc()
|
||||||
|
Loading…
Reference in New Issue
Block a user