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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
__all__ = ['needs_read_lock',
89
94
def %(name)s_read_locked(%(params)s):
92
return unbound(%(passed_params)s)
97
result = unbound(%(passed_params)s)
100
exc_info = sys.exc_info()
104
raise exc_info[0], exc_info[1], exc_info[2]
95
108
read_locked = %(name)s_read_locked
97
110
params, passed_params = _get_parameters(unbound)
124
137
def read_locked(self, *args, **kwargs):
127
return unbound(self, *args, **kwargs)
140
result = unbound(self, *args, **kwargs)
143
exc_info = sys.exc_info()
147
raise exc_info[0], exc_info[1], exc_info[2]
130
151
read_locked.__doc__ = unbound.__doc__
131
152
read_locked.__name__ = unbound.__name__
132
153
return read_locked
138
159
def %(name)s_write_locked(%(params)s):
139
160
self.lock_write()
141
return unbound(%(passed_params)s)
162
result = unbound(%(passed_params)s)
165
exc_info = sys.exc_info()
169
raise exc_info[0], exc_info[1], exc_info[2]
144
173
write_locked = %(name)s_write_locked
146
175
params, passed_params = _get_parameters(unbound)
162
191
def write_locked(self, *args, **kwargs):
163
192
self.lock_write()
165
return unbound(self, *args, **kwargs)
194
result = unbound(self, *args, **kwargs)
196
exc_info = sys.exc_info()
200
raise exc_info[0], exc_info[1], exc_info[2]
168
204
write_locked.__doc__ = unbound.__doc__
169
205
write_locked.__name__ = unbound.__name__
170
206
return write_locked
209
def only_raises(*errors):
210
"""Make a decorator that will only allow the given error classes to be
211
raised. All other errors will be logged and then discarded.
213
Typical use is something like::
215
@only_raises(LockNotHeld, LockBroken)
219
def decorator(unbound):
220
def wrapped(*args, **kwargs):
222
return unbound(*args, **kwargs)
226
trace.mutter('Error suppressed by only_raises:')
227
trace.log_exception_quietly()
228
wrapped.__doc__ = unbound.__doc__
229
wrapped.__name__ = unbound.__name__
173
234
# Default is more functionality, 'bzr' the commandline will request fast
175
236
needs_read_lock = _pretty_needs_read_lock