/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/server.py

Merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
    hooks: An instance of SmartServerHooks.
39
39
    """
40
40
 
41
 
    def __init__(self, backing_transport, host='127.0.0.1', port=0):
 
41
    def __init__(self, backing_transport, host='127.0.0.1', port=0,
 
42
                 root_client_path='/'):
42
43
        """Construct a new server.
43
44
 
44
45
        To actually start it running, call either start_background_thread or
45
46
        serve.
46
47
 
 
48
        :param backing_transport: The transport to serve.
47
49
        :param host: Name of the interface to listen on.
48
50
        :param port: TCP port to listen on, or 0 to allocate a transient port.
 
51
        :param root_client_path: The client path that will correspond to root
 
52
            of backing_transport.
49
53
        """
50
54
        # let connections timeout so that we get a chance to terminate
51
55
        # Keep a reference to the exceptions we want to catch because the socket
63
67
        self.backing_transport = backing_transport
64
68
        self._started = threading.Event()
65
69
        self._stopped = threading.Event()
 
70
        self.root_client_path = root_client_path
66
71
 
67
72
    def serve(self):
68
73
        self._should_terminate = False
134
139
        # propogates to the newly accepted socket.
135
140
        conn.setblocking(True)
136
141
        conn.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
137
 
        handler = SmartServerSocketStreamMedium(conn, self.backing_transport)
 
142
        handler = SmartServerSocketStreamMedium(
 
143
            conn, self.backing_transport, self.root_client_path)
138
144
        connection_thread = threading.Thread(None, handler.serve, name='smart-server-child')
139
145
        connection_thread.setDaemon(True)
140
146
        connection_thread.start()
204
210
 
205
211
    def __init__(self):
206
212
        SmartTCPServer.__init__(self, None)
 
213
        self.client_path_extra = None
207
214
        
208
215
    def get_backing_transport(self, backing_transport_server):
209
216
        """Get a backing transport from a server we are decorating."""
210
217
        return transport.get_transport(backing_transport_server.get_url())
211
218
 
212
 
    def setUp(self, backing_transport_server=None):
213
 
        """Set up server for testing"""
 
219
    def setUp(self, backing_transport_server=None,
 
220
              client_path_extra='/extra/'):
 
221
        """Set up server for testing.
 
222
        
 
223
        :param backing_transport_server: backing server to use.  If not
 
224
            specified, a LocalURLServer at the current working directory will
 
225
            be used.
 
226
        :param client_path_extra: a path segment starting with '/' to append to
 
227
            the root URL for this server.  For instance, a value of '/foo/bar/'
 
228
            will mean the root of the backing transport will be published at a
 
229
            URL like `bzr://127.0.0.1:nnnn/foo/bar/`, rather than
 
230
            `bzr://127.0.0.1:nnnn/`.  Default value is `extra`, so that tests
 
231
            by default will fail unless they do the necessary path translation.
 
232
        """
 
233
        assert client_path_extra.startswith('/')
214
234
        from bzrlib.transport.chroot import ChrootServer
215
235
        if backing_transport_server is None:
216
236
            from bzrlib.transport.local import LocalURLServer
220
240
        self.chroot_server.setUp()
221
241
        self.backing_transport = transport.get_transport(
222
242
            self.chroot_server.get_url())
 
243
        self.root_client_path = self.client_path_extra = client_path_extra
223
244
        self.start_background_thread()
224
245
 
225
246
    def tearDown(self):
226
247
        self.stop_background_thread()
227
248
        self.chroot_server.tearDown()
228
249
 
 
250
    def get_url(self):
 
251
        url = super(SmartTCPServer_for_testing, self).get_url()
 
252
        assert url.endswith('/')
 
253
        return url[:-1] + self.client_path_extra
 
254
 
229
255
    def get_bogus_url(self):
230
256
        """Return a URL which will fail to connect"""
231
257
        return 'bzr://127.0.0.1:1/'