[pypy-commit] pypy py3k: Fix a crash when the 'str' unwrap_spec is given a non-ascii unicode string.
amauryfa
noreply at buildbot.pypy.org
Sat Dec 17 23:01:07 CET 2011
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3k
Changeset: r50640:8d91b7ba9f7c
Date: 2011-12-17 18:37 +0100
http://bitbucket.org/pypy/pypy/changeset/8d91b7ba9f7c/
Log: Fix a crash when the 'str' unwrap_spec is given a non-ascii unicode
string. Now it automatically converts to utf_8 bytes, like CPython.
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -1304,7 +1304,11 @@
return self.str_w(w_obj)
def str_w(self, w_obj):
- return self.unicode_w(w_obj).encode('ascii')
+ try:
+ return self.unicode_w(w_obj).encode('ascii')
+ except UnicodeEncodeError:
+ w_bytes = self.call_method(w_obj, 'encode', self.wrap('utf-8'))
+ return self.bytes_w(w_bytes)
def bytes_w(self, w_obj):
return w_obj.bytes_w(self)
diff --git a/pypy/objspace/std/test/test_floatobject.py b/pypy/objspace/std/test/test_floatobject.py
--- a/pypy/objspace/std/test/test_floatobject.py
+++ b/pypy/objspace/std/test/test_floatobject.py
@@ -773,6 +773,8 @@
def test_invalid(self):
raises(ValueError, float.fromhex, "0P")
+ # A fullwidth Unicode digit
+ raises(ValueError, float.fromhex, "0x1p\uff10")
def test_division_edgecases(self):
import math
More information about the pypy-commit
mailing list