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