-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmdtest.py
78 lines (70 loc) · 1.75 KB
/
cmdtest.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
import webapp2
import command
import twig_db
from reply import Reply
FORM = """
<h1>Command test</h1>
<form method="get" action="/test">
<table>
<tr>
<td align="right">raw text:</td>
<td align="left"><input type="text" name="raw" /></td>
</tr>
<tr>
<td align="right">command:</td>
<td align="left"><input type="text" name="cmd" /></td>
</tr>
<tr>
<td align="right">params:</td>
<td align="left"><input type="text" name="params" /></td>
</tr>
<tr>
<td align="center" colspan="2"><input type="submit" value="test"></td>
</tr>
</table>
</form>
"""
class TestHandler(webapp2.RequestHandler):
def get(self):
raw = self.request.get("raw")
cmd = self.request.get("cmd")
params = self.request.get("params")
if params is None:
params = ''
self.response.write(FORM)
account = "aaa@gmail.com"
r = Reply()
if raw is not None and len(raw)>0:
# find active user of this account
uid = twig_db.getActiveUser(account)
isPreCmd, precmd = command.isIdCommand( raw )
if isPreCmd:
cmd_id, raw = precmd
r.h( cmd_id )
isCmd, data = command.parseText( raw )
if isCmd:
# is command
cmd, params = data
command.dispatchCommand(account, cmd, params, r)
if len( r.dump() ) ==0:
r.l("(blank reply)")
else:
# is text
if uid:
command.dispatchCommand(account, 'send', data, r)
else:
r.l("!no active account found")
else:
if cmd is not None and len(cmd)>0:
command.dispatchCommand( account, cmd, params, r )
reply = r.dump()
if len(reply)>0:
self.response.write( ("""
<h1>Result</h1>
value:<br /><textarea readonly="true" rows="20" cols="50">%s</textarea>
""" % reply))
app = webapp2.WSGIApplication(
[
('/test', TestHandler)
],
debug=True)