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