24
23
from bzrlib.hooks import Hooks
25
from bzrlib.smart import medium
26
24
from bzrlib import (
31
28
from bzrlib.smart.medium import SmartServerSocketStreamMedium
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.
34
Each connection will be served by a SmartServerSocketStreamMedium running in
37
37
hooks: An instance of SmartServerHooks.
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
189
SmartTCPServer.__init__(self,
190
transport.get_transport(urlutils.local_path_to_url('/')))
183
SmartTCPServer.__init__(self, None)
192
185
def get_backing_transport(self, backing_transport_server):
193
186
"""Get a backing transport from a server we are decorating."""
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()
208
202
def tearDown(self):
209
203
self.stop_background_thread()
204
self.chroot_server.tearDown()
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/'
211
class ReadonlySmartTCPServer_for_testing(SmartTCPServer_for_testing):
212
"""Get a readonly server for testing."""
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)