mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-09 18:08:39 +00:00
Renamed raiseError to raisesErrorsAs
This commit is contained in:
parent
4de8e57f56
commit
62158d7861
2 changed files with 28 additions and 8 deletions
|
@ -36,19 +36,39 @@
|
||||||
|
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
import os.path
|
import os.path
|
||||||
|
from functools import wraps
|
||||||
|
from sys import exc_info
|
||||||
|
|
||||||
def get_resource(filename):
|
def get_resource(filename):
|
||||||
return pkg_resources.resource_filename("blocklist", os.path.join("data", filename))
|
return pkg_resources.resource_filename("blocklist", os.path.join("data", filename))
|
||||||
|
|
||||||
def raiseError(error):
|
def raisesErrorsAs(error):
|
||||||
def safer(func):
|
"""
|
||||||
def new(self, *args, **kwargs):
|
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:
|
try:
|
||||||
return func(self, *args, **kwargs)
|
return func(self, *args, **kwargs)
|
||||||
except:
|
except:
|
||||||
raise error
|
(value, tb) = exc_info()[1:]
|
||||||
return new
|
raise error, value, tb
|
||||||
return safer
|
return wrapper
|
||||||
|
return decorator
|
||||||
|
|
||||||
def remove_zeros(ip):
|
def remove_zeros(ip):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
from common import raiseError, remove_zeros
|
from common import raisesErrorsAs, remove_zeros
|
||||||
import re
|
import re
|
||||||
|
|
||||||
class ReaderParseError(Exception):
|
class ReaderParseError(Exception):
|
||||||
|
@ -82,7 +82,7 @@ class BaseReader(object):
|
||||||
blocklist.close()
|
blocklist.close()
|
||||||
return valid
|
return valid
|
||||||
|
|
||||||
@raiseError(ReaderParseError)
|
@raisesErrorsAs(ReaderParseError)
|
||||||
def readranges(self):
|
def readranges(self):
|
||||||
"""Yields each ip range from the file"""
|
"""Yields each ip range from the file"""
|
||||||
blocklist = self.open()
|
blocklist = self.open()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue