mercurial/httprangereader.py
author mpm@selenic.com
Thu, 23 Jun 2005 09:22:30 -0800
changeset 439 f81a011fba3d
parent 372 4b0f562c61f4
child 1559 59b3639df0a9
permissions -rw-r--r--
Use __inline instead of inline -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Use __inline instead of inline This should let us compile bdiff.c on the other OS. manifest hash: c1233bb3c7fc060e49dbd2597c122d903797db9e -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCuu/WywK+sNU5EO8RAtqvAKC0d8Kv8He6xNCwmFnvKcff9BT4gACeLq7n 9JDFxYtWMrgjwlShfay1nL4= =GDFt -----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()