예제 #1
0
파일: app.py 프로젝트: vaultah/L
 def wrapper(*args, **kwargs):
     response = func(*args, **kwargs)
     tpl_vars = {}
     tpl_vars.update(presets)
     if response:
         tpl_vars.update(response.copy())
     return env.get_template(name).render(**tpl_vars)
예제 #2
0
def redirect(url, code=None):
    """ Aborts execution and causes a 303 or 302 redirect, depending on
        the HTTP protocol version. """
    if not code:
       	code = 303 if request.get('SERVER_PROTOCOL') == "HTTP/1.1" else 302
    res = response.copy(cls=HTTPResponse)
    res.status = code
    res.body = ""
    res.set_header('Location', url)
    raise res
예제 #3
0
def return_raise(msg=''):
    """
    直接终止程序,返回结果给客户端
    :params msg 输出内容
    :return 输出字符串
    """
    res = response.copy(cls=HTTPResponse)
    res.status = 200
    res.body = str(msg)
    raise res
예제 #4
0
def return_raise(msg=''):
    """
    直接终止程序,返回结果给客户端
    修改bottle的异常状态码和异常返回body内容
    :param msg: 输出内容
    :return: 输出字符串
    """
    res = response.copy(cls=HTTPResponse)
    res.status = 200
    res.body = str(msg)
    raise res
예제 #5
0
파일: run.py 프로젝트: agalera/PS_LG
    def wrapper(*a, **ka):
        try:
            rv = callback(*a, **ka)
        except HTTPResponse as resp:
            rv = resp

        if not isinstance(rv, HTTPResponse):
            tmp = rv
            rv = response.copy(cls=HTTPResponse)
            rv.body = tmp

        if not rv.content_type:
            rv.body = dumps(rv.body)
            rv.content_type = 'application/json'
        return rv
예제 #6
0
def redirect(url):
    res = response.copy(cls=HTTPResponse)
    res.status = 302
    res.body = b"Redirect"
    res.set_header('Location', urljoin(request.url, url))
    raise res