[Yum-devel] [PATCH 2/2] Add new urlgrabber option 'csumfunc'.

Zdeněk Pavlas zpavlas at redhat.com
Fri Jul 1 16:21:30 UTC 2011


Urlgrabber calls this callback with chunks of downloaded data,
so checksums can be calculated without reopening the file.
---
 urlgrabber/grabber.py |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/urlgrabber/grabber.py b/urlgrabber/grabber.py
index 8e5ea3f..4f563b4 100644
--- a/urlgrabber/grabber.py
+++ b/urlgrabber/grabber.py
@@ -259,6 +259,10 @@ GENERAL ARGUMENTS (kwargs)
     What type of name to IP resolving to use, default is to do both IPV4 and
     IPV6.
 
+  self.csumfunc = None
+
+    Optional callback to checksum downloaded data.
+
 
 RETRY RELATED ARGUMENTS
 
@@ -872,6 +876,7 @@ class URLGrabberOptions:
         self.size = None # if we know how big the thing we're getting is going
                          # to be. this is ultimately a MAXIMUM size for the file
         self.max_header_size = 2097152 #2mb seems reasonable for maximum header size
+        self.csumfunc = None # no checksumming
         
     def __repr__(self):
         return self.format()
@@ -1132,6 +1137,8 @@ class PyCurlFileObject(object):
 
             self._amount_read += len(buf)
             self.fo.write(buf)
+            csum = self.opts.csumfunc
+            if csum: csum(buf)
             return len(buf)
         except KeyboardInterrupt:
             return -1
-- 
1.7.4.4



More information about the Yum-devel mailing list