[pypy-commit] pypy default: catch ParseStringError, raise app-level exception

kostialopuhin noreply at buildbot.pypy.org
Fri Oct 26 10:50:12 CEST 2012


Author: Konstantin Lopuhin <kostia.lopuhin at gmail.com>
Branch: 
Changeset: r58428:be5d72b50028
Date: 2012-07-20 23:21 +0400
http://bitbucket.org/pypy/pypy/changeset/be5d72b50028/

Log:	catch ParseStringError, raise app-level exception

diff --git a/pypy/objspace/std/bytearrayobject.py b/pypy/objspace/std/bytearrayobject.py
--- a/pypy/objspace/std/bytearrayobject.py
+++ b/pypy/objspace/std/bytearrayobject.py
@@ -13,6 +13,8 @@
 from pypy.objspace.std.listtype import get_list_index
 from pypy.objspace.std.sliceobject import W_SliceObject, normalize_simple_slice
 from pypy.objspace.std.stringobject import W_StringObject
+from pypy.objspace.std.strutil import ParseStringError
+from pypy.objspace.std.strutil import string_to_float
 from pypy.objspace.std.tupleobject import W_TupleObject
 from pypy.objspace.std.unicodeobject import W_UnicodeObject
 from pypy.objspace.std import slicetype
@@ -82,7 +84,12 @@
     w_bytearray.data = data
 
 def float__Bytearray(space, w_bytearray):
-    return space.wrap(float(''.join(w_bytearray.data)))
+    try:
+        value = string_to_float(''.join(w_bytearray.data))
+    except ParseStringError, e:
+        raise OperationError(space.w_ValueError, space.wrap(e.msg))
+    else:
+        return space.wrap(value)
 
 def len__Bytearray(space, w_bytearray):
     result = len(w_bytearray.data)


More information about the pypy-commit mailing list