##// END OF EJS Templates
py3: add b'' prefixes in tests/test-hgweb-non-interactive.t...
Pulkit Goyal -
r39694:c20861b6 default
parent child Browse files
Show More
@@ -1,92 +1,92
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 > hg,
15 > hg,
16 > ui as uimod,
16 > ui as uimod,
17 > util,
17 > util,
18 > )
18 > )
19 > ui = uimod.ui
19 > ui = uimod.ui
20 > from mercurial.hgweb.hgweb_mod import (
20 > from mercurial.hgweb.hgweb_mod import (
21 > hgweb,
21 > hgweb,
22 > )
22 > )
23 > stringio = util.stringio
23 > stringio = util.stringio
24 >
24 >
25 > class FileLike(object):
25 > class FileLike(object):
26 > def __init__(self, real):
26 > def __init__(self, real):
27 > self.real = real
27 > self.real = real
28 > def fileno(self):
28 > def fileno(self):
29 > print >> sys.__stdout__, 'FILENO'
29 > print >> sys.__stdout__, 'FILENO'
30 > return self.real.fileno()
30 > return self.real.fileno()
31 > def read(self):
31 > def read(self):
32 > print >> sys.__stdout__, 'READ'
32 > print >> sys.__stdout__, 'READ'
33 > return self.real.read()
33 > return self.real.read()
34 > def readline(self):
34 > def readline(self):
35 > print >> sys.__stdout__, 'READLINE'
35 > print >> sys.__stdout__, 'READLINE'
36 > return self.real.readline()
36 > return self.real.readline()
37 >
37 >
38 > sys.stdin = FileLike(sys.stdin)
38 > sys.stdin = FileLike(sys.stdin)
39 > errors = stringio()
39 > errors = stringio()
40 > input = stringio()
40 > input = stringio()
41 > output = stringio()
41 > output = stringio()
42 >
42 >
43 > def startrsp(status, headers):
43 > def startrsp(status, headers):
44 > print('---- STATUS')
44 > print('---- STATUS')
45 > print(status)
45 > print(status)
46 > print('---- HEADERS')
46 > print('---- HEADERS')
47 > print([i for i in headers if i[0] != 'ETag'])
47 > print([i for i in headers if i[0] != 'ETag'])
48 > print('---- DATA')
48 > print('---- DATA')
49 > return output.write
49 > return output.write
50 >
50 >
51 > env = {
51 > env = {
52 > 'wsgi.version': (1, 0),
52 > 'wsgi.version': (1, 0),
53 > 'wsgi.url_scheme': 'http',
53 > 'wsgi.url_scheme': 'http',
54 > 'wsgi.errors': errors,
54 > 'wsgi.errors': errors,
55 > 'wsgi.input': input,
55 > 'wsgi.input': input,
56 > 'wsgi.multithread': False,
56 > 'wsgi.multithread': False,
57 > 'wsgi.multiprocess': False,
57 > 'wsgi.multiprocess': False,
58 > 'wsgi.run_once': False,
58 > 'wsgi.run_once': False,
59 > 'REQUEST_METHOD': 'GET',
59 > 'REQUEST_METHOD': 'GET',
60 > 'SCRIPT_NAME': '',
60 > 'SCRIPT_NAME': '',
61 > 'PATH_INFO': '',
61 > 'PATH_INFO': '',
62 > 'QUERY_STRING': '',
62 > 'QUERY_STRING': '',
63 > 'SERVER_NAME': '$LOCALIP',
63 > 'SERVER_NAME': '$LOCALIP',
64 > 'SERVER_PORT': os.environ['HGPORT'],
64 > 'SERVER_PORT': os.environ['HGPORT'],
65 > 'SERVER_PROTOCOL': 'HTTP/1.0'
65 > 'SERVER_PROTOCOL': 'HTTP/1.0'
66 > }
66 > }
67 >
67 >
68 > i = hgweb('.')
68 > i = hgweb(b'.')
69 > for c in i(env, startrsp):
69 > for c in i(env, startrsp):
70 > pass
70 > pass
71 > print('---- ERRORS')
71 > print('---- ERRORS')
72 > print(errors.getvalue())
72 > print(errors.getvalue())
73 > print('---- OS.ENVIRON wsgi variables')
73 > print('---- OS.ENVIRON wsgi variables')
74 > print(sorted([x for x in os.environ if x.startswith('wsgi')]))
74 > print(sorted([x for x in os.environ if x.startswith('wsgi')]))
75 > print('---- request.ENVIRON wsgi variables')
75 > print('---- request.ENVIRON wsgi variables')
76 > with i._obtainrepo() as repo:
76 > with i._obtainrepo() as repo:
77 > print(sorted([x for x in repo.ui.environ if x.startswith('wsgi')]))
77 > print(sorted([x for x in repo.ui.environ if x.startswith(b'wsgi')]))
78 > EOF
78 > EOF
79 $ $PYTHON request.py
79 $ $PYTHON request.py
80 ---- STATUS
80 ---- STATUS
81 200 Script output follows
81 200 Script output follows
82 ---- HEADERS
82 ---- HEADERS
83 [('Content-Type', 'text/html; charset=ascii')]
83 [('Content-Type', 'text/html; charset=ascii')]
84 ---- DATA
84 ---- DATA
85 ---- ERRORS
85 ---- ERRORS
86
86
87 ---- OS.ENVIRON wsgi variables
87 ---- OS.ENVIRON wsgi variables
88 []
88 []
89 ---- request.ENVIRON wsgi variables
89 ---- request.ENVIRON wsgi variables
90 ['wsgi.errors', 'wsgi.input', 'wsgi.multiprocess', 'wsgi.multithread', 'wsgi.run_once', 'wsgi.url_scheme', 'wsgi.version']
90 ['wsgi.errors', 'wsgi.input', 'wsgi.multiprocess', 'wsgi.multithread', 'wsgi.run_once', 'wsgi.url_scheme', 'wsgi.version']
91
91
92 $ cd ..
92 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now