Mercurial > hg > mercurial-crew-with-dirclash
comparison tests/test-non-interactive-wsgi @ 5337:8c5ef3b87cb1
Don't try to determine interactivity if ui() called with interactive=False.
WSGI applications are not supposed to refer to sys.stdin. In ed6df6b1c29a,
hgweb and hgwebdir were fixed to pass interactive=False to their ui()'s, but
sys.stdin.isatty() was still called by the ui objects. This change makes sure
only the ui.fixconfig() method will call ui.isatty() (by making the
ui._readline() method, which is currently only called from ui.prompt(),
private). ui.fixconfig() is changed to let config files override the initial
interactivity setting, but not check isatty() if interactive=False was
specified in the creation of the ui.
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Tue, 25 Sep 2007 19:05:34 +0200 |
parents | |
children | e3a0c092b4e2 |
comparison
equal
deleted
inserted
replaced
5336:24de027551c1 | 5337:8c5ef3b87cb1 |
---|---|
1 #!/bin/sh | |
2 | |
3 mkdir repo | |
4 cd repo | |
5 hg init | |
6 echo foo > bar | |
7 hg add bar | |
8 hg commit -m "test" -d "0 0" | |
9 hg tip | |
10 | |
11 cat > request.py <<EOF | |
12 from mercurial import dispatch | |
13 from mercurial.hgweb.hgweb_mod import hgweb | |
14 from mercurial.hgweb.request import _wsgirequest | |
15 from mercurial.ui import ui | |
16 from mercurial import hg | |
17 from StringIO import StringIO | |
18 import sys | |
19 | |
20 class FileLike(object): | |
21 def __init__(self, real): | |
22 self.real = real | |
23 def fileno(self): | |
24 print >> sys.__stdout__, 'FILENO' | |
25 return self.real.fileno() | |
26 def read(self): | |
27 print >> sys.__stdout__, 'READ' | |
28 return self.real.read() | |
29 def readline(self): | |
30 print >> sys.__stdout__, 'READLINE' | |
31 return self.real.readline() | |
32 def isatty(self): | |
33 print >> sys.__stdout__, 'ISATTY' | |
34 return False | |
35 | |
36 sys.stdin = FileLike(sys.stdin) | |
37 errors = StringIO() | |
38 input = StringIO() | |
39 output = StringIO() | |
40 | |
41 def startrsp(headers, data): | |
42 print '---- HEADERS' | |
43 print headers | |
44 print '---- DATA' | |
45 print data | |
46 return output.write | |
47 | |
48 env = { | |
49 'wsgi.version': (1, 0), | |
50 'wsgi.url_scheme': 'http', | |
51 'wsgi.errors': errors, | |
52 'wsgi.input': input, | |
53 'wsgi.multithread': False, | |
54 'wsgi.multiprocess': False, | |
55 'wsgi.run_once': False, | |
56 'REQUEST_METHOD': 'GET', | |
57 'SCRIPT_NAME': '', | |
58 'PATH_INFO': '', | |
59 'QUERY_STRING': '', | |
60 'SERVER_NAME': '127.0.0.1', | |
61 'SERVER_PORT': '20059', | |
62 'SERVER_PROTOCOL': 'HTTP/1.0' | |
63 } | |
64 | |
65 _wsgirequest(hgweb('.'), env, startrsp) | |
66 print '---- ERRORS' | |
67 print errors.getvalue() | |
68 EOF | |
69 | |
70 python request.py |