-
Notifications
You must be signed in to change notification settings - Fork 2
/
echo.py
30 lines (24 loc) · 824 Bytes
/
echo.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
#!/usr/bin/env python
from cocaine.logger import Logger
from cocaine.worker import Worker
import msgpack
DEFAULT_HEADERS = [('Content-type', 'text/plain')]
log = Logger()
def echo(request, response):
log.info("entire echo()")
yield request.read()
log.info("do echo().request.read()")
response.write(msgpack.packb((200, DEFAULT_HEADERS)))
log.info("do echo().response.write() with code and headers")
response.write("echo")
log.info("do echo().response.write(echo), next echo().response.close()")
response.close()
log.info("do echo().response.close() and exit now")
def main():
log.info("entire main()")
w = Worker()
log.info("do main().Worker()")
w.run({"http": echo})
if __name__ == "__main__":
log.info("start echo application worker. prior main()")
main()