~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/protocol.py

Merge up bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
 
42
42
 
43
43
def _decode_tuple(req_line):
44
 
    if req_line == None or req_line == '':
 
44
    if req_line is None or req_line == '':
45
45
        return None
46
46
    if req_line[-1] != '\n':
47
47
        raise errors.SmartProtocolError("request %r not terminated" % req_line)
89
89
        
90
90
        :param bytes: must be a byte string
91
91
        """
92
 
        assert isinstance(bytes, str)
 
92
        if not isinstance(bytes, str):
 
93
            raise ValueError(bytes)
93
94
        self.in_buffer += bytes
94
95
        if not self.has_dispatched:
95
96
            if '\n' not in self.in_buffer:
133
134
            self.request.accept_body(body_data)
134
135
            if self._body_decoder.finished_reading:
135
136
                self.request.end_of_body()
136
 
                assert self.request.finished_reading, \
137
 
                    "no more body, request not finished"
 
137
                if not self.request.finished_reading:
 
138
                    raise AssertionError("no more body, request not finished")
138
139
            if self.request.response is not None:
139
140
                self._send_response(self.request.response)
140
141
                self.excess_buffer = self.in_buffer
141
142
                self.in_buffer = ''
142
143
            else:
143
 
                assert not self.request.finished_reading, \
144
 
                    "no response and we have finished reading."
 
144
                if self.request.finished_reading:
 
145
                    raise AssertionError(
 
146
                        "no response and we have finished reading.")
145
147
 
146
148
    def _send_response(self, response):
147
149
        """Send a smart server response down the output stream."""
148
 
        assert not self._finished, 'response already sent'
 
150
        if self._finished:
 
151
            raise AssertionError('response already sent')
149
152
        args = response.args
150
153
        body = response.body
151
154
        self._finished = True
153
156
        self._write_success_or_failure_prefix(response)
154
157
        self._write_func(_encode_tuple(args))
155
158
        if body is not None:
156
 
            assert isinstance(body, str), 'body must be a str'
 
159
            if not isinstance(body, str):
 
160
                raise ValueError(body)
157
161
            bytes = self._encode_bulk_data(body)
158
162
            self._write_func(bytes)
159
163
 
202
206
 
203
207
    def _send_response(self, response):
204
208
        """Send a smart server response down the output stream."""
205
 
        assert not self._finished, 'response already sent'
 
209
        if (self._finished):
 
210
            raise AssertionError('response already sent')
206
211
        self._finished = True
207
212
        self._write_protocol_version()
208
213
        self._write_success_or_failure_prefix(response)
209
214
        self._write_func(_encode_tuple(response.args))
210
215
        if response.body is not None:
211
 
            assert isinstance(response.body, str), 'body must be a str'
212
 
            assert response.body_stream is None, (
213
 
                'body_stream and body cannot both be set')
 
216
            if not isinstance(response.body, str):
 
217
                raise AssertionError('body must be a str')
 
218
            if not (response.body_stream is None):
 
219
                raise AssertionError(
 
220
                    'body_stream and body cannot both be set')
214
221
            bytes = self._encode_bulk_data(response.body)
215
222
            self._write_func(bytes)
216
223
        elif response.body_stream is not None: