~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/decorators.py

  • Committer: John Arbash Meinel
  • Date: 2009-10-12 20:12:32 UTC
  • mfrom: (4736 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4749.
  • Revision ID: john@arbash-meinel.com-20091012201232-ccnceqvk29u7v22u
Merge bzr.dev 4736

This includes the updates to StaticTuple, etc, to build using Pyrex 0.9.6.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
import sys
26
26
 
 
27
from bzrlib import trace
 
28
 
27
29
 
28
30
def _get_parameters(func):
29
31
    """Recreate the parameters for a function using introspection.
204
206
    return write_locked
205
207
 
206
208
 
 
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.
 
212
 
 
213
    Typical use is something like::
 
214
 
 
215
        @only_raises(LockNotHeld, LockBroken)
 
216
        def unlock(self):
 
217
            # etc
 
218
    """
 
219
    def decorator(unbound):
 
220
        def wrapped(*args, **kwargs):
 
221
            try:
 
222
                return unbound(*args, **kwargs)
 
223
            except errors:
 
224
                raise
 
225
            except:
 
226
                trace.mutter('Error suppressed by only_raises:')
 
227
                trace.log_exception_quietly()
 
228
        wrapped.__doc__ = unbound.__doc__
 
229
        wrapped.__name__ = unbound.__name__
 
230
        return wrapped
 
231
    return decorator
 
232
 
 
233
 
207
234
# Default is more functionality, 'bzr' the commandline will request fast
208
235
# versions.
209
236
needs_read_lock = _pretty_needs_read_lock