Module: deluge Branch: master Commit: 62158d7861f08534ae13774c9ecbaae15a9223ca
Author: John Garland <[email protected]> Date: Mon Apr 26 02:54:13 2010 +1000 Renamed raiseError to raisesErrorsAs --- deluge/plugins/blocklist/blocklist/common.py | 32 ++++++++++++++++++++---- deluge/plugins/blocklist/blocklist/readers.py | 4 +- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/deluge/plugins/blocklist/blocklist/common.py b/deluge/plugins/blocklist/blocklist/common.py index d1181dd..c2076ac 100644 --- a/deluge/plugins/blocklist/blocklist/common.py +++ b/deluge/plugins/blocklist/blocklist/common.py @@ -36,19 +36,39 @@ import pkg_resources import os.path +from functools import wraps +from sys import exc_info def get_resource(filename): return pkg_resources.resource_filename("blocklist", os.path.join("data", filename)) -def raiseError(error): - def safer(func): - def new(self, *args, **kwargs): +def raisesErrorsAs(error): + """ + Factory class that returns a decorator which wraps + the decorated function to raise all exceptions as + the specified error type + """ + def decorator(func): + """ + Returns a function which wraps the given func + to raise all exceptions as error + """ + @wraps(func) + def wrapper(self, *args, **kwargs): + """ + Wraps the function in a try..except block + and calls it with the specified args + + Raises any exceptions as error preserving the + message and traceback + """ try: return func(self, *args, **kwargs) except: - raise error - return new - return safer + (value, tb) = exc_info()[1:] + raise error, value, tb + return wrapper + return decorator def remove_zeros(ip): """ diff --git a/deluge/plugins/blocklist/blocklist/readers.py b/deluge/plugins/blocklist/blocklist/readers.py index 011b2f2..518c6b8 100644 --- a/deluge/plugins/blocklist/blocklist/readers.py +++ b/deluge/plugins/blocklist/blocklist/readers.py @@ -33,7 +33,7 @@ # # -from common import raiseError, remove_zeros +from common import raisesErrorsAs, remove_zeros import re class ReaderParseError(Exception): @@ -82,7 +82,7 @@ class BaseReader(object): blocklist.close() return valid - @raiseError(ReaderParseError) + @raisesErrorsAs(ReaderParseError) def readranges(self): """Yields each ip range from the file""" blocklist = self.open() -- You received this message because you are subscribed to the Google Groups "deluge-commit" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/deluge-commit?hl=en.
