|
From: Jeff A. <ja...@fa...> - 2018-04-06 22:31:10
|
Hello Hartmut.
The fact that jython.exe (and hence org.python.util.jython) works for
you, and not your application, suggests the problem may be in setting up
the encoding of stdin/out/err for the interpreter.
Jython struggles to guess the correct encoding for the console. The
interpreter will look in system properties (at python.io.encoding).
Values may come from the java command, registry file or environment
variables. If it has nothing to go on, it may result in a default ASCII
encoding or desperate use of the Java file.encoding.You can check what
it concluded by asking from within the interpreter about
sys.stderr.encoding, etc..
The launcher also sets the property python.launcher.tty=true, although
this mostly affects whether you get an interactive console prompt. It
may also be worth ensuring a plain console is in use (python.console="")
if you are not using it interactively, and perhaps
python.console.encoding will matter too. (I forget the order of
precedence with python.io.encoding.)
We've done significant work since 2.7.0 on encoding, including
resistance to coding errors in error messages (that may result from
coding errors ... ). When it comes, 2.7.2 would be worth trying anywhere
ASCII is not enough.
Jeff Allen
On 06/04/2018 10:36, Niemann, Hartmut wrote:
> Hello!
>
> I am using Jython 2.7.0 embedded into a java application, that is: not the jython.exe, on windows.
>
> When an exception parameter or a line in the stack trace contains an Umlaut, there seems to be an exception in the exception handler itself,
> because all I get (if one of the source lines has umlauts) is
>
> Exception in thread "main"
> Exception: org.python.core.PyException thrown from the UncaughtExceptionHandler in thread "main"
>
> If the string representation of the exception itself contains an umlaut, stack trace and type of the exception are printed, but the argument is missing.
>
> (If run from jython.exe, the output is completely readable, although some garbage characters are printed instead of the umlauts, which is (sort of) to be expected.)
>
> if I catch the exception like
> except Exception as e:
> print ('Uncaught exception in main: %s' % e)
> print (sys.exc_info())
> import traceback
> traceback.print_tb(sys.exc_info()[2])
> i get reasonable output.
>
> ---- the snippet from the embedding java function is:
> //start python
> PythonInterpreter.initialize(null, null, argv.toArray(new String[0]));
>
> PythonInterpreter py;
> py = new PythonInterpreter();
>
> //exec
> py.exec("import cpsgen_py");
>
> PyObject ret;
> ret = py.eval("cpsgen_py.main()");
>
> if (ret instanceof PyInteger) {
> return ((PyInteger) ret).getValue();
> }
> --- a simple examle to try is
> s = 'Hallöle'
> assert False, s # ä
>
> What do I see here? Am I doing something wrong when setting up the interpreter?
>
>
> Mit freundlichen Grüßen
> Dr. Hartmut Niemann
>
> Siemens AG
> Mobility Division
> Rolling Stock
> Standardization, Remote Control, Display
> MO RS LM EN CCI SRD
> Werner-von-Siemens-Str. 67
> 91052 Erlangen, Deutschland
> Mobil: +49 173 5342327
> mailto:har...@si...
>
> www.siemens.com/ingenuityforlife
>
> Siemens Aktiengesellschaft: Vorsitzender des Aufsichtsrats: Jim Hagemann Snabe; Vorstand: Joe Kaeser, Vorsitzender; Roland Busch, Lisa Davis, Klaus Helmrich, Janina Kugel, Cedrik Neike, Michael Sen, Ralf P. Thomas; Sitz der Gesellschaft: Berlin und München, Deutschland; Registergericht: Berlin Charlottenburg, HRB 12300, München, HRB 6684; WEEE-Reg.-Nr. DE 23691322
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Jython-users mailing list
> Jyt...@li...
> https://lists.sourceforge.net/lists/listinfo/jython-users
>
|