comparison mercurial/hgweb/wsgicgi.py @ 30473:39d13b8c101d

py3: bulk replace sys.stdin/out/err by util's Almost all sys.stdin/out/err in hgext/ and mercurial/ are replaced by util's. There are a few exceptions: - lsprof.py and statprof.py are untouched since they are a kind of vendor code and they never import mercurial modules right now. - ui._readline() needs to replace sys.stdin and stdout to pass them to raw_input(). We'll need another workaround here.
author Yuya Nishihara <yuya@tcha.org>
date Thu, 20 Oct 2016 23:53:36 +0900
parents 37fcfe52c68c
children f1c9fafcbf46
comparison
equal deleted inserted replaced
30472:277f4fe6d01a 30473:39d13b8c101d
9 # http://www.python.org/dev/peps/pep-0333/#the-server-gateway-side 9 # http://www.python.org/dev/peps/pep-0333/#the-server-gateway-side
10 10
11 from __future__ import absolute_import 11 from __future__ import absolute_import
12 12
13 import os 13 import os
14 import sys
15 14
16 from .. import ( 15 from .. import (
17 util, 16 util,
18 ) 17 )
19 18
20 from . import ( 19 from . import (
21 common, 20 common,
22 ) 21 )
23 22
24 def launch(application): 23 def launch(application):
25 util.setbinary(sys.stdin) 24 util.setbinary(util.stdin)
26 util.setbinary(sys.stdout) 25 util.setbinary(util.stdout)
27 26
28 environ = dict(os.environ.iteritems()) 27 environ = dict(os.environ.iteritems())
29 environ.setdefault('PATH_INFO', '') 28 environ.setdefault('PATH_INFO', '')
30 if environ.get('SERVER_SOFTWARE', '').startswith('Microsoft-IIS'): 29 if environ.get('SERVER_SOFTWARE', '').startswith('Microsoft-IIS'):
31 # IIS includes script_name in PATH_INFO 30 # IIS includes script_name in PATH_INFO
32 scriptname = environ['SCRIPT_NAME'] 31 scriptname = environ['SCRIPT_NAME']
33 if environ['PATH_INFO'].startswith(scriptname): 32 if environ['PATH_INFO'].startswith(scriptname):
34 environ['PATH_INFO'] = environ['PATH_INFO'][len(scriptname):] 33 environ['PATH_INFO'] = environ['PATH_INFO'][len(scriptname):]
35 34
36 stdin = sys.stdin 35 stdin = util.stdin
37 if environ.get('HTTP_EXPECT', '').lower() == '100-continue': 36 if environ.get('HTTP_EXPECT', '').lower() == '100-continue':
38 stdin = common.continuereader(stdin, sys.stdout.write) 37 stdin = common.continuereader(stdin, util.stdout.write)
39 38
40 environ['wsgi.input'] = stdin 39 environ['wsgi.input'] = stdin
41 environ['wsgi.errors'] = sys.stderr 40 environ['wsgi.errors'] = util.stderr
42 environ['wsgi.version'] = (1, 0) 41 environ['wsgi.version'] = (1, 0)
43 environ['wsgi.multithread'] = False 42 environ['wsgi.multithread'] = False
44 environ['wsgi.multiprocess'] = True 43 environ['wsgi.multiprocess'] = True
45 environ['wsgi.run_once'] = True 44 environ['wsgi.run_once'] = True
46 45
49 else: 48 else:
50 environ['wsgi.url_scheme'] = 'http' 49 environ['wsgi.url_scheme'] = 'http'
51 50
52 headers_set = [] 51 headers_set = []
53 headers_sent = [] 52 headers_sent = []
54 out = sys.stdout 53 out = util.stdout
55 54
56 def write(data): 55 def write(data):
57 if not headers_set: 56 if not headers_set:
58 raise AssertionError("write() before start_response()") 57 raise AssertionError("write() before start_response()")
59 58