@@ -23,16 +23,19 @@ class BaseHandler(tornado.web.RequestHandler):
2323 def compute_etag (self ):
2424 return None
2525
26+
2627class JsonSerializeTestHandler (BaseHandler ):
2728 def get (self ):
28- obj = dict ( message = " Hello, World!")
29+ obj = { " message" : " Hello, World!", }
2930 self .write (obj )
3031
32+
3133class PlaintextHandler (BaseHandler ):
3234 def get (self ):
3335 self .set_header ('Content-Type' , 'text/plain' )
3436 self .write (b"Hello, World!" )
3537
38+
3639class QueryTestHandler (BaseHandler ):
3740 @gen .coroutine
3841 def get (self ):
@@ -42,26 +45,26 @@ def get(self):
4245 random_id = random .randint (1 , 10000 )
4346 world = yield motor .Op (db .World .find_one , random_id )
4447 # Get first postion on arguments, and so first postion in mongo return
45- world ['id' ] = world .pop ('_id' )
48+ world ['id' ] = str ( world .pop ('_id' ) )
4649 response = json .dumps (world )
4750 else :
48- worlds = []
49- for i in xrange (int (queries )):
50- random_id = random .randint (1 , 10000 )
51- world = yield motor .Op (db .World .find_one , random_id )
51+ worlds = yield [motor .Op (db .World .find_one , random .randint (1 , 10000 ))
52+ for _ in xrange (queries )]
53+ for world in worlds :
5254 # Get first postion on arguments, and so first postion in mongo return
53- world ['id' ] = world .pop ('_id' )
54- worlds .append (world )
55+ world ['id' ] = str (world .pop ('_id' ))
5556 response = json .dumps (worlds )
5657 self .set_header ("Content-Type" , "application/json; charset=UTF-8" )
5758 self .write (response )
5859
60+
5961application = tornado .web .Application ([
6062 (r"/json" , JsonSerializeTestHandler ),
6163 (r"/plaintext" , PlaintextHandler ),
6264 (r"/db" , QueryTestHandler ),
6365])
6466
67+
6568if __name__ == "__main__" :
6669 tornado .options .parse_command_line ()
6770 server = tornado .httpserver .HTTPServer (application )
0 commit comments