[pypy-svn] r52340 - in pypy/branch/buffer/pypy/lib: . test2
arigo at codespeak.net
arigo at codespeak.net
Sun Mar 9 16:26:38 CET 2008
Author: arigo
Date: Sun Mar 9 16:26:38 2008
New Revision: 52340
Modified:
pypy/branch/buffer/pypy/lib/array.py
pypy/branch/buffer/pypy/lib/test2/test_array.py
Log:
More bug fixes.
Modified: pypy/branch/buffer/pypy/lib/array.py
==============================================================================
--- pypy/branch/buffer/pypy/lib/array.py (original)
+++ pypy/branch/buffer/pypy/lib/array.py Sun Mar 9 16:26:38 2008
@@ -168,8 +168,9 @@
if not isinstance(ustr, unicode):
raise TypeError("fromunicode() argument should probably be "
"a unicode string")
- self._frombuffer(ustr) # _frombuffer() does the currect thing using
- # the buffer behavior of unicode objects
+ # _frombuffer() does the currect thing using
+ # the buffer behavior of unicode objects
+ self._frombuffer(buffer(ustr))
def tofile(self, f):
"""Write all items (as machine values) to the file object f. Also
@@ -371,11 +372,6 @@
__rmul__ = __mul__
def __getitem__(self, i):
- if self.typecode == 'c': # speed trick
- try:
- return self._data[i]
- except TypeError:
- pass # "bug": ctypes.create_string_buffer(10)[slice(2,5)]
seqlength = len(self)
if isinstance(i, slice):
start, stop, step = i.indices(seqlength)
@@ -390,6 +386,8 @@
return array(self.typecode, self._data[start * self.itemsize :
stop * self.itemsize])
else:
+ if self.typecode == 'c': # speed trick
+ return self._data[i]
if i < 0:
i += seqlength
if not (0 <= i < seqlength):
@@ -423,6 +421,9 @@
self._data[start * self.itemsize :
stop * self.itemsize] = x._data
else:
+ if self.typecode == 'c': # speed trick
+ self._data[i] = x
+ return
seqlength = len(self)
if i < 0:
i += seqlength
Modified: pypy/branch/buffer/pypy/lib/test2/test_array.py
==============================================================================
--- pypy/branch/buffer/pypy/lib/test2/test_array.py (original)
+++ pypy/branch/buffer/pypy/lib/test2/test_array.py Sun Mar 9 16:26:38 2008
@@ -24,6 +24,12 @@
a *= 3
assert a.tolist() == [12, 34] * 3
+ def test_unicode(self):
+ a = self.array.array('u')
+ a.fromunicode(unichr(9999))
+ assert len(a) == 1
+ assert a.tolist() == [unichr(9999)]
+
class TestArrayOnTopOfCPython(BaseArrayTests):
More information about the Pypy-commit
mailing list