[reportlab-users] FutureWarnings in ttfonts.py with Python 2.3

Robin Becker reportlab-users@reportlab.com
Wed, 24 Mar 2004 16:16:01 +0000


In article <2546C8F5D3D2D411857F00508BDCA4E8031D92B8@dalbar_mail.dalbar.
com>, Marc Stober <MStober@DALBAR.com> writes
>Hello,
>
>I was just wondering if there was any quick fix to the FutureWarnings still
>being returned by ttfonts.py running under Python 2.3? Even running the
>simple example from the user guide (the one with Rina.ttf) shows this:
>
>C:\Python23\lib\site-packages\reportlab\pdfbase\ttfonts.py:181:
>FutureWarning: x<<y losing bits or changing sign will return a long in
>Python 2.4 and up
>  sum = (hi << 16) | (lo & 0xFFFF)
>C:\Python23\lib\site-packages\reportlab\pdfbase\ttfonts.py:190:
>FutureWarning: x<<y losing bits or changing sign will return a long in
>Python 2.4 and up
>  return (hi << 16) | (lo & 0xFFFF)
>
>Thanks, Marc
>mstober@dalbar.com 
> 
.... I don't get that with the latest pyd's and the CVS code. It's an
utter pain that they did the unification without introducing an unsigned
32 bit int so the bit twiddling can continue. The fix seems to be to use

def _L2U32(L):
        return unpack('l',pack('L',L))[0]

.....

_L2U32((hi << 16L) | (lo & 0xFFFF))

where it's required. I think this works in older Pythons as well.
-- 
Robin Becker