Subject Re: [firebird-python] next driver version
Author Hajime Nakagami
> Quickly looking at the doc the module "struct" it looks like it has the
> same functionality from Py 2.5+ to Py 3.2.

Thaks so much.

I will try later (this week end)


2010/10/21 Werner F. Bruhin <werner.bruhin@...>:
>  Hajime,
>
> On 21/10/2010 10:10, Alexandr N Zamaraev wrote:
>> 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 ?
>>
> Would this be possible?
>
> Quickly looking at the doc the module "struct" it looks like it has the
> same functionality from Py 2.5+ to Py 3.2.
>
> Werner
>
>
>