2
# -*- coding: iso-8859-1 -*-
4
# $Id: test_multi_socket.py,v 1.1 2006/11/10 15:03:05 kjetilja Exp $
8
from cStringIO import StringIO
10
from StringIO import StringIO
15
"http://curl.haxx.se",
16
"http://www.python.org",
17
"http://pycurl.sourceforge.net",
20
# Read list of URIs from file specified on commandline
22
urls = open(sys.argv[1], "rb").readlines()
24
# No file was specified
29
print 'Timer callback msecs:', msecs
32
def socket(event, socket, multi, data):
33
print event, socket, multi, data
34
# multi.assign(socket, timer)
37
m = pycurl.CurlMulti()
38
m.setopt(pycurl.M_PIPELINING, 1)
39
m.setopt(pycurl.M_TIMERFUNCTION, timer)
40
m.setopt(pycurl.M_SOCKETFUNCTION, socket)
44
# save info in standard Python attributes
50
c.setopt(c.URL, c.url)
51
c.setopt(c.WRITEFUNCTION, c.body.write)
55
num_handles = len(m.handles)
58
ret, num_handles = m.socket_all()
59
if ret != pycurl.E_CALL_MULTI_PERFORM:
61
# currently no more I/O is pending, could do something in the meantime
62
# (display a progress bar, etc.)
67
# save info in standard Python attributes
68
c.http_code = c.getinfo(c.HTTP_CODE)
76
data = c.body.getvalue()
78
print "**********", c.url, "**********"
81
print "%-53s http_code %3d, %6d bytes" % (c.url, c.http_code, len(data))