/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/transport/http/response.py

  • Committer: Jelmer Vernooij
  • Date: 2019-03-04 00:16:27 UTC
  • mfrom: (7293 work)
  • mto: This revision was merged to the branch mainline in revision 7318.
  • Revision ID: jelmer@jelmer.uk-20190304001627-v6u7o6pf97tukhek
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
    Only read() and seek() (forward) are supported.
50
50
 
51
51
    """
 
52
 
52
53
    def __init__(self, path, infile):
53
54
        """Constructor.
54
55
 
70
71
        return self
71
72
 
72
73
    def __exit__(self, exc_type, exc_val, exc_tb):
73
 
        return False # propogate exceptions.
 
74
        return False  # propogate exceptions.
74
75
 
75
76
    def read(self, size=None):
76
77
        """Read size bytes from the current position in the file.
124
125
 
125
126
# multiple_range: boundary_header boundary (content_range_header data boundary)+
126
127
 
 
128
 
127
129
class RangeFile(ResponseFile):
128
130
    """File-like object that allow access to partial available data.
129
131
 
202
204
            # together they make a beautiful bug, which we will be gracious
203
205
            # about here
204
206
            if (self._unquote_boundary(boundary_line) !=
205
 
                b'--' + self._boundary + b'\r\n'):
 
207
                    b'--' + self._boundary + b'\r\n'):
206
208
                raise errors.InvalidHttpResponse(
207
209
                    self._path,
208
210
                    "Expected a boundary (%s) line, got '%s'"
293
295
            -1 to read to EOF.
294
296
        """
295
297
        if (self._size > 0
296
 
            and self._pos == self._start + self._size):
 
298
                and self._pos == self._start + self._size):
297
299
            if size == 0:
298
300
                return b''
299
301
            else:
333
335
            final_pos = start_pos + offset
334
336
        elif whence == 2:
335
337
            if self._size > 0:
336
 
                final_pos = self._start + self._size + offset # offset < 0
 
338
                final_pos = self._start + self._size + offset  # offset < 0
337
339
            else:
338
340
                raise errors.InvalidRange(
339
341
                    self._path, self._pos,
359
361
                cur_limit = self._start + self._size
360
362
 
361
363
        size = final_pos - self._pos
362
 
        if size > 0: # size can be < 0 if we crossed a range boundary
 
364
        if size > 0:  # size can be < 0 if we crossed a range boundary
363
365
            # We don't need the data, just read it and throw it away
364
366
            self._checked_read(size)
365
367
 
414
416
            content_range = msg.get('content-range', None)
415
417
            if content_range is None:
416
418
                raise errors.InvalidHttpResponse(url,
417
 
                    'Missing the Content-Range header in a 206 range response')
 
419
                                                 'Missing the Content-Range header in a 206 range response')
418
420
            rfile.set_range_from_header(content_range)
419
421
    else:
420
422
        raise errors.InvalidHttpResponse(url,
421
423
                                         'Unknown response code %s' % code)
422
424
 
423
425
    return rfile
424