|
From: Chris M. <ch...@bo...> - 2001-11-17 20:28:09
|
My program works fine in jython, but I can't use jythonc to create an
applet.
I narrowed the problem down to this line of python code:
import random
The stack trace given when I try to run the applet is as follows (it's
longer than that, but I'm trying to keep the message short).
Java Traceback:
at org.python.core.Py.JavaError(Py.java)
at org.python.core.BytecodeLoader.makeCode(BytecodeLoader.java)
at org.python.core.Py.compile_flags(Py.java)
at org.python.core.Py.compile_flags(Py.java)
at org.python.core.Py.compile_flags(Py.java)
at org.python.core.__builtin__.eval(__builtin__.java)
at org.python.core.__builtin__.eval(__builtin__.java)
at java.lang.reflect.Method.invoke(Native Method)
at
org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java)
at
org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java)
at org.python.core.PyObject.__call__(PyObject.java)
at random$_PyInner._verify$1(random.java:377)
at random$_PyInner.call_function(random.java:310)
at org.python.core.PyTableCode.call(PyTableCode.java)
at org.python.core.PyTableCode.call(PyTableCode.java)
at org.python.core.PyFunction.__call__(PyFunction.java)
at random$_PyInner.main$31(random.java:1029)
at random$_PyInner.call_function(random.java:370)
at org.python.core.PyTableCode.call(PyTableCode.java)
at org.python.core.PyCode.call(PyCode.java)
<snip>
So, it appears that the _verify method in the random module is doing an
eval! That's all well and good, but I don't have org.python.core.parser
anywhere in my jar file. Oops.
It turns out that adding that file doesn't help. If I use the --all
flag, I get this:
Java Traceback:
at org.python.core.Py.JavaError(Py.java)
at org.python.core.BytecodeLoader.makeCode(BytecodeLoader.java)
at org.python.core.Py.compile_flags(Py.java)
at org.python.core.Py.compile_flags(Py.java)
at org.python.core.Py.compile_flags(Py.java)
at org.python.core.__builtin__.eval(__builtin__.java)
at org.python.core.__builtin__.eval(__builtin__.java)
at java.lang.reflect.Method.invoke(Native Method)
at
org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java)
at
org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java)
at org.python.core.PyObject.__call__(PyObject.java)
at random$_PyInner._verify$1(random.java:377)
....
File "/usr/local/jython-2.1a3/Lib/random.py", line 0, in main
File "/usr/local/jython-2.1a3/Lib/random.py", line 0, in _verify
java.security.AccessControlException: access denied
(java.lang.RuntimePermission createClassLoader)
at
java.security.AccessControlContext.checkPermission(AccessControlContext.java:272)
at
java.security.AccessController.checkPermission(AccessController.java:399)
at
java.lang.SecurityManager.checkPermission(SecurityManager.java:545)
at
java.lang.SecurityManager.checkCreateClassLoader(SecurityManager.java:610)
at java.lang.ClassLoader.<init>(ClassLoader.java:234)
at org.python.core.BytecodeLoader1.<init>(BytecodeLoader1.java)
at org.python.core.BytecodeLoader.makeLoader(BytecodeLoader.java)
at org.python.core.BytecodeLoader.makeClass(BytecodeLoader.java)
at org.python.core.BytecodeLoader.makeCode(BytecodeLoader.java)
at org.python.core.Py.compile_flags(Py.java)
at org.python.core.Py.compile_flags(Py.java)
at org.python.core.Py.compile_flags(Py.java)
etc, etc.
So, I tried not importing random at all, but rather doing a simple eval:
print eval("1 + 1")
Again, I am required to use --all (which kind of makes sense), and
again, I get an AccessControlException just like above.
Does this mean that I can't use eval or any module that uses eval in my
applets?
C
|
|
From: <bc...@wo...> - 2001-11-18 13:43:18
|
[Chris Monson]
>My program works fine in jython, but I can't use jythonc to create an
>applet.
>
>I narrowed the problem down to this line of python code:
>
> import random
>
>The stack trace given when I try to run the applet is as follows (it's
>longer than that, but I'm trying to keep the message short).
>
> Java Traceback:
>
> at org.python.core.__builtin__.eval(__builtin__.java)
>...
> at random$_PyInner._verify$1(random.java:377)
>
> <snip>
>
>So, it appears that the _verify method in the random module is doing an
>eval!
Indeed. Rather thoughless bit of code there. I suggest you edit your
copy of random.py to have an empty _verify() function:
def _verify(name, expected):
pass
I have posted a patch to CPython and will include a version of random.py
in 2.1b1 that does not use eval().
>That's all well and good, but I don't have org.python.core.parser
>anywhere in my jar file. Oops.
>
>It turns out that adding that file doesn't help. If I use the --all
>flag, I get this:
>Java Traceback:
>
>java.security.AccessControlException: access denied
Using --all with applets is a topic for a different post.
>So, I tried not importing random at all, but rather doing a simple eval:
>
>print eval("1 + 1")
>
>Again, I am required to use --all (which kind of makes sense), and
>again, I get an AccessControlException just like above.
>
>Does this mean that I can't use eval or any module that uses eval in my
>applets?
Correct, you can't use eval() or compile() in a restricted environment
such as applets.
regards,
finn
|
|
From: Chris M. <ch...@bo...> - 2001-11-18 18:26:55
|
Finn Bock wrote:
>[Chris Monson]
>
>>My program works fine in jython, but I can't use jythonc to create an
>>applet.
>>
>>I narrowed the problem down to this line of python code:
>>
>> import random
>>
>>The stack trace given when I try to run the applet is as follows (it's
>>longer than that, but I'm trying to keep the message short).
>>
>>Java Traceback:
>>
>> at org.python.core.__builtin__.eval(__builtin__.java)
>>...
>> at random$_PyInner._verify$1(random.java:377)
>>
>> <snip>
>>
>>So, it appears that the _verify method in the random module is doing an
>>eval!
>>
>
>Indeed. Rather thoughless bit of code there. I suggest you edit your
>copy of random.py to have an empty _verify() function:
>
>def _verify(name, expected):
> pass
>
>I have posted a patch to CPython and will include a version of random.py
>in 2.1b1 that does not use eval().
>
Thanks. That worked (but, you knew it would...). I was not certain
that I could safely change that function in my own module, so I
appreciate the help.
>>So, I tried not importing random at all, but rather doing a simple eval:
>>
>>print eval("1 + 1")
>>
>>Again, I am required to use --all (which kind of makes sense), and
>>again, I get an AccessControlException just like above.
>>
>>Does this mean that I can't use eval or any module that uses eval in my
>>applets?
>>
>
>Correct, you can't use eval() or compile() in a restricted environment
>such as applets.
>
I'll make the logical leap that says I can't do an 'exec' on uncompiled
code, as well.
I was looking at that, and noticed that Jython is building java code
from the dynamic code in the eval, which makes sense from a performance
standpoint, but obviously breaks the applet security manager when it
tries to compile and dynamically load it.
Is there any talk of allowing an option that would bundle the jython
interpreter when compiling with jythonc, so that eval's, exec's, and
compile's can be used in applets? I believe that embedding the
interpreter would allow for that, though I can't be certain without
digging into the source a bit more.
Anyway, it's a thought. I'll be following the list more closely now and
really spending some time in the Jython source. Jython is an incredibly
cool project, and I am interested in contributing where I can.
Thanks again for your help.
C
|
|
From: <bc...@wo...> - 2001-11-19 08:25:15
|
>>[...] you can't use eval() or compile() in a restricted environment >>such as applets. [Chris Monson] >I'll make the logical leap that says I can't do an 'exec' on uncompiled >code, as well. Right. >I was looking at that, and noticed that Jython is building java code >from the dynamic code in the eval, which makes sense from a performance >standpoint, but obviously breaks the applet security manager when it >tries to compile and dynamically load it. > >Is there any talk of allowing an option that would bundle the jython >interpreter when compiling with jythonc, The only 'interpreter' we have is the one that gets included when you specify the --all option. >so that eval's, exec's, and >compile's can be used in applets? I believe that embedding the >interpreter would allow for that, though I can't be certain without >digging into the source a bit more. We would need a whole new subsystem that included a traditional interpreter like CPython's ceval loop. And a whole new compiler that creates whatever bytecode the interpreter is interpreting. Yes, we have talked about it. In Tools/jpythonc/PythonInterpreter.py is the beginning of an interpreter that is running directly off the parse tree. That way we don't need yet another compiler, but the result is likely slower than python bytecode would be. PythonInterpreter is written by JimH and it is some way away from being usefull. regards, finn |