We have a fairly large existing Cocoa code base, and I'm currently
investigating making some services available over the web with this
code. To that end, I've been experimenting with using PyObjC to
script our already existing Cocoa objects in order to reuse as much
code as possible. So far this is going very well, but I've run into a
few things which might be beginner problems.
Anyway, I'm using some code which generates an NSData containing JPG
data, and I'd like to return this data to a web browser either in a
Python CGI or more likely a Python app server of some sort. The
problem I'm having is one of datatypes. I can get an array of bytes
out of the NSData, but as far as I know that's not useful over the
bridge. The only way I can see to turn it into a string like Python
needs (I either have to write a string to stdout or in most app
servers, return a string) is to call description() on the NSData
object, but that gives me the bytes all formatted. That's not going
I got around the problem in a CGI by having an ObjC helper method
write the data to stdout, but that won't work for the app server
case. Is there a typical way around this problem?
Also, how are constants handled? Cocoa has a number of these that you
pass to various calls, do I just have to use their actual value when
calling these methods from Python?
Thanks for any pointers!