~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2009-01-30 00:49:41 UTC
  • mto: (3982.1.1 bzr.integration)
  • mto: This revision was merged to the branch mainline in revision 3983.
  • Revision ID: v.ladeuil+lp@free.fr-20090130004941-820fpd2ryyo127vv
Add more tests, fix pycurl double handling, revert previous tracking.

* bzrlib/tests/test_http.py:
(PredefinedRequestHandler): Renamed from
PreRecordedRequestHandler.
(PredefinedRequestHandler.handle_one_request): Get the canned
response from the test server directly.
(ActivityServerMixin): Make it a true object and intialize the
attributes in the constructor. Tests can now set the
canned_response attribute before querying the server.
(TestActivity.setUp, TestActivity.tearDown,
TestActivity.get_transport, TestActivity.assertActivitiesMatch):
Extracted from test_get to be able to write other tests.
(TestActivity.test_has, TestActivity.test_readv,
TestActivity.test_post): New tests, all cases should be covered
now.

* bzrlib/transport/http/response.py:
(RangeFile.__init__, RangeFile.read, handle_response): Revert
previous tracking, both http implementations can now report
activity from the socket.

* bzrlib/transport/http/_pycurl.py:
(PyCurlTransport._get_ranged, PyCurlTransport._post): Revert
previous tracking.

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)