set svn:keywords property for proper keywords expansion
[plcapi.git] / pycurl / tests / test_getinfo.py
1 #! /usr/bin/env python
2 # -*- coding: iso-8859-1 -*-
3 # vi:ts=4:et
4 # $Id$
5
6 import time
7 import pycurl
8
9
10 ## Callback function invoked when progress information is updated
11 def progress(download_t, download_d, upload_t, upload_d):
12     print "Total to download %d bytes, have %d bytes so far" % \
13           (download_t, download_d)
14
15 url = "http://www.cnn.com"
16
17 print "Starting downloading", url
18 print
19 f = open("body", "wb")
20 h = open("header", "wb")
21 c = pycurl.Curl()
22 c.setopt(c.URL, url)
23 c.setopt(c.WRITEDATA, f)
24 c.setopt(c.NOPROGRESS, 0)
25 c.setopt(c.PROGRESSFUNCTION, progress)
26 c.setopt(c.FOLLOWLOCATION, 1)
27 c.setopt(c.MAXREDIRS, 5)
28 c.setopt(c.WRITEHEADER, h)
29 c.setopt(c.OPT_FILETIME, 1)
30 c.perform()
31
32 print
33 print "HTTP-code:", c.getinfo(c.HTTP_CODE)
34 print "Total-time:", c.getinfo(c.TOTAL_TIME)
35 print "Download speed: %.2f bytes/second" % c.getinfo(c.SPEED_DOWNLOAD)
36 print "Document size: %d bytes" % c.getinfo(c.SIZE_DOWNLOAD)
37 print "Effective URL:", c.getinfo(c.EFFECTIVE_URL)
38 print "Content-type:", c.getinfo(c.CONTENT_TYPE)
39 print "Namelookup-time:", c.getinfo(c.NAMELOOKUP_TIME)
40 print "Redirect-time:", c.getinfo(c.REDIRECT_TIME)
41 print "Redirect-count:", c.getinfo(c.REDIRECT_COUNT)
42 epoch = c.getinfo(c.INFO_FILETIME)
43 print "Filetime: %d (%s)" % (epoch, time.ctime(epoch))
44 print
45 print "Header is in file 'header', body is in file 'body'"
46
47 c.close()
48 f.close()
49 h.close()