~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lazy_import.py

  • Committer: Vincent Ladeuil
  • Date: 2007-06-06 13:52:02 UTC
  • mto: (2485.8.44 bzr.connection.sharing)
  • mto: This revision was merged to the branch mainline in revision 2646.
  • Revision ID: v.ladeuil+lp@free.fr-20070606135202-mqhxcv6z57uce434
Fix merge multiple connections. Test suite *not* passing (sftp
refactoring pending but unrelated to merge).

* bzrlib/builtins.py:
(cmd_merge.run): Fix the multiple connections bug by reusing the
tramsport used to check for a bundle and keep all other used
transports in possible_transports.
(_merge_helper): Add a possible_transports parameter for
reuse.

* bzrlib/transport/__init__.py:
(Transport._reuse_for): By default, Transports are not reusable.
(ConnectedTransport._reuse_for): ConnectedTransports are reusable
under certain conditions.
(_urlRE): Fix misleading group name.
(_try_transport_factories): Moved after get_transport (another use
case for moved lines). The do_catching_redirections was
incorrectly inserted between get_transport and
_try_transport_factories.

* bzrlib/tests/test_transport.py:
(TestReusedTransports.test_reuse_same_transport)
(TestReusedTransports.test_don_t_reuse_different_transport): Add
more tests.

* bzrlib/merge.py:
(_get_tree, Merger.set_other): Add a possible_transports parameter
for reuse.

* bzrlib/bzrdir.py:
(BzrDir.open_containing): Add a possible_transports parameter for
reuse.

* bzrlib/branch.py:
(Branch.open_containing): Add a possible_transports parameter for
reuse.

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
            It will be passed (self, scope, name)
65
65
        :param name: The variable name in the given scope.
66
66
        """
67
 
        object.__setattr__(self, '_scope', scope)
68
 
        object.__setattr__(self, '_factory', factory)
69
 
        object.__setattr__(self, '_name', name)
70
 
        object.__setattr__(self, '_real_obj', None)
 
67
        self._scope = scope
 
68
        self._factory = factory
 
69
        self._name = name
 
70
        self._real_obj = None
71
71
        scope[name] = self
72
72
 
73
73
    def _replace(self):
88
88
                extra=e)
89
89
        obj = factory(self, scope, name)
90
90
        if ScopeReplacer._should_proxy:
91
 
            object.__setattr__(self, '_real_obj', obj)
 
91
            self._real_obj = obj
92
92
        scope[name] = obj
93
93
        return obj
94
94
 
108
108
            _cleanup()
109
109
        return getattr(obj, attr)
110
110
 
111
 
    def __setattr__(self, attr, value):
112
 
        obj = object.__getattribute__(self, '_real_obj')
113
 
        if obj is None:
114
 
            _replace = object.__getattribute__(self, '_replace')
115
 
            obj = _replace()
116
 
            _cleanup = object.__getattribute__(self, '_cleanup')
117
 
            _cleanup()
118
 
        return setattr(obj, attr, value)
119
 
 
120
111
    def __call__(self, *args, **kwargs):
121
112
        _replace = object.__getattribute__(self, '_replace')
122
113
        obj = _replace()
170
161
            from foo import bar, baz would get translated into 2 import
171
162
            requests. On for 'name=bar' and one for 'name=baz'
172
163
        """
173
 
        if (member is not None) and children:
174
 
            raise ValueError('Cannot supply both a member and children')
 
164
        if member is not None:
 
165
            assert not children, \
 
166
                'Cannot supply both a member and children'
175
167
 
176
 
        object.__setattr__(self, '_import_replacer_children', children)
177
 
        object.__setattr__(self, '_member', member)
178
 
        object.__setattr__(self, '_module_path', module_path)
 
168
        self._import_replacer_children = children
 
169
        self._member = member
 
170
        self._module_path = module_path
179
171
 
180
172
        # Indirecting through __class__ so that children can
181
173
        # override _import (especially our instrumented version)
259
251
 
260
252
        :param import_str: The import string to process
261
253
        """
262
 
        if not import_str.startswith('import '):
263
 
            raise ValueError('bad import string %r' % (import_str,))
 
254
        assert import_str.startswith('import ')
264
255
        import_str = import_str[len('import '):]
265
256
 
266
257
        for path in import_str.split(','):
305
296
 
306
297
        :param from_str: The import string to process
307
298
        """
308
 
        if not from_str.startswith('from '):
309
 
            raise ValueError('bad from/import %r' % from_str)
 
299
        assert from_str.startswith('from ')
310
300
        from_str = from_str[len('from '):]
311
301
 
312
302
        from_module, import_list = from_str.split(' import ')