/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/transport/__init__.py

  • Committer: Vincent Ladeuil
  • Date: 2007-02-11 16:06:13 UTC
  • mto: (2323.7.1 redirection)
  • mto: This revision was merged to the branch mainline in revision 2390.
  • Revision ID: v.ladeuil+lp@free.fr-20070211160613-9k1vwo0e1x0si26z
Http redirections are not followed by default. Do not use hints
anymore.

* bzrlib/transport/smart.py:
(SmartTransport.get): Do not use hints.

* bzrlib/transport/sftp.py:
(SFTPTransport.get): Do not use hints.

* bzrlib/transport/memory.py:
(MemoryTransport.get): Do not use hints.

* bzrlib/transport/local.py:
(LocalTransport.get): Do not use hints.

* bzrlib/transport/http/_urllib2_wrappers.py:
(Request.__init__): Redirections are *not* followed by default.

* bzrlib/transport/http/_urllib.py:
(HttpTransport_urllib._get): Do not use hints.

* bzrlib/transport/http/_pycurl.py:
(PyCurlTransport._get): Do not use hints.

* bzrlib/transport/http/__init__.py:
(HttpTransportBase.get, HttpTransportBase._get): Do not use hints.
Fix _get doc anyway.

* bzrlib/transport/ftp.py:
(FtpTransport.get): Do not use hints.

* bzrlib/transport/fakevfat.py:
(FakeVFATTransportDecorator.get): Do not use hints.

* bzrlib/transport/decorator.py
(TransportDecorator.get): Do not use hints.

* bzrlib/transport/chroot.py:
(ChrootTransportDecorator.get): Do not use hints.

* bzrlib/tests/test_transport_hints.py:
Deleted.

* bzrlib/tests/__init__.py:
(test_suite): Do not test hints.

* bzrlib/errors.py:
(UnknownHint): Deleted.

* bzrlib/bzrdir.py:
(BzrDirMetaFormat1.probe_transport): Do not use hints.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
from cStringIO import StringIO
30
30
import re
31
31
import sys
32
 
import textwrap
33
32
 
34
33
from bzrlib.lazy_import import lazy_import
35
34
lazy_import(globals(), """
82
81
        warnings.warn("register_transport(override) is deprecated")
83
82
    _protocol_handlers.setdefault(prefix, []).insert(0, klass)
84
83
 
85
 
def _add_hints_to_get(klass):
86
 
    if getattr(klass,'_get_without_hints',None) is None:
87
 
        # Importing inspect is costly (see
88
 
        # bzrlib.inspect_for_copy). But, on the other hand, it
89
 
        # provides us the service we want in an official way, so
90
 
        # better use it instead of rewriting our own version.
91
 
        import inspect
92
 
        args, varargs, varkw, defaults = inspect.getargspec(klass.get)
93
 
        if varkw is None:
94
 
            # Looks like we have a candidate here
95
 
            mutter('in %(klass)r, original proto is: %(name)s%(joined)s' % \
96
 
                   dict(klass=klass, name='get',
97
 
                        joined=inspect.formatargspec(args, varargs, varkw,
98
 
                                                     defaults,)))
99
 
            klass._get_without_hints = klass.get
100
 
            def get(self, *gvarargs, **hints):
101
 
                return self._get_without_hints(*gvarargs)
102
 
 
103
 
            klass.get = get
104
 
            # Inform user
105
 
            args, varargs, varkw, defaults = inspect.getargspec(klass.get)
106
 
            mutter('in %(klass)r, proto is now: %(name)s%(joined)s' % \
107
 
                   dict(klass=klass, name='get',
108
 
                        joined=inspect.formatargspec(args, varargs, varkw,
109
 
                                                     defaults,)))
110
 
            return True
111
 
    return False
112
84
 
113
85
def register_lazy_transport(scheme, module, classname):
114
86
    """Register lazy-loaded transport class.
128
100
    def _loader(base):
129
101
        mod = __import__(module, globals(), locals(), [classname])
130
102
        klass = getattr(mod, classname)
131
 
        # FIXME: Cache the patched transports ?
132
 
        if _add_hints_to_get(klass):
133
 
            symbol_versioning.warn('Transport %s should declare a **hints'
134
 
                                   ' parameter for its get method'
135
 
                                   % classname,
136
 
                                   DeprecationWarning,
137
 
                                   stacklevel=4)
138
103
        return klass(base)
139
104
    _loader.module = module
140
 
    _loader.classname = classname
141
105
    register_transport(scheme, _loader)
142
106
 
143
107
 
228
192
                   (other.start, other.length, other.ranges))
229
193
 
230
194
 
231
 
class TransportHints(dict):
232
 
    """A specialization of dict targeted to hints handling.
233
 
 
234
 
    This class is only a helper for daughter classes and serve no
235
 
    purpose by itself: its main purpose is to simplify the
236
 
    writing of the daughter classes respecting some simple rules.
237
 
    """
238
 
 
239
 
    _deprecated_hints = {'deprecated_hint_example': 'use shiny_hint instead'}
240
 
    """Hint name associated with the explanation presented as a note"""
241
 
 
242
 
    _valid_hints = {}
243
 
    """Hint name with its default value"""
244
 
 
245
 
    def __init__(self, **hints):
246
 
        """Init object from daughter classes definitions"""
247
 
        for (name, value) in hints.iteritems():
248
 
            status, value = self.check_hint(name, value)
249
 
            if status is 'valid':
250
 
                self[name] = value
251
 
            elif status is 'deprecated':
252
 
                symbol_versioning.warn('hint %s is deprecated: %s' % (name,
253
 
                                                                      value),
254
 
                                       DeprecationWarning)
255
 
            else:
256
 
                raise errors.UnknownHint(name)
257
 
 
258
 
        # Add default values
259
 
        for name, value in self._valid_hints.iteritems():
260
 
            if not self.has_key(name):
261
 
                self[name] = value
262
 
 
263
 
    def check_hint(self, name, value):
264
 
        if self._valid_hints.has_key(name):
265
 
            return 'valid', value
266
 
        elif self._deprecated_hints.has_key(name):
267
 
            return 'deprecated', self._deprecated_hints[name]
268
 
        else:
269
 
            return 'unknown', None
270
 
 
271
 
 
272
 
class TransportGetHints(TransportHints):
273
 
    """Hints for transport get method"""
274
 
 
275
 
    _valid_hints = TransportHints._valid_hints
276
 
 
277
 
    # When a transport is queried for a file, it will silently
278
 
    # follow redirections (if any) except if told otherwise.
279
 
    _valid_hints['follow_redirections'] = True
280
 
 
281
 
 
282
195
class Transport(object):
283
196
    """This class encapsulates methods for retrieving or putting a file
284
197
    from/to a storage location.
308
221
        super(Transport, self).__init__()
309
222
        self.base = base
310
223
 
311
 
    @classmethod
312
 
    def create_get_hints(klass, **hints):
313
 
        """Create a hints object to be used with the get method"""
314
 
        return TransportGetHints(**hints)
315
 
 
316
224
    def _translate_error(self, e, path, raise_generic=True):
317
225
        """Translate an IOError or OSError into an appropriate bzr error.
318
226
 
524
432
                                          "(but must claim to be listable "
525
433
                                          "to trigger this error).")
526
434
 
527
 
    def get(self, relpath, **hints):
 
435
    def get(self, relpath):
528
436
        """Get the file at the given relative path.
529
437
 
530
438
        :param relpath: The relative path to the file
1240
1148
        self._adapted = adapted
1241
1149
        self._calls = []
1242
1150
 
1243
 
    def get(self, name, **hints):
1244
 
        # There is only one test using the information collected
1245
 
        # below and it asks for the name only. So we do not
1246
 
        # record the hints parameter.
1247
 
        # FIXME: Fix the test instead, and record the hints !
 
1151
    def get(self, name):
1248
1152
        self._calls.append((name,))
1249
 
        return self._adapted.get(name, **hints)
 
1153
        return self._adapted.get(name)
1250
1154
 
1251
1155
    def __getattr__(self, name):
1252
1156
        """Thunk all undefined access through to self._adapted."""