xref: /unit/test/python/ns_inspect/wsgi.py (revision 1490:cecf6b11a1e3)
1import json
2import os
3
4try:
5    # Python 3
6    from urllib.parse import parse_qs
7except ImportError:
8    # Python 2
9    from urlparse import parse_qs
10
11
12def application(environ, start_response):
13    ret = {
14        'FileExists': False,
15    }
16
17    d = parse_qs(environ['QUERY_STRING'])
18
19    ret['FileExists'] = os.path.exists(d.get('path')[0])
20
21    out = json.dumps(ret)
22
23    start_response(
24        '200',
25        [
26            ('Content-Type', 'application/json'),
27            ('Content-Length', str(len(out))),
28        ],
29    )
30
31    return out.encode('utf-8')
32