Changed Python exceptions generated by SWIG.
This commit is contained in:
parent
a208f6f6b0
commit
34013a6092
|
@ -68,7 +68,7 @@ class ErrorCheckingTestCase(unittest.TestCase):
|
|||
login = lasso.Login(server)
|
||||
try:
|
||||
login.initFromAuthnRequestMsg("", lasso.httpMethodRedirect)
|
||||
except:
|
||||
except lasso.Error:
|
||||
pass
|
||||
|
||||
|
||||
|
|
|
@ -109,9 +109,8 @@ class LogoutTestCase(unittest.TestCase):
|
|||
logout = lasso.Logout(lassoServer, lasso.providerTypeSp)
|
||||
try:
|
||||
logout.initRequest()
|
||||
except RuntimeError, error:
|
||||
errorCode = int(error.args[0].split(' ', 1)[0])
|
||||
if errorCode != -1:
|
||||
except lasso.Error, error:
|
||||
if error[0] != -1:
|
||||
raise
|
||||
else:
|
||||
self.fail('logout.initRequest without having set identity before should fail')
|
||||
|
@ -149,7 +148,7 @@ class LogoutTestCase(unittest.TestCase):
|
|||
# The processRequestMsg should fail but not abort.
|
||||
try:
|
||||
logout.processRequestMsg('passport=0&lasso=1', lasso.httpMethodRedirect)
|
||||
except SyntaxError:
|
||||
except lasso.SyntaxError:
|
||||
pass
|
||||
else:
|
||||
self.fail('Logout processRequestMsg should have failed.')
|
||||
|
@ -171,7 +170,7 @@ class LogoutTestCase(unittest.TestCase):
|
|||
# The processResponseMsg should fail but not abort.
|
||||
try:
|
||||
logout.processResponseMsg('liberty=&alliance', lasso.httpMethodRedirect)
|
||||
except SyntaxError:
|
||||
except lasso.SyntaxError:
|
||||
pass
|
||||
else:
|
||||
self.fail('Logout processResponseMsg should have failed.')
|
||||
|
@ -209,7 +208,7 @@ class DefederationTestCase(unittest.TestCase):
|
|||
# The processNotificationMsg should fail but not abort.
|
||||
try:
|
||||
defederation.processNotificationMsg('nonLibertyQuery=1', lasso.httpMethodRedirect)
|
||||
except SyntaxError:
|
||||
except lasso.SyntaxError:
|
||||
pass
|
||||
else:
|
||||
self.fail('Defederation processNotificationMsg should have failed.')
|
||||
|
|
87
swig/Lasso.i
87
swig/Lasso.i
|
@ -90,6 +90,30 @@
|
|||
init();
|
||||
}
|
||||
%}
|
||||
#else
|
||||
#ifdef SWIGPYTHON
|
||||
%{
|
||||
PyObject *lassoError;
|
||||
PyObject *lassoSyntaxError;
|
||||
%}
|
||||
|
||||
%init %{
|
||||
lassoError = PyErr_NewException("_lasso.Error", NULL, NULL);
|
||||
Py_INCREF(lassoError);
|
||||
PyModule_AddObject(m, "Error", lassoError);
|
||||
|
||||
lassoSyntaxError = PyErr_NewException("_lasso.SyntaxError", lassoError, NULL);
|
||||
Py_INCREF(lassoSyntaxError);
|
||||
PyModule_AddObject(m, "SyntaxError", lassoSyntaxError);
|
||||
|
||||
lasso_init();
|
||||
%}
|
||||
|
||||
%pythoncode %{
|
||||
Error = _lasso.Error
|
||||
SyntaxError = _lasso.SyntaxError
|
||||
%}
|
||||
|
||||
#else
|
||||
/* Apache fails when lasso_init is called too early in PHP binding. */
|
||||
/* FIXME: To investigate. */
|
||||
|
@ -99,6 +123,7 @@
|
|||
%}
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
|
@ -421,21 +446,65 @@ typedef enum {
|
|||
#endif
|
||||
#define LASSO_ERROR_UNDEFINED -999
|
||||
|
||||
/* Generate a language independant exception from Lasso error codes. */
|
||||
|
||||
/***********************************************************************
|
||||
* Exceptions Generation From Lasso Error Codes
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifdef SWIGPYTHON
|
||||
|
||||
%{
|
||||
|
||||
int get_exception_type(int errorCode)
|
||||
{
|
||||
if (errorCode == LASSO_PROFILE_ERROR_INVALID_QUERY)
|
||||
return SWIG_SyntaxError;
|
||||
else
|
||||
return SWIG_UnknownError;
|
||||
void lasso_exception(int errorCode) {
|
||||
PyObject *errorTuple;
|
||||
|
||||
switch(errorCode) {
|
||||
case LASSO_PROFILE_ERROR_INVALID_QUERY:
|
||||
errorTuple = Py_BuildValue("(is)", errorCode, "Lasso Syntax Error");
|
||||
PyErr_SetObject(lassoSyntaxError, errorTuple);
|
||||
Py_DECREF(errorTuple);
|
||||
break;
|
||||
default:
|
||||
errorTuple = Py_BuildValue("(is)", errorCode, "Lasso Error");
|
||||
PyErr_SetObject(lassoError, errorTuple);
|
||||
Py_DECREF(errorTuple);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
/* Wrappers for Lasso functions that return an error code. */
|
||||
%define THROW_ERROR
|
||||
%exception {
|
||||
int errorCode;
|
||||
errorCode = $action
|
||||
if (errorCode) {
|
||||
lasso_exception(errorCode);
|
||||
SWIG_fail;
|
||||
}
|
||||
}
|
||||
%enddef
|
||||
|
||||
#else
|
||||
|
||||
%{
|
||||
|
||||
int get_exception_type(int errorCode) {
|
||||
int exceptionType;
|
||||
|
||||
switch(errorCode) {
|
||||
case LASSO_PROFILE_ERROR_INVALID_QUERY:
|
||||
exceptionType = SWIG_SyntaxError;
|
||||
break;
|
||||
default:
|
||||
exceptionType = SWIG_UnknownError;
|
||||
break;
|
||||
}
|
||||
return exceptionType;
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
%define THROW_ERROR
|
||||
%exception {
|
||||
|
@ -449,6 +518,8 @@ int get_exception_type(int errorCode)
|
|||
}
|
||||
%enddef
|
||||
|
||||
#endif
|
||||
|
||||
%define END_THROW_ERROR
|
||||
%exception;
|
||||
%enddef
|
||||
|
|
Loading…
Reference in New Issue