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