~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lock.py

  • Committer: Martin Pool
  • Date: 2008-04-24 07:22:53 UTC
  • mto: This revision was merged to the branch mainline in revision 3415.
  • Revision ID: mbp@sourcefrog.net-20080424072253-opmjij7xfy38w27f
Remove every assert statement from bzrlib!

Depending on the context they are:

 * turned into an explicit if/raise of either AssertionError 
   or something more specific -- particularly where they protect
   programming interfaces, complex invariants, or data file integrity
 * removed, if they're redundant with a later check, not protecting
   a meaningful invariant
 * turned into a selftest method on tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
187
187
 
188
188
            :return: A token which can be used to switch back to a read lock.
189
189
            """
190
 
            assert self.filename not in _fcntl_WriteLock._open_locks
 
190
            if self.filename in _fcntl_WriteLock._open_locks:
 
191
                raise AssertionError('file already locked: %r'
 
192
                    % (self.filename,))
191
193
            try:
192
194
                wlock = _fcntl_TemporaryWriteLock(self)
193
195
            except errors.LockError:
213
215
                # write lock.
214
216
                raise errors.LockContention(self.filename)
215
217
 
216
 
            assert self.filename not in _fcntl_WriteLock._open_locks
 
218
            if self.filename in _fcntl_WriteLock._open_locks:
 
219
                raise AssertionError('file already locked: %r'
 
220
                    % (self.filename,))
217
221
 
218
222
            # See if we can open the file for writing. Another process might
219
223
            # have a read lock. We don't use self._open() because we don't want