~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/server.py

  • Committer: John Arbash Meinel
  • Date: 2007-04-28 15:04:17 UTC
  • mfrom: (2466 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2566.
  • Revision ID: john@arbash-meinel.com-20070428150417-trp3pi0pzd411pu4
[merge] bzr.dev 2466

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import errno
20
20
import socket
21
 
import os
22
21
import threading
23
22
 
24
23
from bzrlib.hooks import Hooks
25
 
from bzrlib.smart import medium
26
24
from bzrlib import (
27
25
    trace,
28
26
    transport,
29
 
    urlutils,
30
27
)
31
28
from bzrlib.smart.medium import SmartServerSocketStreamMedium
32
29
 
33
30
 
34
31
class SmartTCPServer(object):
35
 
    """Listens on a TCP socket and accepts connections from smart clients
 
32
    """Listens on a TCP socket and accepts connections from smart clients.
 
33
 
 
34
    Each connection will be served by a SmartServerSocketStreamMedium running in
 
35
    a thread.
36
36
 
37
37
    hooks: An instance of SmartServerHooks.
38
38
    """
180
180
    """
181
181
 
182
182
    def __init__(self):
183
 
        self._homedir = urlutils.local_path_to_url(os.getcwd())[7:]
184
 
        # The server is set up by default like for ssh access: the client
185
 
        # passes filesystem-absolute paths; therefore the server must look
186
 
        # them up relative to the root directory.  it might be better to act
187
 
        # a public server and have the server rewrite paths into the test
188
 
        # directory.
189
 
        SmartTCPServer.__init__(self,
190
 
            transport.get_transport(urlutils.local_path_to_url('/')))
 
183
        SmartTCPServer.__init__(self, None)
191
184
        
192
185
    def get_backing_transport(self, backing_transport_server):
193
186
        """Get a backing transport from a server we are decorating."""
195
188
 
196
189
    def setUp(self, backing_transport_server=None):
197
190
        """Set up server for testing"""
198
 
        from bzrlib.transport.chroot import TestingChrootServer
 
191
        from bzrlib.transport.chroot import ChrootServer
199
192
        if backing_transport_server is None:
200
193
            from bzrlib.transport.local import LocalURLServer
201
194
            backing_transport_server = LocalURLServer()
202
 
        self.chroot_server = TestingChrootServer()
203
 
        self.chroot_server.setUp(backing_transport_server)
 
195
        self.chroot_server = ChrootServer(
 
196
            self.get_backing_transport(backing_transport_server))
 
197
        self.chroot_server.setUp()
204
198
        self.backing_transport = transport.get_transport(
205
199
            self.chroot_server.get_url())
206
200
        self.start_background_thread()
207
201
 
208
202
    def tearDown(self):
209
203
        self.stop_background_thread()
 
204
        self.chroot_server.tearDown()
210
205
 
211
206
    def get_bogus_url(self):
212
207
        """Return a URL which will fail to connect"""
213
208
        return 'bzr://127.0.0.1:1/'
214
209
 
215
210
 
 
211
class ReadonlySmartTCPServer_for_testing(SmartTCPServer_for_testing):
 
212
    """Get a readonly server for testing."""
 
213
 
 
214
    def get_backing_transport(self, backing_transport_server):
 
215
        """Get a backing transport from a server we are decorating."""
 
216
        url = 'readonly+' + backing_transport_server.get_url()
 
217
        return transport.get_transport(url)
 
218