~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/message.py

  • Committer: Vincent Ladeuil
  • Date: 2010-02-10 15:46:03 UTC
  • mfrom: (4985.3.21 update)
  • mto: This revision was merged to the branch mainline in revision 5021.
  • Revision ID: v.ladeuil+lp@free.fr-20100210154603-k4no1gvfuqpzrw7p
Update performs two merges in a more logical order but stop on conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
import collections
18
18
from cStringIO import StringIO
36
36
 
37
37
    def headers_received(self, headers):
38
38
        """Called when message headers are received.
39
 
        
 
39
 
40
40
        This default implementation just stores them in self.headers.
41
41
        """
42
42
        self.headers = headers
67
67
 
68
68
    def protocol_error(self, exception):
69
69
        """Called when there is a protocol decoding error.
70
 
        
 
70
 
71
71
        The default implementation just re-raises the exception.
72
72
        """
73
73
        raise
74
 
    
 
74
 
75
75
    def end_received(self):
76
76
        """Called when the end of the message is received."""
77
77
        # No-op by default.
134
134
 
135
135
    def _args_received(self, args):
136
136
        self.expecting = 'body'
137
 
        self.request_handler.dispatch_command(args[0], args[1:])
 
137
        self.request_handler.args_received(args)
138
138
        if self.request_handler.finished_reading:
139
139
            self._response_sent = True
140
140
            self.responder.send_response(self.request_handler.response)
172
172
 
173
173
    def read_response_tuple(self, expect_body=False):
174
174
        """Reads and returns the response tuple for the current request.
175
 
        
 
175
 
176
176
        :keyword expect_body: a boolean indicating if a body is expected in the
177
177
            response.  Some protocol versions needs this information to know
178
178
            when a response is finished.  If False, read_body_bytes should
283
283
                    self._protocol_decoder._get_in_buffer()[:10],
284
284
                    self._protocol_decoder.state_accept.__name__)
285
285
            raise errors.ConnectionReset(
286
 
                "please check connectivity and permissions",
287
 
                "(and try -Dhpss if further diagnosis is required)")
 
286
                "Unexpected end of message. "
 
287
                "Please check connectivity and permissions, and report a bug "
 
288
                "if problems persist.")
288
289
        self._protocol_decoder.accept_bytes(bytes)
289
290
 
290
291
    def protocol_error(self, exception):
292
293
        self.finished_reading = True
293
294
        self._medium_request.finished_reading()
294
295
        raise
295
 
        
 
296
 
296
297
    def read_response_tuple(self, expect_body=False):
297
298
        """Read a response tuple from the wire."""
298
299
        self._wait_for_response_args()
307
308
 
308
309
    def read_body_bytes(self, count=-1):
309
310
        """Read bytes from the body, decoding into a byte stream.
310
 
        
311
 
        We read all bytes at once to ensure we've checked the trailer for 
 
311
 
 
312
        We read all bytes at once to ensure we've checked the trailer for
312
313
        errors, and then feed the buffer back as read_body_bytes is called.
313
314
 
314
315
        Like the builtin file.read in Python, a count of -1 (the default) means
329
330
        while not self.finished_reading:
330
331
            while self._bytes_parts:
331
332
                bytes_part = self._bytes_parts.popleft()
332
 
                if 'hpss' in debug.debug_flags:
 
333
                if 'hpssdetail' in debug.debug_flags:
333
334
                    mutter('              %d byte part read', len(bytes_part))
334
335
                yield bytes_part
335
336
            self._read_more()
352
353
        raise errors.LockContention('(remote lock)')
353
354
    elif error_name == 'LockFailed':
354
355
        raise errors.LockFailed(*error_args[:2])
 
356
    elif error_name == 'FileExists':
 
357
        raise errors.FileExists(error_args[0])
 
358
    elif error_name == 'NoSuchFile':
 
359
        raise errors.NoSuchFile(error_args[0])
355
360
    else:
356
361
        raise errors.ErrorFromSmartServer(error_tuple)