Skip to content

Commit

Permalink
Consolidate httpclient main() functions
Browse files Browse the repository at this point in the history
  • Loading branch information
bdarnell committed Jun 26, 2011
1 parent b881ec4 commit 5fb6e39
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 20 deletions.
1 change: 1 addition & 0 deletions tornado/curl_httpclient.py
Expand Up @@ -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()
22 changes: 2 additions & 20 deletions tornado/simple_httpclient.py
Expand Up @@ -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
Expand Down Expand Up @@ -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()

0 comments on commit 5fb6e39

Please sign in to comment.