aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2022-02-07 09:03:22 +0200
committerMatti Picus <matti.picus@gmail.com>2022-02-07 09:03:22 +0200
commite488e18854cc1c28bdf98e922e34664def7da5f8 (patch)
tree18bc195d13330ed98547f6736f680f43d69da525
parentadd failing test from issue 3022 (diff)
downloadpypy-e488e18854cc1c28bdf98e922e34664def7da5f8.tar.gz
pypy-e488e18854cc1c28bdf98e922e34664def7da5f8.tar.bz2
pypy-e488e18854cc1c28bdf98e922e34664def7da5f8.zip
improve 1117ad6dc285 (Thomas Grainger)
-rw-r--r--lib_pypy/_hashlib/__init__.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib_pypy/_hashlib/__init__.py b/lib_pypy/_hashlib/__init__.py
index ad5b76a301..50e3a04ab3 100644
--- a/lib_pypy/_hashlib/__init__.py
+++ b/lib_pypy/_hashlib/__init__.py
@@ -10,9 +10,6 @@ except ImportError: builtinify = lambda f: f
def new(name, string=b''):
h = HASH(name)
- if isinstance(string, memoryview):
- # issue 2756: ffi.from_buffer() cannot handle memoryviews
- string = string.tobytes()
h.update(string)
return h
@@ -59,6 +56,11 @@ class HASH(object):
return "<%s HASH object at 0x%s>" % (self.name, id(self))
def update(self, string):
+ if isinstance(string, str):
+ raise TypeError("Unicode-objects must be encoded before hashing")
+ elif isinstance(string, memoryview):
+ # issue 2756: ffi.from_buffer() cannot handle memoryviews
+ string = string.tobytes()
buf = ffi.from_buffer(string)
with self.lock:
# XXX try to not release the GIL for small requests