From: <cg...@us...> - 2009-06-29 06:13:31
|
Revision: 6502 http://jython.svn.sourceforge.net/jython/?rev=6502&view=rev Author: cgroves Date: 2009-06-29 06:13:29 +0000 (Mon, 29 Jun 2009) Log Message: ----------- Add the root dir and WEB-INF/jython to sys.path for PyFilters as well as PyServlets Modified Paths: -------------- trunk/jython/src/org/python/util/PyFilter.java trunk/jython/src/org/python/util/PyServlet.java Modified: trunk/jython/src/org/python/util/PyFilter.java =================================================================== --- trunk/jython/src/org/python/util/PyFilter.java 2009-06-29 05:42:24 UTC (rev 6501) +++ trunk/jython/src/org/python/util/PyFilter.java 2009-06-29 06:13:29 UTC (rev 6502) @@ -11,7 +11,6 @@ import javax.servlet.ServletResponse; import org.python.core.PyException; -import org.python.core.PySystemState; import org.python.util.PythonInterpreter; /** @@ -96,7 +95,7 @@ if (!source.exists()) { throw new ServletException(source.getAbsolutePath() + " does not exist."); } - interp = new PythonInterpreter(null, new PySystemState()); + interp = PyServlet.createInterpreter(config.getServletContext()); } private String getRealPath(ServletContext context, String appPath) { Modified: trunk/jython/src/org/python/util/PyServlet.java =================================================================== --- trunk/jython/src/org/python/util/PyServlet.java 2009-06-29 05:42:24 UTC (rev 6501) +++ trunk/jython/src/org/python/util/PyServlet.java 2009-06-29 06:13:29 UTC (rev 6502) @@ -19,6 +19,7 @@ import org.python.core.PyException; import org.python.core.PyObject; import org.python.core.PyString; +import org.python.core.PyStringMap; import org.python.core.PySystemState; /** @@ -117,6 +118,17 @@ PySystemState.add_extdir(rootPath + "WEB-INF" + File.separator + "lib", true); } + protected static PythonInterpreter createInterpreter(ServletContext servletContext) { + String rootPath = getRootPath(servletContext); + PySystemState sys = new PySystemState(); + PythonInterpreter interp = new PythonInterpreter(new PyStringMap(), sys); + sys.path.append(new PyString(rootPath)); + + String modulesDir = rootPath + "WEB-INF" + File.separator + "jython"; + sys.path.append(new PyString(modulesDir)); + return interp; + } + protected static String getRootPath(ServletContext context) { String rootPath = context.getRealPath("/"); if (!rootPath.endsWith(File.separator)) { @@ -154,15 +166,8 @@ * requests. */ public void reset() { - String rootPath = getRootPath(getServletContext()); destroyCache(); - interp = new PythonInterpreter(null, new PySystemState()); - - PySystemState sys = Py.getSystemState(); - sys.path.append(new PyString(rootPath)); - - String modulesDir = rootPath + "WEB-INF" + File.separator + "jython"; - sys.path.append(new PyString(modulesDir)); + interp = createInterpreter(getServletContext()); } private synchronized HttpServlet getServlet(String path) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |