/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: Martin Pool
  • Date: 2007-10-03 08:06:44 UTC
  • mto: This revision was merged to the branch mainline in revision 2901.
  • Revision ID: mbp@sourcefrog.net-20071003080644-oivy0gkg98sex0ed
Avoid internal error tracebacks on failure to lock on readonly transport (#129701).

Add new LockFailed, which doesn't imply that we failed to get it because of
contention.  Raise this if we fail to create the pending or lock directories
because of Transport errors.

UnlockableTransport is not an internal error.

ReadOnlyLockError has a message which didn't match its name or usage; it's now
deprecated and callers are updated to use LockFailed which is more appropriate.

Add zero_ninetytwo deprecation symbol.

Unify assertMatchesRe with TestCase.assertContainsRe.

When the constructor is deprecated, just say that the class is deprecated, not
the __init__ method - this works better with applyDeprecated in tests.

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
 
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()
149
140
 
150
141
        :param scope: The scope that objects should be imported into.
151
142
            Typically this is globals()
152
 
        :param name: The variable name. Often this is the same as the
 
143
        :param name: The variable name. Often this is the same as the 
153
144
            module_path. 'bzrlib'
154
145
        :param module_path: A list for the fully specified module path
155
146
            ['bzrlib', 'foo', 'bar']
157
148
            None, indicating the module is being imported.
158
149
        :param children: Children entries to be imported later.
159
150
            This should be a map of children specifications.
160
 
            {'foo':(['bzrlib', 'foo'], None,
 
151
            {'foo':(['bzrlib', 'foo'], None, 
161
152
                {'bar':(['bzrlib', 'foo', 'bar'], None {})})
162
153
            }
163
154
        Examples:
170
161
            from foo import bar, baz would get translated into 2 import
171
162
            requests. On for 'name=bar' and one for 'name=baz'
172
163
        """
173
 
        if (member is not None) and children:
174
 
            raise ValueError('Cannot supply both a member and children')
 
164
        if member is not None:
 
165
            assert not children, \
 
166
                'Cannot supply both a member and children'
175
167
 
176
 
        object.__setattr__(self, '_import_replacer_children', children)
177
 
        object.__setattr__(self, '_member', member)
178
 
        object.__setattr__(self, '_module_path', module_path)
 
168
        self._import_replacer_children = children
 
169
        self._member = member
 
170
        self._module_path = module_path
179
171
 
180
172
        # Indirecting through __class__ so that children can
181
173
        # override _import (especially our instrumented version)
259
251
 
260
252
        :param import_str: The import string to process
261
253
        """
262
 
        if not import_str.startswith('import '):
263
 
            raise ValueError('bad import string %r' % (import_str,))
 
254
        assert import_str.startswith('import ')
264
255
        import_str = import_str[len('import '):]
265
256
 
266
257
        for path in import_str.split(','):
305
296
 
306
297
        :param from_str: The import string to process
307
298
        """
308
 
        if not from_str.startswith('from '):
309
 
            raise ValueError('bad from/import %r' % from_str)
 
299
        assert from_str.startswith('from ')
310
300
        from_str = from_str[len('from '):]
311
301
 
312
302
        from_module, import_list = from_str.split(' import ')