I have a java application that allow a user to enter jython codes which reports to my application.
sample jython code:
def reportError(node, context):
context.report('<message>' ) .
The message is currently in the Japanese local default encoding window-31j
My JythonCode.java  thats executes the jython code.
// initializing the interpreter  inside getFunction( )
PyString pString = new PyString( "<sample jython code above>");
PythonInterpreter interpreter  new PythonInterpreter();
interpreter.exec( pString );
// invoke method 
PyFunction function = getFunction((JythonMethodIdentifier) id,
                                          (PythonInterpreter) interpreter);
PyObject ret = function._jcall( args );
The problems is when it reports to my application, i get garbage characters.  
at java.lang.Thread.dumpStack(Unknown Source)
 at my.reporting.RuleContext.report(RuleContext.java:136)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at java.lang.reflect.Method.invoke(Unknown Source)
 at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java)
 at org.python.core.PyMethod.__call__(PyMethod.java)
 at org.python.core.PyObject.__call__(PyObject.java)
 ###  at this point below my PyString has garabage characters ###
 at org.python.core.PyInstance.invoke(PyInstance.java)   

 at org.python.pycode._pyx16.reportError$1(<string>:4)
 at org.python.pycode._pyx16.call_function(<string>)
 at org.python.core.PyTableCode.call(PyTableCode.java)
 at org.python.core.PyTableCode.call(PyTableCode.java)
 at org.python.core.PyFunction.__call__(PyFunction.java)
 at org.python.core.PyObject.__call__(PyObject.java)
 at org.python.core.PyObject._jcallexc(PyObject.java)
 at org.python.core.PyObject._jcall(PyObject.java)
### at this point the charcters in PyString is fine ####
 at my.scripting.jython.JythonCode.invoke(JythonCode.java:252)
I have also tried   codecs.PyUnicode_EncodeUTF8("<sample jython code>", null)
       this returns unknown  ???????? characters
I have tried to use pString.encode("utf-8") before interpreter.exec(pString).
       I get : LookupError: no codec search functions registered: can't find encoding
my jython.jar consist of  org.ziclix.python.*, org.apache.oro.text.regex , org.python.*,  jxxload_help.
I am probably missing the encoding/ package. Some how i should call __init__.py.
I am not sure to go about this encoding issue. I have tried searching online but no luck. Any help would be appreciated. Thank you.


Do you Yahoo!?
vote.yahoo.com - Register online to vote today!