*/t/*.py: Fix the various testing scripts for Python 3 compatibility.
[mLib] / hash / t / unihash-testgen.py
index 2fe8982..1fde21f 100644 (file)
@@ -3,6 +3,9 @@
 ###
 ### Generate test vectors for universal hashing.
 
+import sys as SYS
+if SYS.version_info >= (3,): xrange = range
+
 MOD = 0x104c11db7
 
 def gfmul(x, y):
@@ -17,13 +20,13 @@ def gfmul(x, y):
 def hashtest(k, m):
   h = k
   for ch in m: h = gfmul(h ^ ord(ch), k)
-  print '  0x%08x "%s" 0x%08x;' % (k, m, h)
+  print('  0x%08x "%s" 0x%08x;' % (k, m, h))
 
-print '''\
+print('''\
 ### Test vectors for universal hashing
 ###   [generated]
 
-hash {'''
+hash {''')
 
 for k, m in [(0x00000000, 'anything you like'),
              (0x12345678, 'an exaple test string'),
@@ -36,4 +39,4 @@ for i in xrange(48):
   hashtest(k, "If we don't succeed, we run the risk of failure.")
   k = gfmul(k, m)
 
-print '}'
+print('}')