Esempio n. 1
0
File: app.py Progetto: 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)
Esempio n. 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
Esempio n. 3
0
def return_raise(msg=''):
    """
    直接终止程序,返回结果给客户端
    :params msg 输出内容
    :return 输出字符串
    """
    res = response.copy(cls=HTTPResponse)
    res.status = 200
    res.body = str(msg)
    raise res
Esempio n. 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
Esempio n. 5
0
File: run.py Progetto: 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
Esempio n. 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