6 from colubrid
import BaseApplication
, HttpResponse
, execute
7 from colubrid
.server
import StaticExports
8 from paste
import reloader
12 class HyenaApplication(BaseApplication
):
14 def process_request(self
):
15 if self
.request
.environ
['REQUEST_METHOD'] == 'POST':
17 self
.write_json(self
.request
.form
['json'])
18 return HttpResponse('OK')
21 response
= HttpResponse(self
.read_json())
22 response
['Content-Type'] = 'text/plain' # 'text/x-json'
25 def write_json(self
, json
):
26 open('data.json', 'w').write(json
)
29 json
= self
.read_json_from_disk()
30 data
= simplejson
.loads(json
)
31 data
['fortune'] = os
.popen('fortune').read().replace('\n', '<br />')
32 return simplejson
.dumps(data
)
34 def read_json_from_disk(self
):
35 if os
.path
.isfile('data.json'):
36 return open('data.json').read()
39 return simplejson
.dumps({
42 {'text': 'get my sansonite zip repaired under warranty',
44 {'text': 'guide dushyant on django templates',
46 {'text': 'm$ reimbursement',
51 app
= HyenaApplication
52 app
= StaticExports(app
, {
56 if __name__
== '__main__':