comparison src/parpg/components/lockable.py @ 49:3024ded5ae61

Added functions for Lockable
author KarstenBock@gmx.net
date Fri, 02 Sep 2011 15:57:27 +0200
parents 1cc037593517
children 96af64cf3b81
comparison
equal deleted inserted replaced
48:c017773e8443 49:3024ded5ae61
13 13
14 from parpg.grease.component import Component 14 from parpg.grease.component import Component
15 15
16 class Lockable(Component): 16 class Lockable(Component):
17 """Component that stores the data of a lock""" 17 """Component that stores the data of a lock"""
18 18
19 def __init__(self): 19 def __init__(self):
20 """Constructor""" 20 """Constructor"""
21 Component.__init__(self, locked=bool) 21 Component.__init__(self, closed=bool, locked=bool)
22
23 class LockedError(Exception):
24
25 def __str__(self):
26 return "Is locked"
27
28 class OpenError(Exception):
29
30 def __str__(self):
31 return "Is open"
32
33 def lock(lock):
34 if not lock.closed:
35 raise OpenError
36 lock.locked = True
37
38 def unlock(lock):
39 lock.locked = False
40
41 def open(lock):
42 if lock.locked:
43 raise LockedError
44 lock.closed = False
45
46 def close(lock):
47 lock.closed = True