~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lazy_import.py

  • Committer: Alexander Belchenko
  • Date: 2007-08-10 09:04:38 UTC
  • mto: This revision was merged to the branch mainline in revision 2694.
  • Revision ID: bialix@ukr.net-20070810090438-0835xdz0rl8825qv
fixes after Ian's review

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()
174
165
            assert not children, \
175
166
                'Cannot supply both a member and children'
176
167
 
177
 
        object.__setattr__(self, '_import_replacer_children', children)
178
 
        object.__setattr__(self, '_member', member)
179
 
        object.__setattr__(self, '_module_path', module_path)
 
168
        self._import_replacer_children = children
 
169
        self._member = member
 
170
        self._module_path = module_path
180
171
 
181
172
        # Indirecting through __class__ so that children can
182
173
        # override _import (especially our instrumented version)