Subject Re: [firebird-python] next driver version [1 Attachment]
Author Alexandr N Zamaraev
19.10.2010 14:35, Werner F. Bruhin wrote:
> 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.
val += ord(b[i]) << (8 * (n - i -1))
Why not use module 'struct' to convert binary stream ?