~jelmer/ubuntu/maverick/bzr/2.2.5

« back to all changes in this revision

Viewing changes to bzrlib/transport/decorator.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2009-03-10 14:11:59 UTC
  • mfrom: (1.2.1 upstream) (3.1.68 jaunty)
  • Revision ID: james.westby@ubuntu.com-20090310141159-lwzzo5c1fwrtzgj4
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Implementation of Transport that decorates another transport.
18
18
 
19
 
This does not change the transport behaviour at all, but provides all the 
 
19
This does not change the transport behaviour at all, but provides all the
20
20
stub functions to allow other decorators to be written easily.
21
21
"""
22
22
 
27
27
    """A no-change decorator for Transports.
28
28
 
29
29
    Subclasses of this are new transports that are based on an
30
 
    underlying transport and can override or intercept some 
31
 
    behavior.  For example ReadonlyTransportDecorator prevents 
32
 
    all write attempts, and FakeNFSTransportDecorator simulates 
 
30
    underlying transport and can override or intercept some
 
31
    behavior.  For example ReadonlyTransportDecorator prevents
 
32
    all write attempts, and FakeNFSTransportDecorator simulates
33
33
    some NFS quirks.
34
34
 
35
35
    This decorator class is not directly usable as a decorator:
39
39
 
40
40
    def __init__(self, url, _decorated=None, _from_transport=None):
41
41
        """Set the 'base' path of the transport.
42
 
        
 
42
 
43
43
        :param _decorated: A private parameter for cloning.
44
44
        :param _from_transport: Is available for subclasses that
45
45
            need to share state across clones.
46
46
        """
47
47
        prefix = self._get_url_prefix()
48
48
        if not url.startswith(prefix):
49
 
            raise ValueError(
50
 
                "url %r doesn't start with decorator prefix %r" % \
51
 
                (url, prefix))
52
 
        decorated_url = url[len(prefix):]
 
49
            raise ValueError("url %r doesn't start with decorator prefix %r" %
 
50
                             (url, prefix))
 
51
        not_decorated_url = url[len(prefix):]
53
52
        if _decorated is None:
54
 
            self._decorated = get_transport(decorated_url)
 
53
            self._decorated = get_transport(not_decorated_url)
55
54
        else:
56
55
            self._decorated = _decorated
57
 
        super(TransportDecorator, self).__init__(
58
 
            prefix + self._decorated.base)
 
56
        super(TransportDecorator, self).__init__(prefix + self._decorated.base)
59
57
 
60
58
    def abspath(self, relpath):
61
59
        """See Transport.abspath()."""
126
124
    def put_file(self, relpath, f, mode=None):
127
125
        """See Transport.put_file()."""
128
126
        return self._decorated.put_file(relpath, f, mode)
129
 
    
 
127
 
130
128
    def put_bytes(self, relpath, bytes, mode=None):
131
129
        """See Transport.put_bytes()."""
132
130
        return self._decorated.put_bytes(relpath, bytes, mode)
138
136
    def iter_files_recursive(self):
139
137
        """See Transport.iter_files_recursive()."""
140
138
        return self._decorated.iter_files_recursive()
141
 
    
 
139
 
142
140
    def list_dir(self, relpath):
143
141
        """See Transport.list_dir()."""
144
142
        return self._decorated.list_dir(relpath)
153
151
 
154
152
    def rename(self, rel_from, rel_to):
155
153
        return self._decorated.rename(rel_from, rel_to)
156
 
    
 
154
 
157
155
    def rmdir(self, relpath):
158
156
        """See Transport.rmdir."""
159
157
        return self._decorated.rmdir(relpath)
170
168
        """See Transport.lock_write."""
171
169
        return self._decorated.lock_write(relpath)
172
170
 
 
171
    def _redirected_to(self, source, target):
 
172
        redirected = self._decorated._redirected_to(source, target)
 
173
        if redirected is not None:
 
174
            return self.__class__(self._get_url_prefix() + redirected.base,
 
175
                                  redirected)
 
176
        else:
 
177
            return None
 
178
 
173
179
 
174
180
class DecoratorServer(Server):
175
181
    """Server for the TransportDecorator for testing with.
176
 
    
 
182
 
177
183
    To use this when subclassing TransportDecorator, override override the
178
184
    get_decorator_class method.
179
185
    """
217
223
 
218
224
def get_test_permutations():
219
225
    """Return the permutations to be used in testing.
220
 
    
 
226
 
221
227
    The Decorator class is not directly usable, and testing it would not have
222
228
    any benefit - its the concrete classes which need to be tested.
223
229
    """