htsql / src / htsql_django /

# Copyright (c) 2006-2012, Prometheus Research, LLC

from django.contrib.auth.decorators import login_required
from django.http import HttpResponse
from django.core.urlresolvers import reverse
from django.db import transaction
from . import instance

def to_environ(request):
    environ = request.META.copy()
    prefix = reverse(gateway)
    if prefix.endswith('/'):
        prefix = prefix[:-1]
    if isinstance(environ['PATH_INFO'], unicode):
        environ['PATH_INFO'] = environ['PATH_INFO'].encode('utf-8')
    if isinstance(environ['SCRIPT_NAME'], unicode):
        environ['SCRIPT_NAME'] = environ['SCRIPT_NAME'].encode('utf-8')
    assert environ['PATH_INFO'].startswith(prefix)
    assert environ['SCRIPT_NAME'] == ''
    environ['SCRIPT_NAME'] = prefix
    environ['PATH_INFO'] = environ['PATH_INFO'][len(prefix):]
    return environ

def gateway(request):
    class output:
        status = None
        headers = None
        body = None
    environ = to_environ(request)
    def start_response(status, headers, exc_info=None):
        output.status = status
        output.headers = headers
    output.body = ''.join(instance(environ, start_response))
    response = HttpResponse(output.body, status=int(output.status.split()[0]))
    for header, value in output.headers:
        response[header] = value
    return response
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.