~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/decorator.py

  • Committer: Danny van Heumen
  • Date: 2010-03-09 21:42:11 UTC
  • mto: (4634.139.5 2.0)
  • mto: This revision was merged to the branch mainline in revision 5160.
  • Revision ID: danny@dannyvanheumen.nl-20100309214211-iqh42x6qcikgd9p3
Reverted now-useless TODO list.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006 Canonical Ltd
2
2
#
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.
21
21
"""
22
22
 
23
 
from bzrlib import transport
24
 
 
25
 
 
26
 
class TransportDecorator(transport.Transport):
 
23
from bzrlib.transport import get_transport, Transport, Server
 
24
 
 
25
 
 
26
class TransportDecorator(Transport):
27
27
    """A no-change decorator for Transports.
28
28
 
29
29
    Subclasses of this are new transports that are based on an
50
50
                             (url, prefix))
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)
54
54
        else:
55
55
            self._decorated = _decorated
56
56
        super(TransportDecorator, self).__init__(prefix + self._decorated.base)
177
177
            return None
178
178
 
179
179
 
 
180
class DecoratorServer(Server):
 
181
    """Server for the TransportDecorator for testing with.
 
182
 
 
183
    To use this when subclassing TransportDecorator, override override the
 
184
    get_decorator_class method.
 
185
    """
 
186
 
 
187
    def setUp(self, server=None):
 
188
        """See bzrlib.transport.Server.setUp.
 
189
 
 
190
        :server: decorate the urls given by server. If not provided a
 
191
        LocalServer is created.
 
192
        """
 
193
        if server is not None:
 
194
            self._made_server = False
 
195
            self._server = server
 
196
        else:
 
197
            from bzrlib.transport.local import LocalURLServer
 
198
            self._made_server = True
 
199
            self._server = LocalURLServer()
 
200
            self._server.setUp()
 
201
 
 
202
    def tearDown(self):
 
203
        """See bzrlib.transport.Server.tearDown."""
 
204
        if self._made_server:
 
205
            self._server.tearDown()
 
206
 
 
207
    def get_decorator_class(self):
 
208
        """Return the class of the decorators we should be constructing."""
 
209
        raise NotImplementedError(self.get_decorator_class)
 
210
 
 
211
    def get_url_prefix(self):
 
212
        """What URL prefix does this decorator produce?"""
 
213
        return self.get_decorator_class()._get_url_prefix()
 
214
 
 
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()
 
218
 
 
219
    def get_url(self):
 
220
        """See bzrlib.transport.Server.get_url."""
 
221
        return self.get_url_prefix() + self._server.get_url()
 
222
 
 
223
 
180
224
def get_test_permutations():
181
225
    """Return the permutations to be used in testing.
182
226