-
Notifications
You must be signed in to change notification settings - Fork 0
/
public.py
100 lines (88 loc) · 3.49 KB
/
public.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# -*- coding: utf-8 -*-
# ===============================================================================
#
# Authors: Massimiliano Cannata, Milan Antonovic
#
# Copyright (c) 2015 IST-SUPSI (www.supsi.ch/ist)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# ===============================================================================
import sys
from os import path
sys.path.insert(0, path.abspath(path.dirname(__file__)))
import pprint
import application as app
pp = pprint.PrettyPrinter(indent=4)
def application(environ, start_response):
path = environ['PATH_INFO'].strip()[1:].split("/")
if path[0]=='wa':
return executeWa(environ, start_response)
elif path[0] == 'wns':
return executeWns(environ, start_response)
else:
return executeSos(environ, start_response)
'''
else:
response_body = "istSOS requests not supported for read only users"
start_response('404 Not Found',
[
('Content-Type', 'text/plain; charset=utf-8'),
('Content-Length', str(len(response_body)))
]
)
return [response_body.encode('utf-8')]'''
def executeSos(environ, start_response):
method = str(environ['REQUEST_METHOD']).upper()
# Data RETRIEVAL
if method != "GET":
response_body = '{"success": false, "message": "HTTP method %s not supported", "method": "%s"}' % (method,method)
start_response('200 OK',
[
('Content-Type', 'application/json; charset=utf-8'),
('Content-Length', str(len(response_body)))
]
)
return [response_body.encode('utf-8')]
else:
return app.executeSos(environ, start_response)
def executeWa(environ, start_response):
method = str(environ['REQUEST_METHOD']).upper()
# Data RETRIEVAL
if method != "GET":
response_body = '{"success": false, "message": "HTTP method %s not supported", "method": "%s"}' % (method,method)
start_response('200 OK',
[
('Content-Type', 'application/json; charset=utf-8'),
('Content-Length', str(len(response_body)))
]
)
return [response_body.encode('utf-8')]
else:
return app.executeWa(environ, start_response)
def executeWns(environ, start_response):
method = str(environ['REQUEST_METHOD']).upper()
# Data RETRIEVAL
if method != "GET":
response_body = '{"success": false, "message": "HTTP method %s not supported", "method": "%s"}' % (method,method)
start_response('200 OK',
[
('Content-Type', 'application/json; charset=utf-8'),
('Content-Length', str(len(response_body)))
]
)
return [response_body.encode('utf-8')]
else:
return app.executeWns(environ, start_response)