/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4763.2.4 by John Arbash Meinel
merge bzr.2.1 in preparation for NEWS entry.
1
# Copyright (C) 2006-2010 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
16
17
"""Implementation of Transport that decorates another transport.
18
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
19
This does not change the transport behaviour at all, but provides all the
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
20
stub functions to allow other decorators to be written easily.
21
"""
22
6379.6.7 by Jelmer Vernooij
Move importing from future until after doc string, otherwise the doc string will disappear.
23
from __future__ import absolute_import
24
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
25
from bzrlib import transport
26
27
28
class TransportDecorator(transport.Transport):
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
29
    """A no-change decorator for Transports.
1634.1.1 by Robert Collins
Merge NFS LockDir support (Aaron Bentley, Robert Collins).
30
31
    Subclasses of this are new transports that are based on an
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
32
    underlying transport and can override or intercept some
33
    behavior.  For example ReadonlyTransportDecorator prevents
34
    all write attempts, and FakeNFSTransportDecorator simulates
1634.1.1 by Robert Collins
Merge NFS LockDir support (Aaron Bentley, Robert Collins).
35
    some NFS quirks.
36
37
    This decorator class is not directly usable as a decorator:
38
    you must use a subclass which has overridden the _get_url_prefix() class
39
    method to return the url prefix for the subclass.
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
40
    """
41
2745.5.3 by Robert Collins
* Move transport logging into a new transport class
42
    def __init__(self, url, _decorated=None, _from_transport=None):
43
        """Set the 'base' path of the transport.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
44
2745.5.3 by Robert Collins
* Move transport logging into a new transport class
45
        :param _decorated: A private parameter for cloning.
46
        :param _from_transport: Is available for subclasses that
47
            need to share state across clones.
48
        """
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
49
        prefix = self._get_url_prefix()
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
50
        if not url.startswith(prefix):
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
51
            raise ValueError("url %r doesn't start with decorator prefix %r" %
52
                             (url, prefix))
53
        not_decorated_url = url[len(prefix):]
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
54
        if _decorated is None:
6083.1.1 by Jelmer Vernooij
Use get_transport_from_{url,path} in more places.
55
            self._decorated = transport.get_transport(
56
                not_decorated_url)
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
57
        else:
58
            self._decorated = _decorated
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
59
        super(TransportDecorator, self).__init__(prefix + self._decorated.base)
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
60
61
    def abspath(self, relpath):
62
        """See Transport.abspath()."""
63
        return self._get_url_prefix() + self._decorated.abspath(relpath)
64
1955.3.15 by John Arbash Meinel
Deprecate 'Transport.append' in favor of Transport.append_file or Transport.append_bytes
65
    def append_file(self, relpath, f, mode=None):
66
        """See Transport.append_file()."""
67
        return self._decorated.append_file(relpath, f, mode=mode)
68
69
    def append_bytes(self, relpath, bytes, mode=None):
70
        """See Transport.append_bytes()."""
71
        return self._decorated.append_bytes(relpath, bytes, mode=mode)
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
72
2671.3.3 by Robert Collins
Add mode parameter to Transport.open_file_stream.
73
    def _can_roundtrip_unix_modebits(self):
74
        """See Transport._can_roundtrip_unix_modebits()."""
75
        return self._decorated._can_roundtrip_unix_modebits()
76
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
77
    def clone(self, offset=None):
78
        """See Transport.clone()."""
79
        decorated_clone = self._decorated.clone(offset)
80
        return self.__class__(
2745.5.3 by Robert Collins
* Move transport logging into a new transport class
81
            self._get_url_prefix() + decorated_clone.base, decorated_clone,
82
            self)
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
83
84
    def delete(self, relpath):
85
        """See Transport.delete()."""
86
        return self._decorated.delete(relpath)
87
88
    def delete_tree(self, relpath):
89
        """See Transport.delete_tree()."""
90
        return self._decorated.delete_tree(relpath)
91
2634.1.1 by Robert Collins
(robertc) Reinstate the accidentally backed out external_url patch.
92
    def external_url(self):
93
        """See bzrlib.transport.Transport.external_url."""
94
        # while decorators are in-process only, they
95
        # can be handed back into bzrlib safely, so
96
        # its just the base.
97
        return self.base
98
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
99
    @classmethod
100
    def _get_url_prefix(self):
101
        """Return the URL prefix of this decorator."""
102
        raise NotImplementedError(self._get_url_prefix)
103
2164.2.15 by Vincent Ladeuil
Http redirections are not followed by default. Do not use hints
104
    def get(self, relpath):
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
105
        """See Transport.get()."""
2164.2.15 by Vincent Ladeuil
Http redirections are not followed by default. Do not use hints
106
        return self._decorated.get(relpath)
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
107
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
108
    def get_smart_client(self):
109
        return self._decorated.get_smart_client()
110
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
111
    def has(self, relpath):
112
        """See Transport.has()."""
113
        return self._decorated.has(relpath)
114
115
    def is_readonly(self):
116
        """See Transport.is_readonly."""
117
        return self._decorated.is_readonly()
118
119
    def mkdir(self, relpath, mode=None):
120
        """See Transport.mkdir()."""
121
        return self._decorated.mkdir(relpath, mode)
122
2671.3.9 by Robert Collins
Review feedback and fix VFat emulated transports to not claim to have unix permissions.
123
    def open_write_stream(self, relpath, mode=None):
124
        """See Transport.open_write_stream."""
125
        return self._decorated.open_write_stream(relpath, mode=mode)
2671.3.2 by Robert Collins
Start open_file_stream logic.
126
1955.3.6 by John Arbash Meinel
Lots of deprecation warnings, but no errors
127
    def put_file(self, relpath, f, mode=None):
128
        """See Transport.put_file()."""
129
        return self._decorated.put_file(relpath, f, mode)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
130
1955.3.6 by John Arbash Meinel
Lots of deprecation warnings, but no errors
131
    def put_bytes(self, relpath, bytes, mode=None):
132
        """See Transport.put_bytes()."""
133
        return self._decorated.put_bytes(relpath, bytes, mode)
134
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
135
    def listable(self):
136
        """See Transport.listable."""
137
        return self._decorated.listable()
138
139
    def iter_files_recursive(self):
140
        """See Transport.iter_files_recursive()."""
141
        return self._decorated.iter_files_recursive()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
142
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
143
    def list_dir(self, relpath):
144
        """See Transport.list_dir()."""
145
        return self._decorated.list_dir(relpath)
1608.2.3 by Martin Pool
Add default Transport.rename() to TransportDecorator
146
2745.5.1 by Robert Collins
* New parameter on ``bzrlib.transport.Transport.readv``
147
    def _readv(self, relpath, offsets):
148
        """See Transport._readv."""
149
        return self._decorated._readv(relpath, offsets)
150
2671.3.1 by Robert Collins
* New method ``bzrlib.transport.Transport.get_recommended_page_size``.
151
    def recommended_page_size(self):
152
        """See Transport.recommended_page_size()."""
153
        return self._decorated.recommended_page_size()
154
1608.2.3 by Martin Pool
Add default Transport.rename() to TransportDecorator
155
    def rename(self, rel_from, rel_to):
156
        return self._decorated.rename(rel_from, rel_to)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
157
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
158
    def rmdir(self, relpath):
159
        """See Transport.rmdir."""
160
        return self._decorated.rmdir(relpath)
161
5268.7.1 by Jelmer Vernooij
Fix segment_parameters for most transports.
162
    def _get_segment_parameters(self):
163
        return self._decorated.segment_parameters
164
165
    def _set_segment_parameters(self, value):
166
        self._decorated.segment_parameters = value
167
168
    segment_parameters = property(_get_segment_parameters,
169
        _set_segment_parameters, "See Transport.segment_parameters")
170
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
171
    def stat(self, relpath):
172
        """See Transport.stat()."""
173
        return self._decorated.stat(relpath)
174
175
    def lock_read(self, relpath):
176
        """See Transport.lock_read."""
177
        return self._decorated.lock_read(relpath)
178
179
    def lock_write(self, relpath):
180
        """See Transport.lock_write."""
181
        return self._decorated.lock_write(relpath)
182
3878.4.5 by Vincent Ladeuil
Don't use the exception as a parameter for _redirected_to.
183
    def _redirected_to(self, source, target):
184
        redirected = self._decorated._redirected_to(source, target)
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
185
        if redirected is not None:
186
            return self.__class__(self._get_url_prefix() + redirected.base,
187
                                  redirected)
3878.4.6 by Vincent Ladeuil
Fix bug #270863 by preserving 'bzr+http[s]' decorator.
188
        else:
189
            return None
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
190
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
191
192
def get_test_permutations():
193
    """Return the permutations to be used in testing.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
194
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
195
    The Decorator class is not directly usable, and testing it would not have
196
    any benefit - its the concrete classes which need to be tested.
197
    """
198
    return []