/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

  • Committer: Andrew Bennetts
  • Date: 2008-04-02 00:14:00 UTC
  • mfrom: (3324 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3756.
  • Revision ID: andrew.bennetts@canonical.com-20080402001400-r1pqse38i03dl97w
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

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