-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
executable file
·34 lines (27 loc) · 904 Bytes
/
server.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
#!/usr/bin/env python
'''
HTTP server starting point.
'''
__author__ = 'Aditya Viswanathan'
__email__ = '[email protected]'
import semantics_pb2 as semantics
from flask import Flask, request, Response
from parser import Parser
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello world'
@app.route('/', methods=['POST'])
def parse():
# TODO(aditya): Check for sane content length before deserializing protobuf.
input_text = semantics.InputText()
input_text.ParseFromString(request.get_data())
parser = Parser()
# Get ParseTree as protobuf.
parse_tree = parser.parse(input_text.text)
resp = Response(parse_tree.SerializeToString(), status=200,
mimetype='application/octet-stream')
return resp
if __name__ == '__main__':
# TODO(aditya): Structured port assignment/discovery.
app.run(debug=True, port=8080)