Calling execfile() with xxx$py.class file

View: New views
3 Messages — Rating Filter:   Alert me  

Calling execfile() with xxx$py.class file

by Joey Jarosz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

I have Jython embedded in my application. I have some users who want to not pass the raw text of a python script around to some other users, but rather would prefer to only give them the $py.class file generated by Jython when a py file is loaded. Essentially they want an execfile() equivalent that can accept a $py.class file instead of a .py file.

 

The way I have things setup I have an opportunity to implement such functionality either in python or in my java code, so I was wondering the best way to go about make this happen. It seems like I just need access to the methods that load the .class file and convert them to PyCode so I can then pass that onto Py.runCode() or something – any pointers to the best way to start attacking this problem?

 

Sometimes these scripts are just that, simple scripts – not class or function definitions.

 

--------------------------------------------
Joey Jarosz

Senior Architect

Chip Planning Solutions

Cadence Design Systems, Inc.
(408) 914-6269


Need some IP? Check out www.chipestimate.com  

 


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Jython-users mailing list
Jython-users@...
https://lists.sourceforge.net/lists/listinfo/jython-users

Re: Calling execfile() with xxx$py.class file

by Charlie Groves :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Aug 28, 2009 at 2:50 PM, Joey Jarosz<joey@...> wrote:
> I have Jython embedded in my application. I have some users who want to not
> pass the raw text of a python script around to some other users, but rather
> would prefer to only give them the $py.class file generated by Jython when a
> py file is loaded. Essentially they want an execfile() equivalent that can
> accept a $py.class file instead of a .py file.

I believe if you have the class object, you can call
org.python.core.CodeLoader.loadCode to turn the class into a PyCode
object.  Once you have that PyCode, you can call
org.python.core.Py.runCode to run it.  Is that what you're after?

Charlie

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Jython-users mailing list
Jython-users@...
https://lists.sourceforge.net/lists/listinfo/jython-users

Parent Message unknown Re: Calling execfile() with xxx$py.class file

by Joey Jarosz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Thanks, been away myself… will give this a try when I get back into the office…

 


From: Mark Melvin [mailto:Mark.Melvin@...]
Sent: Tuesday, September 01, 2009 8:41 AM
To: Joey Jarosz; Jython Users
Subject: RE: [Jython-users] Calling execfile() with xxx$py.class file

 

Hi Joey,

 

Sorry for the delay – I have been away.  If it isn’t too late, I have done this in the past:

 

from org.python.core import BytecodeLoader

code = BytecodeLoader.makeCode('xxx$py', '\xCA\xFE\xBA\xBE\x00\x03\x00…..lots of bytecode….x00\x00\t')

exec code

 

If you read your .class file into a raw string, that will work.  There are probably other methods that you can use.  Have a look at org.python.core.BytecodeLoader.

 

HTH,

Mark.

 


From: Joey Jarosz [mailto:joey@...]
Sent: Friday, August 28, 2009 5:50 PM
To: Jython Users
Subject: [Jython-users] Calling execfile() with xxx$py.class file

 

I have Jython embedded in my application. I have some users who want to not pass the raw text of a python script around to some other users, but rather would prefer to only give them the $py.class file generated by Jython when a py file is loaded. Essentially they want an execfile() equivalent that can accept a $py.class file instead of a .py file.

 

The way I have things setup I have an opportunity to implement such functionality either in python or in my java code, so I was wondering the best way to go about make this happen. It seems like I just need access to the methods that load the .class file and convert them to PyCode so I can then pass that onto Py.runCode() or something – any pointers to the best way to start attacking this problem?

 

Sometimes these scripts are just that, simple scripts – not class or function definitions.

 

--------------------------------------------
Joey Jarosz

Senior Architect

Chip Planning Solutions

Cadence Design Systems, Inc.
(408) 914-6269


Need some IP? Check out www.chipestimate.com  

 


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Jython-users mailing list
Jython-users@...
https://lists.sourceforge.net/lists/listinfo/jython-users