/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/lazy_import.py

  • Committer: John Arbash Meinel
  • Date: 2007-03-20 00:49:11 UTC
  • mto: This revision was merged to the branch mainline in revision 2366.
  • Revision ID: john@arbash-meinel.com-20070320004911-0qajqnddr3rf9r2e
Simplify the test even further....
Basically, if you have a file deleted as removed, and then you unversion its directory
it deletes all records in the dirblock, not realizing that some of them might
already be marked as removed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Functionality to create lazy evaluation objects.
18
18
 
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.
64
59
            It will be passed (self, scope, name)
65
60
        :param name: The variable name in the given scope.
66
61
        """
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)
 
62
        self._scope = scope
 
63
        self._factory = factory
 
64
        self._name = name
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
 
            object.__setattr__(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
 
    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
101
    def __call__(self, *args, **kwargs):
121
102
        _replace = object.__getattribute__(self, '_replace')
122
103
        obj = _replace()
149
130
 
150
131
        :param scope: The scope that objects should be imported into.
151
132
            Typically this is globals()
152
 
        :param name: The variable name. Often this is the same as the
 
133
        :param name: The variable name. Often this is the same as the 
153
134
            module_path. 'bzrlib'
154
135
        :param module_path: A list for the fully specified module path
155
136
            ['bzrlib', 'foo', 'bar']
157
138
            None, indicating the module is being imported.
158
139
        :param children: Children entries to be imported later.
159
140
            This should be a map of children specifications.
160
 
            {'foo':(['bzrlib', 'foo'], None,
 
141
            {'foo':(['bzrlib', 'foo'], None, 
161
142
                {'bar':(['bzrlib', 'foo', 'bar'], None {})})
162
143
            }
163
144
        Examples:
170
151
            from foo import bar, baz would get translated into 2 import
171
152
            requests. On for 'name=bar' and one for 'name=baz'
172
153
        """
173
 
        if (member is not None) and children:
174
 
            raise ValueError('Cannot supply both a member and children')
 
154
        if member is not None:
 
155
            assert not children, \
 
156
                'Cannot supply both a member and children'
175
157
 
176
 
        object.__setattr__(self, '_import_replacer_children', children)
177
 
        object.__setattr__(self, '_member', member)
178
 
        object.__setattr__(self, '_module_path', module_path)
 
158
        self._import_replacer_children = children
 
159
        self._member = member
 
160
        self._module_path = module_path
179
161
 
180
162
        # Indirecting through __class__ so that children can
181
163
        # override _import (especially our instrumented version)
259
241
 
260
242
        :param import_str: The import string to process
261
243
        """
262
 
        if not import_str.startswith('import '):
263
 
            raise ValueError('bad import string %r' % (import_str,))
 
244
        assert import_str.startswith('import ')
264
245
        import_str = import_str[len('import '):]
265
246
 
266
247
        for path in import_str.split(','):
305
286
 
306
287
        :param from_str: The import string to process
307
288
        """
308
 
        if not from_str.startswith('from '):
309
 
            raise ValueError('bad from/import %r' % from_str)
 
289
        assert from_str.startswith('from ')
310
290
        from_str = from_str[len('from '):]
311
291
 
312
292
        from_module, import_list = from_str.split(' import ')