diff --git a/NEWS b/NEWS index 6851a311..2a6df275 100644 --- a/NEWS +++ b/NEWS @@ -44,6 +44,9 @@ Other changes: - Binary packages no longer installed by default. The 'psycopg2-binary' package must be used explicitly. - Dropped `!PSYCOPG_DISPLAY_SIZE` build parameter. +- Dropped support for mxDateTime as the default date and time adapter. + mxDatetime support continues to be available as an alternative to Python's + builtin datetime. - No longer use 2to3 during installation for Python 2 & 3 compatibility. All source files are now compatible with Python 2 & 3 as is. - The `!psycopg2.test` package is no longer installed by ``python setup.py diff --git a/psycopg/adapter_datetime.c b/psycopg/adapter_datetime.c index e76dc26b..5620fc78 100644 --- a/psycopg/adapter_datetime.c +++ b/psycopg/adapter_datetime.c @@ -265,8 +265,6 @@ PyTypeObject pydatetimeType = { /** module-level functions **/ -#ifdef PSYCOPG_DEFAULT_PYDATETIME - PyObject * psyco_Date(PyObject *self, PyObject *args) { @@ -458,8 +456,6 @@ exit: return res; } -#endif - PyObject * psyco_DateFromPy(PyObject *self, PyObject *args) { diff --git a/psycopg/adapter_datetime.h b/psycopg/adapter_datetime.h index 47b33ea5..eb0fc920 100644 --- a/psycopg/adapter_datetime.h +++ b/psycopg/adapter_datetime.h @@ -47,9 +47,6 @@ typedef struct { RAISES_NEG HIDDEN int psyco_adapter_datetime_init(void); -/* functions exported to psycopgmodule.c */ -#ifdef PSYCOPG_DEFAULT_PYDATETIME - HIDDEN PyObject *psyco_Date(PyObject *module, PyObject *args); #define psyco_Date_doc \ "Date(year, month, day) -> new date\n\n" \ @@ -86,8 +83,6 @@ HIDDEN PyObject *psyco_TimestampFromTicks(PyObject *module, PyObject *args); "Ticks are the number of seconds since the epoch; see the documentation " \ "of the standard Python time module for details)." -#endif /* PSYCOPG_DEFAULT_PYDATETIME */ - HIDDEN PyObject *psyco_DateFromPy(PyObject *module, PyObject *args); #define psyco_DateFromPy_doc \ "DateFromPy(datetime.date) -> new wrapper" diff --git a/psycopg/adapter_mxdatetime.c b/psycopg/adapter_mxdatetime.c index 9f17da11..cca8790e 100644 --- a/psycopg/adapter_mxdatetime.c +++ b/psycopg/adapter_mxdatetime.c @@ -254,131 +254,6 @@ PyTypeObject mxdatetimeType = { /** module-level functions **/ -#ifdef PSYCOPG_DEFAULT_MXDATETIME - -PyObject * -psyco_Date(PyObject *self, PyObject *args) -{ - PyObject *res, *mx; - int year, month, day; - - if (!PyArg_ParseTuple(args, "iii", &year, &month, &day)) - return NULL; - - mx = mxDateTime.DateTime_FromDateAndTime(year, month, day, 0, 0, 0.0); - if (mx == NULL) return NULL; - - res = PyObject_CallFunction((PyObject *)&mxdatetimeType, "Oi", mx, - PSYCO_MXDATETIME_DATE); - Py_DECREF(mx); - return res; -} - -PyObject * -psyco_Time(PyObject *self, PyObject *args) -{ - PyObject *res, *mx; - int hours, minutes=0; - double seconds=0.0; - - if (!PyArg_ParseTuple(args, "iid", &hours, &minutes, &seconds)) - return NULL; - - mx = mxDateTime.DateTimeDelta_FromTime(hours, minutes, seconds); - if (mx == NULL) return NULL; - - res = PyObject_CallFunction((PyObject *)&mxdatetimeType, "Oi", mx, - PSYCO_MXDATETIME_TIME); - Py_DECREF(mx); - return res; -} - -PyObject * -psyco_Timestamp(PyObject *self, PyObject *args) -{ - PyObject *res, *mx; - int year, month, day; - int hour=0, minute=0; /* default to midnight */ - double second=0.0; - - if (!PyArg_ParseTuple(args, "lii|iid", &year, &month, &day, - &hour, &minute, &second)) - return NULL; - - mx = mxDateTime.DateTime_FromDateAndTime(year, month, day, - hour, minute, second); - if (mx == NULL) return NULL; - - res = PyObject_CallFunction((PyObject *)&mxdatetimeType, "Oi", mx, - PSYCO_MXDATETIME_TIMESTAMP); - Py_DECREF(mx); - return res; -} - -PyObject * -psyco_DateFromTicks(PyObject *self, PyObject *args) -{ - PyObject *res, *mx; - double ticks; - - if (!PyArg_ParseTuple(args,"d", &ticks)) - return NULL; - - if (!(mx = mxDateTime.DateTime_FromTicks(ticks))) - return NULL; - - res = PyObject_CallFunction((PyObject *)&mxdatetimeType, "Oi", mx, - PSYCO_MXDATETIME_DATE); - Py_DECREF(mx); - return res; -} - -PyObject * -psyco_TimeFromTicks(PyObject *self, PyObject *args) -{ - PyObject *res, *mx, *dt; - double ticks; - - if (!PyArg_ParseTuple(args,"d", &ticks)) - return NULL; - - if (!(dt = mxDateTime.DateTime_FromTicks(ticks))) - return NULL; - - if (!(mx = mxDateTime.DateTimeDelta_FromDaysAndSeconds( - 0, ((mxDateTimeObject*)dt)->abstime))) - { - Py_DECREF(dt); - return NULL; - } - - Py_DECREF(dt); - res = PyObject_CallFunction((PyObject *)&mxdatetimeType, "Oi", mx, - PSYCO_MXDATETIME_TIME); - Py_DECREF(mx); - return res; -} - -PyObject * -psyco_TimestampFromTicks(PyObject *self, PyObject *args) -{ - PyObject *mx, *res; - double ticks; - - if (!PyArg_ParseTuple(args, "d", &ticks)) - return NULL; - - if (!(mx = mxDateTime.DateTime_FromTicks(ticks))) - return NULL; - - res = PyObject_CallFunction((PyObject *)&mxdatetimeType, "Oi", mx, - PSYCO_MXDATETIME_TIMESTAMP); - Py_DECREF(mx); - return res; -} - -#endif - PyObject * psyco_DateFromMx(PyObject *self, PyObject *args) { diff --git a/psycopg/adapter_mxdatetime.h b/psycopg/adapter_mxdatetime.h index 1b5d2a64..4b1df689 100644 --- a/psycopg/adapter_mxdatetime.h +++ b/psycopg/adapter_mxdatetime.h @@ -44,35 +44,6 @@ typedef struct { } mxdatetimeObject; -/* functions exported to psycopgmodule.c */ -#ifdef PSYCOPG_DEFAULT_MXDATETIME - -HIDDEN PyObject *psyco_Date(PyObject *module, PyObject *args); -#define psyco_Date_doc \ - "Date(year, month, day) -> new date" - -HIDDEN PyObject *psyco_Time(PyObject *module, PyObject *args); -#define psyco_Time_doc \ - "Time(hour, minutes, seconds) -> new time" - -HIDDEN PyObject *psyco_Timestamp(PyObject *module, PyObject *args); -#define psyco_Timestamp_doc \ - "Time(year, month, day, hour, minutes, seconds) -> new timestamp" - -HIDDEN PyObject *psyco_DateFromTicks(PyObject *module, PyObject *args); -#define psyco_DateFromTicks_doc \ - "DateFromTicks(ticks) -> new date" - -HIDDEN PyObject *psyco_TimeFromTicks(PyObject *module, PyObject *args); -#define psyco_TimeFromTicks_doc \ - "TimeFromTicks(ticks) -> new time" - -HIDDEN PyObject *psyco_TimestampFromTicks(PyObject *module, PyObject *args); -#define psyco_TimestampFromTicks_doc \ - "TimestampFromTicks(ticks) -> new timestamp" - -#endif /* PSYCOPG_DEFAULT_MXDATETIME */ - HIDDEN int psyco_adapter_mxdatetime_init(void); HIDDEN PyObject *psyco_DateFromMx(PyObject *module, PyObject *args); diff --git a/psycopg/psycopgmodule.c b/psycopg/psycopgmodule.c index 6b79442f..596ca31c 100644 --- a/psycopg/psycopgmodule.c +++ b/psycopg/psycopgmodule.c @@ -970,13 +970,6 @@ mxdatetime_init(PyObject *module) if (mxDateTime_ImportModuleAndAPI()) { Dprintf("psycopgmodule: mx.DateTime module import failed"); PyErr_Clear(); - - /* only fail if the mx typacaster should have been the default */ -#ifdef PSYCOPG_DEFAULT_MXDATETIME - PyErr_SetString(PyExc_ImportError, - "can't import mx.DateTime module (requested as default adapter)"); - return -1; -#endif } /* If we can't find mx.DateTime objects at runtime, diff --git a/psycopg/typecast_datetime.c b/psycopg/typecast_datetime.c index d7804007..7e5789b2 100644 --- a/psycopg/typecast_datetime.c +++ b/psycopg/typecast_datetime.c @@ -458,10 +458,8 @@ typecast_PYINTERVAL_cast(const char *str, Py_ssize_t len, PyObject *curs) /* psycopg defaults to using python datetime types */ -#ifdef PSYCOPG_DEFAULT_PYDATETIME #define typecast_DATE_cast typecast_PYDATE_cast #define typecast_TIME_cast typecast_PYTIME_cast #define typecast_INTERVAL_cast typecast_PYINTERVAL_cast #define typecast_DATETIME_cast typecast_PYDATETIME_cast #define typecast_DATETIMETZ_cast typecast_PYDATETIMETZ_cast -#endif diff --git a/psycopg/typecast_mxdatetime.c b/psycopg/typecast_mxdatetime.c index ed0f99e0..46147cc3 100644 --- a/psycopg/typecast_mxdatetime.c +++ b/psycopg/typecast_mxdatetime.c @@ -240,13 +240,3 @@ typecast_MXINTERVAL_cast(const char *str, Py_ssize_t len, PyObject *curs) days, seconds); return mxDateTime.DateTimeDelta_FromDaysAndSeconds(days, seconds); } - -/* psycopg defaults to using mx types */ - -#ifdef PSYCOPG_DEFAULT_MXDATETIME -#define typecast_DATE_cast typecast_MXDATE_cast -#define typecast_TIME_cast typecast_MXTIME_cast -#define typecast_INTERVAL_cast typecast_MXINTERVAL_cast -#define typecast_DATETIME_cast typecast_MXDATE_cast -#define typecast_DATETIMETZ_cast typecast_MXDATE_cast -#endif diff --git a/setup.cfg b/setup.cfg index f1f57e64..43c61d16 100644 --- a/setup.cfg +++ b/setup.cfg @@ -7,9 +7,6 @@ define= # different name set the following option to the pg_config full path. pg_config= -# Set to 1 to use Python datetime objects for default date/time representation. -use_pydatetime=1 - # If the build system does not find the mx.DateTime headers, try # setting its value to the right path. mx_include_dir= diff --git a/setup.py b/setup.py index 1bdc9353..a45ee310 100644 --- a/setup.py +++ b/setup.py @@ -523,12 +523,8 @@ depends = [ parser = configparser.ConfigParser() parser.read('setup.cfg') -# Choose a datetime module -have_pydatetime = True -have_mxdatetime = False -use_pydatetime = parser.getboolean('build_ext', 'use_pydatetime') - # check for mx package +have_mxdatetime = False mxincludedir = '' if parser.has_option('build_ext', 'mx_include_dir'): mxincludedir = parser.get('build_ext', 'mx_include_dir') @@ -543,25 +539,6 @@ if mxincludedir.strip() and os.path.exists(mxincludedir): have_mxdatetime = True version_flags.append('mx') -# now decide which package will be the default for date/time typecasts -if have_pydatetime and (use_pydatetime or not have_mxdatetime): - define_macros.append(('PSYCOPG_DEFAULT_PYDATETIME', '1')) -elif have_mxdatetime: - define_macros.append(('PSYCOPG_DEFAULT_MXDATETIME', '1')) -else: - error_message = """\ -psycopg requires a datetime module: - mx.DateTime module not found - python datetime module not found - -Note that psycopg needs the module headers and not just the module -itself. If you installed Python or mx.DateTime from a binary package -you probably need to install its companion -dev or -devel package.""" - - for line in error_message.split("\n"): - sys.stderr.write("error: " + line) - sys.exit(1) - # generate a nice version string to avoid confusion when users report bugs version_flags.append('pq3') # no more a choice version_flags.append('ext') # no more a choice