summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola' <g.rodola@gmail.com>2013-04-11 10:32:38 +0200
committerGiampaolo Rodola' <g.rodola@gmail.com>2013-04-11 10:32:38 +0200
commit4e194d2d05fbcffb7fb737de3813ec99f68888ae (patch)
tree9dfefb74c2b6b22e122ba0fb39bc4aba59c44ee5
parentf27df30a8e4fc3907e30c71ffe9c96865b63735b (diff)
downloadpsutil-4e194d2d05fbcffb7fb737de3813ec99f68888ae.tar.gz
use functools.wraps() around wrap_exceptions() decorator
-rw-r--r--psutil/_psbsd.py7
-rw-r--r--psutil/_pslinux.py7
-rw-r--r--psutil/_psmswindows.py7
-rw-r--r--psutil/_psosx.py7
4 files changed, 16 insertions, 12 deletions
diff --git a/psutil/_psbsd.py b/psutil/_psbsd.py
index 5ea0c806..47bd5e01 100644
--- a/psutil/_psbsd.py
+++ b/psutil/_psbsd.py
@@ -15,7 +15,7 @@ import _psutil_bsd
import _psutil_posix
from psutil import _psposix
from psutil._error import AccessDenied, NoSuchProcess, TimeoutExpired
-from psutil._compat import namedtuple
+from psutil._compat import namedtuple, wraps
from psutil._common import *
__extra__all__ = []
@@ -142,14 +142,15 @@ network_io_counters = _psutil_bsd.get_network_io_counters
disk_io_counters = _psutil_bsd.get_disk_io_counters
-def wrap_exceptions(method):
+def wrap_exceptions(fun):
"""Call method(self, pid) into a try/except clause so that if an
OSError "No such process" exception is raised we assume the process
has died and raise psutil.NoSuchProcess instead.
"""
+ @wraps(fun)
def wrapper(self, *args, **kwargs):
try:
- return method(self, *args, **kwargs)
+ return fun(self, *args, **kwargs)
except OSError:
err = sys.exc_info()[1]
if err.errno == errno.ESRCH:
diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py
index 15866089..180e477b 100644
--- a/psutil/_pslinux.py
+++ b/psutil/_pslinux.py
@@ -22,7 +22,7 @@ import _psutil_linux
from psutil import _psposix
from psutil._error import AccessDenied, NoSuchProcess, TimeoutExpired
from psutil._common import *
-from psutil._compat import PY3, xrange, long, namedtuple
+from psutil._compat import PY3, xrange, long, namedtuple, wraps
__extra__all__ = [
"IOPRIO_CLASS_NONE", "IOPRIO_CLASS_RT", "IOPRIO_CLASS_BE",
@@ -420,13 +420,14 @@ _status_map = {"R" : STATUS_RUNNING,
# --- decorators
-def wrap_exceptions(callable):
+def wrap_exceptions(fun):
"""Call callable into a try/except clause and translate ENOENT,
EACCES and EPERM in NoSuchProcess or AccessDenied exceptions.
"""
+ @wraps(fun)
def wrapper(self, *args, **kwargs):
try:
- return callable(self, *args, **kwargs)
+ return fun(self, *args, **kwargs)
except EnvironmentError:
# ENOENT (no such file or directory) gets raised on open().
# ESRCH (no such process) can get raised on read() if
diff --git a/psutil/_psmswindows.py b/psutil/_psmswindows.py
index f7b00a36..5713d809 100644
--- a/psutil/_psmswindows.py
+++ b/psutil/_psmswindows.py
@@ -16,7 +16,7 @@ import _psutil_mswindows
from _psutil_mswindows import ERROR_ACCESS_DENIED
from psutil._error import AccessDenied, NoSuchProcess, TimeoutExpired
from psutil._common import *
-from psutil._compat import PY3, xrange, long
+from psutil._compat import PY3, xrange, long, wraps
# Windows specific extended namespace
__extra__all__ = ["ABOVE_NORMAL_PRIORITY_CLASS", "BELOW_NORMAL_PRIORITY_CLASS",
@@ -160,14 +160,15 @@ disk_io_counters = _psutil_mswindows.get_disk_io_counters
# --- decorator
-def wrap_exceptions(callable):
+def wrap_exceptions(fun):
"""Call callable into a try/except clause so that if a
WindowsError 5 AccessDenied exception is raised we translate it
into psutil.AccessDenied
"""
+ @wraps(fun)
def wrapper(self, *args, **kwargs):
try:
- return callable(self, *args, **kwargs)
+ return fun(self, *args, **kwargs)
except OSError:
err = sys.exc_info()[1]
if err.errno in ACCESS_DENIED_SET:
diff --git a/psutil/_psosx.py b/psutil/_psosx.py
index 84a76262..0f29256a 100644
--- a/psutil/_psosx.py
+++ b/psutil/_psosx.py
@@ -15,7 +15,7 @@ import _psutil_osx
import _psutil_posix
from psutil import _psposix
from psutil._error import AccessDenied, NoSuchProcess, TimeoutExpired
-from psutil._compat import namedtuple
+from psutil._compat import namedtuple, wraps
from psutil._common import *
__extra__all__ = []
@@ -123,14 +123,15 @@ disk_io_counters = _psutil_osx.get_disk_io_counters
# --- decorator
-def wrap_exceptions(callable):
+def wrap_exceptions(fun):
"""Call callable into a try/except clause so that if an
OSError EPERM exception is raised we translate it into
psutil.AccessDenied.
"""
+ @wraps(fun)
def wrapper(self, *args, **kwargs):
try:
- return callable(self, *args, **kwargs)
+ return fun(self, *args, **kwargs)
except OSError:
err = sys.exc_info()[1]
if err.errno == errno.ESRCH: