Anton Shestakov <engored@ya.ru>, Sat, 12 Jan 2013 19:37:31 +0900
Display port numbers on startup in http-methods-demo.
http-methods-demo/client.py
Permissions: -rwxr-xr-x
import tornado.httpserver import tornado.httpclient from tornado.options import define, options define('port', default=9999, help='run on the given port', type=int) define('server_port', default=8888, help='assume server is running on given port', type=int) def handler_factory(method): class ResultingHandler(tornado.web.RequestHandler): @tornado.web.asynchronous http_client = tornado.httpclient.AsyncHTTPClient() if method in ('POST', 'PUT'): body = 'I make simple_httpclient happy :)' 'http://localhost:%i/' % options.server_port, def callback(self, response): self.finish(response.body) class MethodClient(tornado.web.Application): (r'/(?:get)?/?', handler_factory('GET')), (r'/head/?', handler_factory('HEAD')), (r'/post/?', handler_factory('POST')), (r'/put/?', handler_factory('PUT')), (r'/delete/?', handler_factory('DELETE')), tornado.web.Application.__init__(self, handlers) tornado.options.parse_command_line() http_server = tornado.httpserver.HTTPServer(MethodClient()) http_server.listen(options.port) logging.info('Client is starting on 127.0.0.1:{0}'.format(options.port)) tornado.ioloop.IOLoop.instance().start() if __name__ == '__main__':