~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lazy_import.py

  • Committer: John Arbash Meinel
  • Date: 2007-04-12 19:02:36 UTC
  • mto: This revision was merged to the branch mainline in revision 2566.
  • Revision ID: john@arbash-meinel.com-20070412190236-9izxi311ng5zofvh
Update lazy_import with tests for the new '_should_proxy' variable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
    to inherit from them).
41
41
"""
42
42
 
43
 
_scope_replacer_should_proxy = False
44
 
 
45
43
 
46
44
class ScopeReplacer(object):
47
45
    """A lazy object that will replace itself in the appropriate scope.
52
50
 
53
51
    __slots__ = ('_scope', '_factory', '_name', '_real_obj')
54
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
 
57
 
55
58
    def __init__(self, scope, factory, name):
56
59
        """Create a temporary object in the specified scope.
57
60
        Once used, a real object will be placed in the scope.
84
87
                          " to another variable?",
85
88
                extra=e)
86
89
        obj = factory(self, scope, name)
87
 
        if _scope_replacer_should_proxy:
 
90
        if ScopeReplacer._should_proxy:
88
91
            self._real_obj = obj
89
92
        scope[name] = obj
90
93
        return obj