-
Notifications
You must be signed in to change notification settings - Fork 2
/
WebServerAPI.py~RF1710646.TMP
65 lines (52 loc) · 1.85 KB
/
WebServerAPI.py~RF1710646.TMP
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
import argparse
class HttpServlet(object):
def __init__(self):
parser = argparse.ArgumentParser()
# Get path of data from command line, MINIST_data as default
parser.add_argument('--pipe_name', type=str,
help='parameter pipe_name is required')
parser.add_argument('--data', type=str,
help='parameter data is required')
self.data = eval(parser.parse_args().data)
self.pipe = open(parser.parse_args().pipe_name, 'w')
self.parameters = self.data['params']
self.cookie = self.data['cookie']
self.reqType = self.data['reqType']
self.__run()
self.pipe.close()
def __run(self):
if self.reqType == 'POST':
self._doPOST(self.printToWeb)
else:
self._doGET(self.printToWeb)
def getCookie(self):
return self.cookie
def getParameter(self, param):
if param in self.parameters:
return self.parameters[param]
return None
def getParameters(self):
return self.parameters
def getRequestType(self):
return self.reqType
def setContentType(self, content_type):
self.pipe.write("command:" + "setContentType(" + str(content_type) + ")")
pass
def setCookie(self, set_cookie):
self.pipe.write("command:" + "setCookie(" + str(set_cookie) + ")")
pass
def setResponseCode(self, code):
self.pipe.write("command:" + "setCode(" + str(code) + ")")
pass
def printToWeb(self, text):
if text is None:
text = ''
self.pipe.write("out:" + str(text) + "\n")
pass
def _doGET(self, echo):
# 默认禁止get方法
self.setResponseCode(501)
def _doPOST(self, echo):
# 默认禁止get方法
self.setResponseCode(501)
pass