~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/protocol.py

Merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
73
73
class SmartServerRequestProtocolOne(SmartProtocolBase):
74
74
    """Server-side encoding and decoding logic for smart version 1."""
75
75
    
76
 
    def __init__(self, backing_transport, write_func):
 
76
    def __init__(self, backing_transport, write_func, root_client_path='/'):
77
77
        self._backing_transport = backing_transport
 
78
        self._root_client_path = root_client_path
78
79
        self.excess_buffer = ''
79
80
        self._finished = False
80
81
        self.in_buffer = ''
100
101
                first_line += '\n'
101
102
                req_args = _decode_tuple(first_line)
102
103
                self.request = request.SmartServerRequestHandler(
103
 
                    self._backing_transport, commands=request.request_handlers)
 
104
                    self._backing_transport, commands=request.request_handlers,
 
105
                    root_client_path=self._root_client_path)
104
106
                self.request.dispatch_command(req_args[0], req_args[1:])
105
107
                if self.request.finished_reading:
106
108
                    # trivial request
467
469
        self._request = request
468
470
        self._body_buffer = None
469
471
        self._request_start_time = None
 
472
        self._last_verb = None
470
473
 
471
474
    def call(self, *args):
472
475
        if 'hpss' in debug.debug_flags:
476
479
            self._request_start_time = time.time()
477
480
        self._write_args(args)
478
481
        self._request.finished_writing()
 
482
        self._last_verb = args[0]
479
483
 
480
484
    def call_with_body_bytes(self, args, body):
481
485
        """Make a remote call of args with body bytes 'body'.
494
498
        bytes = self._encode_bulk_data(body)
495
499
        self._request.accept_bytes(bytes)
496
500
        self._request.finished_writing()
 
501
        self._last_verb = args[0]
497
502
 
498
503
    def call_with_body_readv_array(self, args, body):
499
504
        """Make a remote call with a readv array.
513
518
        self._request.finished_writing()
514
519
        if 'hpss' in debug.debug_flags:
515
520
            mutter('              %d bytes in readv request', len(readv_bytes))
 
521
        self._last_verb = args[0]
516
522
 
517
523
    def cancel_read_body(self):
518
524
        """After expecting a body, a response code may indicate one otherwise.
537
543
                self._request_start_time = None
538
544
            else:
539
545
                mutter('   result:   %s', repr(result)[1:-1])
 
546
        self._response_is_unknown_method(result)
540
547
        if not expect_body:
541
548
            self._request.finished_reading()
542
549
        return result
543
550
 
 
551
    def _response_is_unknown_method(self, result_tuple):
 
552
        """Raise UnexpectedSmartServerResponse if the response is an 'unknonwn
 
553
        method' response to the request.
 
554
        
 
555
        :param response: The response from a smart client call_expecting_body
 
556
            call.
 
557
        :param verb: The verb used in that call.
 
558
        :raises: UnexpectedSmartServerResponse
 
559
        """
 
560
        if (result_tuple == ('error', "Generic bzr smart protocol error: "
 
561
                "bad request '%s'" % self._last_verb) or
 
562
              result_tuple == ('error', "Generic bzr smart protocol error: "
 
563
                "bad request u'%s'" % self._last_verb)):
 
564
            # The response will have no body, so we've finished reading.
 
565
            self._request.finished_reading()
 
566
            raise errors.UnknownSmartMethod(self._last_verb)
 
567
        
544
568
    def read_body_bytes(self, count=-1):
545
569
        """Read bytes from the body, decoding into a byte stream.
546
570