[PyObjC-svn] r2595 - trunk/pyobjc/pyobjc-core/Lib/objc

[email protected] Tue, 05 Oct 2010 07:10:00 -0500
Newsgroups gmane.comp.python.pyobjc.cvs
Message-ID <[email protected]>
Author: ronaldoussoren
Date: Tue Oct  5 07:09:52 2010
New Revision: 2595

Log:
Avoid exceptions when doing str(anNSData).


Modified:
   trunk/pyobjc/pyobjc-core/Lib/objc/_convenience.py

Modified: trunk/pyobjc/pyobjc-core/Lib/objc/_convenience.py
==============================================================================
--- trunk/pyobjc/pyobjc-core/Lib/objc/_convenience.py	(original)
+++ trunk/pyobjc/pyobjc-core/Lib/objc/_convenience.py	Tue Oct  5 07:09:52 2010
@@ -767,8 +767,22 @@
     except TypeError:
         return buff[:][item]
 
+
+if sys.version_info[:2] <= (2,6):
+    def NSData__str__(self):
+        return self.bytes()[:]
+
+elif sys.version_info[0] == 2:
+    def NSData__str__(self):
+        return str(self.bytes().tobytes())
+
+else:
+    def NSData__str__(self):
+        return str(self.bytes().tobytes())
+
+
 CLASS_METHODS['NSData'] = (
-    ('__str__', lambda self: self.bytes()[:]),
+    ('__str__', NSData__str__),
     ('__getitem__', NSData__getitem__),
     ('__getslice__', NSData__getslice__),
 )

------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb