| |
- exceptions.IOError(exceptions.EnvironmentError)
-
- RangeError
- RangeableFileObject
- urllib.ftpwrapper
-
- ftpwrapper
- urllib2.BaseHandler
-
- HTTPRangeHandler
-
- HTTPSRangeHandler
- urllib2.FTPHandler(urllib2.BaseHandler)
-
- FTPRangeHandler
- urllib2.FileHandler(urllib2.BaseHandler)
-
- FileRangeHandler
class HTTPRangeHandler(urllib2.BaseHandler) |
|
Handler that enables HTTP Range headers.
This was extremely simple. The Range header is a HTTP feature to
begin with so all this class does is tell urllib2 that the
"206 Partial Content" reponse from the HTTP server is what we
expected.
Example:
import urllib2
import byterange
range_handler = range.HTTPRangeHandler()
opener = urllib2.build_opener(range_handler)
# install it
urllib2.install_opener(opener)
# create Request and set Range header
req = urllib2.Request('http://www.python.org/')
req.header['Range'] = 'bytes=30-50'
f = urllib2.urlopen(req) |
|
Methods defined here:
- http_error_206(self, req, fp, code, msg, hdrs)
- http_error_416(self, req, fp, code, msg, hdrs)
Methods inherited from urllib2.BaseHandler:
- __lt__(self, other)
- add_parent(self, parent)
- close(self)
Data and other attributes inherited from urllib2.BaseHandler:
- handler_order = 500
|
class HTTPSRangeHandler(HTTPRangeHandler) |
|
Range Header support for HTTPS. |
|
- Method resolution order:
- HTTPSRangeHandler
- HTTPRangeHandler
- urllib2.BaseHandler
Methods defined here:
- https_error_206(self, req, fp, code, msg, hdrs)
- https_error_416(self, req, fp, code, msg, hdrs)
Methods inherited from HTTPRangeHandler:
- http_error_206(self, req, fp, code, msg, hdrs)
- http_error_416(self, req, fp, code, msg, hdrs)
Methods inherited from urllib2.BaseHandler:
- __lt__(self, other)
- add_parent(self, parent)
- close(self)
Data and other attributes inherited from urllib2.BaseHandler:
- handler_order = 500
|
class RangeableFileObject |
|
File object wrapper to enable raw range handling.
This was implemented primarilary for handling range
specifications for file:// urls. This object effectively makes
a file object look like it consists only of a range of bytes in
the stream.
Examples:
# expose 10 bytes, starting at byte position 20, from
# /etc/aliases.
>>> fo = RangeableFileObject(file('/etc/passwd', 'r'), (20,30))
# seek seeks within the range (to position 23 in this case)
>>> fo.seek(3)
# tell tells where your at _within the range_ (position 3 in
# this case)
>>> fo.tell()
# read EOFs if an attempt is made to read past the last
# byte in the range. the following will return only 7 bytes.
>>> fo.read(30) |
|
Methods defined here:
- __getattr__(self, name)
- This effectively allows us to wrap at the instance level.
Any attribute not found in _this_ object will be searched for
in self.fo. This includes methods.
- __init__(self, fo, rangetup)
- Create a RangeableFileObject.
fo -- a file like object. only the read() method need be
supported but supporting an optimized seek() is
preferable.
rangetup -- a (firstbyte,lastbyte) tuple specifying the range
to work over.
The file object provided is assumed to be at byte offset 0.
- read(self, size=-1)
- Read within the range.
This method will limit the size read based on the range.
- readline(self, size=-1)
- Read lines within the range.
This method will limit the size read based on the range.
- seek(self, offset, whence=0)
- Seek within the byte range.
Positioning is identical to that described under tell().
- tell(self)
- Return the position within the range.
This is different from fo.seek in that position 0 is the
first byte position of the range tuple. For example, if
this object was created with a range tuple of (500,899),
tell() will return 0 when at byte position 500 of the file.
|
|