On 1/5/10 11:41 AM, has wrote:
If I understand you, Tk implements a 'do script' handler that executes
arbitrary Tcl scripts (right...no potential security issues there, then) and
you are installing your own 'do script' handler as well.
Yes, that's basically it.
If that's the case, make sure your handler gets installed _after_ Tk has
auto-installed its version, otherwise Tk will simply replace yours with its
own. I'm not familiar with Tk though, so can't tell you at what point you need
to do this.
Alternatively, give your handler a different name and Apple event code so that
it doesn't conflict with Tk's handler in the first place.
This turned out to be the solution. However:
It appears that Tcl and Python differ in some respects in code
execution. Python doesn't appear to return a value from code that is
passed to the "exec" statement.
Here, first, is my aemreceive code:
from aemreceive import *
def doScript(script):
exec script
installeventhandler(
doScript,
'CoKvscpt',
('----', 'script', kae.typeUnicodeText)
)
And here is my sample AppleScript code:
tell application "MyApp"
run script "print \"foo\""
end tell
The comparable Tcl code snippet, "puts \"foo\"", returns a value of
"foo"--the string printed to standard output. I expect to see the same
thing in Python. But the Python function above returns no output to
AppleScript--the value of "foo" goes down a black hole. I don't see the
output logged to Console, either.
I didn't see this issue with the sample code that has includes with
aemreceive, but that code explicitly returns values:
def unicodeNumbers(text):
return [ord(c) for c in text]
So I'm trying to figure out how to capture the standard output of a
Python code snippet that's been "exec'ed." More of a general Python
question than a Mac question, granted, but the context wouldn't make
much sense on comp.lang.python.
As far as the security issues, I agree, that's a concern. My basic idea
is to expose a selection of commands in my application, either wrapped
in AppleScript commands or simply as Python commands accessed via the
"run script" command. The goal *isn't* to encourage arbitrary Python
snippets.
Thanks,
Kevin
--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
_______________________________________________
Pythonmac-SIG maillist - Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig