74
74
return urllib2.Request.get_method(self)
77
def get_url(url, method=None):
77
def get_url(url, method=None, ranges=None):
79
79
mutter("get_url %s", url)
80
80
manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
191
193
raise TransportError(orig_error=e)
193
def get(self, relpath, decode=False):
194
"""Get the file at the given relative path.
196
:param relpath: The relative path to the file
195
def _get(self, relpath, decode=False, ranges=None):
200
198
path = self.abspath(relpath)
199
return get_url(path, ranges=ranges)
202
200
except urllib2.HTTPError, e:
203
201
mutter('url error code: %s for has url: %r', e.code, path)
204
202
if e.code == 404:
214
212
% (self.abspath(relpath), str(e)),
215
def get(self, relpath, decode=False):
216
"""Get the file at the given relative path.
218
:param relpath: The relative path to the file
220
return self._get(relpath, decode=decode)
222
def readv(self, relpath, offsets):
223
"""Get parts of the file at the given relative path.
225
:offsets: A list of (offset, size) tuples.
226
:return: A list or generator of (offset, data) tuples
228
response = self._get(relpath,
229
ranges=','.join(['%d-%d' % (off, off + size - 1)
230
for off, size in offsets]))
231
if response.code == 206:
232
for off, size in offsets:
233
yield off, response.read(size)
234
elif response.code == 200:
235
fp = StringIO(response.read())
236
for off, size in offsets:
238
yield off, fp.read(size)
217
240
def put(self, relpath, f, mode=None):
218
241
"""Copy the file-like or string object into the location.