~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/counted_lock.py

  • Committer: Martin Pool
  • Date: 2008-06-05 07:59:29 UTC
  • mto: This revision was merged to the branch mainline in revision 3479.
  • Revision ID: mbp@sourcefrog.net-20080605075929-j5pet0dpcnj32r7x
CountedLock.unlock should raise LockNotHeld if appropriate

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
 
1
# Copyright (C) 2007, 2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
17
17
"""Counted lock class"""
18
18
 
19
19
 
20
 
from bzrlib.errors import (
21
 
    LockError,
22
 
    ReadOnlyError,
 
20
from bzrlib import (
 
21
    errors,
23
22
    )
24
23
 
25
24
 
40
39
        self._lock_mode = None
41
40
        self._lock_count = 0
42
41
 
 
42
    def __repr__(self):
 
43
        return "%s(%r)" % (self.__class__.__name__,
 
44
            self._real_lock)
 
45
 
43
46
    def break_lock(self):
44
47
        self._real_lock.break_lock()
45
48
        self._lock_mode = None
71
74
            self._real_lock.lock_write()
72
75
            self._lock_mode = 'w'
73
76
        elif self._lock_mode != 'w':
74
 
            raise ReadOnlyError(self)
 
77
            raise errors.ReadOnlyError(self)
75
78
        self._lock_count += 1
76
79
 
77
80
    def unlock(self):
78
81
        if self._lock_count == 0:
79
 
            raise LockError("%s not locked" % (self,))
 
82
            raise errors.LockNotHeld("%r not locked" % (self,))
80
83
        elif self._lock_count == 1:
81
84
            self._real_lock.unlock()
82
85
            self._lock_mode = None