~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lazy_import.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-04-19 22:03:15 UTC
  • mfrom: (2413.4.2 api-doc-builders)
  • Revision ID: pqm@pqm.ubuntu.com-20070419220315-zw3uloe4se8laybs
(John Arbash Meinel) 'make api-docs' will generate api documentation using epydoc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
    needed.
49
49
    """
50
50
 
51
 
    __slots__ = ('_scope', '_factory', '_name')
 
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
52
57
 
53
58
    def __init__(self, scope, factory, name):
54
59
        """Create a temporary object in the specified scope.
62
67
        self._scope = scope
63
68
        self._factory = factory
64
69
        self._name = name
 
70
        self._real_obj = None
65
71
        scope[name] = self
66
72
 
67
73
    def _replace(self):
81
87
                          " to another variable?",
82
88
                extra=e)
83
89
        obj = factory(self, scope, name)
 
90
        if ScopeReplacer._should_proxy:
 
91
            self._real_obj = obj
84
92
        scope[name] = obj
85
93
        return obj
86
94
 
92
100
        # del self._name
93
101
 
94
102
    def __getattribute__(self, attr):
95
 
        _replace = object.__getattribute__(self, '_replace')
96
 
        obj = _replace()
97
 
        _cleanup = object.__getattribute__(self, '_cleanup')
98
 
        _cleanup()
 
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()
99
109
        return getattr(obj, attr)
100
110
 
101
111
    def __call__(self, *args, **kwargs):