[Python-Dev] Adding resume (206) support to urllib(2)

Fredrik Lundh fredrik at pythonware.com
Wed Dec 13 07:17:10 CET 2006


Martin v. Löwis wrote:

>> I've just been putting together a podcasting doodad and have included resuming 
>> support in it. Is this something that's already in the pipeline or should I 
>> abstract it out to urllib and submit a patch?
> 
> Not sure where you got the impression that 206 is "resume"; in my copy
> of the spec it's "partial content", and you must have put a Range:
> header into the request to get that in the first place.
> 
> If I had to use that, I'd implement it right on top of httplib, and
> wouldn't bother with urllib*: this is really specific to http, and
> adding it to urllib would break the abstraction.

given that urllib2 already supports partial requests, I'm not sure I see 
the point of reimplementing this on top of httplib.  an example:

   import urllib2

   request = urllib2.Request("http://www.pythonware.com/daily/index.htm")
   request.add_header("range", "bytes=0-999")

   http_file = urllib2.urlopen(request)

   print http_file.headers["content-range"]
   print len(http_file.read())

this prints:

   bytes 0-999/245105
   1000

</F>



More information about the Python-Dev mailing list