server.py 文件源码

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

项目:ops 作者: xiaomatech 项目源码 文件源码
def sink(req, resp):
    do_log_history(req, resp)

    paths = filter(lambda x: x != '', req.path.split('/'))
    ctrl_name = func_name = 'index'
    if len(paths) >= 2:
        ctrl_name = paths[0]
        func_name = paths[1]
    elif len(paths) == 1:
        func_name = paths[0]
    ctrl = loader.ctrl(ctrl_name)

    if ctrl == None or not hasattr(ctrl, func_name):
        resp.status = falcon.HTTP_404
        resp.body = "Not Found"
    else:
        try:
            content = getattr(ctrl, func_name)(req, resp)
            if resp.body == None:
                if isinstance(content, unicode):
                    resp.body = unicode.encode(content, 'utf-8', 'ignore')
                elif isinstance(content, str):
                    resp.body = content
                else:
                    resp.body = json.dumps(content)
        except Exception as ex:
            log_error(ex)
            resp.status = falcon.HTTP_500
            resp.body = str(ex)
            #resp.body = 'A server error occurred. Please contact the administrator'
    do_log_result(req, resp)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号