This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Jython/Python and the fly likes Hooking function calls in Python code with Jython library Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Languages » Jython/Python
Bookmark "Hooking function calls in Python code with Jython library" Watch "Hooking function calls in Python code with Jython library" New topic
Author

Hooking function calls in Python code with Jython library

Andreas Pax Lück
Greenhorn

Joined: Nov 04, 2009
Posts: 18
Hi friends.

I'm using the Jython library in my Java project in order to provide Python code execution.

I'd like to restrict access to specific Java classes/packages as well as invocations of Jython's built-in functions.

I implemented an own class loader and set it in Jyhton interpreter:



But the Jython library also provides Python's built-in functions that aren't implemented as Java code, so I cannot catch them with the custom class loader. Here's a list with those supported functions: Built-in functions

How can I detect disallowed function invocations (for example: open(filename[, mode[, bufsize]])) in Pyhton user code? Is there any special hooking mechanism that can be used during code parsing or execution?

I reversed some Jython classes and searched for any possibility but its intrinsic processes aren't very easy to understand.

Cheers

PAX


"Wenn man irgendwann mal von allen akzeptiert wird, dann weiß man, dass man irgendwas falsch gemacht hat."
Excerpt by: Mr. Weidner
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hooking function calls in Python code with Jython library
 
Similar Threads
Jython with JDK1.5
Creating subclass of abstract class at runtime
possibility of dynamic java code transfer?
Some Groovy vs Python observations.
What is the difference between 'deep' and 'shallow' binding?