Message6402

Author anamitrab
Recipients anamitrab
Date 2011-02-22.21:00:02
SpamBayes Score 1.11022e-16
Marked as misclassified No
Message-id <1298408403.44.0.290312568539.issue1709@psf.upfronthosting.co.za>
In-reply-to
Content
The test case is simple and is shown below using a java test class

package com.ibm.tivoli.maximo.script;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;

import javax.script.*;

import org.python.util.PythonInterpreter;

import java.io.*;

public class TestJythonDateModule {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception
	{
		if(args.length>=1 && args[0].equals("usejsr"))
		{
			ScriptEngineManager factory = new ScriptEngineManager();
			ScriptEngine engine = factory.getEngineByName("jython");
			BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("c:\\harrier75\\datetimetest.py")));
			//engine.eval(reader);;
			CompiledScript cs = ((Compilable)engine).compile(reader);
			cs.eval();
		}
		else
		{
			 PythonInterpreter jython = new PythonInterpreter();
			 InputStream scriptStream = new FileInputStream("c:\\harrier75\\datetimetest.py");
	
			 try {
				 jython.execfile(scriptStream);
			 }
			 catch (Exception e) {
				 e.printStackTrace();
			 }
		}

	}

}

The datetimetest.py script is as below


import datetime

today = datetime.date.today()
print today
print 'ctime:', today.ctime()
print 'tuple:', today.timetuple()
print 'ordinal:', today.toordinal()
print 'Year:', today.year
print 'Mon :', today.month
print 'Day :', today.day

When we run the above test java class using the usejsr option - it gives an error as below. the non jsr 223 approach works perfect. This implies the jsr223 approach is broken and does not work for datetime module.

usejsr option
--------------
C:\harrier75\applications\maximo\businessobjects\classes>C:\harrier75\tools\java
\jre\bin\java -classpath .;C:\harrier75\jython\jython.jar;C:\harrier75\jython\Li
b com.ibm.tivoli.maximo.script.TestJythonDateModule usejsr
2011-02-20
ctime:Exception in thread "main" javax.script.ScriptException: AttributeError: '
java.sql.Date' object has no attribute 'ctime' in <script> at line number 5
        at org.python.jsr223.PyScriptEngine.scriptException(PyScriptEngine.java:
191)
        at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:42)
        at org.python.jsr223.PyScriptEngine.access$300(PyScriptEngine.java:20)
        at org.python.jsr223.PyScriptEngine$PyCompiledScript.eval(PyScriptEngine
.java:220)
        at javax.script.CompiledScript.eval(CompiledScript.java:101)
        at com.ibm.tivoli.maximo.script.TestJythonDateModule.main(TestJythonDate
Module.java:27)
Caused by:
Traceback (most recent call last):
  File "<script>", line 5, in <module>
AttributeError: 'java.sql.Date' object has no attribute 'ctime'

        at org.python.core.PyException.fillInStackTrace(PyException.java:70)
        at java.lang.Throwable.<init>(Throwable.java:56)
        at org.python.core.PyException.<init>(PyException.java:46)
        at org.python.core.PyException.<init>(PyException.java:43)
        at org.python.core.PyException.<init>(PyException.java:61)
        at org.python.core.Py.AttributeError(Py.java:166)
        at org.python.core.PyObject.noAttributeError(PyObject.java:930)
        at org.python.core.PyObject.object___getattribute__(PyObject.java:3692)
        at org.python.core.PyObject$object___getattribute___exposer.__call__(Unk
nown Source)
        at org.python.core.Deriveds.__findattr_ex__(Deriveds.java:59)
        at org.python.core.PyObjectDerived.__findattr_ex__(PyObjectDerived.java:
983)
        at org.python.core.PyObject.__getattr__(PyObject.java:923)
        at org.python.pycode._pyx0.f$0(<script>:10)
        at org.python.pycode._pyx0.call_function(<script>)
        at org.python.core.PyTableCode.call(PyTableCode.java:165)
        at org.python.core.PyCode.call(PyCode.java:18)
        at org.python.core.Py.runCode(Py.java:1261)
        at org.python.core.__builtin__.eval(__builtin__.java:484)
        at org.python.core.__builtin__.eval(__builtin__.java:488)
        at org.python.util.PythonInterpreter.eval(PythonInterpreter.java:198)
        at org.python.jsr223.PyScriptEngine.eval(PyScriptEngine.java:40)
        ... 4 more

The same thing if I run without the usejsr option I get this output


C:\harrier75\applications\maximo\businessobjects\classes>C:\harrier75\tools\java
\jre\bin\java -classpath .;C:\harrier75\jython\jython.jar;C:\harrier75\jython\Li
b com.ibm.tivoli.maximo.script.TestJythonDateModule
2011-02-20
ctime: Sun Feb 20 00:00:00 2011
tuple: (2011, 2, 20, 0, 0, 0, 6, 51, -1)
ordinal: 734188
Year: 2011
Mon : 2
Day : 20

C:\harrier75\applications\maximo\businessobjects\classes>
History
Date User Action Args
2011-02-22 21:00:03anamitrabsetmessageid: <1298408403.44.0.290312568539.issue1709@psf.upfronthosting.co.za>
2011-02-22 21:00:03anamitrabsetrecipients: + anamitrab
2011-02-22 21:00:03anamitrablinkissue1709 messages
2011-02-22 21:00:02anamitrabcreate