本文整理汇总了Python中supybot.utils.exnToString函数的典型用法代码示例。如果您正苦于以下问题:Python exnToString函数的具体用法?Python exnToString怎么用?Python exnToString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了exnToString函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testExnToString
def testExnToString(self):
try:
raise KeyError(1)
except Exception as e:
self.assertEqual(utils.exnToString(e), 'KeyError: 1')
try:
raise EOFError()
except Exception as e:
self.assertEqual(utils.exnToString(e), 'EOFError')
示例2: icalc
def icalc(self, irc, msg, args, text):
"""<math expression>
This is the same as the calc command except that it allows integer
math, and can thus cause the bot to suck up CPU. Hence it requires
the 'trusted' capability to use.
"""
if self._calc_match_forbidden_chars.match(text):
# Note: this is important to keep this to forbid usage of
# __builtins__
irc.error(_('There\'s really no reason why you should have '
'underscores or brackets in your mathematical '
'expression. Please remove them.'))
return
# This removes spaces, too, but we'll leave the removal of _[] for
# safety's sake.
text = self._calc_remover(text)
if 'lambda' in text:
irc.error(_('You can\'t use lambda in this command.'))
return
text = text.replace('lambda', '')
try:
self.log.info('evaluating %q from %s', text, msg.prefix)
irc.reply(str(eval(text, self._mathEnv, self._mathEnv)))
except OverflowError:
maxFloat = math.ldexp(0.9999999999999999, 1024)
irc.error(_('The answer exceeded %s or so.') % maxFloat)
except TypeError:
irc.error(_('Something in there wasn\'t a valid number.'))
except NameError as e:
irc.error(_('%s is not a defined function.') % str(e).split()[1])
except Exception as e:
irc.error(utils.exnToString(e))
示例3: sing
def sing(self, irc, msg, args, input):
"""
Usage: sing artist [: title] [: * | line | pattern] --
Example: @sing bon jovi : wanted dead or alive --
Searches http://lyricsmania.com
"""
args = map(lambda x: x.strip(), re.split(':', input))
line = None
try:
artist, title, line = args
logger.info('got %s, %s, %s' % (artist, title, line))
except ValueError:
try:
artist, title = args
logger.info('got %s, %s' % (artist, title))
except:
artist = args[0]
logger.info('got %s' % (artist))
try:
title = randtitle(artist)
except Exception, e:
logger.error(utils.exnToString(e))
irc.reply("Arrgh! Something went horribly wrong")
return
示例4: rank
def rank(self, irc, msg, args, channel, expr):
"""[<channel>] <stat expression>
Returns the ranking of users according to the given stat expression.
Valid variables in the stat expression include 'msgs', 'chars',
'words', 'smileys', 'frowns', 'actions', 'joins', 'parts', 'quits',
'kicks', 'kicked', 'topics', and 'modes'. Any simple mathematical
expression involving those variables is permitted.
"""
# XXX I could do this the right way, and abstract out a safe eval,
# or I could just copy/paste from the Math plugin.
if expr != expr.translate(utils.str.chars, '_[]'):
irc.error('There\'s really no reason why you should have '
'underscores or brackets in your mathematical '
'expression. Please remove them.', Raise=True)
if 'lambda' in expr:
irc.error('You can\'t use lambda in this command.', Raise=True)
expr = expr.lower()
users = []
for ((c, id), stats) in self.db.items():
if ircutils.strEqual(c, channel) and ircdb.users.hasUser(id):
e = self._env.copy()
for attr in stats._values:
e[attr] = float(getattr(stats, attr))
try:
v = eval(expr, e, e)
except ZeroDivisionError:
v = float('inf')
except NameError, e:
irc.errorInvalid('stat variable', str(e).split()[1])
except Exception, e:
irc.error(utils.exnToString(e), Raise=True)
users.append((v, ircdb.users.getUser(id).name))
示例5: __call__
def __call__(self, irc, msg, args, state):
try:
super(optional, self).__call__(irc, msg, args, state)
except (callbacks.ArgumentError, callbacks.Error), e:
log.debug('Got %s, returning default.', utils.exnToString(e))
state.errored = False
setDefault(state, self.default)
示例6: connectError
def connectError(self, server, e):
if isinstance(e, Exception):
if isinstance(e, socket.gaierror):
e = e.args[1]
else:
e = utils.exnToString(e)
self.warning('Error connecting to %s: %s', server, e)
示例7: ircquote
def ircquote(self, irc, msg, args, s):
"""<string to be sent to the server>
Sends the raw string given to the server.
"""
try:
m = ircmsgs.IrcMsg(s)
except Exception, e:
irc.error(utils.exnToString(e))
示例8: simpleeval
def simpleeval(self, irc, msg, args, text):
"""<expression>
Evaluates the given expression.
"""
try:
irc.reply(repr(eval(text)))
except Exception as e:
irc.reply(utils.exnToString(e))
示例9: add
def add(self, irc, msg, args, filename):
"""<filename>
Basically does the equivalent of tail -f to the targets.
"""
try:
self._add(filename)
except EnvironmentError, e:
irc.error(utils.exnToString(e))
return
示例10: disconnect
def disconnect(self, server, e=None):
if e:
if isinstance(e, Exception):
e = utils.exnToString(e)
else:
e = str(e)
if not e.endswith('.'):
e += '.'
self.warning('Disconnect from %s: %s', server, e)
else:
self.info('Disconnect from %s.', server)
示例11: _callCommand
def _callCommand(self, command, irc, msg, *args, **kwargs):
method = self.getCommandMethod(command)
if command[0] in mess:
msg.tag("messcmd", command[0])
try:
method(irc, msg, *args, **kwargs)
except Exception, e:
self.log.exception("Mess: Uncaught exception in %s.", command)
if conf.supybot.reply.error.detailed():
irc.error(utils.exnToString(e))
else:
irc.replyError()
示例12: eval
def eval(self, irc, msg, args):
"""<text>
This is the help for eval. Since Owner doesn't have an eval command
anymore, we needed to add this so as not to invalidate any of the tests
that depended on that eval command.
"""
try:
irc.reply(repr(eval(' '.join(args))))
except callbacks.ArgumentError:
raise
except Exception, e:
irc.reply(utils.exnToString(e))
示例13: open
def open(self, filename):
self.filename = filename
reader = unpreserve.Reader(IrcUserCreator, self)
try:
self.noFlush = True
try:
reader.readFile(filename)
self.noFlush = False
self.flush()
except EnvironmentError, e:
log.error('Invalid user dictionary file, resetting to empty.')
log.error('Exact error: %s', utils.exnToString(e))
except Exception, e:
log.exception('Exact error:')
示例14: open
def open(self, filename):
self.noFlush = True
try:
self.filename = filename
reader = unpreserve.Reader(IrcChannelCreator, self)
try:
reader.readFile(filename)
self.noFlush = False
self.flush()
except EnvironmentError, e:
log.error("Invalid channel database, resetting to empty.")
log.error("Exact error: %s", utils.exnToString(e))
except Exception, e:
log.error("Invalid channel database, resetting to empty.")
log.exception("Exact error:")
示例15: eval
def eval(self, irc, msg, args, s):
"""<expression>
Evaluates <expression> (which should be a Python expression) and
returns its value. If an exception is raised, reports the
exception (and logs the traceback to the bot's logfile).
"""
try:
self._evalEnv.update(locals())
x = eval(s, self._evalEnv, self._evalEnv)
self._evalEnv['___'] = self._evalEnv['__']
self._evalEnv['__'] = self._evalEnv['_']
self._evalEnv['_'] = x
irc.reply(repr(x))
except SyntaxError as e:
irc.reply(format('%s: %q', utils.exnToString(e), s))