[pypy-svn] r61389 - in pypy/trunk/pypy/objspace/std: . test

arigo at codespeak.net arigo at codespeak.net
Tue Jan 27 14:16:23 CET 2009


Author: arigo
Date: Tue Jan 27 14:16:23 2009
New Revision: 61389

Modified:
   pypy/trunk/pypy/objspace/std/stringobject.py
   pypy/trunk/pypy/objspace/std/test/test_unicodeobject.py
   pypy/trunk/pypy/objspace/std/unicodeobject.py
Log:
Fix unicode_replace__Unicode_ANY_ANY_ANY:
must use space.bufferstr_w() instead of space.buffer_w().as_str().
The difference is nicely documented in bufferstr_w() :-)


Modified: pypy/trunk/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/stringobject.py	(original)
+++ pypy/trunk/pypy/objspace/std/stringobject.py	Tue Jan 27 14:16:23 2009
@@ -52,6 +52,7 @@
                     space.wrap(i),
                     space.wrap(i+1),
                     space.wrap("ordinal not in range(128)")]))
+        assert False, "unreachable"
 
 def unicode_w__String(space, w_self):
     # XXX should this use the default encoding?

Modified: pypy/trunk/pypy/objspace/std/test/test_unicodeobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/test/test_unicodeobject.py	(original)
+++ pypy/trunk/pypy/objspace/std/test/test_unicodeobject.py	Tue Jan 27 14:16:23 2009
@@ -770,3 +770,8 @@
                 return u'bar'
 
         assert unicode(A()) == u'bar'
+
+    def test_replace_with_buffer(self):
+        assert u'abc'.replace(buffer('b'), buffer('e')) == u'aec'
+        assert u'abc'.replace(buffer('b'), u'e') == u'aec'
+        assert u'abc'.replace(u'b', buffer('e')) == u'aec'

Modified: pypy/trunk/pypy/objspace/std/unicodeobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/unicodeobject.py	(original)
+++ pypy/trunk/pypy/objspace/std/unicodeobject.py	Tue Jan 27 14:16:23 2009
@@ -230,9 +230,8 @@
     if ival < 0:
         ival += ulen
     if ival < 0 or ival >= ulen:
-        exc = space.call_function(space.w_IndexError,
-                                  space.wrap("unicode index out of range"))
-        raise OperationError(space.w_IndexError, exc)
+        raise OperationError(space.w_IndexError,
+                             space.wrap("unicode index out of range"))
     return W_UnicodeObject(uni[ival])
 
 def getitem__Unicode_Slice(space, w_uni, w_slice):
@@ -768,8 +767,8 @@
 
 def unicode_replace__Unicode_ANY_ANY_ANY(space, w_self, w_old, w_new,
                                          w_maxsplit):
-    old = unicode(space.buffer_w(w_old).as_str())
-    new = unicode(space.buffer_w(w_new).as_str())
+    old = unicode(space.bufferstr_w(w_old))
+    new = unicode(space.bufferstr_w(w_new))
     return _unicode_replace(space, w_self, old, new, w_maxsplit)
 
 def _unicode_replace(space, w_self, old, new, w_maxsplit):



More information about the Pypy-commit mailing list