file access in jythonc

J

John Howard

I have the following in a jythonc program to be executed in a html
file.

f1 = open("filename","r")

I get message about filePermission read error. Program compiles and
jar file is created. Just the html code gives message.

Any ideas?
 
A

Alan Kennedy

[John Howard]
I have the following in a jythonc program to be executed in a html
file.

f1 = open("filename","r")

I get message about filePermission read error. Program compiles and
jar file is created. Just the html code gives message.

Any ideas?

I am presuming that when you say "executed in a html file" you mean that
this code is to be embedded in a rendered html page as displayed in a
browser, such as mozilla or ie, which means that your code is an
"applet", and thus allowed to execute only in the "applet sandbox"
inside that browser. Which significantly restricts the access rights of
the applet to access system resources such as local files, for a range
of very good security reasons, described here

http://java.sun.com/docs/books/tutorial/applet/overview/security.html
http://java.sun.com/docs/books/tutorial/security1.2/overview/

You can approach the problem by

1. Digitally signing your applet or jar file.
http://www.jguru.com/faq/view.jsp?EID=11475

2. Configuring the your browser to permit file access to local files
(potentially opening a massive security hole in your browser).
http://www.developer.com/java/ent/article.php/630621

HTH,
 
J

John Howard

Alan Kennedy said:
[John Howard]
I have the following in a jythonc program to be executed in a html
file.

f1 = open("filename","r")

I get message about filePermission read error. Program compiles and
jar file is created. Just the html code gives message.

Any ideas?

I am presuming that when you say "executed in a html file" you mean that
this code is to be embedded in a rendered html page as displayed in a
browser, such as mozilla or ie, which means that your code is an
"applet", and thus allowed to execute only in the "applet sandbox"
inside that browser. Which significantly restricts the access rights of
the applet to access system resources such as local files, for a range
of very good security reasons, described here

http://java.sun.com/docs/books/tutorial/applet/overview/security.html
http://java.sun.com/docs/books/tutorial/security1.2/overview/

You can approach the problem by

1. Digitally signing your applet or jar file.
http://www.jguru.com/faq/view.jsp?EID=11475

2. Configuring the your browser to permit file access to local files
(potentially opening a massive security hole in your browser).
http://www.developer.com/java/ent/article.php/630621

HTH,
Yes, you are correct. I do want to execute in html page. I need read
access only for a file that is already there from another source. It's
unclear to me exactly where the filepermission code goes. In the
jython program? I looked at my ie parameters and saw no place to
change access to files. I did a search in altavista on FilePermission
and it looks like a lot of others also have questions. Can this even
be done with jythonc? It seems to me that being able to do so opens up
many, many possibilities for useful code!
 
J

John Howard

I have the following in a jythonc program to be executed in a html
file.

f1 = open("filename","r")

I get message about filePermission read error. Program compiles and
jar file is created. Just the html code gives message.

Any ideas?

I've looked up the references below and done several searches of
filepermissions. It seems to me that for jythonc to have any use in
development of "practical" products, programs have to be able to
access local files easily. If not, then this, in my opinion, is going
to be a MAJOR issue for jython!! I love the syntax and ease of
programming in python, but if it cannot be used for useful programs,
why bother?! BTW, how does java handle this? Is the same problem there
also?
 
D

Diez B. Roggisch

I've looked up the references below and done several searches of
filepermissions. It seems to me that for jythonc to have any use in
development of "practical" products, programs have to be able to
access local files easily. If not, then this, in my opinion, is going
to be a MAJOR issue for jython!! I love the syntax and ease of
programming in python, but if it cannot be used for useful programs,
why bother?! BTW, how does java handle this? Is the same problem there
also?

Don't blame jython for things it hasn't to do with - as Alan said, java puts
restrictions on the things an applet can do. That restrictions can be
relaxed by signing the applet - go search google for stuff like java,
applet, signing, local, file, access.

A common mistake for jython users is to think that there must be special
jython related documentation for their problems - but usually its not, for
the simple reason that there are tons of docs on java out there. Jython
docs only cover the differences. So go look for java solutions to your
problems, and then feel the joy of using java-classes with a language
without checked exceptions and what not that makes coding in java so ...
verbose.
 
J

John Howard

Diez B. Roggisch said:
Don't blame jython for things it hasn't to do with - as Alan said, java puts
restrictions on the things an applet can do. That restrictions can be
relaxed by signing the applet - go search google for stuff like java,
applet, signing, local, file, access.

A common mistake for jython users is to think that there must be special
jython related documentation for their problems - but usually its not, for
the simple reason that there are tons of docs on java out there. Jython
docs only cover the differences. So go look for java solutions to your
problems, and then feel the joy of using java-classes with a language
without checked exceptions and what not that makes coding in java so ...
verbose.

So...are you saying it can be done? That is, a IE can access a local
file (assuming it's there, of course) using a jythonc product?
Question is -- HOW???
 
D

Diez B. Roggisch

So...are you saying it can be done? That is, a IE can access a local
file (assuming it's there, of course) using a jythonc product?
Question is -- HOW???

As I said - search google for JAVA APPLETS ACCESSING LOCAL FILES - then you
can do that using jython. As a matter of fact, the whole process has to do
with signing jars - nobody cares if these contain classes generated by
javac, jikes, jythonc or carefully handwritten jvm bytecode....
 
N

Neil Benn

<snip>
Hello,

The reason that you cannot access local files is for security
reasons. If you could access local files; then what would stop an
applet running the (Jython) command :

os.remove("kernal32.dll")

As the previous responder stated, you will need to understand the
java security model, beneath is a link to the Java Security Tutorial :

http://java.sun.com/docs/books/tutorial/security1.2/

I know that it is a pain the the arse to deal with but imagine what
a disaster it would be if the security wasn't there!

Cheers,

Neil

--

Neil Benn
Senior Automation Engineer
Cenix BioScience
BioInnovations Zentrum
Tatzberg 47
D-01307
Dresden
Germany

Tel : +49 (0)351 4173 154
e-mail : (e-mail address removed)
Cenix Website : http://www.cenix-bioscience.com
 
J

John Howard

Diez B. Roggisch said:
As I said - search google for JAVA APPLETS ACCESSING LOCAL FILES - then you
can do that using jython. As a matter of fact, the whole process has to do
with signing jars - nobody cares if these contain classes generated by
javac, jikes, jythonc or carefully handwritten jvm bytecode....

So does that mean that a jre does not have to be on the local pc? The
local pc does not have to set policies, etc. If that is true, then all
I've said about jython I take back. It is truly useful!
 
A

Alan Kennedy

[John Howard]
So does that mean that a jre does not have to be on the local pc?

No: there *must* be a JRE on the local PC: how could the java/jython run
at all without an execution environment?

The JRE on the local PC is the very thing that is preventing you from
reading files from local drives.

If you want to, you can permit any and all applet to load files from
your local drive. In Internet Explorer, select
"Tools->Options"->Security->Custom Level->Microsoft VM->Java
Permissions->Custom->Java Custom Settings.

In that control panel you can disable all of the protections that your
browser puts in place to protect you from hostile applets on the
Internet at large. Feel free to dismantle those security barriers, at
your own risk: by doing so you're opening the contents of your hard-disk
to the world. I Hope you're not storing any private or sensitive
information on there.
The local pc does not have to set policies, etc.

No, that's precisely where you set policies. Where else could they be set?

Alternatively, as others have pointed out multiple times, you can
digitally sign your applets so that they can be recognized and thus
given more permissions than unknown applets.
 
D

Diez B. Roggisch

As I said - search google for JAVA APPLETS ACCESSING LOCAL FILES - then
So does that mean that a jre does not have to be on the local pc? The
local pc does not have to set policies, etc. If that is true, then all
I've said about jython I take back. It is truly useful!

What exactly makes you conclude this from my above statements? And did you
even _think_ for a moment to follow my and others suggestions to search on
google?
 
J

John Howard

Alan Kennedy said:
[John Howard]
So does that mean that a jre does not have to be on the local pc?

No: there *must* be a JRE on the local PC: how could the java/jython run
at all without an execution environment?

The JRE on the local PC is the very thing that is preventing you from
reading files from local drives.

If you want to, you can permit any and all applet to load files from
your local drive. In Internet Explorer, select
"Tools->Options"->Security->Custom Level->Microsoft VM->Java
Permissions->Custom->Java Custom Settings.

In that control panel you can disable all of the protections that your
browser puts in place to protect you from hostile applets on the
Internet at large. Feel free to dismantle those security barriers, at
your own risk: by doing so you're opening the contents of your hard-disk
to the world. I Hope you're not storing any private or sensitive
information on there.
The local pc does not have to set policies, etc.

No, that's precisely where you set policies. Where else could they be set?

Alternatively, as others have pointed out multiple times, you can
digitally sign your applets so that they can be recognized and thus
given more permissions than unknown applets.

I said jre, but meant jvm. But your answer is revealing also! From
what you are saying, it is NOT possible to have a html page that can
access a local file unless at least a jre is present. Again, not good.
I think I'll just write the whole project in C. Forget jython!
 
J

John Howard

Alan Kennedy said:
[John Howard]
So does that mean that a jre does not have to be on the local pc?

No: there *must* be a JRE on the local PC: how could the java/jython run
at all without an execution environment?

The JRE on the local PC is the very thing that is preventing you from
reading files from local drives.

If you want to, you can permit any and all applet to load files from
your local drive. In Internet Explorer, select
"Tools->Options"->Security->Custom Level->Microsoft VM->Java
Permissions->Custom->Java Custom Settings.

In that control panel you can disable all of the protections that your
browser puts in place to protect you from hostile applets on the
Internet at large. Feel free to dismantle those security barriers, at
your own risk: by doing so you're opening the contents of your hard-disk
to the world. I Hope you're not storing any private or sensitive
information on there.
The local pc does not have to set policies, etc.

No, that's precisely where you set policies. Where else could they be set?

Alternatively, as others have pointed out multiple times, you can
digitally sign your applets so that they can be recognized and thus
given more permissions than unknown applets.

I said jre, but meant jvm. But your answer is revealing also! From
what you are saying, it is NOT possible to have a html page that can
access a local file unless at least a jre is present. Again, not good.
I think I'll just write the whole project in C. Forget jython!


You know, maybe I am making too much of this. I am thinking - if a jre
is there, why not just run the program as a java program?! Just have
the client load the jre and that should do it. Am I not correct?
Having thought the whole C thing over, python is still the way to go.
I apologise for being so nasty. I really did not mean to offend
anyone. You took time to respond and I do appreciate it.

Thanks!!
 
J

Jeremy Jones

John said:
Having thought the whole C thing over, python is still the way to go.
Something I've done a couple of times in the past is to follow Bruce
Eckel's "Browser as Desktop UI" model
(http://mindview.net/WebLog/log-0045). I've created a web-based
application that runs on a "client" or standalone machine. You can
either use the Python built-in SimpleHTTPServer or CGIHTTPServer, or,
preferably, one of the Python web frameworks like CherryPy that creates
a standalone server for you. I can definitely highly recommend
CherryPy. Anyway, a standalone CherryPy server running your application
would likely solve all your problems. You just have to have Python
installed and (currently) only one .py file.

Jeremy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top