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