An automated tool exists to convert python 3 to 2 code; see http://pypi.python.org/pypi/3to2
So maybe development can be done in 3 and backported automagically
with only minor tweaks.
Interesting, had to have a look at it and try it out, for this
installed Py 2.7 and the things needed for this, to be 1,000% ensure
that I don't affect my own stuff.
I run the new fb driver through it and attach the patch of the
changes it generated (I didn't include fberrmsgs.py as in there it
just changed all the strings to u'unicodestrings'.
There are a few obvious things I changed manually after I run it
through 3to2:
- from fberrmsgs import messages
- class BaseConnect(object): - needed to add (object) otherwise 2.7-
doesn't recognize it as a new class
- all "super()" of the classes which inherit from BaseConnect
At this point it compiles without any errors but I get this
traceback at runtime.
hon.exe" "C:\dev\firebirdNewDriver\firebirdsql\fbcore.py"
dsn= localhost:C:\dev\firebirdNewDriver\firebirdsql/test.fdb
Traceback (most recent call last):
File "C:\dev\firebirdNewDriver\firebirdsql\fbcore.py", line 1172,
in <module>
conn = create_database(TEST_DSN, TEST_USER, TEST_PASS,
port=3050)
File "C:\dev\firebirdNewDriver\firebirdsql\fbcore.py", line 1097,
in __init__
self._op_accept()
File "C:\dev\firebirdNewDriver\firebirdsql\fbcore.py", line 717,
in _op_accept
while bytes_to_bint(b) == self.op_dummy:
File "C:\dev\firebirdNewDriver\firebirdsql\fbcore.py", line 169,
in bytes_to_bint
val += b[i] << (8 * (n - i -1))
TypeError: unsupported operand type(s) for <<: 'str' and 'int'
This is the function containing line 169:
def bytes_to_bint(b): # Read as big endian
val = 0
n = len(b)
for i in xrange(n):
val += b[i] << (8 * (n - i -1))
if b[0] & 128: # First byte MSB eq 1 means
negative.
val = ctypes.c_int(val).value
return val
In 3.0 the input "b" is "bytes" where in 2.x this is now a "str".
This type of stuff is way over my head, hopefully someone can let me
know how this should be changed to be correct in Py 2.x.