[Twisted-Python] [PATCH] Fix FutureWarning

Moshe Zadka m at moshez.org
Mon May 12 09:00:59 EDT 2003


hex()/oct() will return signed strings for negative ints in 2.4 and
onwards. Here is a patch to twisted/world/structfile.py to prevent
that from affecting twisted:
[by the by, I also switched from except: to except TypeError, seeing
as this is the only error we expect hex() to throw]

Index: twisted/world/structfile.py
===================================================================
RCS file: /cvs/Twisted/twisted/world/structfile.py,v
retrieving revision 1.1
diff -u -r1.1 structfile.py
--- twisted/world/structfile.py	7 May 2003 13:56:32 -0000	1.1
+++ twisted/world/structfile.py	12 May 2003 12:58:50 -0000
@@ -198,8 +198,13 @@
             f.write('<tr>')
             for item in row:
                 try:
-                    item = hex(item)
-                except:
+                    if item >= 0:
+                        item = hex(item)
+                    else:
+                        item = hex((1L<<32)-item).lower()
+                        if item[-1] == 'l':
+                            item = item[:-1]
+                except TypeError:
                     item = str(item)
                 f.write('<td>'+item+'</td>')
             f.write('</tr>')

-- 
Moshe Zadka -- http://moshez.org/
Buffy: I don't like you hanging out with someone that... short.
Riley: Yeah, a lot of young people nowadays are experimenting with shortness.
Agile Programming Language -- http://www.python.org/




More information about the Twisted-Python mailing list