[Informixdb-cvs] SF.net SVN: informixdb: [160] branches/informixdb-py3k
Brought to you by:
chaese,
f-apolloner
From: <ch...@us...> - 2007-09-02 22:06:14
|
Revision: 160 http://informixdb.svn.sourceforge.net/informixdb/?rev=160&view=rev Author: chaese Date: 2007-09-02 15:06:12 -0700 (Sun, 02 Sep 2007) Log Message: ----------- Some necessary changes for Python 3.0 and some workarounds to quirks/bugs in Python 3.0 alpha 1. Modified Paths: -------------- branches/informixdb-py3k/ext/_informixdb.ec branches/informixdb-py3k/informixdb.py branches/informixdb-py3k/setup.py branches/informixdb-py3k/tests/dbapi20.py branches/informixdb-py3k/tests/testdbapi.py Modified: branches/informixdb-py3k/ext/_informixdb.ec =================================================================== --- branches/informixdb-py3k/ext/_informixdb.ec 2007-09-02 21:58:25 UTC (rev 159) +++ branches/informixdb-py3k/ext/_informixdb.ec 2007-09-02 22:06:12 UTC (rev 160) @@ -361,8 +361,7 @@ }; static PyTypeObject Sblob_type = { - PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) - 0, /* ob_size*/ + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type),0) "_informixdb.Sblob", /* tp_name */ sizeof(Sblob), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -400,7 +399,7 @@ (initproc)Sblob_init, /* tp_init */ DEFERRED_ADDRESS(PyType_GenericAlloc), /* tp_alloc */ DEFERRED_ADDRESS(PyType_GenericNew), /* tp_new */ - DEFERRED_ADDRESS(_PyObject_Del) /* tp_free */ + DEFERRED_ADDRESS(PyObject_Del) /* tp_free */ }; $endif; @@ -667,8 +666,7 @@ fetchmany(), fetchall(), or by iterating over the Cursor object."); static PyTypeObject Cursor_type = { - PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) - 0, /* ob_size*/ + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type),0) "_informixdb.Cursor", /* tp_name */ sizeof(Cursor), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -706,7 +704,7 @@ (initproc)Cursor_init, /* tp_init */ DEFERRED_ADDRESS(PyType_GenericAlloc), /* tp_alloc */ DEFERRED_ADDRESS(PyType_GenericNew), /* tp_new */ - DEFERRED_ADDRESS(_PyObject_Del) /* tp_free */ + DEFERRED_ADDRESS(PyObject_Del) /* tp_free */ }; static void doCloseCursor(Cursor *cur, int doFree); @@ -927,8 +925,7 @@ informixdb.connect() method instead."); static PyTypeObject Connection_type = { - PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) - 0, /* ob_size*/ + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type),0) "_informixdb.Connection", /* tp_name */ sizeof(Connection), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -966,7 +963,7 @@ (initproc)Connection_init, /* tp_init */ DEFERRED_ADDRESS(PyType_GenericAlloc), /* tp_alloc */ DEFERRED_ADDRESS(PyType_GenericNew), /* tp_new */ - DEFERRED_ADDRESS(_PyObject_Del) /* tp_free */ + DEFERRED_ADDRESS(PyObject_Del) /* tp_free */ }; static PyObject *dberror_type(PyObject *override); @@ -1092,7 +1089,7 @@ Py_XDECREF(self->messages); Py_XDECREF(self->errorhandler); - self->ob_type->tp_free((PyObject*)self); + Py_Type(self)->tp_free((PyObject*)self); } /* If this connection has transactions, commit and @@ -2689,7 +2686,7 @@ free(self->cursorName); } - self->ob_type->tp_free((PyObject*)self); + Py_Type(self)->tp_free((PyObject*)self); } static PyObject *Cursor_close(Cursor *self) @@ -3443,7 +3440,7 @@ PyObject *s,*val; char *str; - val = self->values->ob_type->tp_repr(self->values); + val = Py_Type(self->values)->tp_repr(self->values); if (!val) return NULL; str = PyString_AsString(val); @@ -3456,7 +3453,7 @@ PyObject* DBAPIType_str(DBAPIType* self) { - return self->values->ob_type->tp_repr(self->values); + return Py_Type(self->values)->tp_repr(self->values); } PyDoc_STRVAR(DBAPIType_doc, @@ -3474,8 +3471,7 @@ 1"); static PyTypeObject DBAPIType_type = { - PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type)) - 0, /* ob_size*/ + PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type),0) "_informixdb.DBAPIType", /* tp_name */ sizeof(DBAPIType), /* tp_basicsize */ 0, /* tp_itemsize */ @@ -3513,7 +3509,7 @@ (initproc)DBAPIType_init, /* tp_init */ DEFERRED_ADDRESS(PyType_GenericAlloc), /* tp_alloc */ DEFERRED_ADDRESS(PyType_GenericNew), /* tp_new */ - DEFERRED_ADDRESS(_PyObject_Del) /* tp_free */ + DEFERRED_ADDRESS(PyObject_Del) /* tp_free */ }; static PyObject* dbtp_create(char* types[]) @@ -3769,7 +3765,7 @@ self->lo_spec = NULL; } Py_XDECREF(self->conn); - self->ob_type->tp_free((PyObject*)self); + Py_Type(self)->tp_free((PyObject*)self); } static PyObject *Sblob_close(Sblob *self) { @@ -4139,9 +4135,9 @@ Py_DECREF(d); \ PyModule_AddObject(m, #name, Exc##name); \ } while(0); - defException(Warning, PyExc_StandardError); + defException(Warning, PyExc_Exception); setupdb_error(ExcWarning); - defException(Error, PyExc_StandardError); + defException(Error, PyExc_Exception); defException(InterfaceError, ExcError); defException(DatabaseError, ExcError); setupdb_error(ExcDatabaseError); @@ -4153,18 +4149,18 @@ defException(NotSupportedError, ExcDatabaseError); #undef defException - Cursor_type.ob_type = &PyType_Type; + Py_Type(&Cursor_type) = &PyType_Type; Cursor_type.tp_alloc = PyType_GenericAlloc; Cursor_type.tp_new = PyType_GenericNew; - Cursor_type.tp_free = _PyObject_Del; - Connection_type.ob_type = &PyType_Type; + Cursor_type.tp_free = PyObject_Del; + Py_Type(&Connection_type) = &PyType_Type; Connection_type.tp_alloc = PyType_GenericAlloc; Connection_type.tp_new = PyType_GenericNew; - Connection_type.tp_free = _PyObject_Del; - DBAPIType_type.ob_type = &PyType_Type; + Connection_type.tp_free = PyObject_Del; + Py_Type(&DBAPIType_type) = &PyType_Type; DBAPIType_type.tp_alloc = PyType_GenericAlloc; DBAPIType_type.tp_new = PyType_GenericNew; - DBAPIType_type.tp_free = _PyObject_Del; + DBAPIType_type.tp_free = PyObject_Del; Connection_getseters[0].closure = ExcWarning; Connection_getseters[1].closure = ExcError; @@ -4182,10 +4178,10 @@ PyType_Ready(&DBAPIType_type); $ifdef HAVE_ESQL9; - Sblob_type.ob_type = &PyType_Type; + Py_Type(&Sblob_type) = &PyType_Type; Sblob_type.tp_alloc = PyType_GenericAlloc; Sblob_type.tp_new = PyType_GenericNew; - Sblob_type.tp_free = _PyObject_Del; + Sblob_type.tp_free = PyObject_Del; PyType_Ready(&Sblob_type); Py_INCREF(&Sblob_type); $endif; Modified: branches/informixdb-py3k/informixdb.py =================================================================== --- branches/informixdb-py3k/informixdb.py 2007-09-02 21:58:25 UTC (rev 159) +++ branches/informixdb-py3k/informixdb.py 2007-09-02 22:06:12 UTC (rev 160) @@ -88,7 +88,7 @@ try: date2 = datetime.date(y+y2,m2+1,d) except ValueError: - raise ValueError, "month arithmetic yielded an invalid date." + raise ValueError("month arithmetic yielded an invalid date.") # apply the resulting timedelta to the operand return other + (date2 - otherdate) else: return NotImplemented @@ -153,12 +153,12 @@ class Cursor(_Cursor): __doc__ = _Cursor.__doc__ def __new__(self, *args, **kwargs): - raise InterfaceError, "Use Connection.cursor() to instantiate a cursor." + raise InterfaceError("Use Connection.cursor() to instantiate a cursor.") del _Cursor class Connection(_Connection): __doc__ = _Connection.__doc__ def __new__(self, *args, **kwargs): - raise InterfaceError, "Use connect() to instantiate a connection." + raise InterfaceError("Use connect() to instantiate a connection.") del _Connection try: # Same for Sblobs if we have support for them in _informixdb @@ -166,6 +166,6 @@ class Sblob(_Sblob): __doc__ = _Sblob.__doc__ def __new__(self, *args, **kwargs): - raise InterfaceError, "Use Connection.Sblob() to instantiate an Sblob." + raise InterfaceError("Use Connection.Sblob() to instantiate an Sblob.") del _Sblob except: pass Modified: branches/informixdb-py3k/setup.py =================================================================== --- branches/informixdb-py3k/setup.py 2007-09-02 21:58:25 UTC (rev 159) +++ branches/informixdb-py3k/setup.py 2007-09-02 22:06:12 UTC (rev 160) @@ -64,7 +64,8 @@ esqlver = re.compile(r"(IBM)?.*ESQL Version (\d+)\.(\d+)") cout = os.popen(' '.join(self.esql_parts[0:1] + [ '-V' ]),'r') esqlversion = None - for line in cout: + # result from os.popen is not iterable in Python 3.0a1, workaround + for line in cout.read().split("\n"): matchobj = esqlver.match(line) if matchobj: matchgroups = matchobj.groups() @@ -89,9 +90,9 @@ token = token[1:-1] esql_config.append(token) ret = cout.close() - if ret != None: - raise DistutilsSetupError, \ - "\nCan't find esql. Please set INFORMIXDIR correctly." + if ret != None and ret != 0: + raise DistutilsSetupError( + "\nCan't find esql. Please set INFORMIXDIR correctly.") if get_platform()=="win32": for arg in esql_config: @@ -135,7 +136,7 @@ dir = os.path.dirname(file) f = os.path.basename(file) cmd = ' '.join(self.esql_parts + [ '-e', f ]) - print cmd + print (cmd) curdir = os.getcwd() os.chdir(dir) Modified: branches/informixdb-py3k/tests/dbapi20.py =================================================================== --- branches/informixdb-py3k/tests/dbapi20.py 2007-09-02 21:58:25 UTC (rev 159) +++ branches/informixdb-py3k/tests/dbapi20.py 2007-09-02 22:06:12 UTC (rev 160) @@ -205,8 +205,8 @@ def test_Exceptions(self): # Make sure required exceptions exist, and are in the # defined heirarchy. - self.failUnless(issubclass(self.driver.Warning,StandardError)) - self.failUnless(issubclass(self.driver.Error,StandardError)) + self.failUnless(issubclass(self.driver.Warning,Exception)) + self.failUnless(issubclass(self.driver.Error,Exception)) self.failUnless( issubclass(self.driver.InterfaceError,self.driver.Error) ) @@ -734,7 +734,7 @@ that returns two result sets, first the number of rows in booze then "name from booze" ''' - raise NotImplementedError,'Helper not implemented' + raise NotImplementedError('Helper not implemented') #sql=""" # create procedure deleteme as # begin @@ -746,7 +746,7 @@ def help_nextset_tearDown(self,cur): 'If cleaning up is needed after nextSetTest' - raise NotImplementedError,'Helper not implemented' + raise NotImplementedError('Helper not implemented') #cur.execute("drop procedure deleteme") def test_nextset(self): @@ -779,7 +779,7 @@ con.close() def test_nextset(self): - raise NotImplementedError,'Drivers need to override this test' + raise NotImplementedError('Drivers need to override this test') def test_arraysize(self): # Not much here - rest of the tests for this are in test_fetchmany @@ -814,7 +814,7 @@ def test_setoutputsize(self): # Real test for setoutputsize is driver dependant - raise NotImplementedError,'Driver need to override this test' + raise NotImplementedError('Driver need to override this test') def test_None(self): con = self._connect() Modified: branches/informixdb-py3k/tests/testdbapi.py =================================================================== --- branches/informixdb-py3k/tests/testdbapi.py 2007-09-02 21:58:25 UTC (rev 159) +++ branches/informixdb-py3k/tests/testdbapi.py 2007-09-02 22:06:12 UTC (rev 160) @@ -2,7 +2,7 @@ import dbapi20 import unittest import informixdb -import popen2 +#import popen2 class TestDBAPI(dbapi20.DatabaseAPI20Test): driver = informixdb @@ -39,11 +39,13 @@ con = self._connect() con.close() except: - cmd = "dbaccess" - cout,cin = popen2.popen2(cmd) - cin.write('create database ifxtest') - cin.close() - cout.read() + pass + # popen2 doesn't exist (yet?) in Python 3.0a1 + #cmd = "dbaccess" + #cout,cin = popen2.popen2(cmd) + #cin.write('create database ifxtest') + #cin.close() + #cout.read() con = self._connect() try: @@ -63,7 +65,7 @@ try: c = con.cursor() c.execute("SELECT * MORF SYNTAXERROR"); - except self.driver.DatabaseError, e: + except self.driver.DatabaseError as e: # this are not really whitebox tests anymore, but handy # anyway self.assertEqual(e.sqlcode, -201, @@ -85,32 +87,32 @@ it = iter(cur) - # it.next() should raise an Error if called before + # it.__next__() should raise an Error if called before # executing a select-type query - self.assertRaises(self.driver.Error, it.next) + self.assertRaises(self.driver.Error, it.__next__) # it.fetchone should raise an Error if called after # executing a query that cannnot return rows self.executeDDL1(cur) - self.assertRaises(self.driver.Error, it.next) + self.assertRaises(self.driver.Error, it.__next__) # it.fetchone should raise an Error if called after # executing a query that cannnot return rows cur.execute("insert into %sbooze values ('Victoria Bitter')" % ( self.table_prefix )) - self.assertRaises(self.driver.Error,it.next) + self.assertRaises(self.driver.Error,it.__next__) cur.execute('select name from %sbooze' % self.table_prefix) count = 0 for r in cur: count += 1 self.assertEqual(r[0],'Victoria Bitter', - 'iter(cursor).next retrieved incorrect data' + 'iter(cursor).__next__ retrieved incorrect data' ) self.assertEqual(count, 1, - 'iter(cursor).next should have retrieved a single row' + 'iter(cursor).__next__ should have retrieved a single row' ) finally: con.close() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |