Here is a patch that allows the use of a web server or proxy which doesn't
support byte ranges to access a yum repository. If the server responds to a
byte range request with the entire file, then urlgrabber will discard the bytes
up to the beginning of the byte range.
The original grabber.py script is the one included in the
python-urlgrabber-3.1.0-2 rpm in Enterprise Linux 5 (a.k.a. rhel5 or centos5).
Thanks,
Herbert.
--- grabber.py.orig 2006-12-06 08:35:42.000000000 -0800
+++ grabber.py 2007-07-16 13:11:41.000000000 -0700
@@ -1202,6 +1202,9 @@
# if we have a known range, only try to read that much.
(low, high) = self.opts.range
amount = high - low
+ if self.fo.code == 200:
+ if DEBUG: DEBUG.debug('range request got complete content,
skipping %i bytes', low)
+ self._poor_mans_seek(low)
except TypeError, ValueError:
amount = None
bs = 1024*8
@@ -1225,6 +1228,26 @@
return size
+ def _poor_mans_seek(self,offset):
+ """Seek by calling the wrapped file objects read() method.
+ This is used for file like objects that do not have native
+ seek support. The wrapped objects read() method is called
+ to manually seek to the desired position.
+ offset -- read this number of bytes from the wrapped
+ file object.
+ raise RangeError if we encounter EOF before reaching the
+ specified offset.
+ """
+ pos = 0
+ bufsize = 1024
+ while pos < offset:
+ if (pos + bufsize) > offset:
+ bufsize = offset - pos
+ buf = self.fo.read(bufsize)
+ if len(buf) != bufsize:
+ raise RangeError('Requested Range Not Satisfiable')
+ pos+= bufsize
+
def _fill_buffer(self, amt=None):
"""fill the buffer to contain at least 'amt' bytes by reading
from the underlying file object. If amt is None, then it will
_______________________________________________
Yum-devel mailing list
[email protected]
https://lists.dulug.duke.edu/mailman/listinfo/yum-devel