depot.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:solaris-ips 作者: oracle 项目源码 文件源码
def nasty_before_handler(nasty_depot, maxroll=100):
        """Cherrypy Tool callable which generates various problems prior to a
        request.  Possible outcomes: retryable HTTP error, short nap."""

        # Must be set in _cp_config on associated request handler.
        assert nasty_depot

        # Adjust nastiness values once per incoming request.
        nasty_depot.nasty_housekeeping()

        # Just roll the main nasty dice once.
        if not nasty_depot.need_nasty(maxroll=maxroll):
                return False

        while True:
                roll = random.randint(0, 10)
                if roll == 0:
                        nasty_depot.nasty_nap()
                        if random.randint(0, 1) == 1:
                                # Nap was enough. Let the normal handler run.
                                return False
                if 1 <= roll <= 8:
                        nasty_depot.nasty_raise_error()
                else:
                        cherrypy.log("NASTY: return bogus or empty response")
                        response = cherrypy.response
                        response.body = random.choice(['',
                            'set this is a bogus action',
                            'Instead of office chair, '
                                'package contained bobcat.',
                            '{"this is a": "fragment of json"}'])
                        return True
        return False
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号