diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2009-03-29 21:44:14 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2009-03-29 21:44:14 +0400 |
commit | 68e088f1cf3e3b8daa4a5d17acb6f0525ca6de95 (patch) | |
tree | a7b25263104f72f16d340119a09fcbcf29f8e695 /source/blender/freestyle/intern/python/BPy_ViewShape.cpp | |
parent | d79ddebaaec697e1775a6f652a1ee064eb053bf4 (diff) |
Improvements on error handling in the Python API.
Diffstat (limited to 'source/blender/freestyle/intern/python/BPy_ViewShape.cpp')
-rw-r--r-- | source/blender/freestyle/intern/python/BPy_ViewShape.cpp | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/source/blender/freestyle/intern/python/BPy_ViewShape.cpp b/source/blender/freestyle/intern/python/BPy_ViewShape.cpp index fd676c54c7b..09803b45aa5 100644 --- a/source/blender/freestyle/intern/python/BPy_ViewShape.cpp +++ b/source/blender/freestyle/intern/python/BPy_ViewShape.cpp @@ -150,11 +150,15 @@ int ViewShape___init__(BPy_ViewShape *self, PyObject *args, PyObject *kwds) if( !obj ) { self->vs = new ViewShape(); - } else if( BPy_ViewShape_Check(obj) ) { + } else if( BPy_SShape_Check(obj) ) { self->vs = new ViewShape( ((BPy_SShape *) obj)->ss ); } else if( BPy_ViewShape_Check(obj) ) { self->vs = new ViewShape(*( ((BPy_ViewShape *) obj)->vs )); + + } else { + PyErr_SetString(PyExc_TypeError, "invalid argument"); + return -1; } return 0; @@ -212,10 +216,8 @@ PyObject * ViewShape_getId( BPy_ViewShape *self ) { PyObject * ViewShape_setSShape( BPy_ViewShape *self , PyObject *args) { PyObject *py_ss = 0; - if(!( PyArg_ParseTuple(args, "O", &py_ss) && BPy_SShape_Check(py_ss) )) { - cout << "ERROR: ViewShape_SetSShape" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "O!", &SShape_Type, &py_ss) )) + return NULL; self->vs->setSShape( ((BPy_SShape *) py_ss)->ss ); @@ -226,10 +228,8 @@ PyObject * ViewShape_setVertices( BPy_ViewShape *self , PyObject *args) { PyObject *list = 0; PyObject *tmp; - if(!( PyArg_ParseTuple(args, "O", &list) && PyList_Check(list) )) { - cout << "ERROR: ViewShape_SetVertices" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "O!", &PyList_Type, &list) )) + return NULL; vector< ViewVertex *> v; @@ -237,8 +237,10 @@ PyObject * ViewShape_setVertices( BPy_ViewShape *self , PyObject *args) { tmp = PyList_GetItem(list, i); if( BPy_ViewVertex_Check(tmp) ) v.push_back( ((BPy_ViewVertex *) tmp)->vv ); - else - Py_RETURN_NONE; + else { + PyErr_SetString(PyExc_TypeError, "argument must be list of ViewVertex objects"); + return NULL; + } } self->vs->setVertices( v ); @@ -250,10 +252,8 @@ PyObject * ViewShape_setEdges( BPy_ViewShape *self , PyObject *args) { PyObject *list = 0; PyObject *tmp; - if(!( PyArg_ParseTuple(args, "O", &list) && PyList_Check(list) )) { - cout << "ERROR: ViewShape_SetVertices" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "O!", &PyList_Type, &list) )) + return NULL; vector<ViewEdge *> v; @@ -261,8 +261,10 @@ PyObject * ViewShape_setEdges( BPy_ViewShape *self , PyObject *args) { tmp = PyList_GetItem(list, i); if( BPy_ViewEdge_Check(tmp) ) v.push_back( ((BPy_ViewEdge *) tmp)->ve ); - else - Py_RETURN_NONE; + else { + PyErr_SetString(PyExc_TypeError, "argument must be list of ViewEdge objects"); + return NULL; + } } self->vs->setEdges( v ); @@ -273,10 +275,8 @@ PyObject * ViewShape_setEdges( BPy_ViewShape *self , PyObject *args) { PyObject * ViewShape_AddEdge( BPy_ViewShape *self , PyObject *args) { PyObject *py_ve = 0; - if(!( PyArg_ParseTuple(args, "O", &py_ve) && BPy_ViewEdge_Check(py_ve) )) { - cout << "ERROR: ViewShape_AddEdge" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "O!", &ViewEdge_Type, &py_ve) )) + return NULL; self->vs->AddEdge( ((BPy_ViewEdge *) py_ve)->ve ); @@ -286,10 +286,8 @@ PyObject * ViewShape_AddEdge( BPy_ViewShape *self , PyObject *args) { PyObject * ViewShape_AddVertex( BPy_ViewShape *self , PyObject *args) { PyObject *py_vv = 0; - if(!( PyArg_ParseTuple(args, "O", &py_vv) && BPy_ViewVertex_Check(py_vv) )) { - cout << "ERROR: ViewShape_AddNewVertex" << endl; - Py_RETURN_NONE; - } + if(!( PyArg_ParseTuple(args, "O!", &ViewVertex_Type, &py_vv) )) + return NULL; self->vs->AddVertex( ((BPy_ViewVertex *) py_vv)->vv ); |