1. Pypy
  2. Untitled project
  3. pypy

Commits

Amaury Forgeot d'Arc  committed f76981e

test_md5 now passes

  • Participants
  • Parent commits 82ba9ff
  • Branches py3k

Comments (0)

Files changed (2)

File lib_pypy/binascii.py

View file
     result = 0
     crc = ~long(crc) & 0xffffffffL
     for c in s:
-        crc = crc_32_tab[(crc ^ long(ord(c))) & 0xffL] ^ (crc >> 8)
+        crc = crc_32_tab[(crc ^ c) & 0xffL] ^ (crc >> 8)
         #/* Note:  (crc >> 8) MUST zero fill on left
 
     result = crc ^ 0xffffffffL
 def b2a_hex(s):
     result = []
     for char in s:
-        c = (ord(char) >> 4) & 0xf
+        c = (char >> 4) & 0xf
         if c > 9:
             c = c + ord('a') - 10
         else:
             c = c + ord('0')
         result.append(chr(c))
-        c = ord(char) & 0xf
+        c = char & 0xf
         if c > 9:
             c = c + ord('a') - 10
         else:
             c = c + ord('0')
-        result.append(chr(c))
-    return ''.join(result)
+        result.append(c)
+    return bytes(result)
 
 hexlify = b2a_hex
 
     for a, b in pairs_gen(t):
         if a < 0 or b < 0:
             raise TypeError('Non-hexadecimal digit found')
-        result.append(chr((a << 4) + b))
-    return ''.join(result)
+        result.append((a << 4) + b)
+    return bytes(result)
     
 
 unhexlify = a2b_hex

File pypy/module/_md5/test/test_md5.py

View file
         for input, expected in cases:
             d = md5.md5(input)
             assert d.hexdigest() == expected
-            assert d.digest() == binascii.hexlify(expected.encode('ascii'))
+            assert d.digest() == binascii.unhexlify(expected.encode('ascii'))
 
 
     def test_copy(self):
         Test passing a buffer object.
         """
         md5 = self.md5
-        d1 = md5.md5(buffer("abcde"))
-        d1.update(buffer("jkl"))
+        d1 = md5.md5(buffer(b"abcde"))
+        d1.update(buffer(b"jkl"))
         assert d1.hexdigest() == 'e570e7110ecef72fcb772a9c05d03373'
 
 
         Test passing unicode strings.
         """
         md5 = self.md5
-        d1 = md5.md5(u"abcde")
-        d1.update(u"jkl")
-        assert d1.hexdigest() == 'e570e7110ecef72fcb772a9c05d03373'
-        raises(UnicodeEncodeError, d1.update, u'\xe9')
+        raises(TypeError, md5.md5, "abcde")
+        d1 = md5.md5()
+        raises(TypeError, d1.update, "jkl")