forked from tornadoweb/tornado
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
28 lines (20 loc) · 736 Bytes
/
test.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
import sys
import re
sys.path.insert(0, './')
import tornado.web
class MyHandler(tornado.web.RequestHandler):
def get(self, *args, **kwargs):
print(args, kwargs)
self.write("%s %s"%(args, kwargs))
handlers = [
('/users/(?P<user>\w+)/items/(\w+)/sortby/(?P<sortby>\w+)', MyHandler)
]
url = tornado.web.url('/users/(?P<user>\w+)/items/(\w+)/sortby/(?P<sortby>\w+)', None)
print('reverse', url.reverse('all', user='michael', sortby='name'))
sys.exit()
m = re.match('/users/(?P<user>\w+)/items/(\w+)(?:/sortby/(?P<sort>\w+)|)', '/users/michael/items/all/sortby/name')
print(m.groups())
print(m.groupdict())
app = tornado.web.Application(handlers)
app.listen(8888)
tornado.ioloop.IOLoop.current().start()