Commits

Anonymous committed b50a4dc

Fix unicode exclusion in PyByteArray.setslice
Discovered by test_memoryio test_unicode that bytearray.extend(s)
allows s to be unicode when it shouldn't. Now can remove skip.

Comments (0)

Files changed (2)

Lib/test/test_memoryio.py

         memio.seek(1, 1)
         self.assertEqual(memio.read(), buf[1:])
 
-    # This test isn't working on Ubuntu on an Apple Intel powerbook,
-    # Jython 2.7b1+ (default:6b4a1088566e, Feb 10 2013, 14:36:47) 
-    # [OpenJDK 64-Bit Server VM (Oracle Corporation)] on java1.7.0_09
-    @unittest.skipIf(support.is_jython,
-                     "FIXME: Currently not working on jython")
     def test_unicode(self):
         memio = self.ioclass()
 

src/org/python/core/PyByteArray.java

 
     /**
      * Sets the given range of elements according to Python slice assignment semantics from a
-     * {@link PyString}.
+     * {@link PyString} that is not a {@link PyUnicode}.
      *
      * @see #setslice(int, int, int, PyObject)
      * @param start the position of the first element.
      * @param step the step size.
      * @param value a PyString object consistent with the slice assignment
      * @throws PyException (SliceSizeError) if the value size is inconsistent with an extended slice
+     * @throws PyException (ValueError) if the value is a <code>PyUnicode</code>
      */
     private void setslice(int start, int stop, int step, PyString value) throws PyException {
-        String v = value.asString();
-        int len = v.length();
-        if (step == 1) {
-            // Delete this[start:stop] and open a space of the right size
-            storageReplace(start, stop - start, len);
-            setBytes(start, v);
+        if (value instanceof PyUnicode) {
+            // Has to be 8-bit PyString
+            throw Py.TypeError("can't set bytearray slice from unicode");
         } else {
-            // This is an extended slice which means we are replacing elements
-            int n = sliceLength(start, stop, step);
-            if (n != len) {
-                throw SliceSizeError("bytes", len, n);
+            // Assignment is from 8-bit data
+            String v = value.asString();
+            int len = v.length();
+            if (step == 1) {
+                // Delete this[start:stop] and open a space of the right size
+                storageReplace(start, stop - start, len);
+                setBytes(start, v);
+            } else {
+                // This is an extended slice which means we are replacing elements
+                int n = sliceLength(start, stop, step);
+                if (n != len) {
+                    throw SliceSizeError("bytes", len, n);
+                }
+                setBytes(start, step, v);
             }
-            setBytes(start, step, v);
         }
     }