1
# Copyright (C) 2006-2010 Canonical Ltd
1
# Copyright (C) 2006 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
20
20
stub functions to allow other decorators to be written easily.
23
from bzrlib import transport
26
class TransportDecorator(transport.Transport):
23
from bzrlib.transport import get_transport, Transport, Server
26
class TransportDecorator(Transport):
27
27
"""A no-change decorator for Transports.
29
29
Subclasses of this are new transports that are based on an
51
51
not_decorated_url = url[len(prefix):]
52
52
if _decorated is None:
53
self._decorated = transport.get_transport(not_decorated_url)
53
self._decorated = get_transport(not_decorated_url)
55
55
self._decorated = _decorated
56
56
super(TransportDecorator, self).__init__(prefix + self._decorated.base)
180
class DecoratorServer(Server):
181
"""Server for the TransportDecorator for testing with.
183
To use this when subclassing TransportDecorator, override override the
184
get_decorator_class method.
187
def setUp(self, server=None):
188
"""See bzrlib.transport.Server.setUp.
190
:server: decorate the urls given by server. If not provided a
191
LocalServer is created.
193
if server is not None:
194
self._made_server = False
195
self._server = server
197
from bzrlib.transport.local import LocalURLServer
198
self._made_server = True
199
self._server = LocalURLServer()
203
"""See bzrlib.transport.Server.tearDown."""
204
if self._made_server:
205
self._server.tearDown()
207
def get_decorator_class(self):
208
"""Return the class of the decorators we should be constructing."""
209
raise NotImplementedError(self.get_decorator_class)
211
def get_url_prefix(self):
212
"""What URL prefix does this decorator produce?"""
213
return self.get_decorator_class()._get_url_prefix()
215
def get_bogus_url(self):
216
"""See bzrlib.transport.Server.get_bogus_url."""
217
return self.get_url_prefix() + self._server.get_bogus_url()
220
"""See bzrlib.transport.Server.get_url."""
221
return self.get_url_prefix() + self._server.get_url()
180
224
def get_test_permutations():
181
225
"""Return the permutations to be used in testing.