LSSTApplications
10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
home
lsstsw
stack
Linux64
pex_exceptions
10.0+46
python
lsst
pex
exceptions
wrappers.py
Go to the documentation of this file.
1
import
warnings
2
import
__builtin__
3
4
from
.
import
exceptionsLib
5
6
registry = {}
7
8
def
register
(cls):
9
"""A Python decorator that adds a Python exception wrapper to the registry that maps C++ Exceptions
10
to their Python wrapper classes.
11
"""
12
registry[cls.WrappedClass] = cls
13
return
cls
14
15
class
ExceptionMeta
(type):
16
"""A metaclass for custom exception wrappers, which adds lookup of class attributes
17
by delegating to the Swig-generated wrapper.
18
"""
19
20
def
__getattr__
(self, name):
21
return
getattr(self.WrappedClass, name)
22
23
@register
24
class
Exception
(StandardError):
25
"""The base class for Python-wrapped LSST C++ exceptions.
26
"""
27
28
__metaclass__ = ExceptionMeta
29
30
# wrappers.py is an implementation detail, not a public namespace, so we pretend this is defined
31
# in the package for pretty-printing purposes
32
__module__ =
"lsst.pex.exceptions"
33
34
WrappedClass = exceptionsLib.Exception
35
36
def
__init__
(self, arg, *args, **kwds):
37
if
isinstance(arg, exceptionsLib.Exception):
38
cpp = arg
39
message = cpp.what()
40
else
:
41
message = arg
42
cpp = self.
WrappedClass
(message, *args, **kwds)
43
super(Exception, self).
__init__
(message)
44
self.
cpp
= cpp
45
46
def
__getattr__
(self, name):
47
return
getattr(self.
cpp
, name)
48
49
def
__repr__
(self):
50
return
"%s('%s')"
% (type(self).__name__, self.cpp.what())
51
52
def
__str__
(self):
53
return
self.cpp.asString()
54
55
@register
56
class
LogicError
(
Exception
):
57
WrappedClass = exceptionsLib.LogicError
58
59
@register
60
class
DomainError
(
LogicError
):
61
WrappedClass = exceptionsLib.DomainError
62
63
@register
64
class
InvalidParameterError
(
LogicError
):
65
WrappedClass = exceptionsLib.InvalidParameterError
66
67
@register
68
class
LengthError
(
LogicError
):
69
WrappedClass = exceptionsLib.LengthError
70
71
@register
72
class
OutOfRangeError
(
LogicError
):
73
WrappedClass = exceptionsLib.OutOfRangeError
74
75
@register
76
class
RuntimeError
(
Exception
, __builtin__.RuntimeError):
77
WrappedClass = exceptionsLib.RuntimeError
78
79
@register
80
class
RangeError
(
RuntimeError
):
81
WrappedClass = exceptionsLib.RangeError
82
83
@register
84
class
OverflowError
(
RuntimeError
, __builtin__.OverflowError):
85
WrappedClass = exceptionsLib.OverflowError
86
87
@register
88
class
UnderflowError
(
RuntimeError
, __builtin__.ArithmeticError):
89
WrappedClass = exceptionsLib.UnderflowError
90
91
@register
92
class
NotFoundError
(
Exception
, __builtin__.LookupError):
93
WrappedClass = exceptionsLib.NotFoundError
94
95
@register
96
class
MemoryError
(
RuntimeError
, __builtin__.MemoryError):
97
WrappedClass = exceptionsLib.MemoryError
98
99
@register
100
class
IoError
(
RuntimeError
, __builtin__.IOError):
101
WrappedClass = exceptionsLib.IoError
102
103
@register
104
class
TypeError
(
RuntimeError
, __builtin__.TypeError):
105
WrappedClass = exceptionsLib.TypeError
106
107
@register
108
class
TimeoutError
(
RuntimeError
):
109
WrappedClass = exceptionsLib.TimeoutError
110
111
def
translate
(cpp):
112
"""Translate a C++ Exception instance to Python and return it."""
113
PyType = registry.get(type(cpp),
None
)
114
if
PyType
is
None
:
115
warnings.warn(
"Could not find appropriate Python type for C++ Exception"
)
116
PyType = Exception
117
return
PyType(cpp)
118
lsst::pex.exceptions.wrappers.register
def register
Definition:
wrappers.py:8
lsst::pex.exceptions.wrappers.TypeError
Definition:
wrappers.py:104
lsst::pex.exceptions.wrappers.MemoryError
Definition:
wrappers.py:96
lsst::pex.exceptions.wrappers.InvalidParameterError
Definition:
wrappers.py:64
lsst::pex.exceptions.wrappers.Exception.WrappedClass
WrappedClass
Definition:
wrappers.py:34
lsst::pex.exceptions.wrappers.Exception
Definition:
wrappers.py:24
lsst::pex.exceptions.wrappers.translate
def translate
Definition:
wrappers.py:111
lsst::pex.exceptions.wrappers.RuntimeError
Definition:
wrappers.py:76
lsst::pex.exceptions.wrappers.TimeoutError
Definition:
wrappers.py:108
lsst::pex.exceptions.wrappers.DomainError
Definition:
wrappers.py:60
lsst::pex.exceptions.wrappers.Exception.__init__
def __init__
Definition:
wrappers.py:36
lsst::pex.exceptions.wrappers.Exception.__str__
def __str__
Definition:
wrappers.py:52
lsst::pex.exceptions.wrappers.Exception.cpp
cpp
Definition:
wrappers.py:44
lsst::pex.exceptions.wrappers.Exception.__getattr__
def __getattr__
Definition:
wrappers.py:46
lsst::pex.exceptions.wrappers.OutOfRangeError
Definition:
wrappers.py:72
lsst::pex.exceptions.wrappers.RangeError
Definition:
wrappers.py:80
lsst::pex.exceptions.wrappers.LogicError
Definition:
wrappers.py:56
lsst::pex.exceptions.wrappers.UnderflowError
Definition:
wrappers.py:88
lsst::pex.exceptions.wrappers.NotFoundError
Definition:
wrappers.py:92
lsst::pex.exceptions.wrappers.IoError
Definition:
wrappers.py:100
lsst::pex.exceptions.wrappers.OverflowError
Definition:
wrappers.py:84
lsst::pex.exceptions.wrappers.LengthError
Definition:
wrappers.py:68
lsst::pex.exceptions.wrappers.ExceptionMeta
Definition:
wrappers.py:15
lsst::pex.exceptions.wrappers.ExceptionMeta.__getattr__
def __getattr__
Definition:
wrappers.py:20
lsst::pex.exceptions.wrappers.Exception.__repr__
def __repr__
Definition:
wrappers.py:49
Generated on Thu Sep 24 2015 02:29:23 for LSSTApplications by
1.8.5