Created
September 21, 2014 02:10
-
-
Save prologic/c68e4f6cac0ae2cf594c to your computer and use it in GitHub Desktop.
created by github.com/tr3buchet/gister
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
"""wget Example | |
A basic wget-like clone that asynchronously connections | |
a remote web server requesting a given resource. | |
""" | |
from __future__ import print_function | |
from circuits import Component, Manager | |
from circuits.web.client import Client, request | |
class WebClient(Component): | |
def init(self, url, **kwargs): | |
self.url = url | |
Client(channel=self.channel).register(self) | |
def ready(self, *args): | |
self.fire(request("GET", self.url)) | |
def response(self, response): | |
print("{0:d} {1:s}".format(response.status, response.reason)) | |
print( | |
"\n".join( | |
"{0:s}: {1:s}".format(k, v) | |
for k, v in response.headers.items() | |
) | |
) | |
print(response.read()) | |
m = Manager() | |
WebClient("http://www.google.com", channel="c1").register(m) | |
WebClient("http://www.yahoo.com", channel="c2").register(m) | |
m.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment