##// END OF EJS Templates
revlog: simplify the v1 immediate parser...
revlog: simplify the v1 immediate parser - read all the data at once (large files are handled by the lazy parser) - cache the entire file for inline revlogs - simplify looping

File last commit:

r4869:be591b74 default
r4975:8b7e480a default
Show More
wsgicgi.py
73 lines | 2.3 KiB | text/x-python | PythonLexer
Eric Hopper
This patch make several WSGI related alterations....
r2506 # hgweb/wsgicgi.py - CGI->WSGI translator
#
# Copyright 2006 Eric Hopper <hopper@omnifarious.org>
#
# This software may be used and distributed according to the terms
# of the GNU General Public License, incorporated herein by reference.
#
# This was originally copied from the public domain code at
# http://www.python.org/dev/peps/pep-0333/#the-server-gateway-side
import os, sys
Alexis S. L. Carvalho
Switch CGI stdout to binary on windows...
r4076 from mercurial import util
Eric Hopper
This patch make several WSGI related alterations....
r2506
def launch(application):
Alexis S. L. Carvalho
wsgicgi: change stdin to binary mode
r4484 util.set_binary(sys.stdin)
Alexis S. L. Carvalho
Switch CGI stdout to binary on windows...
r4076 util.set_binary(sys.stdout)
Eric Hopper
This patch make several WSGI related alterations....
r2506
environ = dict(os.environ.items())
Thomas Arendsen Hein
white space and line break cleanups
r3673 environ['wsgi.input'] = sys.stdin
environ['wsgi.errors'] = sys.stderr
environ['wsgi.version'] = (1, 0)
environ['wsgi.multithread'] = False
Eric Hopper
This patch make several WSGI related alterations....
r2506 environ['wsgi.multiprocess'] = True
Thomas Arendsen Hein
white space and line break cleanups
r3673 environ['wsgi.run_once'] = True
Eric Hopper
This patch make several WSGI related alterations....
r2506
Wesley J. Landaker
Handle CGI SSL detection via HTTPS environment better....
r4869 if environ.get('HTTPS','off').lower() in ('on','1','yes'):
Eric Hopper
This patch make several WSGI related alterations....
r2506 environ['wsgi.url_scheme'] = 'https'
else:
environ['wsgi.url_scheme'] = 'http'
headers_set = []
headers_sent = []
Alexis S. L. Carvalho
hgweb: fix unbundle....
r2558 out = sys.stdout
Eric Hopper
This patch make several WSGI related alterations....
r2506
def write(data):
if not headers_set:
Thomas Arendsen Hein
white space and line break cleanups
r3673 raise AssertionError("write() before start_response()")
Eric Hopper
This patch make several WSGI related alterations....
r2506
elif not headers_sent:
Thomas Arendsen Hein
white space and line break cleanups
r3673 # Before the first output, send the stored headers
status, response_headers = headers_sent[:] = headers_set
out.write('Status: %s\r\n' % status)
for header in response_headers:
out.write('%s: %s\r\n' % header)
out.write('\r\n')
Eric Hopper
This patch make several WSGI related alterations....
r2506
Alexis S. L. Carvalho
hgweb: fix unbundle....
r2558 out.write(data)
out.flush()
Eric Hopper
This patch make several WSGI related alterations....
r2506
Thomas Arendsen Hein
white space and line break cleanups
r3673 def start_response(status, response_headers, exc_info=None):
Eric Hopper
This patch make several WSGI related alterations....
r2506 if exc_info:
try:
if headers_sent:
# Re-raise original exception if headers sent
raise exc_info[0], exc_info[1], exc_info[2]
finally:
exc_info = None # avoid dangling circular ref
elif headers_set:
raise AssertionError("Headers already set!")
Thomas Arendsen Hein
white space and line break cleanups
r3673 headers_set[:] = [status, response_headers]
Eric Hopper
This patch make several WSGI related alterations....
r2506 return write
result = application(environ, start_response)
try:
for data in result:
if data: # don't send headers until body appears
write(data)
if not headers_sent:
write('') # send headers now if body was empty
finally:
if hasattr(result,'close'):
result.close()