/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
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
25
from . import (Transport, get_transport)
26
27
28
class TransportDecorator(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:
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
55
            self._decorated = get_transport(not_decorated_url)
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
56
        else:
57
            self._decorated = _decorated
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
58
        super(TransportDecorator, self).__init__(prefix + self._decorated.base)
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
59
60
    def abspath(self, relpath):
61
        """See Transport.abspath()."""
62
        return self._get_url_prefix() + self._decorated.abspath(relpath)
63
1955.3.15 by John Arbash Meinel
Deprecate 'Transport.append' in favor of Transport.append_file or Transport.append_bytes
64
    def append_file(self, relpath, f, mode=None):
65
        """See Transport.append_file()."""
66
        return self._decorated.append_file(relpath, f, mode=mode)
67
68
    def append_bytes(self, relpath, bytes, mode=None):
69
        """See Transport.append_bytes()."""
70
        return self._decorated.append_bytes(relpath, bytes, mode=mode)
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
71
2671.3.3 by Robert Collins
Add mode parameter to Transport.open_file_stream.
72
    def _can_roundtrip_unix_modebits(self):
73
        """See Transport._can_roundtrip_unix_modebits()."""
74
        return self._decorated._can_roundtrip_unix_modebits()
75
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
76
    def clone(self, offset=None):
77
        """See Transport.clone()."""
78
        decorated_clone = self._decorated.clone(offset)
79
        return self.__class__(
2745.5.3 by Robert Collins
* Move transport logging into a new transport class
80
            self._get_url_prefix() + decorated_clone.base, decorated_clone,
81
            self)
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
82
83
    def delete(self, relpath):
84
        """See Transport.delete()."""
85
        return self._decorated.delete(relpath)
86
87
    def delete_tree(self, relpath):
88
        """See Transport.delete_tree()."""
89
        return self._decorated.delete_tree(relpath)
90
2634.1.1 by Robert Collins
(robertc) Reinstate the accidentally backed out external_url patch.
91
    def external_url(self):
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
92
        """See breezy.transport.Transport.external_url."""
2634.1.1 by Robert Collins
(robertc) Reinstate the accidentally backed out external_url patch.
93
        # while decorators are in-process only, they
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
94
        # can be handed back into breezy safely, so
2634.1.1 by Robert Collins
(robertc) Reinstate the accidentally backed out external_url patch.
95
        # its just the base.
96
        return self.base
97
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
98
    @classmethod
99
    def _get_url_prefix(self):
100
        """Return the URL prefix of this decorator."""
101
        raise NotImplementedError(self._get_url_prefix)
102
2164.2.15 by Vincent Ladeuil
Http redirections are not followed by default. Do not use hints
103
    def get(self, relpath):
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
104
        """See Transport.get()."""
2164.2.15 by Vincent Ladeuil
Http redirections are not followed by default. Do not use hints
105
        return self._decorated.get(relpath)
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
106
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
107
    def get_smart_client(self):
108
        return self._decorated.get_smart_client()
109
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
110
    def has(self, relpath):
111
        """See Transport.has()."""
112
        return self._decorated.has(relpath)
113
114
    def is_readonly(self):
115
        """See Transport.is_readonly."""
116
        return self._decorated.is_readonly()
117
118
    def mkdir(self, relpath, mode=None):
119
        """See Transport.mkdir()."""
120
        return self._decorated.mkdir(relpath, mode)
121
2671.3.9 by Robert Collins
Review feedback and fix VFat emulated transports to not claim to have unix permissions.
122
    def open_write_stream(self, relpath, mode=None):
123
        """See Transport.open_write_stream."""
124
        return self._decorated.open_write_stream(relpath, mode=mode)
2671.3.2 by Robert Collins
Start open_file_stream logic.
125
1955.3.6 by John Arbash Meinel
Lots of deprecation warnings, but no errors
126
    def put_file(self, relpath, f, mode=None):
127
        """See Transport.put_file()."""
128
        return self._decorated.put_file(relpath, f, mode)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
129
1955.3.6 by John Arbash Meinel
Lots of deprecation warnings, but no errors
130
    def put_bytes(self, relpath, bytes, mode=None):
131
        """See Transport.put_bytes()."""
132
        return self._decorated.put_bytes(relpath, bytes, mode)
133
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
134
    def listable(self):
135
        """See Transport.listable."""
136
        return self._decorated.listable()
137
138
    def iter_files_recursive(self):
139
        """See Transport.iter_files_recursive()."""
140
        return self._decorated.iter_files_recursive()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
141
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
142
    def list_dir(self, relpath):
143
        """See Transport.list_dir()."""
144
        return self._decorated.list_dir(relpath)
1608.2.3 by Martin Pool
Add default Transport.rename() to TransportDecorator
145
2745.5.1 by Robert Collins
* New parameter on ``bzrlib.transport.Transport.readv``
146
    def _readv(self, relpath, offsets):
147
        """See Transport._readv."""
148
        return self._decorated._readv(relpath, offsets)
149
2671.3.1 by Robert Collins
* New method ``bzrlib.transport.Transport.get_recommended_page_size``.
150
    def recommended_page_size(self):
151
        """See Transport.recommended_page_size()."""
152
        return self._decorated.recommended_page_size()
153
1608.2.3 by Martin Pool
Add default Transport.rename() to TransportDecorator
154
    def rename(self, rel_from, rel_to):
155
        return self._decorated.rename(rel_from, rel_to)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
156
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
157
    def rmdir(self, relpath):
158
        """See Transport.rmdir."""
159
        return self._decorated.rmdir(relpath)
160
5268.7.1 by Jelmer Vernooij
Fix segment_parameters for most transports.
161
    def _get_segment_parameters(self):
162
        return self._decorated.segment_parameters
163
164
    def _set_segment_parameters(self, value):
165
        self._decorated.segment_parameters = value
166
167
    segment_parameters = property(_get_segment_parameters,
168
        _set_segment_parameters, "See Transport.segment_parameters")
169
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
170
    def stat(self, relpath):
171
        """See Transport.stat()."""
172
        return self._decorated.stat(relpath)
173
174
    def lock_read(self, relpath):
175
        """See Transport.lock_read."""
176
        return self._decorated.lock_read(relpath)
177
178
    def lock_write(self, relpath):
179
        """See Transport.lock_write."""
180
        return self._decorated.lock_write(relpath)
181
3878.4.5 by Vincent Ladeuil
Don't use the exception as a parameter for _redirected_to.
182
    def _redirected_to(self, source, target):
183
        redirected = self._decorated._redirected_to(source, target)
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
184
        if redirected is not None:
185
            return self.__class__(self._get_url_prefix() + redirected.base,
186
                                  redirected)
3878.4.6 by Vincent Ladeuil
Fix bug #270863 by preserving 'bzr+http[s]' decorator.
187
        else:
188
            return None
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
189
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
190
191
def get_test_permutations():
192
    """Return the permutations to be used in testing.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
193
1558.10.2 by Robert Collins
Refactor the FakeNFS support into a TransportDecorator.
194
    The Decorator class is not directly usable, and testing it would not have
195
    any benefit - its the concrete classes which need to be tested.
196
    """
197
    return []