equal
deleted
inserted
replaced
30 class HTTPRangeHandler(urllib2.BaseHandler): |
30 class HTTPRangeHandler(urllib2.BaseHandler): |
31 """Handler that enables HTTP Range headers. |
31 """Handler that enables HTTP Range headers. |
32 |
32 |
33 This was extremely simple. The Range header is a HTTP feature to |
33 This was extremely simple. The Range header is a HTTP feature to |
34 begin with so all this class does is tell urllib2 that the |
34 begin with so all this class does is tell urllib2 that the |
35 "206 Partial Content" reponse from the HTTP server is what we |
35 "206 Partial Content" response from the HTTP server is what we |
36 expected. |
36 expected. |
37 |
37 |
38 Example: |
38 Example: |
39 import urllib2 |
39 import urllib2 |
40 import byterange |
40 import byterange |
62 # HTTP's Range Not Satisfiable error |
62 # HTTP's Range Not Satisfiable error |
63 raise RangeError('Requested Range Not Satisfiable') |
63 raise RangeError('Requested Range Not Satisfiable') |
64 |
64 |
65 class RangeableFileObject(object): |
65 class RangeableFileObject(object): |
66 """File object wrapper to enable raw range handling. |
66 """File object wrapper to enable raw range handling. |
67 This was implemented primarilary for handling range |
67 This was implemented primarily for handling range |
68 specifications for file:// urls. This object effectively makes |
68 specifications for file:// urls. This object effectively makes |
69 a file object look like it consists only of a range of bytes in |
69 a file object look like it consists only of a range of bytes in |
70 the stream. |
70 the stream. |
71 |
71 |
72 Examples: |
72 Examples: |
429 def range_tuple_normalize(range_tup): |
429 def range_tuple_normalize(range_tup): |
430 """Normalize a (first_byte,last_byte) range tuple. |
430 """Normalize a (first_byte,last_byte) range tuple. |
431 Return a tuple whose first element is guaranteed to be an int |
431 Return a tuple whose first element is guaranteed to be an int |
432 and whose second element will be '' (meaning: the last byte) or |
432 and whose second element will be '' (meaning: the last byte) or |
433 an int. Finally, return None if the normalized tuple == (0,'') |
433 an int. Finally, return None if the normalized tuple == (0,'') |
434 as that is equivelant to retrieving the entire file. |
434 as that is equivalent to retrieving the entire file. |
435 """ |
435 """ |
436 if range_tup is None: |
436 if range_tup is None: |
437 return None |
437 return None |
438 # handle first byte |
438 # handle first byte |
439 fb = range_tup[0] |
439 fb = range_tup[0] |