Hi Sonny,

just looked at your changes for patching the Jython engine. Before doing
that a question for you: is it intentional that your changes only apply
to the "exec(...)" method and not the others (e.g. "apply(...)")? If so,
what would be the reasoning (unless, of course, I oversee the obvious)?

[Please realize that I have no working knowledge about Jython's inner
workings, so maybe you can shed some light to this?]

Regards,

---rony

------------------- here's the present unified diff of your patch in my
local copy ------------------
--- JythonEngine.java.orig    2006-08-14 14:48:02.547874000 +0200
+++ JythonEngine.java    2006-10-28 13:32:22.128012800 +0200
@@ -16,8 +16,11 @@
 
 package org.apache.bsf.engines.jython;
 
+import java.beans.PropertyChangeEvent;
 import java.io.ByteArrayInputStream;
 import java.util.Vector;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import org.apache.bsf.BSFDeclaredBean;
 import org.apache.bsf.BSFException;
@@ -28,6 +31,7 @@
 import org.python.core.PyException;
 import org.python.core.PyJavaInstance;
 import org.python.core.PyObject;
+import org.python.core.PySystemState;
 import org.python.util.InteractiveInterpreter;
 
 /**
@@ -41,7 +45,8 @@
 
 public class JythonEngine extends BSFEngineImpl {
   BSFPythonInterpreter interp;
- 
+  private final static Pattern fromRegExp = Pattern.compile("from
([.^\\S]*)");
+
   /**
    * call the named method of the given object.
    */
@@ -141,7 +146,13 @@
   public void exec (String source, int lineNo, int columnNo,
             Object script) throws BSFException {
     try {
-      interp.exec (byteify(script.toString ()));
+      String scriptString = script.toString();
+      Matcher matcher = fromRegExp.matcher(scriptString);
+      while (matcher.find()) {
+          String packageName = matcher.group(1);
+          PySystemState.add_package(packageName);
+      }
+      interp.exec (byteify(scriptString));
     } catch (PyException e) {
       throw new BSFException (BSFException.REASON_EXECUTION_ERROR,
                   "exception from Jython:\n" + e, e);
@@ -241,4 +252,15 @@
           }
       }
   }
+
+
+  public void propertyChange(PropertyChangeEvent e) {
+      super.propertyChange(e);
+      String name = e.getPropertyName();
+      Object value = e.getNewValue();
+      if (name.equals("classLoader")) {
+        Py.getSystemState().setClassLoader((ClassLoader) value);
+      }
+
+  }
 }
------------------- here's the present unified diff of your patch in my
local copy (The end.) ------------------







---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to