Hello list,

I've tried to convert the pgdb-code to make it Python 3.0 ready.
However, my attempt failed. I have done some preliminary work - all the
"no brainers", so to speak - but for some stuff I have really no clue at
all(tm) how C language bindings work in Python.

It appears that ints are removed in favor of longs (at least the headers
indicate that intobject.h will be completely removed as of 3.1), some
macros also (DL_EXPORT, staticforward). The comment in the 2.5 headers
for staticforward indicates it was used for broken compilers only, so I
threw that one completely out. What DL_EXPORT does except for returning
whatever it gets as a parameter is also out of my grasp. I've however
defined a trivial DL_EXPORT macro if none is defined in Python.h.

Then there were two or three minor adjustments in setup.py, basically
only syntactic stuff.

I would really appreciate it if someone with knowledge would take a look
at it. Postgres support would also move Python 3 a big step forward.

Patch is attached...

Kind regards,
Johannes
diff -C 3 -r PyGreSQL-4.0-pre081031-orig/pgmodule.c 
PyGreSQL-4.0-pre081031/pgmodule.c
*** PyGreSQL-4.0-pre081031-orig/pgmodule.c      2008-10-31 22:13:57.000000000 
+0100
--- PyGreSQL-4.0-pre081031/pgmodule.c   2008-11-17 16:06:32.000000000 +0100
***************
*** 41,46 ****
--- 41,55 ----
  #undef vsnprintf
  
  #include <Python.h>
+ #include <longobject.h>
+ #include <unicodeobject.h>
+ 
+ /* Temporary workaround for Python 3.0, which does not define the DL_EXPORT
+  * macro any more */
+ #ifndef DL_EXPORT     /* declarations for DLL import/export */
+ #define DL_EXPORT(RTYPE) RTYPE
+ #endif
+ 
  
  /* PyObject_Del does not exist in older versions of Python: */
  #if PY_VERSION_HEX < 0x01060000
***************
*** 141,147 ****
        PGresult        *last_result;   /* last result content */
  }     pgobject;
  
! staticforward PyTypeObject PgType;
  
  #define is_pgobject(v) ((v)->ob_type == &PgType)
  
--- 150,156 ----
        PGresult        *last_result;   /* last result content */
  }     pgobject;
  
! static PyTypeObject PgType;
  
  #define is_pgobject(v) ((v)->ob_type == &PgType)
  
***************
*** 170,176 ****
        long            num_rows;               /* number of (affected) rows */
  }     pgqueryobject;
  
! staticforward PyTypeObject PgQueryType;
  
  #define is_pgqueryobject(v) ((v)->ob_type == &PgQueryType)
  
--- 179,185 ----
        long            num_rows;               /* number of (affected) rows */
  }     pgqueryobject;
  
! static PyTypeObject PgQueryType;
  
  #define is_pgqueryobject(v) ((v)->ob_type == &PgQueryType)
  
***************
*** 189,195 ****
        int                     num_fields;             /* number of fields in 
each row */
  }     pgsourceobject;
  
! staticforward PyTypeObject PgSourceType;
  
  #define is_pgsourceobject(v) ((v)->ob_type == &PgSourceType)
  
--- 198,204 ----
        int                     num_fields;             /* number of fields in 
each row */
  }     pgsourceobject;
  
! static PyTypeObject PgSourceType;
  
  #define is_pgsourceobject(v) ((v)->ob_type == &PgSourceType)
  
***************
*** 205,211 ****
        int                     lo_fd;                  /* large object fd */
  }     pglargeobject;
  
! staticforward PyTypeObject PglargeType;
  
  #define is_pglargeobject(v) ((v)->ob_type == &PglargeType)
  #endif /* LARGE_OBJECTS */
--- 214,220 ----
        int                     lo_fd;                  /* large object fd */
  }     pglargeobject;
  
! static PyTypeObject PglargeType;
  
  #define is_pglargeobject(v) ((v)->ob_type == &PglargeType)
  #endif /* LARGE_OBJECTS */
***************
*** 574,580 ****
                                self->result_type = RESULT_DML;
                                num_rows = atol(temp);
                        }
!                       return PyInt_FromLong(num_rows);
  
                        /* query failed */
                case PGRES_EMPTY_QUERY:
--- 583,589 ----
                                self->result_type = RESULT_DML;
                                num_rows = atol(temp);
                        }
!                       return PyLong_FromLong(num_rows);
  
                        /* query failed */
                case PGRES_EMPTY_QUERY:
***************
*** 626,632 ****
                return Py_None;
        }
  
!       return PyInt_FromLong(oid);
  }
  
  /* fetches rows from last result */
--- 635,641 ----
                return Py_None;
        }
  
!       return PyLong_FromLong(oid);
  }
  
  /* fetches rows from last result */
***************
*** 684,690 ****
                                str = Py_None;
                        }
                        else
!                               str = 
PyString_FromString(PQgetvalue(self->last_result, self->current_row, j));
  
                        PyTuple_SET_ITEM(rowtuple, j, str);
                }
--- 693,699 ----
                                str = Py_None;
                        }
                        else
!                               str = 
PyUnicode_FromString(PQgetvalue(self->last_result, self->current_row, j));
  
                        PyTuple_SET_ITEM(rowtuple, j, str);
                }
***************
*** 789,798 ****
                return -1;
  
        /* gets field number */
!       if (PyString_Check(param))
!               num = PQfnumber(self->last_result, PyString_AsString(param));
!       else if (PyInt_Check(param))
!               num = PyInt_AsLong(param);
        else
        {
                PyErr_SetString(PyExc_TypeError, usage);
--- 798,807 ----
                return -1;
  
        /* gets field number */
!       if (PyUnicode_Check(param))
!               num = PQfnumber(self->last_result, PyUnicode_AS_DATA(param));
!       else if (PyLong_Check(param))
!               num = PyLong_AsLong(param);
        else
        {
                PyErr_SetString(PyExc_TypeError, usage);
***************
*** 821,831 ****
                return NULL;
  
        /* affects field information */
!       PyTuple_SET_ITEM(result, 0, PyInt_FromLong(num));
        PyTuple_SET_ITEM(result, 1,
!               PyString_FromString(PQfname(self->last_result, num)));
        PyTuple_SET_ITEM(result, 2,
!               PyInt_FromLong(PQftype(self->last_result, num)));
  
        return result;
  }
--- 830,840 ----
                return NULL;
  
        /* affects field information */
!       PyTuple_SET_ITEM(result, 0, PyLong_FromLong(num));
        PyTuple_SET_ITEM(result, 1,
!               PyUnicode_FromString(PQfname(self->last_result, num)));
        PyTuple_SET_ITEM(result, 2,
!               PyLong_FromLong(PQftype(self->last_result, num)));
  
        return result;
  }
***************
*** 924,930 ****
        if ((num = pgsource_fieldindex(self, param, short_usage)) == -1)
                return NULL;
  
!       return PyString_FromString(PQgetvalue(self->last_result,
                                                                        
self->current_row, num));
  }
  
--- 933,939 ----
        if ((num = pgsource_fieldindex(self, param, short_usage)) == -1)
                return NULL;
  
!       return PyUnicode_FromString(PQgetvalue(self->last_result,
                                                                        
self->current_row, num));
  }
  
***************
*** 973,1016 ****
  
        /* arraysize */
        if (!strcmp(name, "arraysize"))
!               return PyInt_FromLong(self->arraysize);
  
        /* resulttype */
        if (!strcmp(name, "resulttype"))
!               return PyInt_FromLong(self->result_type);
  
        /* ntuples */
        if (!strcmp(name, "ntuples"))
!               return PyInt_FromLong(self->max_row);
  
        /* nfields */
        if (!strcmp(name, "nfields"))
!               return PyInt_FromLong(self->num_fields);
  
        /* attributes list */
        if (!strcmp(name, "__members__"))
        {
                PyObject *list = PyList_New(5);
  
!               PyList_SET_ITEM(list, 0, PyString_FromString("pgcnx"));
!               PyList_SET_ITEM(list, 1, PyString_FromString("arraysize"));
!               PyList_SET_ITEM(list, 2, PyString_FromString("resulttype"));
!               PyList_SET_ITEM(list, 3, PyString_FromString("ntuples"));
!               PyList_SET_ITEM(list, 4, PyString_FromString("nfields"));
  
                return list;
        }
  
        /* module name */
        if (!strcmp(name, "__module__"))
!               return PyString_FromString(MODULE_NAME);
  
        /* class name */
        if (!strcmp(name, "__class__"))
!               return PyString_FromString("pgsource");
  
        /* seeks name in methods (fallback) */
!       return Py_FindMethod(pgsource_methods, (PyObject *) self, name);
  }
  
  /* sets query object attributes */
--- 982,1028 ----
  
        /* arraysize */
        if (!strcmp(name, "arraysize"))
!               return PyLong_FromLong(self->arraysize);
  
        /* resulttype */
        if (!strcmp(name, "resulttype"))
!               return PyLong_FromLong(self->result_type);
  
        /* ntuples */
        if (!strcmp(name, "ntuples"))
!               return PyLong_FromLong(self->max_row);
  
        /* nfields */
        if (!strcmp(name, "nfields"))
!               return PyLong_FromLong(self->num_fields);
  
        /* attributes list */
        if (!strcmp(name, "__members__"))
        {
                PyObject *list = PyList_New(5);
  
!               PyList_SET_ITEM(list, 0, PyUnicode_FromString("pgcnx"));
!               PyList_SET_ITEM(list, 1, PyUnicode_FromString("arraysize"));
!               PyList_SET_ITEM(list, 2, PyUnicode_FromString("resulttype"));
!               PyList_SET_ITEM(list, 3, PyUnicode_FromString("ntuples"));
!               PyList_SET_ITEM(list, 4, PyUnicode_FromString("nfields"));
  
                return list;
        }
  
        /* module name */
        if (!strcmp(name, "__module__"))
!               return PyUnicode_FromString(MODULE_NAME);
  
        /* class name */
        if (!strcmp(name, "__class__"))
!               return PyUnicode_FromString("pgsource");
  
        /* seeks name in methods (fallback) */
!       /* TODO: Is this an appropriate python3 replacement? I have NO clue... 
*/
!       /* Why the hell does this not compile? Abort instead of doing something 
stupid. */
!       abort();
! /*    return PyCFunction_NewEx(pgsource_methods, (PyObject *) self, name); */
  }
  
  /* sets query object attributes */
***************
*** 1020,1032 ****
        /* arraysize */
        if (!strcmp(name, "arraysize"))
        {
!               if (!PyInt_Check(v))
                {
                        PyErr_SetString(PyExc_TypeError, "arraysize must be 
integer.");
                        return -1;
                }
  
!               self->arraysize = PyInt_AsLong(v);
                return 0;
        }
  
--- 1032,1044 ----
        /* arraysize */
        if (!strcmp(name, "arraysize"))
        {
!               if (!PyLong_Check(v))
                {
                        PyErr_SetString(PyExc_TypeError, "arraysize must be 
integer.");
                        return -1;
                }
  
!               self->arraysize = PyLong_AsLong(v);
                return 0;
        }
  
***************
*** 1059,1065 ****
  }
  
  /* query type definition */
! staticforward PyTypeObject PgSourceType = {
        PyObject_HEAD_INIT(NULL)
  
        0,                                                      /* ob_size */
--- 1071,1077 ----
  }
  
  /* query type definition */
! static PyTypeObject PgSourceType = {
        PyObject_HEAD_INIT(NULL)
  
        0,                                                      /* ob_size */
***************
*** 1208,1214 ****
        }
  
        /* allocate buffer and runs read */
!       buffer = PyString_FromStringAndSize((char *) NULL, size);
  
        if ((size = lo_read(self->pgcnx->cnx, self->lo_fd, BUF(buffer), size)) 
< 0)
        {
--- 1220,1226 ----
        }
  
        /* allocate buffer and runs read */
!       buffer = PyUnicode_FromStringAndSize((char *) NULL, size);
  
        if ((size = lo_read(self->pgcnx->cnx, self->lo_fd, BUF(buffer), size)) 
< 0)
        {
***************
*** 1293,1299 ****
        }
  
        /* returns position */
!       return PyInt_FromLong(ret);
  }
  
  /* gets large object size */
--- 1305,1311 ----
        }
  
        /* returns position */
!       return PyLong_FromLong(ret);
  }
  
  /* gets large object size */
***************
*** 1342,1348 ****
        }
  
        /* returns size */
!       return PyInt_FromLong(end);
  }
  
  /* gets large object cursor position */
--- 1354,1360 ----
        }
  
        /* returns size */
!       return PyLong_FromLong(end);
  }
  
  /* gets large object cursor position */
***************
*** 1375,1381 ****
        }
  
        /* returns size */
!       return PyInt_FromLong(start);
  }
  
  /* exports large object as unix file */
--- 1387,1393 ----
        }
  
        /* returns size */
!       return PyLong_FromLong(start);
  }
  
  /* exports large object as unix file */
***************
*** 1480,1486 ****
        if (!strcmp(name, "oid"))
        {
                if (check_lo_obj(self, 0))
!                       return PyInt_FromLong(self->lo_oid);
  
                Py_INCREF(Py_None);
                return Py_None;
--- 1492,1498 ----
        if (!strcmp(name, "oid"))
        {
                if (check_lo_obj(self, 0))
!                       return PyLong_FromLong(self->lo_oid);
  
                Py_INCREF(Py_None);
                return Py_None;
***************
*** 1488,1494 ****
  
        /* error (status) message */
        if (!strcmp(name, "error"))
!               return PyString_FromString(PQerrorMessage(self->pgcnx->cnx));
  
        /* attributes list */
        if (!strcmp(name, "__members__"))
--- 1500,1506 ----
  
        /* error (status) message */
        if (!strcmp(name, "error"))
!               return PyUnicode_FromString(PQerrorMessage(self->pgcnx->cnx));
  
        /* attributes list */
        if (!strcmp(name, "__members__"))
***************
*** 1497,1505 ****
  
                if (list)
                {
!                       PyList_SET_ITEM(list, 0, PyString_FromString("oid"));
!                       PyList_SET_ITEM(list, 1, PyString_FromString("pgcnx"));
!                       PyList_SET_ITEM(list, 2, PyString_FromString("error"));
                }
  
                return list;
--- 1509,1517 ----
  
                if (list)
                {
!                       PyList_SET_ITEM(list, 0, PyUnicode_FromString("oid"));
!                       PyList_SET_ITEM(list, 1, PyUnicode_FromString("pgcnx"));
!                       PyList_SET_ITEM(list, 2, PyUnicode_FromString("error"));
                }
  
                return list;
***************
*** 1507,1520 ****
  
        /* module name */
        if (!strcmp(name, "__module__"))
!               return PyString_FromString(MODULE_NAME);
  
        /* class name */
        if (!strcmp(name, "__class__"))
!               return PyString_FromString("pglarge");
  
        /* seeks name in methods (fallback) */
!       return Py_FindMethod(pglarge_methods, (PyObject *) self, name);
  }
  
  /* prints query object in human readable format */
--- 1519,1533 ----
  
        /* module name */
        if (!strcmp(name, "__module__"))
!               return PyUnicode_FromString(MODULE_NAME);
  
        /* class name */
        if (!strcmp(name, "__class__"))
!               return PyUnicode_FromString("pglarge");
  
        /* seeks name in methods (fallback) */
!       /* TODO: Is this an appropriate python3 replacement? I have NO clue... 
*/
!       return PyCFunction_NewEx(pglarge_methods, (PyObject *) self, name);
  }
  
  /* prints query object in human readable format */
***************
*** 1531,1537 ****
  }
  
  /* object type definition */
! staticforward PyTypeObject PglargeType = {
        PyObject_HEAD_INIT(NULL)
        0,                                                      /* ob_size */
        "pglarge",                                      /* tp_name */
--- 1544,1550 ----
  }
  
  /* object type definition */
! static PyTypeObject PglargeType = {
        PyObject_HEAD_INIT(NULL)
        0,                                                      /* ob_size */
        "pglarge",                                      /* tp_name */
***************
*** 1593,1617 ****
  #ifdef DEFAULT_VARS
        /* handles defaults variables (for uninitialised vars) */
        if ((!pghost) && (pg_default_host != Py_None))
!               pghost = PyString_AsString(pg_default_host);
  
        if ((pgport == -1) && (pg_default_port != Py_None))
!               pgport = PyInt_AsLong(pg_default_port);
  
        if ((!pgopt) && (pg_default_opt != Py_None))
!               pgopt = PyString_AsString(pg_default_opt);
  
        if ((!pgtty) && (pg_default_tty != Py_None))
!               pgtty = PyString_AsString(pg_default_tty);
  
        if ((!pgdbname) && (pg_default_base != Py_None))
!               pgdbname = PyString_AsString(pg_default_base);
  
        if ((!pguser) && (pg_default_user != Py_None))
!               pguser = PyString_AsString(pg_default_user);
  
        if ((!pgpasswd) && (pg_default_passwd != Py_None))
!               pgpasswd = PyString_AsString(pg_default_passwd);
  #endif /* DEFAULT_VARS */
  
        if ((npgobj = (pgobject *) pgobject_New()) == NULL)
--- 1606,1630 ----
  #ifdef DEFAULT_VARS
        /* handles defaults variables (for uninitialised vars) */
        if ((!pghost) && (pg_default_host != Py_None))
!               pghost = PyUnicode_AsUTF8String(pg_default_host);
  
        if ((pgport == -1) && (pg_default_port != Py_None))
!               pgport = PyLong_AsLong(pg_default_port);
  
        if ((!pgopt) && (pg_default_opt != Py_None))
!               pgopt = PyUnicode_AsUTF8String(pg_default_opt);
  
        if ((!pgtty) && (pg_default_tty != Py_None))
!               pgtty = PyUnicode_AsUTF8String(pg_default_tty);
  
        if ((!pgdbname) && (pg_default_base != Py_None))
!               pgdbname = PyUnicode_AsUTF8String(pg_default_base);
  
        if ((!pguser) && (pg_default_user != Py_None))
!               pguser = PyUnicode_AsUTF8String(pg_default_user);
  
        if ((!pgpasswd) && (pg_default_passwd != Py_None))
!               pgpasswd = PyUnicode_AsUTF8String(pg_default_passwd);
  #endif /* DEFAULT_VARS */
  
        if ((npgobj = (pgobject *) pgobject_New()) == NULL)
***************
*** 1749,1755 ****
        }
  
        /* request that the server abandon processing of the current command */
!       return PyInt_FromLong((long) PQrequestCancel(self->cnx));
  }
  
  /* get connection socket */
--- 1762,1768 ----
        }
  
        /* request that the server abandon processing of the current command */
!       return PyLong_FromLong((long) PQrequestCancel(self->cnx));
  }
  
  /* get connection socket */
***************
*** 1774,1782 ****
        }
  
  #ifdef NO_PQSOCKET
!       return PyInt_FromLong((long) self->cnx->sock);
  #else
!       return PyInt_FromLong((long) PQsocket(self->cnx));
  #endif
  }
  
--- 1787,1795 ----
        }
  
  #ifdef NO_PQSOCKET
!       return PyLong_FromLong((long) self->cnx->sock);
  #else
!       return PyLong_FromLong((long) PQsocket(self->cnx));
  #endif
  }
  
***************
*** 1795,1801 ****
                return NULL;
        }
  
!       return PyInt_FromLong((long) PQntuples(self->last_result));
  }
  
  /* list fields names from query result */
--- 1808,1814 ----
                return NULL;
        }
  
!       return PyLong_FromLong((long) PQntuples(self->last_result));
  }
  
  /* list fields names from query result */
***************
*** 1826,1832 ****
        for (i = 0; i < n; i++)
        {
                name = PQfname(self->last_result, i);
!               str = PyString_FromString(name);
                PyTuple_SET_ITEM(fieldstuple, i, str);
        }
  
--- 1839,1845 ----
        for (i = 0; i < n; i++)
        {
                name = PQfname(self->last_result, i);
!               str = PyUnicode_FromString(name);
                PyTuple_SET_ITEM(fieldstuple, i, str);
        }
  
***************
*** 1860,1866 ****
  
        /* gets fields name and builds object */
        name = PQfname(self->last_result, i);
!       return PyString_FromString(name);
  }
  
  /* gets fields number from name in last result */
--- 1873,1879 ----
  
        /* gets fields name and builds object */
        name = PQfname(self->last_result, i);
!       return PyUnicode_FromString(name);
  }
  
  /* gets fields number from name in last result */
***************
*** 1887,1893 ****
                return NULL;
        }
  
!       return PyInt_FromLong(num);
  }
  
  /* retrieves last result */
--- 1900,1906 ----
                return NULL;
        }
  
!       return PyLong_FromLong(num);
  }
  
  /* retrieves last result */
***************
*** 1956,1962 ****
                                                break;
  
                                        case 3:
!                                               tmp_obj = 
PyString_FromString(s);
                                                val = 
PyFloat_FromString(tmp_obj, NULL);
                                                Py_DECREF(tmp_obj);
                                                break;
--- 1969,1975 ----
                                                break;
  
                                        case 3:
!                                               tmp_obj = 
PyUnicode_FromString(s);
                                                val = 
PyFloat_FromString(tmp_obj, NULL);
                                                Py_DECREF(tmp_obj);
                                                break;
***************
*** 1982,1995 ****
                                                }
                                                else
                                                {
!                                                       tmp_obj = 
PyString_FromString(s);
                                                        val = 
PyFloat_FromString(tmp_obj, NULL);
                                                }
                                                Py_DECREF(tmp_obj);
                                                break;
  
                                        default:
!                                               val = PyString_FromString(s);
                                                break;
                                }
  
--- 1995,2008 ----
                                                }
                                                else
                                                {
!                                                       tmp_obj = 
PyUnicode_FromString(s);
                                                        val = 
PyFloat_FromString(tmp_obj, NULL);
                                                }
                                                Py_DECREF(tmp_obj);
                                                break;
  
                                        default:
!                                               val = PyUnicode_FromString(s);
                                                break;
                                }
  
***************
*** 2080,2086 ****
                                                break;
  
                                        case 3:
!                                               tmp_obj = 
PyString_FromString(s);
                                                val = 
PyFloat_FromString(tmp_obj, NULL);
                                                Py_DECREF(tmp_obj);
                                                break;
--- 2093,2099 ----
                                                break;
  
                                        case 3:
!                                               tmp_obj = 
PyUnicode_FromString(s);
                                                val = 
PyFloat_FromString(tmp_obj, NULL);
                                                Py_DECREF(tmp_obj);
                                                break;
***************
*** 2106,2119 ****
                                                }
                                                else
                                                {
!                                                       tmp_obj = 
PyString_FromString(s);
                                                        val = 
PyFloat_FromString(tmp_obj, NULL);
                                                }
                                                Py_DECREF(tmp_obj);
                                                break;
  
                                        default:
!                                               val = PyString_FromString(s);
                                                break;
                                }
  
--- 2119,2132 ----
                                                }
                                                else
                                                {
!                                                       tmp_obj = 
PyUnicode_FromString(s);
                                                        val = 
PyFloat_FromString(tmp_obj, NULL);
                                                }
                                                Py_DECREF(tmp_obj);
                                                break;
  
                                        default:
!                                               val = PyUnicode_FromString(s);
                                                break;
                                }
  
***************
*** 2183,2189 ****
                        return NULL;
                }
  
!               if ((temp = PyString_FromString(notify->relname)) == NULL)
                {
                        PQclear(result);
                        return NULL;
--- 2196,2202 ----
                        return NULL;
                }
  
!               if ((temp = PyUnicode_FromString(notify->relname)) == NULL)
                {
                        PQclear(result);
                        return NULL;
***************
*** 2191,2197 ****
  
                PyTuple_SET_ITEM(notify_result, 0, temp);
  
!               if ((temp = PyInt_FromLong(notify->be_pid)) == NULL)
                {
                        PQclear(result);
                        Py_DECREF(notify_result);
--- 2204,2210 ----
  
                PyTuple_SET_ITEM(notify_result, 0, temp);
  
!               if ((temp = PyLong_FromLong(notify->be_pid)) == NULL)
                {
                        PQclear(result);
                        Py_DECREF(notify_result);
***************
*** 2304,2310 ****
                                        return Py_None;
                                }
                                /* otherwise, return the oid */
!                               return PyInt_FromLong(oid);
                        case PGRES_COPY_OUT:            /* no data will be 
received */
                        case PGRES_COPY_IN:
                                Py_INCREF(Py_None);
--- 2317,2323 ----
                                        return Py_None;
                                }
                                /* otherwise, return the oid */
!                               return PyLong_FromLong(oid);
                        case PGRES_COPY_OUT:            /* no data will be 
received */
                        case PGRES_COPY_IN:
                                Py_INCREF(Py_None);
***************
*** 2387,2393 ****
        switch (PQgetline(self->cnx, line, MAX_BUFFER_SIZE))
        {
                case 0:
!                       str = PyString_FromString(line);
                        break;
                case 1:
                        PyErr_SetString(PyExc_MemoryError, "buffer overflow");
--- 2400,2406 ----
        switch (PQgetline(self->cnx, line, MAX_BUFFER_SIZE))
        {
                case 0:
!                       str = PyUnicode_FromString(line);
                        break;
                case 1:
                        PyErr_SetString(PyExc_MemoryError, "buffer overflow");
***************
*** 2445,2451 ****
  static PyObject *
  pgquery_repr(pgqueryobject * self)
  {
!       return PyString_FromString("<pg query result>");
  }
  
  /* insert table */
--- 2458,2464 ----
  static PyObject *
  pgquery_repr(pgqueryobject * self)
  {
!       return PyUnicode_FromString("<pg query result>");
  }
  
  /* insert table */
***************
*** 2589,2595 ****
                                else
                                        bufsiz = 0;
                        }
!                       else if (PyString_Check(item))
                        {
                                const char* t = PyString_AS_STRING(item);
                                while (*t && bufsiz)
--- 2602,2608 ----
                                else
                                        bufsiz = 0;
                        }
!                       else if (PyUnicode_Check(item))
                        {
                                const char* t = PyString_AS_STRING(item);
                                while (*t && bufsiz)
***************
*** 2602,2611 ****
                                        *bufpt++ = *t++; --bufsiz;
                                }
                        }
!                       else if (PyInt_Check(item) || PyLong_Check(item))
                        {
                                PyObject* s = PyObject_Str(item);
!                               const char* t = PyString_AsString(s);
                                while (*t && bufsiz)
                                {
                                        *bufpt++ = *t++; --bufsiz;
--- 2615,2624 ----
                                        *bufpt++ = *t++; --bufsiz;
                                }
                        }
!                       else if (PyLong_Check(item) || PyLong_Check(item))
                        {
                                PyObject* s = PyObject_Str(item);
!                               const char* t = PyUnicode_AsUTF8String(s);
                                while (*t && bufsiz)
                                {
                                        *bufpt++ = *t++; --bufsiz;
***************
*** 2615,2621 ****
                        else
                        {
                                PyObject* s = PyObject_Repr(item);
!                               const char* t = PyString_AsString(s);
                                while (*t && bufsiz)
                                {
                                        if (*t == '\\' || *t == '\t' || *t == 
'\n')
--- 2628,2634 ----
                        else
                        {
                                PyObject* s = PyObject_Repr(item);
!                               const char* t = PyUnicode_AsUTF8String(s);
                                while (*t && bufsiz)
                                {
                                        if (*t == '\\' || *t == '\t' || *t == 
'\n')
***************
*** 2696,2702 ****
                return NULL;
        }
  
!       return PyInt_FromLong(PQtransactionStatus(self->cnx));
  }
  
  /* get parameter setting */
--- 2709,2715 ----
                return NULL;
        }
  
!       return PyLong_FromLong(PQtransactionStatus(self->cnx));
  }
  
  /* get parameter setting */
***************
*** 2724,2730 ****
        name = PQparameterStatus(self->cnx, name);
  
        if (name)
!               return PyString_FromString(name);
  
        /* unknown parameter, return None */
        Py_INCREF(Py_None);
--- 2737,2743 ----
        name = PQparameterStatus(self->cnx, name);
  
        if (name)
!               return PyUnicode_FromString(name);
  
        /* unknown parameter, return None */
        Py_INCREF(Py_None);
***************
*** 2889,2925 ****
        {
                char *r = PQhost(self->cnx);
  
!               return r ? PyString_FromString(r) : 
PyString_FromString("localhost");
        }
  
        /* postmaster port */
        if (!strcmp(name, "port"))
!               return PyInt_FromLong(atol(PQport(self->cnx)));
  
        /* selected database */
        if (!strcmp(name, "db"))
!               return PyString_FromString(PQdb(self->cnx));
  
        /* selected options */
        if (!strcmp(name, "options"))
!               return PyString_FromString(PQoptions(self->cnx));
  
        /* selected postgres tty */
        if (!strcmp(name, "tty"))
!               return PyString_FromString(PQtty(self->cnx));
  
        /* error (status) message */
        if (!strcmp(name, "error"))
!               return PyString_FromString(PQerrorMessage(self->cnx));
  
        /* connection status : 1 - OK, 0 - BAD */
        if (!strcmp(name, "status"))
!               return PyInt_FromLong(PQstatus(self->cnx) == CONNECTION_OK ? 1 
: 0);
  
        /* provided user name */
        if (!strcmp(name, "user"))
!               return PyString_FromString("Deprecated facility");
!       /* return PyString_FromString(fe_getauthname("<unknown user>")); */
  
        /* attributes list */
        if (!strcmp(name, "__members__"))
--- 2902,2938 ----
        {
                char *r = PQhost(self->cnx);
  
!               return r ? PyUnicode_FromString(r) : 
PyUnicode_FromString("localhost");
        }
  
        /* postmaster port */
        if (!strcmp(name, "port"))
!               return PyLong_FromLong(atol(PQport(self->cnx)));
  
        /* selected database */
        if (!strcmp(name, "db"))
!               return PyUnicode_FromString(PQdb(self->cnx));
  
        /* selected options */
        if (!strcmp(name, "options"))
!               return PyUnicode_FromString(PQoptions(self->cnx));
  
        /* selected postgres tty */
        if (!strcmp(name, "tty"))
!               return PyUnicode_FromString(PQtty(self->cnx));
  
        /* error (status) message */
        if (!strcmp(name, "error"))
!               return PyUnicode_FromString(PQerrorMessage(self->cnx));
  
        /* connection status : 1 - OK, 0 - BAD */
        if (!strcmp(name, "status"))
!               return PyLong_FromLong(PQstatus(self->cnx) == CONNECTION_OK ? 1 
: 0);
  
        /* provided user name */
        if (!strcmp(name, "user"))
!               return PyUnicode_FromString("Deprecated facility");
!       /* return PyUnicode_FromString(fe_getauthname("<unknown user>")); */
  
        /* attributes list */
        if (!strcmp(name, "__members__"))
***************
*** 2928,2951 ****
  
                if (list)
                {
!                       PyList_SET_ITEM(list, 0, PyString_FromString("host"));
!                       PyList_SET_ITEM(list, 1, PyString_FromString("port"));
!                       PyList_SET_ITEM(list, 2, PyString_FromString("db"));
!                       PyList_SET_ITEM(list, 3, 
PyString_FromString("options"));
!                       PyList_SET_ITEM(list, 4, PyString_FromString("tty"));
!                       PyList_SET_ITEM(list, 5, PyString_FromString("error"));
!                       PyList_SET_ITEM(list, 6, PyString_FromString("status"));
!                       PyList_SET_ITEM(list, 7, PyString_FromString("user"));
                }
  
                return list;
        }
! 
!       return Py_FindMethod(pgobj_methods, (PyObject *) self, name);
  }
  
  /* object type definition */
! staticforward PyTypeObject PgType = {
        PyObject_HEAD_INIT(NULL)
        0,                                                      /* ob_size */
        "pgobject",                                     /* tp_name */
--- 2941,2966 ----
  
                if (list)
                {
!                       PyList_SET_ITEM(list, 0, PyUnicode_FromString("host"));
!                       PyList_SET_ITEM(list, 1, PyUnicode_FromString("port"));
!                       PyList_SET_ITEM(list, 2, PyUnicode_FromString("db"));
!                       PyList_SET_ITEM(list, 3, 
PyUnicode_FromString("options"));
!                       PyList_SET_ITEM(list, 4, PyUnicode_FromString("tty"));
!                       PyList_SET_ITEM(list, 5, PyUnicode_FromString("error"));
!                       PyList_SET_ITEM(list, 6, 
PyUnicode_FromString("status"));
!                       PyList_SET_ITEM(list, 7, PyUnicode_FromString("user"));
                }
  
                return list;
        }
!       
!       /* TODO: Is this an appropriate python3 replacement? I have NO clue... 
*/
!       return PyCFunction_NewEx(pgobj_methods, (PyObject *) self, name);
! /*    return Py_FindMethod(pgobj_methods, (PyObject *) self, name); */
  }
  
  /* object type definition */
! static PyTypeObject PgType = {
        PyObject_HEAD_INIT(NULL)
        0,                                                      /* ob_size */
        "pgobject",                                     /* tp_name */
***************
*** 2987,2997 ****
  pgquery_getattr(pgqueryobject * self, char *name)
  {
        /* list postgreSQL connection fields */
!       return Py_FindMethod(pgquery_methods, (PyObject *) self, name);
  }
  
  /* query type definition */
! staticforward PyTypeObject PgQueryType = {
        PyObject_HEAD_INIT(NULL)
        0,                                                      /* ob_size */
        "pgqueryobject",                        /* tp_name */
--- 3002,3014 ----
  pgquery_getattr(pgqueryobject * self, char *name)
  {
        /* list postgreSQL connection fields */
!       /* TODO: Is this an appropriate python3 replacement? I have NO clue... 
*/
!       return PyCFunction_NewEx(pgquery_methods, (PyObject *) self, name);
!       /*return Py_FindMethod(pgquery_methods, (PyObject *) self, name);*/
  }
  
  /* query type definition */
! static PyTypeObject PgQueryType = {
        PyObject_HEAD_INIT(NULL)
        0,                                                      /* ob_size */
        "pgqueryobject",                        /* tp_name */
***************
*** 3161,3167 ****
        old = pg_default_host;
  
        if (temp)
!               pg_default_host = PyString_FromString(temp);
        else
        {
                Py_INCREF(Py_None);
--- 3178,3184 ----
        old = pg_default_host;
  
        if (temp)
!               pg_default_host = PyUnicode_FromString(temp);
        else
        {
                Py_INCREF(Py_None);
***************
*** 3212,3218 ****
        old = pg_default_base;
  
        if (temp)
!               pg_default_base = PyString_FromString(temp);
        else
        {
                Py_INCREF(Py_None);
--- 3229,3235 ----
        old = pg_default_base;
  
        if (temp)
!               pg_default_base = PyUnicode_FromString(temp);
        else
        {
                Py_INCREF(Py_None);
***************
*** 3263,3269 ****
        old = pg_default_opt;
  
        if (temp)
!               pg_default_opt = PyString_FromString(temp);
        else
        {
                Py_INCREF(Py_None);
--- 3280,3286 ----
        old = pg_default_opt;
  
        if (temp)
!               pg_default_opt = PyUnicode_FromString(temp);
        else
        {
                Py_INCREF(Py_None);
***************
*** 3315,3321 ****
        old = pg_default_tty;
  
        if (temp)
!               pg_default_tty = PyString_FromString(temp);
        else
        {
                Py_INCREF(Py_None);
--- 3332,3338 ----
        old = pg_default_tty;
  
        if (temp)
!               pg_default_tty = PyUnicode_FromString(temp);
        else
        {
                Py_INCREF(Py_None);
***************
*** 3367,3373 ****
        old = pg_default_user;
  
        if (temp)
!               pg_default_user = PyString_FromString(temp);
        else
        {
                Py_INCREF(Py_None);
--- 3384,3390 ----
        old = pg_default_user;
  
        if (temp)
!               pg_default_user = PyUnicode_FromString(temp);
        else
        {
                Py_INCREF(Py_None);
***************
*** 3399,3405 ****
        old = pg_default_passwd;
  
        if (temp)
!               pg_default_passwd = PyString_FromString(temp);
        else
        {
                Py_INCREF(Py_None);
--- 3416,3422 ----
        old = pg_default_passwd;
  
        if (temp)
!               pg_default_passwd = PyUnicode_FromString(temp);
        else
        {
                Py_INCREF(Py_None);
***************
*** 3451,3457 ****
        old = pg_default_port;
  
        if (port != -1)
!               pg_default_port = PyInt_FromLong(port);
        else
        {
                Py_INCREF(Py_None);
--- 3468,3474 ----
        old = pg_default_port;
  
        if (port != -1)
!               pg_default_port = PyLong_FromLong(port);
        else
        {
                Py_INCREF(Py_None);
***************
*** 3548,3582 ****
        PyDict_SetItemString(dict, "NotSupportedError", NotSupportedError);
  
        /* Make the version available */
!       v = PyString_FromString(PyPgVersion);
        PyDict_SetItemString(dict, "version", v);
        PyDict_SetItemString(dict, "__version__", v);
        Py_DECREF(v);
  
        /* results type for queries */
!       PyDict_SetItemString(dict, "RESULT_EMPTY", 
PyInt_FromLong(RESULT_EMPTY));
!       PyDict_SetItemString(dict, "RESULT_DML", PyInt_FromLong(RESULT_DML));
!       PyDict_SetItemString(dict, "RESULT_DDL", PyInt_FromLong(RESULT_DDL));
!       PyDict_SetItemString(dict, "RESULT_DQL", PyInt_FromLong(RESULT_DQL));
  
  #ifdef PQfreeNotify   /* must be 7.4 or later */
        /* transaction states */
!       PyDict_SetItemString(dict,"TRANS_IDLE",PyInt_FromLong(PQTRANS_IDLE));
!       
PyDict_SetItemString(dict,"TRANS_ACTIVE",PyInt_FromLong(PQTRANS_ACTIVE));
!       
PyDict_SetItemString(dict,"TRANS_INTRANS",PyInt_FromLong(PQTRANS_INTRANS));
!       
PyDict_SetItemString(dict,"TRANS_INERROR",PyInt_FromLong(PQTRANS_INERROR));
!       
PyDict_SetItemString(dict,"TRANS_UNKNOWN",PyInt_FromLong(PQTRANS_UNKNOWN));
  #endif
  
  #ifdef LARGE_OBJECTS
        /* create mode for large objects */
!       PyDict_SetItemString(dict, "INV_READ", PyInt_FromLong(INV_READ));
!       PyDict_SetItemString(dict, "INV_WRITE", PyInt_FromLong(INV_WRITE));
  
        /* position flags for lo_lseek */
!       PyDict_SetItemString(dict, "SEEK_SET", PyInt_FromLong(SEEK_SET));
!       PyDict_SetItemString(dict, "SEEK_CUR", PyInt_FromLong(SEEK_CUR));
!       PyDict_SetItemString(dict, "SEEK_END", PyInt_FromLong(SEEK_END));
  #endif /* LARGE_OBJECTS */
  
  #ifdef DEFAULT_VARS
--- 3565,3599 ----
        PyDict_SetItemString(dict, "NotSupportedError", NotSupportedError);
  
        /* Make the version available */
!       v = PyUnicode_FromString(PyPgVersion);
        PyDict_SetItemString(dict, "version", v);
        PyDict_SetItemString(dict, "__version__", v);
        Py_DECREF(v);
  
        /* results type for queries */
!       PyDict_SetItemString(dict, "RESULT_EMPTY", 
PyLong_FromLong(RESULT_EMPTY));
!       PyDict_SetItemString(dict, "RESULT_DML", PyLong_FromLong(RESULT_DML));
!       PyDict_SetItemString(dict, "RESULT_DDL", PyLong_FromLong(RESULT_DDL));
!       PyDict_SetItemString(dict, "RESULT_DQL", PyLong_FromLong(RESULT_DQL));
  
  #ifdef PQfreeNotify   /* must be 7.4 or later */
        /* transaction states */
!       PyDict_SetItemString(dict,"TRANS_IDLE",PyLong_FromLong(PQTRANS_IDLE));
!       
PyDict_SetItemString(dict,"TRANS_ACTIVE",PyLong_FromLong(PQTRANS_ACTIVE));
!       
PyDict_SetItemString(dict,"TRANS_INTRANS",PyLong_FromLong(PQTRANS_INTRANS));
!       
PyDict_SetItemString(dict,"TRANS_INERROR",PyLong_FromLong(PQTRANS_INERROR));
!       
PyDict_SetItemString(dict,"TRANS_UNKNOWN",PyLong_FromLong(PQTRANS_UNKNOWN));
  #endif
  
  #ifdef LARGE_OBJECTS
        /* create mode for large objects */
!       PyDict_SetItemString(dict, "INV_READ", PyLong_FromLong(INV_READ));
!       PyDict_SetItemString(dict, "INV_WRITE", PyLong_FromLong(INV_WRITE));
  
        /* position flags for lo_lseek */
!       PyDict_SetItemString(dict, "SEEK_SET", PyLong_FromLong(SEEK_SET));
!       PyDict_SetItemString(dict, "SEEK_CUR", PyLong_FromLong(SEEK_CUR));
!       PyDict_SetItemString(dict, "SEEK_END", PyLong_FromLong(SEEK_END));
  #endif /* LARGE_OBJECTS */
  
  #ifdef DEFAULT_VARS
Dateien PyGreSQL-4.0-pre081031-orig/.pgmodule.c.swp und 
PyGreSQL-4.0-pre081031/.pgmodule.c.swp sind verschieden.
diff -C 3 -r PyGreSQL-4.0-pre081031-orig/setup.py 
PyGreSQL-4.0-pre081031/setup.py
*** PyGreSQL-4.0-pre081031-orig/setup.py        2008-10-31 22:13:57.000000000 
+0100
--- PyGreSQL-4.0-pre081031/setup.py     2008-11-17 15:32:58.000000000 +0100
***************
*** 47,56 ****
        """Retrieve information about installed version of PostgreSQL."""
        f = os.popen("pg_config --%s" % s)
        d = f.readline().strip()
!       if f.close() is not None:
!               raise Exception, "pg_config tool is not available."
        if not d:
!               raise Exception, "Could not get %s information." % s
        return d
  
  def mk_include():
--- 47,56 ----
        """Retrieve information about installed version of PostgreSQL."""
        f = os.popen("pg_config --%s" % s)
        d = f.readline().strip()
!       if f.close() != 0:
!               raise Exception("pg_config tool is not available.")
        if not d:
!               raise Exception("Could not get %s information." % s)
        return d
  
  def mk_include():
_______________________________________________
PyGreSQL mailing list
PyGreSQL@Vex.Net
http://mailman.vex.net/mailman/listinfo/pygresql

Reply via email to