~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/readonly.py

  • Committer: abentley
  • Date: 2006-04-20 23:47:53 UTC
  • mfrom: (1681 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1683.
  • Revision ID: abentley@lappy-20060420234753-6a6874b76f09f86d
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Implementation of Transport that adapts another transport to be readonly."""
18
18
 
19
19
from bzrlib.errors import TransportNotPossible
20
 
from bzrlib.transport import get_transport, Transport, Server
21
 
 
22
 
 
23
 
class ReadonlyTransportDecorator(Transport):
 
20
from bzrlib.transport.decorator import TransportDecorator, DecoratorServer
 
21
 
 
22
 
 
23
class ReadonlyTransportDecorator(TransportDecorator):
24
24
    """A decorator that can convert any transport to be readonly.
25
 
    
26
 
    This does not use __getattr__ hacks as we need to ensure that
27
 
    new writable methods are overridden correctly.
 
25
 
 
26
    This is requested via the 'readonly+' prefix to get_transport().
28
27
    """
29
28
 
30
 
    def __init__(self, url, _decorated=None):
31
 
        """Set the 'base' path where files will be stored.
32
 
        
33
 
        _decorated is a private parameter for cloning."""
34
 
        assert url.startswith('readonly+')
35
 
        decorated_url = url[len('readonly+'):]
36
 
        if _decorated is None:
37
 
            self._decorated = get_transport(decorated_url)
38
 
        else:
39
 
            self._decorated = _decorated
40
 
        super(ReadonlyTransportDecorator, self).__init__(
41
 
            "readonly+" + self._decorated.base)
42
 
 
43
 
    def clone(self, offset=None):
44
 
        """See Transport.clone()."""
45
 
        decorated_clone = self._decorated.clone(offset)
46
 
        return ReadonlyTransportDecorator("readonly+" + decorated_clone.base,
47
 
                                          decorated_clone)
48
 
 
49
 
    def abspath(self, relpath):
50
 
        """See Transport.abspath()."""
51
 
        return "readonly+" + self._decorated.abspath(relpath)
52
 
 
53
29
    def append(self, relpath, f):
54
30
        """See Transport.append()."""
55
31
        raise TransportNotPossible('readonly transport')
56
 
 
57
 
    def has(self, relpath):
58
 
        """See Transport.has()."""
59
 
        return self._decorated.has(relpath)
 
32
    
 
33
    @classmethod
 
34
    def _get_url_prefix(self):
 
35
        """Readonly transport decorators are invoked via 'readonly+'"""
 
36
        return 'readonly+'
60
37
 
61
38
    def delete(self, relpath):
62
39
        """See Transport.delete()."""
66
43
        """See Transport.delete_tree()."""
67
44
        raise TransportNotPossible('readonly transport')
68
45
 
69
 
    def get(self, relpath):
70
 
        """See Transport.get()."""
71
 
        return self._decorated.get(relpath)
72
 
 
73
46
    def put(self, relpath, f, mode=None):
74
47
        """See Transport.put()."""
75
48
        raise TransportNotPossible('readonly transport')
82
55
        """See Transport.is_readonly."""
83
56
        return True
84
57
 
85
 
    def listable(self):
86
 
        """See Transport.listable."""
87
 
        return self._decorated.listable()
88
 
 
89
 
    def iter_files_recursive(self):
90
 
        """See Transport.iter_files_recursive()."""
91
 
        return self._decorated.iter_files_recursive()
92
 
    
93
 
    def list_dir(self, relpath):
94
 
        """See Transport.list_dir()."""
95
 
        return self._decorated.list_dir(relpath)
96
 
    
97
58
    def rmdir(self, relpath):
98
59
        """See Transport.rmdir."""
99
60
        raise TransportNotPossible('readonly transport')
100
61
 
101
 
    def should_cache(self):
102
 
        """See Transport.should_cache()."""
103
 
        return self._decorated.should_cache()
104
 
 
105
 
    def stat(self, relpath):
106
 
        """See Transport.stat()."""
107
 
        return self._decorated.stat(relpath)
108
 
 
109
 
    def lock_read(self, relpath):
110
 
        """See Transport.lock_read."""
111
 
        return self._decorated.lock_read(relpath)
112
 
 
113
62
    def lock_write(self, relpath):
114
63
        """See Transport.lock_write."""
115
64
        raise TransportNotPossible('readonly transport')
116
65
 
117
66
 
118
 
class ReadonlyServer(Server):
 
67
class ReadonlyServer(DecoratorServer):
119
68
    """Server for the ReadonlyTransportDecorator for testing with."""
120
69
 
121
 
    def setUp(self, server=None):
122
 
        """See bzrlib.transport.Server.setUp.
123
 
 
124
 
        :server: decorate the urls given by server. If not provided a
125
 
        LocalServer is created.
126
 
        """
127
 
        if server is not None:
128
 
            self._made_server = False
129
 
            self._server = server
130
 
        else:
131
 
            from bzrlib.transport.local import LocalRelpathServer
132
 
            self._made_server = True
133
 
            self._server = LocalRelpathServer()
134
 
            self._server.setUp()
135
 
 
136
 
    def tearDown(self):
137
 
        """See bzrlib.transport.Server.tearDown."""
138
 
        if self._made_server:
139
 
            self._server.tearDown()
140
 
 
141
 
    def get_bogus_url(self):
142
 
        """See bzrlib.transport.Server.get_bogus_url."""
143
 
        return "readonly+" + self._server.get_bogus_url()
144
 
 
145
 
    def get_url(self):
146
 
        """See bzrlib.transport.Server.get_url."""
147
 
        return "readonly+" + self._server.get_url()
 
70
    def get_decorator_class(self):
 
71
        return ReadonlyTransportDecorator
148
72
 
149
73
 
150
74
def get_test_permutations():