From: Finn B. <bc...@us...> - 2001-02-07 09:27:26
|
Update of /cvsroot/jython/jython/org/python/util In directory usw-pr-cvs1:/tmp/cvs-serv21597 Modified Files: PyServlet.java Log Message: - Set a deafult python.home unless specified as properties. - Set a fake __file__ attribute before running any python code. - Add the servlet root path to sys.path. Index: PyServlet.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/util/PyServlet.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** PyServlet.java 2001/02/03 19:31:08 1.1 --- PyServlet.java 2001/02/07 09:27:43 1.2 *************** *** 27,31 **** * e.g. http://localhost:8080/test/hello.py * ! * class test(HttpServlet): * def doGet(self,req, res): * res.setContentType("text/html"); --- 27,31 ---- * e.g. http://localhost:8080/test/hello.py * ! * class hello(HttpServlet): * def doGet(self,req, res): * res.setContentType("text/html"); *************** *** 65,68 **** --- 65,70 ---- public void init() { + String rootPath = getServletContext().getRealPath("/"); + Properties props = new Properties(); Enumeration e = getInitParameterNames(); *************** *** 70,75 **** String name = (String) e.nextElement(); props.setProperty(name, getInitParameter(name)); } - PythonInterpreter.initialize(System.getProperties(), props, new String[0]); interp = new PythonInterpreter(); --- 72,82 ---- String name = (String) e.nextElement(); props.setProperty(name, getInitParameter(name)); + } + if (props.getProperty("python.home") == null && + System.getProperty("python.home") == null) { + props.setProperty("python.home", rootPath + File.separator + + "WEB-INF" + File.separator + + "lib"); } PythonInterpreter.initialize(System.getProperties(), props, new String[0]); interp = new PythonInterpreter(); *************** *** 80,83 **** --- 87,92 ---- sys.add_package("javax.servlet.jsp"); sys.add_package("javax.servlet.jsp.tagext"); + + sys.path.append(new PyString(rootPath)); } *************** *** 87,90 **** --- 96,102 ---- String spath = ((HttpServletRequest) req).getServletPath(); String rpath = getServletContext().getRealPath(spath); + + interp.set("__file__", rpath); + HttpServlet servlet = getServlet(rpath); if (servlet != null) |