[Pyobjc-dev] [ pyobjc-Bugs-681880 ] Conversion to objc string should complain about non-ASCII
Brought to you by:
ronaldoussoren
From: SourceForge.net <no...@so...> - 2003-02-06 19:36:46
|
Bugs item #681880, was opened at 2003-02-06 11:42 You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=114534&aid=681880&group_id=14534 Category: None Group: None Status: Open Resolution: None Priority: 5 Submitted By: David Eppstein (eppstein) Assigned to: Nobody/Anonymous (nobody) Summary: Conversion to objc string should complain about non-ASCII Initial Comment: In Python, a str can contain any byte sequence, and has no specified encoding; to fix an encoding, unicode must be used instead, and non-ascii strings can not be converted to unicode without also providing an encoding. NSString is like unicode in that an encoding is known; therefore NSString should be like unicode in not allowing non-ascii strings to be converted to it without providing an encoding. However, in the current version of PyObjC, any string can be converted to an NSString without complaint. This is inconsistent with Python's unicode behavior and could lead to undetected bugs. The following test code fails the assertion and demonstrates the problem. import unittest import objc from Foundation import NSString class TestEncoding(unittest.TestCase): def testEncoding(self): try: u = u'\xc3\xbc\xc3\xb1\xc3\xae\xc3\xa7\xc3\xb8d\xc3\xa8' s = NSString.stringWithString_(u.encode('iso-8859-1')) self.assertEqual(u,s) # unlikely to be equal since stringWithString_ # has no way of guessing the correct encoding except UnicodeError: pass # should get here, UnicodeError raised # when passing non-ascii str to objc def suite(): suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(TestEncoding)) return suite if __name__ == '__main__': unittest.main( ) ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=114534&aid=681880&group_id=14534 |