/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/decorators.py

  • Committer: Andrew Bennetts
  • Date: 2010-01-12 03:53:21 UTC
  • mfrom: (4948 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4964.
  • Revision ID: andrew.bennetts@canonical.com-20100112035321-hofpz5p10224ryj3
Merge lp:bzr, resolving conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
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
16
16
 
17
17
 
18
18
__all__ = ['needs_read_lock',
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.
71
73
 
72
74
    This decorator can be applied to methods of any class with lock_read() and
73
75
    unlock() methods.
74
 
    
 
76
 
75
77
    Typical usage:
76
 
        
 
78
 
77
79
    class Branch(...):
78
80
        @needs_read_lock
79
81
        def branch_method(self, ...):
124
126
 
125
127
    This decorator can be applied to methods of any class with lock_read() and
126
128
    unlock() methods.
127
 
    
 
129
 
128
130
    Typical usage:
129
 
        
 
131
 
130
132
    class Branch(...):
131
133
        @needs_read_lock
132
134
        def branch_method(self, ...):
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