-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_service.py
More file actions
34 lines (23 loc) · 838 Bytes
/
string_service.py
File metadata and controls
34 lines (23 loc) · 838 Bytes
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
# coding=utf-8
import textwrap
from tornado import httpserver, ioloop, web
from tornado.options import define, options
define('port', default=8000, help='run on the given port', type=int)
class ReverseHandler(web.RequestHandler):
def get(self, input):
self.write(input[::-1])
class WrapperHandler(web.RequestHandler):
def post(self):
text = self.get_argument('text')
width = self.get_argument('width', 40)
self.write(textwrap.fill(text, int(width)))
if __name__ == '__main__':
options.parse_command_line()
app = web.Application(
handlers=[
(r'/reverse/(\w+)', ReverseHandler),
(r'/wrap', WrapperHandler),
], debug=True)
http_server = httpserver.HTTPServer(app)
http_server.listen(options.port)
ioloop.IOLoop.instance().start()