Browse Source

[1179] some more consistency moves

Jelte Jansen 13 years ago
parent
commit
b25df34f6a

+ 9 - 29
src/lib/python/isc/datasrc/client_python.cc

@@ -86,6 +86,9 @@ DataSourceClient_findZone(PyObject* po_self, PyObject* args) {
         } catch (const std::exception& exc) {
             PyErr_SetString(getDataSourceException("Error"), exc.what());
             return (NULL);
+        } catch (...) {
+            PyErr_SetString(getDataSourceException("Error"), "Unexpected exception");
+            return (NULL);
         }
     } else {
         return (NULL);
@@ -108,6 +111,9 @@ DataSourceClient_getIterator(PyObject* po_self, PyObject* args) {
         } catch (const std::exception& exc) {
             PyErr_SetString(getDataSourceException("Error"), exc.what());
             return (NULL);
+        } catch (...) {
+            PyErr_SetString(getDataSourceException("Error"), "Unexpected exception");
+            return (NULL);
         }
     } else {
         return (NULL);
@@ -132,6 +138,9 @@ DataSourceClient_getUpdater(PyObject* po_self, PyObject* args) {
         } catch (const std::exception& exc) {
             PyErr_SetString(getDataSourceException("Error"), exc.what());
             return (NULL);
+        } catch (...) {
+            PyErr_SetString(getDataSourceException("Error"), "Unexpected exception");
+            return (NULL);
         }
     } else {
         return (NULL);
@@ -260,35 +269,6 @@ PyTypeObject datasourceclient_type = {
     0                                   // tp_version_tag
 };
 
-namespace internal {
-// Module Initialization, all statics are initialized here
-bool
-initModulePart_DataSourceClient(PyObject* mod) {
-    // We initialize the static description object with PyType_Ready(),
-    // then add it to the module. This is not just a check! (leaving
-    // this out results in segmentation faults)
-    if (PyType_Ready(&datasourceclient_type) < 0) {
-        return (false);
-    }
-    void* dscp = &datasourceclient_type;
-    if (PyModule_AddObject(mod, "DataSourceClient", static_cast<PyObject*>(dscp)) < 0) {
-        return (false);
-    }
-    Py_INCREF(&datasourceclient_type);
-
-    isc::dns::python::addClassVariable(datasourceclient_type, "SUCCESS",
-                                       Py_BuildValue("I", result::SUCCESS));
-    isc::dns::python::addClassVariable(datasourceclient_type, "EXIST",
-                                       Py_BuildValue("I", result::EXIST));
-    isc::dns::python::addClassVariable(datasourceclient_type, "NOTFOUND",
-                                       Py_BuildValue("I", result::NOTFOUND));
-    isc::dns::python::addClassVariable(datasourceclient_type, "PARTIALMATCH",
-                                       Py_BuildValue("I", result::PARTIALMATCH));
-
-    return (true);
-}
-} // namespace internal
-
 } // namespace python
 } // namespace datasrc
 } // namespace isc

+ 102 - 9
src/lib/python/isc/datasrc/datasrc.cc

@@ -29,9 +29,12 @@
 #include "updater_python.h"
 
 #include <util/python/pycppwrapper_util.h>
+#include <dns/python/pydnspp_common.h>
 
+using namespace isc::datasrc;
 using namespace isc::datasrc::python;
 using namespace isc::util::python;
+using namespace isc::dns::python;
 
 namespace isc {
 namespace datasrc {
@@ -54,19 +57,111 @@ getDataSourceException(const char* ex_name) {
     return (ex_obj);
 }
 
-namespace internal {
-bool initModulePart_DataSourceClient(PyObject* mod);
-bool initModulePart_ZoneFinder(PyObject* mod);
-bool initModulePart_ZoneIterator(PyObject* mod);
-bool initModulePart_ZoneUpdater(PyObject* mod);
-} // end namespace internal
-
 } // end namespace python
 } // end namespace datasrc
 } // end namespace isc
 
 namespace {
 
+bool
+initModulePart_DataSourceClient(PyObject* mod) {
+    // We initialize the static description object with PyType_Ready(),
+    // then add it to the module. This is not just a check! (leaving
+    // this out results in segmentation faults)
+    if (PyType_Ready(&datasourceclient_type) < 0) {
+        return (false);
+    }
+    void* dscp = &datasourceclient_type;
+    if (PyModule_AddObject(mod, "DataSourceClient", static_cast<PyObject*>(dscp)) < 0) {
+        return (false);
+    }
+    Py_INCREF(&datasourceclient_type);
+
+    addClassVariable(datasourceclient_type, "SUCCESS",
+                     Py_BuildValue("I", result::SUCCESS));
+    addClassVariable(datasourceclient_type, "EXIST",
+                     Py_BuildValue("I", result::EXIST));
+    addClassVariable(datasourceclient_type, "NOTFOUND",
+                     Py_BuildValue("I", result::NOTFOUND));
+    addClassVariable(datasourceclient_type, "PARTIALMATCH",
+                     Py_BuildValue("I", result::PARTIALMATCH));
+
+    return (true);
+}
+
+bool
+initModulePart_ZoneFinder(PyObject* mod) {
+    // We initialize the static description object with PyType_Ready(),
+    // then add it to the module. This is not just a check! (leaving
+    // this out results in segmentation faults)
+    if (PyType_Ready(&zonefinder_type) < 0) {
+        return (false);
+    }
+    void* zip = &zonefinder_type;
+    if (PyModule_AddObject(mod, "ZoneFinder", static_cast<PyObject*>(zip)) < 0) {
+        return (false);
+    }
+    Py_INCREF(&zonefinder_type);
+
+    addClassVariable(zonefinder_type, "SUCCESS",
+                     Py_BuildValue("I", ZoneFinder::SUCCESS));
+    addClassVariable(zonefinder_type, "DELEGATION",
+                     Py_BuildValue("I", ZoneFinder::DELEGATION));
+    addClassVariable(zonefinder_type, "NXDOMAIN",
+                     Py_BuildValue("I", ZoneFinder::NXDOMAIN));
+    addClassVariable(zonefinder_type, "NXRRSET",
+                     Py_BuildValue("I", ZoneFinder::NXRRSET));
+    addClassVariable(zonefinder_type, "CNAME",
+                     Py_BuildValue("I", ZoneFinder::CNAME));
+    addClassVariable(zonefinder_type, "DNAME",
+                     Py_BuildValue("I", ZoneFinder::DNAME));
+
+    addClassVariable(zonefinder_type, "FIND_DEFAULT",
+                     Py_BuildValue("I", ZoneFinder::FIND_DEFAULT));
+    addClassVariable(zonefinder_type, "FIND_GLUE_OK",
+                     Py_BuildValue("I", ZoneFinder::FIND_GLUE_OK));
+    addClassVariable(zonefinder_type, "FIND_DNSSEC",
+                     Py_BuildValue("I", ZoneFinder::FIND_DNSSEC));
+
+
+    return (true);
+}
+
+bool
+initModulePart_ZoneIterator(PyObject* mod) {
+    // We initialize the static description object with PyType_Ready(),
+    // then add it to the module. This is not just a check! (leaving
+    // this out results in segmentation faults)
+    if (PyType_Ready(&zoneiterator_type) < 0) {
+        return (false);
+    }
+    void* zip = &zoneiterator_type;
+    if (PyModule_AddObject(mod, "ZoneIterator", static_cast<PyObject*>(zip)) < 0) {
+        return (false);
+    }
+    Py_INCREF(&zoneiterator_type);
+
+    return (true);
+}
+
+bool
+initModulePart_ZoneUpdater(PyObject* mod) {
+    // We initialize the static description object with PyType_Ready(),
+    // then add it to the module. This is not just a check! (leaving
+    // this out results in segmentation faults)
+    if (PyType_Ready(&zoneupdater_type) < 0) {
+        return (false);
+    }
+    void* zip = &zoneupdater_type;
+    if (PyModule_AddObject(mod, "ZoneUpdater", static_cast<PyObject*>(zip)) < 0) {
+        return (false);
+    }
+    Py_INCREF(&zoneupdater_type);
+
+    return (true);
+}
+
+
 PyObject* po_DataSourceError;
 PyObject* po_NotImplemented;
 
@@ -86,8 +181,6 @@ PyModuleDef iscDataSrc = {
 
 } // end anonymous namespace
 
-using namespace isc::datasrc::python::internal;
-
 PyMODINIT_FUNC
 PyInit_datasrc(void) {
     PyObject* mod = PyModule_Create(&iscDataSrc);

+ 6 - 41
src/lib/python/isc/datasrc/finder_python.cc

@@ -100,6 +100,9 @@ PyObject* ZoneFinder_getOrigin(PyObject* po_self, PyObject*) {
     } catch (const std::exception& exc) {
         PyErr_SetString(getDataSourceException("Error"), exc.what());
         return (NULL);
+    } catch (...) {
+        PyErr_SetString(getDataSourceException("Error"), "Unexpected exception");
+        return (NULL);
     }
 }
 
@@ -134,6 +137,9 @@ PyObject* ZoneFinder_find(PyObject* po_self, PyObject* args) {
         } catch (const std::exception& exc) {
             PyErr_SetString(getDataSourceException("Error"), exc.what());
             return (NULL);
+        } catch (...) {
+            PyErr_SetString(getDataSourceException("Error"), "Unexpected exception");
+            return (NULL);
         }
     } else {
         return (NULL);
@@ -212,47 +218,6 @@ PyTypeObject zonefinder_type = {
     0                                   // tp_version_tag
 };
 
-namespace internal {
-// Module Initialization, all statics are initialized here
-bool
-initModulePart_ZoneFinder(PyObject* mod) {
-    // We initialize the static description object with PyType_Ready(),
-    // then add it to the module. This is not just a check! (leaving
-    // this out results in segmentation faults)
-    if (PyType_Ready(&zonefinder_type) < 0) {
-        return (false);
-    }
-    void* zip = &zonefinder_type;
-    if (PyModule_AddObject(mod, "ZoneFinder", static_cast<PyObject*>(zip)) < 0) {
-        return (false);
-    }
-    Py_INCREF(&zonefinder_type);
-
-    isc::dns::python::addClassVariable(zonefinder_type, "SUCCESS",
-                                       Py_BuildValue("I", ZoneFinder::SUCCESS));
-    isc::dns::python::addClassVariable(zonefinder_type, "DELEGATION",
-                                       Py_BuildValue("I", ZoneFinder::DELEGATION));
-    isc::dns::python::addClassVariable(zonefinder_type, "NXDOMAIN",
-                                       Py_BuildValue("I", ZoneFinder::NXDOMAIN));
-    isc::dns::python::addClassVariable(zonefinder_type, "NXRRSET",
-                                       Py_BuildValue("I", ZoneFinder::NXRRSET));
-    isc::dns::python::addClassVariable(zonefinder_type, "CNAME",
-                                       Py_BuildValue("I", ZoneFinder::CNAME));
-    isc::dns::python::addClassVariable(zonefinder_type, "DNAME",
-                                       Py_BuildValue("I", ZoneFinder::DNAME));
-
-    isc::dns::python::addClassVariable(zonefinder_type, "FIND_DEFAULT",
-                                       Py_BuildValue("I", ZoneFinder::FIND_DEFAULT));
-    isc::dns::python::addClassVariable(zonefinder_type, "FIND_GLUE_OK",
-                                       Py_BuildValue("I", ZoneFinder::FIND_GLUE_OK));
-    isc::dns::python::addClassVariable(zonefinder_type, "FIND_DNSSEC",
-                                       Py_BuildValue("I", ZoneFinder::FIND_DNSSEC));
-
-
-    return (true);
-}
-} // namespace internal
-
 PyObject*
 createZoneFinderObject(isc::datasrc::ZoneFinderPtr source) {
     s_ZoneFinder* py_zi = static_cast<s_ZoneFinder*>(

+ 3 - 20
src/lib/python/isc/datasrc/iterator_python.cc

@@ -96,6 +96,9 @@ PyObject* ZoneIterator_getNextRRset(PyObject* po_self, PyObject*) {
     } catch (const std::exception& exc) {
         PyErr_SetString(getDataSourceException("Error"), exc.what());
         return (NULL);
+    } catch (...) {
+        PyErr_SetString(getDataSourceException("Error"), "Unexpected exception");
+        return (NULL);
     }
 }
 
@@ -173,26 +176,6 @@ PyTypeObject zoneiterator_type = {
     0                                   // tp_version_tag
 };
 
-namespace internal {
-// Module Initialization, all statics are initialized here
-bool
-initModulePart_ZoneIterator(PyObject* mod) {
-    // We initialize the static description object with PyType_Ready(),
-    // then add it to the module. This is not just a check! (leaving
-    // this out results in segmentation faults)
-    if (PyType_Ready(&zoneiterator_type) < 0) {
-        return (false);
-    }
-    void* zip = &zoneiterator_type;
-    if (PyModule_AddObject(mod, "ZoneIterator", static_cast<PyObject*>(zip)) < 0) {
-        return (false);
-    }
-    Py_INCREF(&zoneiterator_type);
-
-    return (true);
-}
-} // namespace internal
-
 PyObject*
 createZoneIteratorObject(isc::datasrc::ZoneIteratorPtr source) {
     s_ZoneIterator* py_zi = static_cast<s_ZoneIterator*>(

+ 9 - 20
src/lib/python/isc/datasrc/updater_python.cc

@@ -146,6 +146,9 @@ PyObject* ZoneUpdater_getClass(PyObject* po_self, PyObject*) {
     } catch (const std::exception& exc) {
         PyErr_SetString(getDataSourceException("Error"), exc.what());
         return (NULL);
+    } catch (...) {
+        PyErr_SetString(getDataSourceException("Error"), "Unexpected exception");
+        return (NULL);
     }
 }
 
@@ -156,6 +159,9 @@ PyObject* ZoneUpdater_getOrigin(PyObject* po_self, PyObject*) {
     } catch (const std::exception& exc) {
         PyErr_SetString(getDataSourceException("Error"), exc.what());
         return (NULL);
+    } catch (...) {
+        PyErr_SetString(getDataSourceException("Error"), "Unexpected exception");
+        return (NULL);
     }
 }
 
@@ -190,6 +196,9 @@ PyObject* ZoneUpdater_find(PyObject* po_self, PyObject* args) {
         } catch (const std::exception& exc) {
             PyErr_SetString(getDataSourceException("Error"), exc.what());
             return (NULL);
+        } catch (...) {
+            PyErr_SetString(getDataSourceException("Error"), "Unexpected exception");
+            return (NULL);
         }
     } else {
         return (NULL);
@@ -279,26 +288,6 @@ PyTypeObject zoneupdater_type = {
     0                                   // tp_version_tag
 };
 
-namespace internal {
-// Module Initialization, all statics are initialized here
-bool
-initModulePart_ZoneUpdater(PyObject* mod) {
-    // We initialize the static description object with PyType_Ready(),
-    // then add it to the module. This is not just a check! (leaving
-    // this out results in segmentation faults)
-    if (PyType_Ready(&zoneupdater_type) < 0) {
-        return (false);
-    }
-    void* zip = &zoneupdater_type;
-    if (PyModule_AddObject(mod, "ZoneUpdater", static_cast<PyObject*>(zip)) < 0) {
-        return (false);
-    }
-    Py_INCREF(&zoneupdater_type);
-
-    return (true);
-}
-} // namespace internal
-
 PyObject*
 createZoneUpdaterObject(isc::datasrc::ZoneUpdaterPtr source) {
     s_ZoneUpdater* py_zi = static_cast<s_ZoneUpdater*>(