On 10 Jan, 2008, at 18:00, has wrote:
On 10 Jan 2008, at 06:54, Ronald Oussoren wrote:I'm trying to create a PyObjC wrapper for objc-appscript,Why?Partly just to know how, as one of objc-appscript's goals is to provide a foundation for implementing other appscript bridges, and this lets me explore the ins and outs. Partly so I can do casual testing in an interactive interpreter. (Yeah, I'm a slob.)
Using Python for unittest an interactive exploration is actually a major usecase for PyObjC, so don't feel to bad about this ;-)
Partly because I've been toying with the idea of having objc-aem provide the basis for appscript support in Jonathan Wight's PyObjC- based 'Run Python Script' Automator action.and I'm wondering how to wrap methods that have NSError** arguments, e.g.:The easiest way is to mark the arguments as 'out' in the Objective-C prototype (and then recompile), that way PyObjC will pick up the right metadata from the ObjC runtime and you won't need the bridgesupport fileAhh, too easy. Duh.
I keep trying to make it as easy as possible to create Objective-C code that is trivial to wrap using PyObjC, although documentation and advocacy is rather lacking :-(
The logical thing would be to convert a returned NSError into a Python exception, but BridgeSupport's gen_bridge_metadata tool doesn't seem to provide any help here, simply flagging the argument as 'opaque'. Any advice on how to proceed (with or without using BS)?Don't try to convert the NSError to an exception, that would make your wrapper complete different from other wrappers and hence more likely to cause confusion for users.Okay. (Is this something that's changed since PyObjC 1.x, or is my memory just playing tricks?)
That's probably just your memory. NSException's are bridged to Python exceptions, that may cause the confusion.
Cocoa basicly has two ways to do structured error handling:* Exceptions, which are basicly only used for handling programmer errors (trying to change a immutable dictionary
raises an exception)* NSErrors, which are used for everything else (OS Errors, running out of resources, ...)
* Several ancient API's use strings instead of NSErrors. (I know, this is item 3 in a 2 item list)
Python uses exceptions for all of these. Ronald
Thanks, has -- http://appscript.sourceforge.net http://rb-appscript.rubyforge.org _______________________________________________ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig