Пример #1
0
    def serve(environ, start_response):

        root = root_url.lstrip('/')

        tail, get = (util.request_uri(environ).split('?') + [''])[:2]
        tail = tail[len(util.application_uri(environ)):]

        result = []

        content_type = 'text/plain'
        status = '200 OK'
        if tail.startswith(root):

            tail = tail[len(root):]

            get = parse_qs(get)
            method = environ['REQUEST_METHOD']

            text, post = '', {}
            if method == 'POST':
                text = environ['wsgi.input'].\
                    read(int(environ.get('CONTENT_LENGTH', 0)))
                post = parse_qs(text)

            response = server.process_request(
                Request(tail, text, get, post, {}))

            content_type = response.content_type
            status = get_http_response_code(response)
            result.append(response.text)

        headers = [('Content-type', content_type)]
        start_response(status, headers)

        return result
Пример #2
0
Файл: _wsgi.py Проект: Kjir/pyws
    def serve(environ, start_response):

        root = root_url.lstrip("/")

        tail, get = (util.request_uri(environ).split("?") + [""])[:2]
        tail = tail[len(util.application_uri(environ)) :]

        result = []

        content_type = "text/plain"
        status = "200 OK"
        if tail.lstrip("/").startswith(root):

            tail = tail[len(root) :]

            get = parse_qs(get)
            method = environ["REQUEST_METHOD"]

            text, post = "", {}
            if method == "POST":
                text = environ["wsgi.input"].read(int(environ.get("CONTENT_LENGTH", 0)))
                post = parse_qs(text)

            response = server.process_request(Request(tail, text, get, post, {}))

            content_type = response.content_type
            status = get_http_response_code(response)
            result.append(response.text)

        headers = [("Content-type", content_type)]
        start_response(status, headers)

        return result
Пример #3
0
def serve(request, tail, server):
    """
    Django adapter. It has three arguments:

    #. ``request`` is a Django request object,
    #. ``tail`` is everything that's left from an URL, which adapter is
       attached to,
    #. ``server`` is a pyws server object.

    First two are the context of an application, function ``serve`` transforms
    them into a pyws request object. Then it feeds the request to the server,
    gets the response and transforms it into a Django response object.
    """

    request = Request(tail,
        request.raw_post_data if not request.GET else '',
        parse_qs(request.META['QUERY_STRING']),
        parse_qs(request.raw_post_data),
        request.COOKIES,
    )

    response = server.process_request(request)

    return HttpResponse(
        response.text, content_type=response.content_type,
        status=get_http_response_code_num(response))
Пример #4
0
    def serve(environ, start_response):

        root = root_url.lstrip('/')

        tail, get = (util.request_uri(environ).split('?') + [''])[:2]
        tail = tail[len(util.application_uri(environ)):]

        result = []

        content_type = 'text/plain'
        status = '200 OK'
        if tail.startswith(root):

            tail = tail[len(root):]

            get = parse_qs(get)
            method = environ['REQUEST_METHOD']

            text, post = '', {}
            if method == 'POST':
                text = environ['wsgi.input'].\
                    read(int(environ.get('CONTENT_LENGTH', 0)))
                post = parse_qs(text)

            response = server.process_request(
                Request(tail, text, get, post, {}))

            content_type = response.content_type
            status = get_http_response_code(response)
            result.append(response.text)

        headers = [('Content-type', content_type)]
        start_response(status, headers)

        return result