~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-02-05 11:00:39 UTC
  • mfrom: (3982.1.1 bzr.integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090205110039-w9oelsyvyx160qwy
(vila) Progress bar at socket level for http

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
    # maximum size of read requests -- used to avoid MemoryError issues in recv
68
68
    _max_read_size = 512 * 1024
69
69
 
70
 
    def __init__(self, path, infile, report_activity=None):
 
70
    def __init__(self, path, infile):
71
71
        """Constructor.
72
72
 
73
73
        :param path: File url, for error reports.
74
74
        :param infile: File-like socket set at body start.
75
 
        :param report_activity: A Transport._report_activity function to call
76
 
            as bytes are read.
77
75
        """
78
76
        self._path = path
79
77
        self._file = infile
80
78
        self._boundary = None
81
 
        self._report_activity = report_activity
82
79
        # When using multi parts response, this will be set with the headers
83
80
        # associated with the range currently read.
84
81
        self._headers = None
231
228
            limited = self._start + self._size - self._pos
232
229
            if size >= 0:
233
230
                limited = min(limited, size)
234
 
        osutils.pumpfile(self._file, buffer, limited, self._max_read_size,
235
 
            report_activity=self._report_activity, direction='read')
 
231
        osutils.pumpfile(self._file, buffer, limited, self._max_read_size)
236
232
        data = buffer.getvalue()
237
233
 
238
234
        # Update _pos respecting the data effectively read
281
277
        return self._pos
282
278
 
283
279
 
284
 
def handle_response(url, code, msg, data, report_activity=None):
 
280
def handle_response(url, code, msg, data):
285
281
    """Interpret the code & headers and wrap the provided data in a RangeFile.
286
282
 
287
283
    This is a factory method which returns an appropriate RangeFile based on
295
291
    :return: A file-like object that can seek()+read() the 
296
292
             ranges indicated by the headers.
297
293
    """
298
 
    rfile = RangeFile(url, data, report_activity=report_activity)
 
294
    rfile = RangeFile(url, data)
299
295
    if code == 200:
300
296
        # A whole file
301
297
        size = msg.getheader('content-length', None)