[pypy-commit] pypy cffi-libs: adapt file copied from py3.6 for python2

mattip pypy.commits at gmail.com
Tue May 21 08:47:05 EDT 2019


Author: Matti Picus <matti.picus at gmail.com>
Branch: cffi-libs
Changeset: r96655:ca639af9285d
Date: 2019-05-21 15:45 +0300
http://bitbucket.org/pypy/pypy/changeset/ca639af9285d/

Log:	adapt file copied from py3.6 for python2

diff --git a/lib_pypy/_hashlib/__init__.py b/lib_pypy/_hashlib/__init__.py
--- a/lib_pypy/_hashlib/__init__.py
+++ b/lib_pypy/_hashlib/__init__.py
@@ -56,7 +56,10 @@
         return "<%s HASH object at 0x%s>" % (self.name, id(self))
 
     def update(self, string):
-        buf = ffi.from_buffer(string)
+        if isinstance(string, unicode):
+            buf = ffi.from_buffer(string.encode('utf-8'))
+        else:
+            buf = ffi.from_buffer(string)
         with self.lock:
             # XXX try to not release the GIL for small requests
             lib.EVP_DigestUpdate(self.ctx, buf, len(buf))
@@ -76,8 +79,8 @@
         hexdigits = '0123456789abcdef'
         result = []
         for c in digest:
-            result.append(hexdigits[(c >> 4) & 0xf])
-            result.append(hexdigits[ c       & 0xf])
+            result.append(hexdigits[(ord(c) >> 4) & 0xf])
+            result.append(hexdigits[ ord(c)       & 0xf])
         return ''.join(result)
 
     @property


More information about the pypy-commit mailing list