Here are patches for a BETA port of PyGreSQL to Python 3.2. I don't
claim to know anything about Python extensions or internals. I used
2to3 on the python code and followed the guidelines from
http://python3porting.com for both the C code and fixing Python code
that 2to3 doesn't handle. Someone who understands Python exception
internals should look at the exception initialization code. I doubt I
got it right...
I haven't fully tested it yet. I only needed Unicode string queries and
it runs well with my code. I tried to leave the 2.x C code as it was.
The patched Python files are 3.x. While the package is running well for
me, there may be some bugs in the handling of Integers and Strings
(especially conversion from Postgres non-Unicode strings to Python
Unicode strings).
Things left to do:
1. Fix setup.py to handle 2.x and 3.x
2. Fix Python code to handle both 2.x and 3.x (or fix setup.py to select
the correct files to install)
3. Test all the functionality.
Brad Davis
P.S. Let me know of this doesn't come through correctly.
diff -c PyGreSQL-4.1.1/pg.py PyGreSQL-4.1.1.NEW/pg.py
*** PyGreSQL-4.1.1/pg.py 2013-01-08 07:47:33.000000000 -0700
--- PyGreSQL-4.1.1.NEW/pg.py 2015-01-28 10:36:16.178567705 -0700
***************
*** 32,37 ****
--- 32,38 ----
import select
import warnings
+ import collections
try:
frozenset
except NameError: # Python < 2.4
***************
*** 329,346 ****
def _do_debug(self, s):
"""Print a debug message."""
if self.debug:
! if isinstance(self.debug, basestring):
! print self.debug % s
elif isinstance(self.debug, file):
file.write(s + '\n')
! elif callable(self.debug):
self.debug(s)
else:
! print s
def _quote_text(self, d):
"""Quote text value."""
! if not isinstance(d, basestring):
d = str(d)
return "'%s'" % self.escape_string(d)
--- 330,347 ----
def _do_debug(self, s):
"""Print a debug message."""
if self.debug:
! if isinstance(self.debug, str):
! print(self.debug % s)
elif isinstance(self.debug, file):
file.write(s + '\n')
! elif isinstance(self.debug, collections.Callable):
self.debug(s)
else:
! print(s)
def _quote_text(self, d):
"""Quote text value."""
! if not isinstance(d, str):
d = str(d)
return "'%s'" % self.escape_string(d)
***************
*** 348,354 ****
def _quote_bool(self, d):
"""Quote boolean value."""
! if isinstance(d, basestring):
if not d:
return 'NULL'
d = d.lower() in self._bool_true
--- 349,355 ----
def _quote_bool(self, d):
"""Quote boolean value."""
! if isinstance(d, str):
if not d:
return 'NULL'
d = d.lower() in self._bool_true
***************
*** 363,369 ****
"""Quote date value."""
if not d:
return 'NULL'
! if isinstance(d, basestring) and d.lower() in self._date_literals:
return d
return self._quote_text(d)
--- 364,370 ----
"""Quote date value."""
if not d:
return 'NULL'
! if isinstance(d, str) and d.lower() in self._date_literals:
return d
return self._quote_text(d)
***************
*** 377,383 ****
"""Quote money value."""
if d is None or d == '':
return 'NULL'
! if not isinstance(d, basestring):
d = str(d)
return d
--- 378,384 ----
"""Quote money value."""
if d is None or d == '':
return 'NULL'
! if not isinstance(d, str):
d = str(d)
return d
***************
*** 561,567 ****
# make sure that all classes have a namespace
self._pkeys = dict([
('.' in cl and cl or 'public.' + cl, pkey)
! for cl, pkey in newpkey.iteritems()])
return self._pkeys
qcl = self._add_schema(cl) # build fully qualified class name
--- 562,568 ----
# make sure that all classes have a namespace
self._pkeys = dict([
('.' in cl and cl or 'public.' + cl, pkey)
! for cl, pkey in newpkey.items()])
return self._pkeys
qcl = self._add_schema(cl) # build fully qualified class name
***************
*** 594,600 ****
cl, pkey = _join_parts(r[:2]), r[2]
self._pkeys.setdefault(cl, []).append(pkey)
# (only) for composite primary keys, the values will be frozensets
! for cl, pkey in self._pkeys.iteritems():
self._pkeys[cl] = len(pkey) > 1 and frozenset(pkey) or pkey[0]
self._do_debug(self._pkeys)
--- 595,601 ----
cl, pkey = _join_parts(r[:2]), r[2]
self._pkeys.setdefault(cl, []).append(pkey)
# (only) for composite primary keys, the values will be frozensets
! for cl, pkey in self._pkeys.items():
self._pkeys[cl] = len(pkey) > 1 and frozenset(pkey) or pkey[0]
self._do_debug(self._pkeys)
***************
*** 616,628 ****
"""
where = kinds and "pg_class.relkind IN (%s) AND" % ','.join(
["'%s'" % x for x in kinds]) or ''
! return map(_join_parts, self.db.query(
"SELECT pg_namespace.nspname, pg_class.relname "
"FROM pg_class "
"JOIN pg_namespace ON pg_namespace.oid = pg_class.relnamespace "
"WHERE %s pg_class.relname !~ '^Inv' AND "
"pg_class.relname !~ '^pg_' "
! "ORDER BY 1, 2" % where).getresult())
def get_tables(self):
"""Return list of tables in connected database."""
--- 617,629 ----
"""
where = kinds and "pg_class.relkind IN (%s) AND" % ','.join(
["'%s'" % x for x in kinds]) or ''
! return list(map(_join_parts, self.db.query(
"SELECT pg_namespace.nspname, pg_class.relname "
"FROM pg_class "
"JOIN pg_namespace ON pg_namespace.oid = pg_class.relnamespace "
"WHERE %s pg_class.relname !~ '^Inv' AND "
"pg_class.relname !~ '^pg_' "
! "ORDER BY 1, 2" % where).getresult()))
def get_tables(self):
"""Return list of tables in connected database."""
***************
*** 758,764 ****
attnames = '*'
else:
attnames = self.get_attnames(qcl)
! if isinstance(keyname, basestring):
keyname = (keyname,)
if not isinstance(arg, dict):
if len(keyname) > 1:
--- 759,765 ----
attnames = '*'
else:
attnames = self.get_attnames(qcl)
! if isinstance(keyname, str):
keyname = (keyname,)
if not isinstance(arg, dict):
if len(keyname) > 1:
***************
*** 772,778 ****
res = self.db.query(q).dictresult()
if not res:
raise _db_error('No such record in %s where %s' % (qcl, where))
! for att, value in res[0].iteritems():
arg[att == 'oid' and qoid or att] = value
return arg
--- 773,779 ----
res = self.db.query(q).dictresult()
if not res:
raise _db_error('No such record in %s where %s' % (qcl, where))
! for att, value in res[0].items():
arg[att == 'oid' and qoid or att] = value
return arg
***************
*** 812,818 ****
res = self.db.query(q)
if ret:
res = res.dictresult()
! for att, value in res[0].iteritems():
d[att == 'oid' and qoid or att] = value
elif isinstance(res, int):
d[qoid] = res
--- 813,819 ----
res = self.db.query(q)
if ret:
res = res.dictresult()
! for att, value in res[0].items():
d[att == 'oid' and qoid or att] = value
elif isinstance(res, int):
d[qoid] = res
***************
*** 858,864 ****
keyname = self.pkey(qcl)
except KeyError:
raise _prg_error('Class %s has no primary key' % qcl)
! if isinstance(keyname, basestring):
keyname = (keyname,)
try:
where = ' AND '.join(['%s = %s'
--- 859,865 ----
keyname = self.pkey(qcl)
except KeyError:
raise _prg_error('Class %s has no primary key' % qcl)
! if isinstance(keyname, str):
keyname = (keyname,)
try:
where = ' AND '.join(['%s = %s'
***************
*** 882,888 ****
res = self.db.query(q)
if ret:
res = res.dictresult()[0]
! for att, value in res.iteritems():
d[att == 'oid' and qoid or att] = value
else:
if selectable:
--- 883,889 ----
res = self.db.query(q)
if ret:
res = res.dictresult()[0]
! for att, value in res.items():
d[att == 'oid' and qoid or att] = value
else:
if selectable:
***************
*** 906,912 ****
if a is None:
a = {} # empty if argument is not present
attnames = self.get_attnames(qcl)
! for n, t in attnames.iteritems():
if n == 'oid':
continue
if t in ('int', 'integer', 'smallint', 'bigint',
--- 907,913 ----
if a is None:
a = {} # empty if argument is not present
attnames = self.get_attnames(qcl)
! for n, t in attnames.items():
if n == 'oid':
continue
if t in ('int', 'integer', 'smallint', 'bigint',
***************
*** 947,953 ****
keyname = self.pkey(qcl)
except KeyError:
raise _prg_error('Class %s has no primary key' % qcl)
! if isinstance(keyname, basestring):
keyname = (keyname,)
attnames = self.get_attnames(qcl)
try:
--- 948,954 ----
keyname = self.pkey(qcl)
except KeyError:
raise _prg_error('Class %s has no primary key' % qcl)
! if isinstance(keyname, str):
keyname = (keyname,)
attnames = self.get_attnames(qcl)
try:
***************
*** 967,972 ****
# if run as script, print some information
if __name__ == '__main__':
! print('PyGreSQL version' + version)
print('')
print(__doc__)
--- 968,973 ----
# if run as script, print some information
if __name__ == '__main__':
! print(('PyGreSQL version' + version))
print('')
print(__doc__)
diff -c PyGreSQL-4.1.1/pgdb.py PyGreSQL-4.1.1.NEW/pgdb.py
*** PyGreSQL-4.1.1/pgdb.py 2013-01-08 07:47:33.000000000 -0700
--- PyGreSQL-4.1.1.NEW/pgdb.py 2015-01-28 10:36:42.154556601 -0700
***************
*** 122,129 ****
def _cast_money(value):
! return Decimal(''.join(filter(
! lambda v: v in '0123456789.-', value)))
def _cast_bytea(value):
--- 122,128 ----
def _cast_money(value):
! return Decimal(''.join([v for v in value if v in '0123456789.-']))
def _cast_bytea(value):
***************
*** 145,151 ****
_cast = {'bool': _cast_bool, 'bytea': _cast_bytea,
'int2': int, 'int4': int, 'serial': int,
! 'int8': long, 'oid': long, 'oid8': long,
'float4': _cast_float, 'float8': _cast_float,
'numeric': Decimal, 'money': _cast_money}
--- 144,150 ----
_cast = {'bool': _cast_bool, 'bytea': _cast_bytea,
'int2': int, 'int4': int, 'serial': int,
! 'int8': int, 'oid': int, 'oid8': int,
'float4': _cast_float, 'float8': _cast_float,
'numeric': Decimal, 'money': _cast_money}
***************
*** 243,249 ****
"""Quote value depending on its type."""
if isinstance(val, (datetime, date, time, timedelta)):
val = str(val)
! elif isinstance(val, unicode):
val = val.encode('utf8')
if isinstance(val, str):
if isinstance(val, Binary):
--- 242,248 ----
"""Quote value depending on its type."""
if isinstance(val, (datetime, date, time, timedelta)):
val = str(val)
! elif isinstance(val, str):
val = val.encode('utf8')
if isinstance(val, str):
if isinstance(val, Binary):
***************
*** 251,257 ****
else:
val = self._cnx.escape_string(val)
val = "'%s'" % val
! elif isinstance(val, (int, long)):
pass
elif isinstance(val, float):
if isinf(val):
--- 250,256 ----
else:
val = self._cnx.escape_string(val)
val = "'%s'" % val
! elif isinstance(val, int):
pass
elif isinstance(val, float):
if isinf(val):
***************
*** 261,267 ****
elif val is None:
val = 'NULL'
elif isinstance(val, (list, tuple)):
! val = '(%s)' % ','.join(map(lambda v: str(self._quote(v)), val))
elif Decimal is not float and isinstance(val, Decimal):
pass
elif hasattr(val, '__pg_repr__'):
--- 260,266 ----
elif val is None:
val = 'NULL'
elif isinstance(val, (list, tuple)):
! val = '(%s)' % ','.join([str(self._quote(v)) for v in val])
elif Decimal is not float and isinstance(val, Decimal):
pass
elif hasattr(val, '__pg_repr__'):
***************
*** 353,361 ****
self.rowcount = -1
except DatabaseError:
raise
! except Error, err:
raise _db_error("error '%s' in '%s'" % (err, sql))
! except Exception, err:
raise _op_error("internal error in '%s': %s" % (sql, err))
# then initialize result raw count and description
if self._src.resulttype == RESULT_DQL:
--- 352,360 ----
self.rowcount = -1
except DatabaseError:
raise
! except Error as err:
raise _db_error("error '%s' in '%s'" % (err, sql))
! except Exception as err:
raise _op_error("internal error in '%s': %s" % (sql, err))
# then initialize result raw count and description
if self._src.resulttype == RESULT_DQL:
***************
*** 402,408 ****
result = self._src.fetch(size)
except DatabaseError:
raise
! except Error, err:
raise _db_error(str(err))
row_factory = self.row_factory
typecast = self._type_cache.typecast
--- 401,407 ----
result = self._src.fetch(size)
except DatabaseError:
raise
! except Error as err:
raise _db_error(str(err))
row_factory = self.row_factory
typecast = self._type_cache.typecast
***************
*** 410,416 ****
return [row_factory([typecast(*args)
for args in zip(coltypes, row)]) for row in result]
! def next(self):
"""Return the next row (support for the iteration protocol)."""
res = self.fetchone()
if res is None:
--- 409,415 ----
return [row_factory([typecast(*args)
for args in zip(coltypes, row)]) for row in result]
! def __next__(self):
"""Return the next row (support for the iteration protocol)."""
res = self.fetchone()
if res is None:
***************
*** 611,633 ****
if frozenset.__module__ == '__builtin__':
def __new__(cls, values):
! if isinstance(values, basestring):
values = values.split()
return super(pgdbType, cls).__new__(cls, values)
else: # Python < 2.4
def __init__(self, values):
! if isinstance(values, basestring):
values = values.split()
super(pgdbType, self).__init__(values)
def __eq__(self, other):
! if isinstance(other, basestring):
return other in self
else:
return super(pgdbType, self).__eq__(other)
def __ne__(self, other):
! if isinstance(other, basestring):
return other not in self
else:
return super(pgdbType, self).__ne__(other)
--- 610,632 ----
if frozenset.__module__ == '__builtin__':
def __new__(cls, values):
! if isinstance(values, str):
values = values.split()
return super(pgdbType, cls).__new__(cls, values)
else: # Python < 2.4
def __init__(self, values):
! if isinstance(values, str):
values = values.split()
super(pgdbType, self).__init__(values)
def __eq__(self, other):
! if isinstance(other, str):
return other in self
else:
return super(pgdbType, self).__eq__(other)
def __ne__(self, other):
! if isinstance(other, str):
return other not in self
else:
return super(pgdbType, self).__ne__(other)
***************
*** 697,702 ****
# If run as script, print some information:
if __name__ == '__main__':
! print('PyGreSQL version', version)
print('')
print(__doc__)
--- 696,701 ----
# If run as script, print some information:
if __name__ == '__main__':
! print(('PyGreSQL version', version))
print('')
print(__doc__)
diff -c PyGreSQL-4.1.1/pgmodule.c PyGreSQL-4.1.1.NEW/pgmodule.c
*** PyGreSQL-4.1.1/pgmodule.c 2013-01-08 07:47:33.000000000 -0700
--- PyGreSQL-4.1.1.NEW/pgmodule.c 2015-01-28 11:11:48.731645666 -0700
***************
*** 30,35 ****
--- 30,77 ----
/* Note: This should be linked against the same C runtime lib as Python */
#include <Python.h>
+ #if PY_MAJOR_VERSION >= 3
+ # define DL_EXPORT PyAPI_FUNC
+ # define DL_IMPORT PyAPI_DATA
+ # define staticforward static
+ # define statichere static
+ # define PyInt_FromLong(x) PyLong_FromLong(x)
+ # define PyInt_Check(x) PyLong_Check(x)
+ # define PyInt_AsLong(x) PyLong_AsLong(x)
+ # define PyInt_FromString(x, y, z) PyLong_FromString(x, y, z)
+ # define PyStringObject PyUnicodeObject
+ # define PyString_FromString(x) PyUnicode_FromString(x)
+ # define PyString_FromStringAndSize(x, y) PyUnicode_FromStringAndSize(x, y)
+ # define PyString_Check(x) PyUnicode_Check(x)
+ # define PyString_AsString(x) PyBytes_AsString(x)
+ # define _PyString_Resize(x, y) PyUnicode_Resize(x, y)
+ # define PyString_Size(x) PyBytes_Size(x)
+ # define PyFloat_FromString(x, y) PyFloat_FromString(x)
+ # define PyString_AS_STRING(x) PyBytes_AS_STRING(x)
+ static PyObject *Py_FindMethod(PyMethodDef table[], PyObject *self, const
char * name)
+ {
+ PyMethodDef *ml = table;
+
+ if (strcmp(name, "__doc__") == 0)
+ {
+ const char *doc = Py_TYPE(self)->tp_doc;
+ if (doc != NULL)
+ return PyBytes_FromString(doc);
+ }
+ for (; ml->ml_name != NULL; ml++)
+ {
+ if (strcmp(name, ml->ml_name) == 0)
+ return PyCFunction_New(ml, self);
+ }
+ PyErr_SetString(PyExc_AttributeError, name);
+ return NULL;
+ }
+ #else
+ # if PY_MINOR_VERSION < 6
+ # define Py_TYPE(ob) (((PyObject *)(ob))->ob_type)
+ # endif
+ #endif
+
#include <libpq-fe.h>
/* some definitions from <libpq/libpq-fs.h> */
***************
*** 137,143 ****
staticforward PyTypeObject PgType;
! #define is_pgobject(v) ((v)->ob_type == &PgType)
static PyObject *
pgobject_New(void)
--- 179,185 ----
staticforward PyTypeObject PgType;
! #define is_pgobject(v) (Py_TYPE(v) == &PgType)
static PyObject *
pgobject_New(void)
***************
*** 165,171 ****
staticforward PyTypeObject PgNoticeType;
! #define is_pgnoticeobject(v) ((v)->ob_type == &PgNoticeType)
/* pg query object */
--- 207,213 ----
staticforward PyTypeObject PgNoticeType;
! #define is_pgnoticeobject(v) (Py_TYPE(v) == &PgNoticeType)
/* pg query object */
***************
*** 180,186 ****
staticforward PyTypeObject PgQueryType;
! #define is_pgqueryobject(v) ((v)->ob_type == &PgQueryType)
/* pg source object */
--- 222,228 ----
staticforward PyTypeObject PgQueryType;
! #define is_pgqueryobject(v) (Py_TYPE(v) == &PgQueryType)
/* pg source object */
***************
*** 199,205 ****
staticforward PyTypeObject PgSourceType;
! #define is_pgsourceobject(v) ((v)->ob_type == &PgSourceType)
#ifdef LARGE_OBJECTS
--- 241,247 ----
staticforward PyTypeObject PgSourceType;
! #define is_pgsourceobject(v) (Py_TYPE(v) == &PgSourceType)
#ifdef LARGE_OBJECTS
***************
*** 215,221 ****
staticforward PyTypeObject PglargeType;
! #define is_pglargeobject(v) ((v)->ob_type == &PglargeType)
#endif /* LARGE_OBJECTS */
/* --------------------------------------------------------------------- */
--- 257,263 ----
staticforward PyTypeObject PglargeType;
! #define is_pglargeobject(v) (Py_TYPE(v) == &PglargeType)
#endif /* LARGE_OBJECTS */
/* --------------------------------------------------------------------- */
***************
*** 1185,1192 ****
--- 1227,1238 ----
/* query type definition */
staticforward PyTypeObject PgSourceType = {
+ #if PY_MAJOR_VERSION >= 3
+ PyVarObject_HEAD_INIT(NULL, 0) /*
ob_size */
+ #else
PyObject_HEAD_INIT(NULL)
0, /*
ob_size */
+ #endif
"pgsourceobject", /* tp_name */
sizeof(pgsourceobject), /* tp_basicsize */
0, /*
tp_itemsize */
***************
*** 1659,1666 ****
--- 1705,1716 ----
/* object type definition */
staticforward PyTypeObject PglargeType = {
+ #if PY_MAJOR_VERSION >= 3
+ PyVarObject_HEAD_INIT(NULL, 0) /* ob_size */
+ #else
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
+ #endif
"pglarge", /* tp_name */
sizeof(pglargeobject), /* tp_basicsize */
0, /* tp_itemsize
*/
***************
*** 3439,3446 ****
--- 3489,3500 ----
/* object type definition */
staticforward PyTypeObject PgType = {
+ #if PY_MAJOR_VERSION >= 3
+ PyVarObject_HEAD_INIT(NULL, 0) /* ob_size */
+ #else
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
+ #endif
"pgobject", /* tp_name */
sizeof(pgobject), /* tp_basicsize */
0, /* tp_itemsize
*/
***************
*** 3540,3547 ****
--- 3594,3605 ----
/* object type definition */
staticforward PyTypeObject PgNoticeType = {
+ #if PY_MAJOR_VERSION >= 3
+ PyVarObject_HEAD_INIT(NULL, 0) /* ob_size */
+ #else
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
+ #endif
"pgnoticeobject", /* tp_name */
sizeof(pgnoticeobject), /* tp_basicsize */
0, /* tp_itemsize
*/
***************
*** 3590,3597 ****
--- 3648,3659 ----
/* query type definition */
staticforward PyTypeObject PgQueryType = {
+ #if PY_MAJOR_VERSION >= 3
+ PyVarObject_HEAD_INIT(NULL, 0) /* ob_size */
+ #else
PyObject_HEAD_INIT(NULL)
0, /*
ob_size */
+ #endif
"pgqueryobject", /* tp_name */
sizeof(pgqueryobject), /* tp_basicsize */
0, /*
tp_itemsize */
***************
*** 4166,4194 ****
static char pg__doc__[] = "Python interface to PostgreSQL DB";
/* Initialization function for the module */
DL_EXPORT(void)
init_pg(void)
{
PyObject *mod,
*dict,
*v;
/* Initialize here because some WIN platforms get confused otherwise */
! PgType.ob_type = PgNoticeType.ob_type =
! PgQueryType.ob_type = PgSourceType.ob_type = &PyType_Type;
#ifdef LARGE_OBJECTS
! PglargeType.ob_type = &PyType_Type;
#endif
/* Create the module and add the functions */
! mod = Py_InitModule4("_pg", pg_methods, pg__doc__, NULL,
PYTHON_API_VERSION);
dict = PyModule_GetDict(mod);
/* Exceptions as defined by DB-API 2.0 */
Error = PyErr_NewException("pg.Error", PyExc_StandardError, NULL);
PyDict_SetItemString(dict, "Error", Error);
Warning = PyErr_NewException("pg.Warning", PyExc_StandardError, NULL);
PyDict_SetItemString(dict, "Warning", Warning);
InterfaceError = PyErr_NewException("pg.InterfaceError", Error, NULL);
--- 4228,4284 ----
static char pg__doc__[] = "Python interface to PostgreSQL DB";
/* Initialization function for the module */
+ #if PY_MAJOR_VERSION >= 3
+ static struct PyModuleDef moduledef = {
+ PyModuleDef_HEAD_INIT,
+ "_pg",
+ pg__doc__,
+ -1,
+ pg_methods,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ };
+
+ PyMODINIT_FUNC PyInit__pg(void)
+ #else
DL_EXPORT(void)
init_pg(void)
+ #endif
{
PyObject *mod,
*dict,
*v;
/* Initialize here because some WIN platforms get confused otherwise */
! Py_TYPE(&PgType) = Py_TYPE(&PgNoticeType) =
! Py_TYPE(&PgQueryType) = Py_TYPE(&PgSourceType) = &PyType_Type;
#ifdef LARGE_OBJECTS
! Py_TYPE(&PglargeType) = &PyType_Type;
#endif
/* Create the module and add the functions */
! #if PY_MAJOR_VERSION >= 3
! mod = PyModule_Create(&moduledef);
! #else
! mod = Py_InitModule3("_pg", pg_methods, pg__doc__);
! #endif
dict = PyModule_GetDict(mod);
/* Exceptions as defined by DB-API 2.0 */
+ #if PY_MAJOR_VERSION >= 3
+ Error = PyErr_NewException("pg.Error", PyExc_Exception, NULL);
+ #else
Error = PyErr_NewException("pg.Error", PyExc_StandardError, NULL);
+ #endif
PyDict_SetItemString(dict, "Error", Error);
+ #if PY_MAJOR_VERSION >= 3
+ Warning = PyErr_NewException("pg.Warning", PyExc_Warning, NULL);
+ #else
Warning = PyErr_NewException("pg.Warning", PyExc_StandardError, NULL);
+ #endif
PyDict_SetItemString(dict, "Warning", Warning);
InterfaceError = PyErr_NewException("pg.InterfaceError", Error, NULL);
***************
*** 4267,4273 ****
--- 4357,4372 ----
pg_default_passwd = Py_None;
#endif /* DEFAULT_VARS */
+ #if PY_MAJOR_VERSION >= 3
+ /* Check for errors */
+ if (PyErr_Occurred()) {
+ Py_FatalError("can't initialize module _pg");
+ return NULL;
+ }
+ return mod;
+ #else
/* Check for errors */
if (PyErr_Occurred())
Py_FatalError("can't initialize module _pg");
+ #endif
}
diff -c PyGreSQL-4.1.1/setup.py PyGreSQL-4.1.1.NEW/setup.py
*** PyGreSQL-4.1.1/setup.py 2013-01-08 07:47:33.000000000 -0700
--- PyGreSQL-4.1.1.NEW/setup.py 2015-01-27 15:41:08.022691908 -0700
***************
*** 40,46 ****
import sys
! if not (2, 3) <= sys.version_info[:2] < (3, 0):
raise Exception("Sorry, PyGreSQL %s"
" does not support this Python version" % version)
--- 40,49 ----
import sys
! #if not (2, 3) <= sys.version_info[:2] < (3, 0):
! # raise Exception("Sorry, PyGreSQL %s"
! # " does not support this Python version" % version)
! if not (3, 0) <= sys.version_info[:2] < (4, 0):
raise Exception("Sorry, PyGreSQL %s"
" does not support this Python version" % version)
_______________________________________________
PyGreSQL mailing list
[email protected]
https://mail.vex.net/mailman/listinfo.cgi/pygresql