Renamed raiseError to raisesErrorsAs
This commit is contained in:
parent
4de8e57f56
commit
62158d7861
|
@ -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):
|
||||
"""
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue