7
by William Grant
Add trivial WSGI app and test. |
1 |
# Copyright (c) 2011 Canonical Ltd
|
2 |
#
|
|
3 |
# This program is free software: you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU Affero General Public License as published by
|
|
5 |
# the Free Software Foundation, either version 3 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU Affero General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU Affero General Public
|
|
14 |
# License along with this program. If not, see
|
|
15 |
# <http://www.gnu.org/licenses/>.
|
|
16 |
||
17 |
__metaclass__ = type |
|
18 |
||
19 |
import web |
|
20 |
||
8
by William Grant
A little bit of server. |
21 |
from grackle.server.model import CassandraConnection |
22 |
||
23 |
conn = None |
|
24 |
||
7
by William Grant
Add trivial WSGI app and test. |
25 |
|
26 |
class root: |
|
27 |
||
28 |
def GET(self): |
|
29 |
web.header('Content-Type', 'text/plain') |
|
30 |
return ( |
|
31 |
'Service endpoint for Grackle.\n\n' |
|
32 |
'When you want mail that was archived in Grackle, you can get it '
|
|
33 |
'from Grackle') |
|
34 |
||
35 |
||
36 |
class archive: |
|
37 |
||
38 |
def GET(self, name): |
|
39 |
web.header('Content-Type', 'text/plain') |
|
8
by William Grant
A little bit of server. |
40 |
args = web.input() |
41 |
if not getattr(args, 'op', None): |
|
42 |
return self.index(name) |
|
43 |
||
44 |
if args.op == 'get_messages': |
|
45 |
return self.get_messages(name) |
|
46 |
||
47 |
def POST(self, name): |
|
48 |
data = web.data() |
|
49 |
conn.add_message(name, data) |
|
50 |
web.ctx.status = '201 Created' |
|
51 |
||
52 |
def index(self, name): |
|
7
by William Grant
Add trivial WSGI app and test. |
53 |
return ('Service for archive %s.' % name) |
54 |
||
8
by William Grant
A little bit of server. |
55 |
def get_messages(self, name): |
56 |
return repr(conn.get_messages(name)) |
|
57 |
||
7
by William Grant
Add trivial WSGI app and test. |
58 |
|
59 |
urls = ( |
|
60 |
'/', 'root', |
|
61 |
'/archive/(.+)', 'archive', |
|
62 |
)
|
|
63 |
||
64 |
app = web.application(urls, globals(), autoreload=False) |
|
65 |
||
66 |
if __name__ == "__main__": |
|
8
by William Grant
A little bit of server. |
67 |
conn = CassandraConnection('grackle', 'localhost/9160') |
7
by William Grant
Add trivial WSGI app and test. |
68 |
app.run() |