summaryrefslogtreecommitdiff
path: root/psycopg/psycopgmodule.c
diff options
context:
space:
mode:
authorJames Henstridge <james@jamesh.id.au>2008-12-26 23:46:35 +0900
committerJames Henstridge <james@jamesh.id.au>2008-12-26 23:46:35 +0900
commit345a254ca05b0b07f5fc3dbb0520ae00a35fb923 (patch)
treefd316dfda6731d4fb4e7a72f68d2574f5fe62fa2 /psycopg/psycopgmodule.c
parente7b8d6505e89571c7637d0377f6a4ce2cc6106b0 (diff)
downloadpsycopg2-345a254ca05b0b07f5fc3dbb0520ae00a35fb923.tar.gz
Remove conditionals on support for booleans and datetimes, since they
are guaranteed to be available in Python 2.4.
Diffstat (limited to 'psycopg/psycopgmodule.c')
-rw-r--r--psycopg/psycopgmodule.c58
1 files changed, 21 insertions, 37 deletions
diff --git a/psycopg/psycopgmodule.c b/psycopg/psycopgmodule.c
index 6c658fc..d991a6a 100644
--- a/psycopg/psycopgmodule.c
+++ b/psycopg/psycopgmodule.c
@@ -47,7 +47,6 @@ HIDDEN mxDateTimeModule_APIObject *mxDateTimeP = NULL;
#endif
/* some module-level variables, like the datetime module */
-#ifdef HAVE_PYDATETIME
#include <datetime.h>
#include "psycopg/adapter_datetime.h"
HIDDEN PyObject *pyDateTimeModuleP = NULL;
@@ -55,7 +54,6 @@ HIDDEN PyObject *pyDateTypeP = NULL;
HIDDEN PyObject *pyTimeTypeP = NULL;
HIDDEN PyObject *pyDateTimeTypeP = NULL;
HIDDEN PyObject *pyDeltaTypeP = NULL;
-#endif
/* pointers to the psycopg.tz classes */
HIDDEN PyObject *pyPsycopgTzModule = NULL;
@@ -276,22 +274,13 @@ psyco_adapters_init(PyObject *mod)
microprotocols_add(&PyFloat_Type, NULL, (PyObject*)&asisType);
microprotocols_add(&PyInt_Type, NULL, (PyObject*)&asisType);
microprotocols_add(&PyLong_Type, NULL, (PyObject*)&asisType);
+ microprotocols_add(&PyBool_Type, NULL, (PyObject*)&pbooleanType);
microprotocols_add(&PyString_Type, NULL, (PyObject*)&qstringType);
microprotocols_add(&PyUnicode_Type, NULL, (PyObject*)&qstringType);
microprotocols_add(&PyBuffer_Type, NULL, (PyObject*)&binaryType);
microprotocols_add(&PyList_Type, NULL, (PyObject*)&listType);
-#ifdef HAVE_MXDATETIME
- /* the module has already been initialized, so we can obtain the callable
- objects directly from its dictionary :) */
- call = PyMapping_GetItemString(mod, "TimestampFromMx");
- microprotocols_add(mxDateTimeP->DateTime_Type, NULL, call);
- call = PyMapping_GetItemString(mod, "TimeFromMx");
- microprotocols_add(mxDateTimeP->DateTimeDelta_Type, NULL, call);
-#endif
-
-#ifdef HAVE_PYDATETIME
/* as above, we use the callable objects from the psycopg module */
call = PyMapping_GetItemString(mod, "DateFromPy");
microprotocols_add((PyTypeObject*)pyDateTypeP, NULL, call);
@@ -301,10 +290,14 @@ psyco_adapters_init(PyObject *mod)
microprotocols_add((PyTypeObject*)pyDateTimeTypeP, NULL, call);
call = PyMapping_GetItemString(mod, "IntervalFromPy");
microprotocols_add((PyTypeObject*)pyDeltaTypeP, NULL, call);
-#endif
-#ifdef HAVE_PYBOOL
- microprotocols_add(&PyBool_Type, NULL, (PyObject*)&pbooleanType);
+#ifdef HAVE_MXDATETIME
+ /* the module has already been initialized, so we can obtain the callable
+ objects directly from its dictionary :) */
+ call = PyMapping_GetItemString(mod, "TimestampFromMx");
+ microprotocols_add(mxDateTimeP->DateTime_Type, NULL, call);
+ call = PyMapping_GetItemString(mod, "TimeFromMx");
+ microprotocols_add(mxDateTimeP->DateTimeDelta_Type, NULL, call);
#endif
#ifdef HAVE_DECIMAL
@@ -659,6 +652,15 @@ static PyMethodDef psycopgMethods[] = {
{"List", (PyCFunction)psyco_List,
METH_VARARGS, psyco_List_doc},
+ {"DateFromPy", (PyCFunction)psyco_DateFromPy,
+ METH_VARARGS, psyco_DateFromPy_doc},
+ {"TimeFromPy", (PyCFunction)psyco_TimeFromPy,
+ METH_VARARGS, psyco_TimeFromPy_doc},
+ {"TimestampFromPy", (PyCFunction)psyco_TimestampFromPy,
+ METH_VARARGS, psyco_TimestampFromPy_doc},
+ {"IntervalFromPy", (PyCFunction)psyco_IntervalFromPy,
+ METH_VARARGS, psyco_IntervalFromPy_doc},
+
#ifdef HAVE_MXDATETIME
{"DateFromMx", (PyCFunction)psyco_DateFromMx,
METH_VARARGS, psyco_DateFromMx_doc},
@@ -670,17 +672,6 @@ static PyMethodDef psycopgMethods[] = {
METH_VARARGS, psyco_IntervalFromMx_doc},
#endif
-#ifdef HAVE_PYDATETIME
- {"DateFromPy", (PyCFunction)psyco_DateFromPy,
- METH_VARARGS, psyco_DateFromPy_doc},
- {"TimeFromPy", (PyCFunction)psyco_TimeFromPy,
- METH_VARARGS, psyco_TimeFromPy_doc},
- {"TimestampFromPy", (PyCFunction)psyco_TimestampFromPy,
- METH_VARARGS, psyco_TimestampFromPy_doc},
- {"IntervalFromPy", (PyCFunction)psyco_IntervalFromPy,
- METH_VARARGS, psyco_IntervalFromPy_doc},
-#endif
-
{NULL, NULL, 0, NULL} /* Sentinel */
};
@@ -694,7 +685,7 @@ init_psycopg(void)
#ifdef PSYCOPG_DEBUG
if (getenv("PSYCOPG_DEBUG"))
- psycopg_debug_enabled = 1;
+ psycopg_debug_enabled = 1;
#endif
Dprintf("initpsycopg: initializing psycopg %s", PSYCOPG_VERSION);
@@ -706,6 +697,7 @@ init_psycopg(void)
qstringType.ob_type = &PyType_Type;
binaryType.ob_type = &PyType_Type;
isqlquoteType.ob_type = &PyType_Type;
+ pbooleanType.ob_type = &PyType_Type;
asisType.ob_type = &PyType_Type;
listType.ob_type = &PyType_Type;
chunkType.ob_type = &PyType_Type;
@@ -716,6 +708,7 @@ init_psycopg(void)
if (PyType_Ready(&qstringType) == -1) return;
if (PyType_Ready(&binaryType) == -1) return;
if (PyType_Ready(&isqlquoteType) == -1) return;
+ if (PyType_Ready(&pbooleanType) == -1) return;
if (PyType_Ready(&asisType) == -1) return;
if (PyType_Ready(&listType) == -1) return;
if (PyType_Ready(&chunkType) == -1) return;
@@ -725,11 +718,6 @@ init_psycopg(void)
if (PyType_Ready(&lobjectType) == -1) return;
#endif
-#ifdef HAVE_PYBOOL
- pbooleanType.ob_type = &PyType_Type;
- if (PyType_Ready(&pbooleanType) == -1) return;
-#endif
-
/* import mx.DateTime module, if necessary */
#ifdef HAVE_MXDATETIME
mxdatetimeType.ob_type = &PyType_Type;
@@ -743,7 +731,6 @@ init_psycopg(void)
#endif
/* import python builtin datetime module, if available */
-#ifdef HAVE_PYDATETIME
pyDateTimeModuleP = PyImport_ImportModule("datetime");
if (pyDateTimeModuleP == NULL) {
Dprintf("initpsycopg: can't import datetime module");
@@ -759,7 +746,6 @@ init_psycopg(void)
pyTimeTypeP = PyObject_GetAttrString(pyDateTimeModuleP, "time");
pyDateTimeTypeP = PyObject_GetAttrString(pyDateTimeModuleP, "datetime");
pyDeltaTypeP = PyObject_GetAttrString(pyDateTimeModuleP, "timedelta");
-#endif
/* import psycopg2.tz anyway (TODO: replace with C-level module?) */
pyPsycopgTzModule = PyImport_ImportModule("psycopg2.tz");
@@ -828,14 +814,12 @@ init_psycopg(void)
qstringType.tp_alloc = PyType_GenericAlloc;
listType.tp_alloc = PyType_GenericAlloc;
chunkType.tp_alloc = PyType_GenericAlloc;
+ pydatetimeType.tp_alloc = PyType_GenericAlloc;
#ifdef PSYCOPG_EXTENSIONS
lobjectType.tp_alloc = PyType_GenericAlloc;
#endif
-#ifdef HAVE_PYDATETIME
- pydatetimeType.tp_alloc = PyType_GenericAlloc;
-#endif
#ifdef HAVE_MXDATETIME
mxdatetimeType.tp_alloc = PyType_GenericAlloc;