예제 #1
0
def dispatch(env, start_response):
    """
    WSGI dispatcher

    This represents the main WSGI app for Seshat.
    To use with `waitress`, for example::

        from waitress import serve
        serve(dispatch)

    """
    req = request_obj(env)
    newHTTPObject = None

    log_request(req)

    found = route_table.get(req)

    if found is not None:
        obj = found.__module__+"/"+found.__name__
        newHTTPObject = found(req)
        log_obj(req, obj)
        return reply(newHTTPObject, req, start_response)

    else:
        content, head = error_catcher.error("404", req)
        header = head._generate_header(req, len(content))
        start_response(head.status, header)
        log_response(req, head)
        return [content.encode("utf-8")]
예제 #2
0
def reply(newHTTPObject, req, start_response):
    newHTTPObj = greenlet(newHTTPObject._build)
    content, head = newHTTPObj.switch()

    if error_catcher.check(head):
        content, head = error_catcher.error(head, req)

    header = head._generate_header(req, len(content))

    start_response(head.status, header)

    log_response(req, head)

    g = greenlet(req.log)
    g.switch(head)

    return [content.encode("utf-8")]