summaryrefslogtreecommitdiffhomepage
path: root/test/python/ns_inspect/wsgi.py
blob: fa1222e4fe7b13074514aeeb1ff4129cc39ff187 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import json
import os

try:
    # Python 3
    from urllib.parse import parse_qs
except ImportError:
    # Python 2
    from urlparse import parse_qs


def application(environ, start_response):
    ret = {
        'FileExists': False,
    }

    d = parse_qs(environ['QUERY_STRING'])

    ret['FileExists'] = os.path.exists(d.get('path')[0])

    out = json.dumps(ret)

    start_response(
        '200',
        [
            ('Content-Type', 'application/json'),
            ('Content-Length', str(len(out))),
        ],
    )

    return out.encode('utf-8')