/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/smart/medium.py

  • Committer: Robert Collins
  • Date: 2008-04-04 00:43:07 UTC
  • mfrom: (3331 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3333.
  • Revision ID: robertc@robertcollins.net-20080404004307-0whomfhm3yal2rvw
Resolve conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
    )
36
36
from bzrlib.smart.protocol import (
37
37
    REQUEST_VERSION_TWO,
 
38
    SmartClientRequestProtocolOne,
38
39
    SmartServerRequestProtocolOne,
39
40
    SmartServerRequestProtocolTwo,
40
41
    )
54
55
    which will typically be a LocalTransport looking at the server's filesystem.
55
56
    """
56
57
 
57
 
    def __init__(self, backing_transport):
 
58
    def __init__(self, backing_transport, root_client_path='/'):
58
59
        """Construct new server.
59
60
 
60
61
        :param backing_transport: Transport for the directory served.
61
62
        """
62
63
        # backing_transport could be passed to serve instead of __init__
63
64
        self.backing_transport = backing_transport
 
65
        self.root_client_path = root_client_path
64
66
        self.finished = False
65
67
 
66
68
    def serve(self):
92
94
            bytes = bytes[len(REQUEST_VERSION_TWO):]
93
95
        else:
94
96
            protocol_class = SmartServerRequestProtocolOne
95
 
        protocol = protocol_class(self.backing_transport, self._write_out)
 
97
        protocol = protocol_class(
 
98
            self.backing_transport, self._write_out, self.root_client_path)
96
99
        protocol.accept_bytes(bytes)
97
100
        return protocol
98
101
 
140
143
 
141
144
class SmartServerSocketStreamMedium(SmartServerStreamMedium):
142
145
 
143
 
    def __init__(self, sock, backing_transport):
 
146
    def __init__(self, sock, backing_transport, root_client_path='/'):
144
147
        """Constructor.
145
148
 
146
149
        :param sock: the socket the server will read from.  It will be put
147
150
            into blocking mode.
148
151
        """
149
 
        SmartServerStreamMedium.__init__(self, backing_transport)
 
152
        SmartServerStreamMedium.__init__(
 
153
            self, backing_transport, root_client_path=root_client_path)
150
154
        self.push_back = ''
151
155
        sock.setblocking(True)
152
156
        self.socket = sock
368
372
class SmartClientMedium(object):
369
373
    """Smart client is a medium for sending smart protocol requests over."""
370
374
 
 
375
    def __init__(self):
 
376
        super(SmartClientMedium, self).__init__()
 
377
        self._protocol_version_error = None
 
378
        self._protocol_version = None
 
379
 
 
380
    def protocol_version(self):
 
381
        """Find out the best protocol version to use."""
 
382
        if self._protocol_version_error is not None:
 
383
            raise self._protocol_version_error
 
384
        if self._protocol_version is None:
 
385
            try:
 
386
                medium_request = self.get_request()
 
387
                # Send a 'hello' request in protocol version one, for maximum
 
388
                # backwards compatibility.
 
389
                client_protocol = SmartClientRequestProtocolOne(medium_request)
 
390
                self._protocol_version = client_protocol.query_version()
 
391
            except errors.SmartProtocolError, e:
 
392
                # Cache the error, just like we would cache a successful
 
393
                # result.
 
394
                self._protocol_version_error = e
 
395
                raise
 
396
        return self._protocol_version
 
397
 
371
398
    def disconnect(self):
372
399
        """If this medium maintains a persistent connection, close it.
373
400
        
385
412
    """
386
413
 
387
414
    def __init__(self):
 
415
        SmartClientMedium.__init__(self)
388
416
        self._current_request = None
389
417
        # Be optimistic: we assume the remote end can accept new remote
390
418
        # requests until we get an error saying otherwise.  (1.2 adds some