Author: Amaury Forgeot d'Arc <[email protected]>
Branch: py3k
Changeset: r58832:63900b5df415
Date: 2012-11-11 22:48 +0100
http://bitbucket.org/pypy/pypy/changeset/63900b5df415/
Log: Add array.frombytes, depreate array_fromstring
diff --git a/pypy/module/array/interp_array.py
b/pypy/module/array/interp_array.py
--- a/pypy/module/array/interp_array.py
+++ b/pypy/module/array/interp_array.py
@@ -66,6 +66,7 @@
array_tostring = SMM('tostring', 1)
array_tobytes = SMM('tobytes', 1)
array_fromstring = SMM('fromstring', 2)
+array_frombytes = SMM('frombytes', 2)
array_tounicode = SMM('tounicode', 1)
array_fromunicode = SMM('fromunicode', 2)
array_tofile = SMM('tofile', 2)
@@ -547,8 +548,13 @@
def array_fromlist__Array_List(space, self, w_lst):
self.fromlist(w_lst)
+ def array_frombytes__Array_ANY(space, self, w_s):
+ self.fromstring(space.bytes_w(w_s))
+
def array_fromstring__Array_ANY(space, self, w_s):
- self.fromstring(space.bytes_w(w_s))
+ space.warn("fromstring() is deprecated. Use frombytes() instead.",
+ self.space.w_DeprecationWarning)
+ self.fromstring(space.str_w(w_s))
def array_tobytes__Array(space, self):
cbuf = self._charbuf_start()
diff --git a/pypy/module/array/test/test_array.py
b/pypy/module/array/test/test_array.py
--- a/pypy/module/array/test/test_array.py
+++ b/pypy/module/array/test/test_array.py
@@ -150,13 +150,26 @@
def test_fromstring(self):
for t in 'bBhHiIlLfd':
a = self.array(t)
- a.fromstring(b'\x00' * a.itemsize * 2)
+ a.fromstring('\x00' * a.itemsize * 2)
assert len(a) == 2 and a[0] == 0 and a[1] == 0
if a.itemsize > 1:
- raises(ValueError, a.fromstring, b'\x00' * (a.itemsize - 1))
- raises(ValueError, a.fromstring, b'\x00' * (a.itemsize + 1))
- raises(ValueError, a.fromstring, b'\x00' * (2 * a.itemsize -
1))
- raises(ValueError, a.fromstring, b'\x00' * (2 * a.itemsize +
1))
+ raises(ValueError, a.fromstring, '\x00' * (a.itemsize - 1))
+ raises(ValueError, a.fromstring, '\x00' * (a.itemsize + 1))
+ raises(ValueError, a.fromstring, '\x00' * (2 * a.itemsize - 1))
+ raises(ValueError, a.fromstring, '\x00' * (2 * a.itemsize + 1))
+ b = self.array(t, b'\x00' * a.itemsize * 2)
+ assert len(b) == 2 and b[0] == 0 and b[1] == 0
+
+ def test_frombytes(self):
+ for t in 'bBhHiIlLfd':
+ a = self.array(t)
+ a.frombytes(b'\x00' * a.itemsize * 2)
+ assert len(a) == 2 and a[0] == 0 and a[1] == 0
+ if a.itemsize > 1:
+ raises(ValueError, a.frombytes, b'\x00' * (a.itemsize - 1))
+ raises(ValueError, a.frombytes, b'\x00' * (a.itemsize + 1))
+ raises(ValueError, a.frombytes, b'\x00' * (2 * a.itemsize - 1))
+ raises(ValueError, a.frombytes, b'\x00' * (2 * a.itemsize + 1))
b = self.array(t, b'\x00' * a.itemsize * 2)
assert len(b) == 2 and b[0] == 0 and b[1] == 0
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit