mercurial/httprangereader.py
author Thomas Arendsen Hein <thomas@intevation.de>
Sun, 26 Jun 2005 12:04:59 +0100
changeset 476 0a338d506268
parent 372 4b0f562c61f4
child 1559 59b3639df0a9
permissions -rw-r--r--
Really _call_ method revlog.count in revlog.lookup() -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Really _call_ method revlog.count in revlog.lookup() This fixes e.g. 'hg export 398737777' (exists in the mercurial repo). manifest hash: 9de9ad4c40d0746cb3db346a01c373e3b4aba54a -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFCvovbW7P1GVgWeRoRAiyEAJ9gVZZiMGA3YItcWRHeai/9C+dMTgCbBiii QoFaXQ9wZDds8fVVsvENAYw= =msWK -----END PGP SIGNATURE-----

# httprangereader.py - just what it says
#
# Copyright 2005 Matt Mackall <mpm@selenic.com>
#
# This software may be used and distributed according to the terms
# of the GNU General Public License, incorporated herein by reference.

import byterange, urllib2

class httprangereader:
    def __init__(self, url):
        self.url = url
        self.pos = 0
    def seek(self, pos):
        self.pos = pos
    def read(self, bytes=None):
        opener = urllib2.build_opener(byterange.HTTPRangeHandler())
        urllib2.install_opener(opener)
        req = urllib2.Request(self.url)
        end = ''
        if bytes: end = self.pos + bytes
        req.add_header('Range', 'bytes=%d-%s' % (self.pos, end))
        f = urllib2.urlopen(req)
        return f.read()