mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-02-07 12:50:32 +03:00
If we are depending on Python 2.4, we don't need to make decimal module
support conditional.
This commit is contained in:
parent
345a254ca0
commit
83b03e5e36
|
@ -280,8 +280,11 @@ psyco_adapters_init(PyObject *mod)
|
|||
microprotocols_add(&PyUnicode_Type, NULL, (PyObject*)&qstringType);
|
||||
microprotocols_add(&PyBuffer_Type, NULL, (PyObject*)&binaryType);
|
||||
microprotocols_add(&PyList_Type, NULL, (PyObject*)&listType);
|
||||
microprotocols_add((PyTypeObject*)psyco_GetDecimalType(),
|
||||
NULL, (PyObject*)&asisType);
|
||||
|
||||
/* as above, we use the callable objects from the psycopg module */
|
||||
/* the module has already been initialized, so we can obtain the callable
|
||||
objects directly from its dictionary :) */
|
||||
call = PyMapping_GetItemString(mod, "DateFromPy");
|
||||
microprotocols_add((PyTypeObject*)pyDateTypeP, NULL, call);
|
||||
call = PyMapping_GetItemString(mod, "TimeFromPy");
|
||||
|
@ -292,18 +295,12 @@ psyco_adapters_init(PyObject *mod)
|
|||
microprotocols_add((PyTypeObject*)pyDeltaTypeP, NULL, call);
|
||||
|
||||
#ifdef HAVE_MXDATETIME
|
||||
/* the module has already been initialized, so we can obtain the callable
|
||||
objects directly from its dictionary :) */
|
||||
/* as above, we use the callable objects from the psycopg module */
|
||||
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
|
||||
microprotocols_add((PyTypeObject*)psyco_GetDecimalType(),
|
||||
NULL, (PyObject*)&asisType);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* psyco_encodings_fill
|
||||
|
@ -583,9 +580,7 @@ psyco_GetDecimalType(void)
|
|||
{
|
||||
PyObject *decimalType = NULL;
|
||||
static PyObject *cachedType = NULL;
|
||||
|
||||
#ifdef HAVE_DECIMAL
|
||||
PyObject *decimal = PyImport_ImportModule("decimal");
|
||||
PyObject *decimal;
|
||||
|
||||
/* Use the cached object if running from the main interpreter. */
|
||||
int can_cache = psyco_is_main_interp();
|
||||
|
@ -595,6 +590,7 @@ psyco_GetDecimalType(void)
|
|||
}
|
||||
|
||||
/* Get a new reference to the Decimal type. */
|
||||
decimal = PyImport_ImportModule("decimal");
|
||||
if (decimal) {
|
||||
decimalType = PyObject_GetAttrString(decimal, "Decimal");
|
||||
Py_DECREF(decimal);
|
||||
|
@ -607,11 +603,10 @@ psyco_GetDecimalType(void)
|
|||
|
||||
/* Store the object from future uses. */
|
||||
if (can_cache && !cachedType) {
|
||||
Py_INCREF(decimalType);
|
||||
cachedType = decimalType;
|
||||
}
|
||||
|
||||
#endif /* HAVE_DECIMAL */
|
||||
|
||||
return decimalType;
|
||||
}
|
||||
|
||||
|
|
|
@ -115,7 +115,6 @@ typecast_BOOLEAN_cast(const char *s, Py_ssize_t len, PyObject *curs)
|
|||
|
||||
/** DECIMAL - cast any kind of number into a Python Decimal object **/
|
||||
|
||||
#ifdef HAVE_DECIMAL
|
||||
static PyObject *
|
||||
typecast_DECIMAL_cast(const char *s, Py_ssize_t len, PyObject *curs)
|
||||
{
|
||||
|
@ -135,9 +134,6 @@ typecast_DECIMAL_cast(const char *s, Py_ssize_t len, PyObject *curs)
|
|||
|
||||
return res;
|
||||
}
|
||||
#else
|
||||
#define typecast_DECIMAL_cast typecast_FLOAT_cast
|
||||
#endif
|
||||
|
||||
/* some needed aliases */
|
||||
#define typecast_NUMBER_cast typecast_FLOAT_cast
|
||||
|
|
|
@ -12,12 +12,6 @@ define=PSYCOPG_EXTENSIONS,PSYCOPG_NEW_BOOLEAN,HAVE_PQFREEMEM,HAVE_PQPROTOCOL3,PS
|
|||
# Set to 1 to use Python datatime objects for default date/time representation
|
||||
use_pydatetime=1
|
||||
|
||||
# Set to 1 if you want to enable "Decimal" type on python 2.3.
|
||||
# If the "decimal" module is found in the PYTHONPATH it will be used, else
|
||||
# fall back on the float type (this is disabled by default to be compatible
|
||||
# with old versions of psycopg 1 and pre-beta versions of psycopg 2.)
|
||||
use_decimal=0
|
||||
|
||||
# If the build system does not find the mx.DateTime headers, try
|
||||
# uncommenting the following line and setting its value to the right path.
|
||||
#mx_include_dir=
|
||||
|
|
13
setup.py
13
setup.py
|
@ -55,7 +55,7 @@ from distutils.sysconfig import get_python_inc
|
|||
from distutils.ccompiler import get_default_compiler
|
||||
|
||||
PSYCOPG_VERSION = '2.0.8'
|
||||
version_flags = ['dt']
|
||||
version_flags = ['dt', 'dec']
|
||||
|
||||
PLATFORM_IS_WINDOWS = sys.platform.lower().startswith('win')
|
||||
|
||||
|
@ -86,14 +86,12 @@ class psycopg_build_ext(build_ext):
|
|||
"Use Python datatime objects for date and time representation."),
|
||||
('pg-config=', None,
|
||||
"The name of the pg_config binary and/or full path to find it"),
|
||||
('use-decimal', None,
|
||||
"Use Decimal type even on Python 2.3 if the module is provided."),
|
||||
('have-ssl', None,
|
||||
"Compile with OpenSSL built PostgreSQL libraries (Windows only)."),
|
||||
])
|
||||
|
||||
boolean_options = build_ext.boolean_options[:]
|
||||
boolean_options.extend(('use-pydatetime', 'use-decimal', 'have-ssl'))
|
||||
boolean_options.extend(('use-pydatetime', 'have-ssl'))
|
||||
|
||||
DEFAULT_PG_CONFIG = "pg_config"
|
||||
|
||||
|
@ -323,13 +321,6 @@ sources = [
|
|||
parser = ConfigParser.ConfigParser()
|
||||
parser.read('setup.cfg')
|
||||
|
||||
# Choose if to use Decimal type
|
||||
use_decimal = int(parser.get('build_ext', 'use_decimal'))
|
||||
if sys.version_info[0] >= 2 and (
|
||||
sys.version_info[1] >= 4 or (sys.version_info[1] == 3 and use_decimal)):
|
||||
define_macros.append(('HAVE_DECIMAL','1'))
|
||||
version_flags.append('dec')
|
||||
|
||||
# Choose a datetime module
|
||||
have_pydatetime = True
|
||||
have_mxdatetime = False
|
||||
|
|
Loading…
Reference in New Issue
Block a user