~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/client.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-02-04 12:56:11 UTC
  • mfrom: (3842.3.22 call_with_body_stream)
  • Revision ID: pqm@pqm.ubuntu.com-20090204125611-m7kqmwruvndk7yrv
Add client and server APIs for streamed request bodies.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
            self._headers = dict(headers)
38
38
 
39
39
    def _send_request(self, protocol_version, method, args, body=None,
40
 
                      readv_body=None):
 
40
                      readv_body=None, body_stream=None):
41
41
        encoder, response_handler = self._construct_protocol(
42
42
            protocol_version)
43
43
        encoder.set_headers(self._headers)
45
45
            if readv_body is not None:
46
46
                raise AssertionError(
47
47
                    "body and readv_body are mutually exclusive.")
 
48
            if body_stream is not None:
 
49
                raise AssertionError(
 
50
                    "body and body_stream are mutually exclusive.")
48
51
            encoder.call_with_body_bytes((method, ) + args, body)
49
52
        elif readv_body is not None:
50
 
            encoder.call_with_body_readv_array((method, ) + args,
51
 
                    readv_body)
 
53
            if body_stream is not None:
 
54
                raise AssertionError(
 
55
                    "readv_body and body_stream are mutually exclusive.")
 
56
            encoder.call_with_body_readv_array((method, ) + args, readv_body)
 
57
        elif body_stream is not None:
 
58
            encoder.call_with_body_stream((method, ) + args, body_stream)
52
59
        else:
53
60
            encoder.call(method, *args)
54
61
        return response_handler
61
68
            hook(params)
62
69
            
63
70
    def _call_and_read_response(self, method, args, body=None, readv_body=None,
64
 
            expect_response_body=True):
 
71
            body_stream=None, expect_response_body=True):
65
72
        self._run_call_hooks(method, args, body, readv_body)
66
73
        if self._medium._protocol_version is not None:
67
74
            response_handler = self._send_request(
68
75
                self._medium._protocol_version, method, args, body=body,
69
 
                readv_body=readv_body)
 
76
                readv_body=readv_body, body_stream=body_stream)
70
77
            return (response_handler.read_response_tuple(
71
78
                        expect_body=expect_response_body),
72
79
                    response_handler)
77
84
                    self._medium._remember_remote_is_before((1, 6))
78
85
                response_handler = self._send_request(
79
86
                    protocol_version, method, args, body=body,
80
 
                    readv_body=readv_body)
 
87
                    readv_body=readv_body, body_stream=body_stream)
81
88
                try:
82
89
                    response_tuple = response_handler.read_response_tuple(
83
90
                        expect_body=expect_response_body)
165
172
                args[0], args[1:], readv_body=body, expect_response_body=True)
166
173
        return (response, response_handler)
167
174
 
 
175
    def call_with_body_stream(self, args, stream):
 
176
        response, response_handler = self._call_and_read_response(
 
177
                args[0], args[1:], body_stream=stream,
 
178
                expect_response_body=False)
 
179
        return (response, response_handler)
 
180
 
168
181
    def remote_path_from_transport(self, transport):
169
182
        """Convert transport into a path suitable for using in a request.
170
183