##// END OF EJS Templates
py3: avoid b'' output in test-hgweb-non-interactive.t...
Matt Harbison -
r39949:8bd589ae default
parent child Browse files
Show More
@@ -1,92 +1,96 b''
1 Tests if hgweb can run without touching sys.stdin, as is required
1 Tests if hgweb can run without touching sys.stdin, as is required
2 by the WSGI standard and strictly implemented by mod_wsgi.
2 by the WSGI standard and strictly implemented by mod_wsgi.
3
3
4 $ hg init repo
4 $ hg init repo
5 $ cd repo
5 $ cd repo
6 $ echo foo > bar
6 $ echo foo > bar
7 $ hg add bar
7 $ hg add bar
8 $ hg commit -m "test"
8 $ hg commit -m "test"
9 $ cat > request.py <<EOF
9 $ cat > request.py <<EOF
10 > from __future__ import absolute_import
10 > from __future__ import absolute_import
11 > import os
11 > import os
12 > import sys
12 > import sys
13 > from mercurial import (
13 > from mercurial import (
14 > dispatch,
14 > dispatch,
15 > encoding,
15 > hg,
16 > hg,
17 > pycompat,
16 > ui as uimod,
18 > ui as uimod,
17 > util,
19 > util,
18 > )
20 > )
19 > ui = uimod.ui
21 > ui = uimod.ui
20 > from mercurial.hgweb.hgweb_mod import (
22 > from mercurial.hgweb.hgweb_mod import (
21 > hgweb,
23 > hgweb,
22 > )
24 > )
23 > stringio = util.stringio
25 > stringio = util.stringio
24 >
26 >
25 > class FileLike(object):
27 > class FileLike(object):
26 > def __init__(self, real):
28 > def __init__(self, real):
27 > self.real = real
29 > self.real = real
28 > def fileno(self):
30 > def fileno(self):
29 > print >> sys.__stdout__, 'FILENO'
31 > print >> sys.__stdout__, 'FILENO'
30 > return self.real.fileno()
32 > return self.real.fileno()
31 > def read(self):
33 > def read(self):
32 > print >> sys.__stdout__, 'READ'
34 > print >> sys.__stdout__, 'READ'
33 > return self.real.read()
35 > return self.real.read()
34 > def readline(self):
36 > def readline(self):
35 > print >> sys.__stdout__, 'READLINE'
37 > print >> sys.__stdout__, 'READLINE'
36 > return self.real.readline()
38 > return self.real.readline()
37 >
39 >
38 > sys.stdin = FileLike(sys.stdin)
40 > sys.stdin = FileLike(sys.stdin)
39 > errors = stringio()
41 > errors = stringio()
40 > input = stringio()
42 > input = stringio()
41 > output = stringio()
43 > output = stringio()
42 >
44 >
43 > def startrsp(status, headers):
45 > def startrsp(status, headers):
44 > print('---- STATUS')
46 > print('---- STATUS')
45 > print(status)
47 > print(status)
46 > print('---- HEADERS')
48 > print('---- HEADERS')
47 > print([i for i in headers if i[0] != 'ETag'])
49 > print([i for i in headers if i[0] != 'ETag'])
48 > print('---- DATA')
50 > print('---- DATA')
49 > return output.write
51 > return output.write
50 >
52 >
51 > env = {
53 > env = {
52 > 'wsgi.version': (1, 0),
54 > 'wsgi.version': (1, 0),
53 > 'wsgi.url_scheme': 'http',
55 > 'wsgi.url_scheme': 'http',
54 > 'wsgi.errors': errors,
56 > 'wsgi.errors': errors,
55 > 'wsgi.input': input,
57 > 'wsgi.input': input,
56 > 'wsgi.multithread': False,
58 > 'wsgi.multithread': False,
57 > 'wsgi.multiprocess': False,
59 > 'wsgi.multiprocess': False,
58 > 'wsgi.run_once': False,
60 > 'wsgi.run_once': False,
59 > 'REQUEST_METHOD': 'GET',
61 > 'REQUEST_METHOD': 'GET',
60 > 'SCRIPT_NAME': '',
62 > 'SCRIPT_NAME': '',
61 > 'PATH_INFO': '',
63 > 'PATH_INFO': '',
62 > 'QUERY_STRING': '',
64 > 'QUERY_STRING': '',
63 > 'SERVER_NAME': '$LOCALIP',
65 > 'SERVER_NAME': '$LOCALIP',
64 > 'SERVER_PORT': os.environ['HGPORT'],
66 > 'SERVER_PORT': os.environ['HGPORT'],
65 > 'SERVER_PROTOCOL': 'HTTP/1.0'
67 > 'SERVER_PROTOCOL': 'HTTP/1.0'
66 > }
68 > }
67 >
69 >
68 > i = hgweb(b'.')
70 > i = hgweb(b'.')
69 > for c in i(env, startrsp):
71 > for c in i(env, startrsp):
70 > pass
72 > pass
71 > print('---- ERRORS')
73 > sys.stdout.flush()
72 > print(errors.getvalue())
74 > pycompat.stdout.write(b'---- ERRORS\n')
75 > pycompat.stdout.write(b'%s\n' % errors.getvalue())
73 > print('---- OS.ENVIRON wsgi variables')
76 > print('---- OS.ENVIRON wsgi variables')
74 > print(sorted([x for x in os.environ if x.startswith('wsgi')]))
77 > print(sorted([x for x in os.environ if x.startswith('wsgi')]))
75 > print('---- request.ENVIRON wsgi variables')
78 > print('---- request.ENVIRON wsgi variables')
76 > with i._obtainrepo() as repo:
79 > with i._obtainrepo() as repo:
77 > print(sorted([x for x in repo.ui.environ if x.startswith(b'wsgi')]))
80 > print(sorted([encoding.strfromlocal(x) for x in repo.ui.environ
81 > if x.startswith(b'wsgi')]))
78 > EOF
82 > EOF
79 $ "$PYTHON" request.py
83 $ "$PYTHON" request.py
80 ---- STATUS
84 ---- STATUS
81 200 Script output follows
85 200 Script output follows
82 ---- HEADERS
86 ---- HEADERS
83 [('Content-Type', 'text/html; charset=ascii')]
87 [('Content-Type', 'text/html; charset=ascii')]
84 ---- DATA
88 ---- DATA
85 ---- ERRORS
89 ---- ERRORS
86
90
87 ---- OS.ENVIRON wsgi variables
91 ---- OS.ENVIRON wsgi variables
88 []
92 []
89 ---- request.ENVIRON wsgi variables
93 ---- request.ENVIRON wsgi variables
90 ['wsgi.errors', 'wsgi.input', 'wsgi.multiprocess', 'wsgi.multithread', 'wsgi.run_once', 'wsgi.url_scheme', 'wsgi.version']
94 ['wsgi.errors', 'wsgi.input', 'wsgi.multiprocess', 'wsgi.multithread', 'wsgi.run_once', 'wsgi.url_scheme', 'wsgi.version']
91
95
92 $ cd ..
96 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now