~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lazy_import.py

  • Committer: John Arbash Meinel
  • Date: 2006-11-10 15:38:16 UTC
  • mto: This revision was merged to the branch mainline in revision 2129.
  • Revision ID: john@arbash-meinel.com-20061110153816-46acf76fc86a512b
use try/finally to clean up a nested progress bar during weave fetching

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
    needed.
49
49
    """
50
50
 
51
 
    __slots__ = ('_scope', '_factory', '_name', '_real_obj')
52
 
 
53
 
    # Setting this to True will allow you to do x = y, and still access members
54
 
    # from both variables. This should not normally be enabled, but is useful
55
 
    # when building documentation.
56
 
    _should_proxy = False
 
51
    __slots__ = ('_scope', '_factory', '_name')
57
52
 
58
53
    def __init__(self, scope, factory, name):
59
54
        """Create a temporary object in the specified scope.
67
62
        self._scope = scope
68
63
        self._factory = factory
69
64
        self._name = name
70
 
        self._real_obj = None
71
65
        scope[name] = self
72
66
 
73
67
    def _replace(self):
87
81
                          " to another variable?",
88
82
                extra=e)
89
83
        obj = factory(self, scope, name)
90
 
        if ScopeReplacer._should_proxy:
91
 
            self._real_obj = obj
92
84
        scope[name] = obj
93
85
        return obj
94
86
 
100
92
        # del self._name
101
93
 
102
94
    def __getattribute__(self, attr):
103
 
        obj = object.__getattribute__(self, '_real_obj')
104
 
        if obj is None:
105
 
            _replace = object.__getattribute__(self, '_replace')
106
 
            obj = _replace()
107
 
            _cleanup = object.__getattribute__(self, '_cleanup')
108
 
            _cleanup()
 
95
        _replace = object.__getattribute__(self, '_replace')
 
96
        obj = _replace()
 
97
        _cleanup = object.__getattribute__(self, '_cleanup')
 
98
        _cleanup()
109
99
        return getattr(obj, attr)
110
100
 
111
101
    def __call__(self, *args, **kwargs):