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