Skip to content

Instantly share code, notes, and snippets.

@prologic
Created September 21, 2014 02:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prologic/c68e4f6cac0ae2cf594c to your computer and use it in GitHub Desktop.
Save prologic/c68e4f6cac0ae2cf594c to your computer and use it in GitHub Desktop.
created by github.com/tr3buchet/gister
#!/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