]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Consolidate httpclient main() functions
authorBen Darnell <ben@bendarnell.com>
Sun, 26 Jun 2011 21:03:51 +0000 (14:03 -0700)
committerBen Darnell <ben@bendarnell.com>
Sun, 26 Jun 2011 21:03:51 +0000 (14:03 -0700)
tornado/curl_httpclient.py
tornado/simple_httpclient.py

index 8b4e97e800d2c4021800834679ed481bbe4c6379..7e8d78f2edf0c56449212031ea9265b7f20fc40e 100644 (file)
@@ -429,4 +429,5 @@ def _curl_debug(debug_type, debug_msg):
         logging.debug('%s %r', debug_types[debug_type], debug_msg)
 
 if __name__ == "__main__":
+    AsyncHTTPClient.configure(CurlAsyncHTTPClient)
     main()
index 5d0886790b3d088485029bf792847bab7e505e1e..d592c580d86a3f592407010da2b31642c63e81c9 100644 (file)
@@ -2,7 +2,7 @@
 from __future__ import with_statement
 
 from tornado.escape import utf8, _unicode, native_str
-from tornado.httpclient import HTTPRequest, HTTPResponse, HTTPError, AsyncHTTPClient
+from tornado.httpclient import HTTPRequest, HTTPResponse, HTTPError, AsyncHTTPClient, main
 from tornado.httputil import HTTPHeaders
 from tornado.ioloop import IOLoop
 from tornado.iostream import IOStream, SSLIOStream
@@ -418,24 +418,6 @@ def match_hostname(cert, hostname):
         raise CertificateError("no appropriate commonName or "
             "subjectAltName fields were found")
 
-def main():
-    from tornado.options import define, options, parse_command_line
-    define("print_headers", type=bool, default=False)
-    define("print_body", type=bool, default=True)
-    define("follow_redirects", type=bool, default=True)
-    args = parse_command_line()
-    client = SimpleAsyncHTTPClient()
-    io_loop = IOLoop.instance()
-    for arg in args:
-        def callback(response):
-            io_loop.stop()
-            response.rethrow()
-            if options.print_headers:
-                print response.headers
-            if options.print_body:
-                print response.body
-        client.fetch(arg, callback, follow_redirects=options.follow_redirects)
-        io_loop.start()
-
 if __name__ == "__main__":
+    AsyncHTTPClient.configure(SimpleAsyncHTTPClient)
     main()