Re: [Pyobjc-dev] Re: [ pyobjc-Bugs-679748 ] NSMutableString gets converted to Python string
Brought to you by:
ronaldoussoren
From: Bob I. <bo...@re...> - 2003-02-03 22:16:49
|
On Monday, Feb 3, 2003, at 16:48 America/New_York, Just van Rossum wrote: > Bill Bumgarner wrote: > >> On Monday, Feb 3, 2003, at 15:45 US/Eastern, Just van Rossum wrote: >>> Bill Bumgarner wrote: >>>> - a python object that provides a character buffer style interface >>>> to the contents of an NSString. >>> >>> How would this work for NSStrings containing unicode? >> >> I have no clue yet. > > What works nicely now is that the conversion of unicode strings to > NSStrings and vice versa is really transparant: pass Python unicode > strings to ObjC call expecting an NSString and it works. The other way > also: if the NSString is representable in 7-bit ascii you get a str, if > not you get a unicode string. I worry about that Python users will have > to convert to a unicode string after all when this conversion _doesn't_ > take place. I have no idea how to make an object can behave _like_ a > unicode string and have it work everywhere. Maybe time for a post to > c.l.py... What about this: class UnicodeNSStringWrapper(unicode): def __new__(clazz, myNSString): s = unicode.__new__(somethingToConvertNSStringInstanceToPyUnicodeObject(myNS String)) s._objc = myNSString return s def __getattr__(self, attr): try: return getattr(self._objc, attr) except: raise AttributeError, '%r object has no attribute %r' % (self.__class__.__name__, self._objc) It should do anything that unicode() will do, just like the str subclass I posted a bit ago.. and you don't lose any of the NSString functionality. -bob |