Subject | Re: [firebird-python] next driver version [1 Attachment] |
---|---|
Author | Alexandr N Zamaraev |
Post date | 2010-10-21T08:10:52Z |
19.10.2010 14:35, Werner F. Bruhin wrote:
Why not use module 'struct' to convert binary stream ?
> File "C:\dev\firebirdNewDriver\firebirdsql\fbcore.py", line 169, inval += ord(b[i]) << (8 * (n - i -1))
> 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.
Why not use module 'struct' to convert binary stream ?