• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.exnToString函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中supybot.utils.exnToString函数的典型用法代码示例。如果您正苦于以下问题:Python exnToString函数的具体用法?Python exnToString怎么用?Python exnToString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了exnToString函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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')
开发者ID:Hoaas,项目名称:Limnoria,代码行数:9,代码来源:test_utils.py


示例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))
开发者ID:Hoaas,项目名称:Limnoria,代码行数:33,代码来源:plugin.py


示例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
开发者ID:D0MF,项目名称:supybot-plugins,代码行数:26,代码来源:plugin.py


示例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))
开发者ID:Affix,项目名称:Fedbot,代码行数:33,代码来源:plugin.py


示例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)
开发者ID:boamaod,项目名称:Limnoria,代码行数:7,代码来源:commands.py


示例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)
开发者ID:jrabbit,项目名称:ubotu-fr,代码行数:7,代码来源:__init__.py


示例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))
开发者ID:boamaod,项目名称:Limnoria,代码行数:9,代码来源:plugin.py


示例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))
开发者ID:AssetsIncorporated,项目名称:Limnoria,代码行数:9,代码来源:plugin.py


示例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
开发者ID:hacklab,项目名称:doorbot,代码行数:10,代码来源:plugin.py


示例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)
开发者ID:jrabbit,项目名称:ubotu-fr,代码行数:11,代码来源:__init__.py


示例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()
开发者ID:bnrubin,项目名称:ubuntu-bots,代码行数:12,代码来源:plugin.py


示例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))
开发者ID:resistivecorpse,项目名称:Limnoria,代码行数:13,代码来源:test.py


示例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:')
开发者ID:Elwell,项目名称:supybot,代码行数:14,代码来源:ircdb.py


示例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:")
开发者ID:jrabbit,项目名称:ubotu-fr,代码行数:15,代码来源:ircdb.py


示例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))
开发者ID:AssetsIncorporated,项目名称:Limnoria,代码行数:16,代码来源:plugin.py


示例16: format

    def format(self, irc, msg, args):
        """<format string> [<arg> ...]

        Expands a Python-style format string using the remaining args.  Just be
        sure always to use %s, not %d or %f or whatever, because all the args
        are strings.
        """
        if not args:
            raise callbacks.ArgumentError
        s = args.pop(0)
        try:
            s %= tuple(args)
            irc.reply(s)
        except TypeError, e:
            self.log.debug(utils.exnToString(e))
            irc.error('Not enough arguments for the format string.',Raise=True)
开发者ID:Kefkius,项目名称:mazabot,代码行数:16,代码来源:plugin.py


示例17: add

    def add(self, irc, msg, args, filename, identifier, channet):
        """<filename> <identifier> <channel,network...>

        Add FILENAME as IDENTIFIER for announcing in
        Make sure the bot has rights to read whatever you tail.
        channels are written as #channel,network|#channel2,network2
        """
        try:
            self.config[filename] = {}
            self.config[filename]['identifier'] = identifier
            self.config[filename]['channels'] = channet
            json.dump(self.config, open(self.registryValue('configfile'), 'w'))
            self._add(filename)
        except EnvironmentError as e:
            irc.error(utils.exnToString(e))
            return
        irc.replySuccess()
开发者ID:IotaSpencer,项目名称:supyplugins,代码行数:17,代码来源:plugin.py


示例18: 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.
        """
        if msg.nick not in irc.state.channels[channel].users:
            irc.error(format('You must be in %s to use this command.', channel))
            return
        # 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 self._calc_match_forbidden_chars.match(expr):
            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 \
               (id == 0 or 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 as e:
                    irc.errorInvalid(_('stat variable'), str(e).split()[1])
                except Exception as e:
                    irc.error(utils.exnToString(e), Raise=True)
                if id == 0:
                    users.append((v, irc.nick))
                else:
                    users.append((v, ircdb.users.getUser(id).name))
        users.sort()
        users.reverse()
        s = utils.str.commaAndify(['#%s %s (%.3g)' % (i+1, u, v)
                                   for (i, (v, u)) in enumerate(users)])
        irc.reply(s)
开发者ID:Ban3,项目名称:Limnoria,代码行数:45,代码来源:plugin.py


示例19: songs

    def songs(self, irc, msg, args, input):
        """<string>
        fetches song list from lyricsmania.com"""

        args = map(lambda x: x.strip(), re.split(':', input))

        try:
            artist, searchstring = args
        except:
            artist, searchstring = args[0], None

        songs = []
        try:
            songs = songlist(artist, searchstring)
        except Exception, e:
            logger.error(utils.exnToString(e))
            irc.reply("Arrgh! Something went horribly wrong")
            return
开发者ID:D0MF,项目名称:supybot-plugins,代码行数:18,代码来源:plugin.py


示例20: email

    def email(self, irc, msg, args):
        """<first name> <middle initial> <last name>

        Returns possible email address matches for the given name.
        """
        s = '.'.join(args)
        url = 'http://www.ohio-state.edu/cgi-bin/inquiry2.cgi?keyword=%s' % s
        try:
            data = utils.web.getUrl(url)
            emails = []
            for line in data.splitlines():
                line.strip()
                if 'Published address' in line:
                    emails.append(line.split()[-1])
            if len(emails) == 0:
                irc.reply('There seem to be no matches to that name.')
            elif len(emails) == 1:
                irc.reply(emails[0])
            else:
                irc.reply('Possible matches: %s.' % ', '.join(emails))
        except Exception, e:
            irc.error(utils.exnToString(e))
开发者ID:D0MF,项目名称:supybot-plugins-1,代码行数:22,代码来源:plugin.py



注:本文中的supybot.utils.exnToString函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.sortBy函数代码示例发布时间:2022-05-27
下一篇:
Python schedule.removeEvent函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap