Commits

Ronald Oussoren committed 28cab07

Merged revisions 2597 via svnmerge from
https://svn.red-bean.com/pyobjc/trunk/pyobjc

........
r2597 | ronaldoussoren | 2010-10-05 14:15:27 +0200 (Tue, 05 Oct 2010) | 3 lines

- Small tweaks for the nsdata tests
- Ensure nsbitmap wrappers work with python2.6
........

Comments (0)

Files changed (2)

pyobjc-framework-Cocoa/Modules/_AppKit_nsbitmap.m

 	if (result != NULL) {
 		for(i=0; i<5; i++) {
 			if (dataPlanes[i]) {
-#if PY_VERSION_HEX <= 0x02069900
+#if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION <= 6
 				PyObject* buffer = PyBuffer_FromReadWriteMemory(dataPlanes[i], bytesPerPlane);
 #else
 				Py_buffer info;
 		return NULL;
 	}
 
-#if  PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 6
+#if  PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION <= 6
 	result = PyBuffer_FromReadWriteMemory(bitmapData, bytesPerPlane);
 #else
 
 	 * interface, therefore create a mutable bytes object to do that for us.
 	 */
 	Py_buffer info;
-#if 0
-	NSMutableData* data = [[NSMutableData alloc] initWithBytesNoCopy:bitmapData length: bytesPerPlane freeWhenDone:NO];
-	PyObject* bytesBuf = PyObjC_ObjCToPython("@", &data);
-	[data release];
-	if (bytesBuf == NULL) {
-		return NULL;
-	}
-
-	if (PyBuffer_FillInfo(&info, bytesBuf, bitmapData, bytesPerPlane, 0, PyBUF_FULL) < 0) {
-#endif
 	if (PyBuffer_FillInfo(&info, NULL, bitmapData, bytesPerPlane, 0, PyBUF_FULL) < 0) {
 		return NULL;
 	}

pyobjc-framework-Cocoa/PyObjCTest/test_nsdata.py

         bytesValue = data.bytes()
         self.assertEqual(len(bytesValue), len(rawBytes), "bytes() and rawBytes not equal length.")
 
-        self.assertEquals(rawBytes, bytesValue)
+        if sys.version_info[:2] <= (2,6):
+            self.assertEquals(buffer(rawBytes), bytesValue)
+
+        else:
+            self.assertEquals(rawBytes, bytesValue)
 
         try:
             bytesValue[3] = b'\xAE'
         self.assertEqual(buffer(m)[:], m[:])
 
 
+class TestRegressions (TestCase):
+    def testDataStr(self):
+        if sys.version_info[0] == 2:
+            input = buffer("hello")
+            input_str = "hello"
+        else:
+            input = b"hello"
+            input_str = str(input)
 
+        buf = NSData.dataWithData_(input)
+        self.assertEquals(str(buf), input_str)
 
 
 if __name__ == '__main__':