Author: cito
Date: Sat Nov 21 18:51:18 2015
New Revision: 582
Log:
Make the module name available on the class
That's a bit more reasonable than returning it in the getattr method.
Modified:
trunk/module/pgmodule.c
Modified: trunk/module/pgmodule.c
==============================================================================
--- trunk/module/pgmodule.c Sat Nov 21 18:43:40 2015 (r581)
+++ trunk/module/pgmodule.c Sat Nov 21 18:51:18 2015 (r582)
@@ -54,8 +54,6 @@
#endif
/* default values */
-#define MODULE_NAME "pg"
-#define MODULE_NAME_DB "pgdb"
#define PG_ARRAYSIZE 1
/* flags for object validity checks */
@@ -960,10 +958,6 @@
if (!strcmp(name, "error"))
return PyStr_FromString(PQerrorMessage(self->pgcnx->cnx));
- /* module name */
- if (!strcmp(name, "__module__"))
- return PyStr_FromString(MODULE_NAME);
-
/* seeks name in methods (fallback) */
return PyObject_GenericGetAttr((PyObject *) self, nameobj);
}
@@ -2253,10 +2247,6 @@
return PyInt_FromLong(PQserverVersion(self->cnx));
#endif
- /* module name */
- if (!strcmp(name, "__module__"))
- return PyStr_FromString(MODULE_NAME);
-
return PyObject_GenericGetAttr((PyObject *) self, nameobj);
}
@@ -2868,10 +2858,6 @@
if (!strcmp(name, "nfields"))
return PyInt_FromLong(self->num_fields);
- /* module name */
- if (!strcmp(name, "__module__"))
- return PyStr_FromString(MODULE_NAME_DB);
-
/* seeks name in methods (fallback) */
return PyObject_GenericGetAttr((PyObject *) self, nameobj);
}
@@ -3531,10 +3517,6 @@
}
}
- /* module name */
- if (!strcmp(name, "__module__"))
- return PyStr_FromString(MODULE_NAME);
-
return PyObject_GenericGetAttr((PyObject *) self, nameobj);
}
@@ -4216,7 +4198,7 @@
/* Initialization function for the module */
MODULE_INIT_FUNC(_pg)
{
- PyObject *mod, *dict, *v;
+ PyObject *mod, *dict, *s;
/* Create the module and add the functions */
@@ -4246,6 +4228,19 @@
#endif
) return NULL;
+ /* make the module names available */
+ s = PyStr_FromString("pg");
+ PyDict_SetItemString(connType.tp_dict, "__module__", s);
+ PyDict_SetItemString(noticeType.tp_dict, "__module__", s);
+ PyDict_SetItemString(queryType.tp_dict, "__module__", s);
+#ifdef LARGE_OBJECTS
+ PyDict_SetItemString(largeType.tp_dict, "__module__", s);
+#endif
+ Py_DECREF(s);
+ s = PyStr_FromString("pgdb");
+ PyDict_SetItemString(sourceType.tp_dict, "__module__", s);
+ Py_DECREF(s);
+
dict = PyModule_GetDict(mod);
/* Exceptions as defined by DB-API 2.0 */
@@ -4284,10 +4279,10 @@
PyDict_SetItemString(dict, "NotSupportedError", NotSupportedError);
/* Make the version available */
- v = PyStr_FromString(PyPgVersion);
- PyDict_SetItemString(dict, "version", v);
- PyDict_SetItemString(dict, "__version__", v);
- Py_DECREF(v);
+ s = PyStr_FromString(PyPgVersion);
+ PyDict_SetItemString(dict, "version", s);
+ PyDict_SetItemString(dict, "__version__", s);
+ Py_DECREF(s);
/* results type for queries */
PyDict_SetItemString(dict, "RESULT_EMPTY",
PyInt_FromLong(RESULT_EMPTY));
_______________________________________________
PyGreSQL mailing list
[email protected]
https://mail.vex.net/mailman/listinfo.cgi/pygresql