Hi Sharon,
I’ve spent some time to find out, what’s going wrong when using the german
characters.
Your second suggestion generally works fine for me. But there is something,
that makes
me wonder, whether it is a bug or not:
After a STAX job changes the default encoding from “ascii” to “latin-1” using
import sys
reload(sys)
sys.setdefaultencoding( "latin-1" )
all other jobs started later also show default encoding “latin-1” from start!
I wrote a job that only checks the setting but does not set it:
import sys
print "Jython Encoding: " + sys.getdefaultencoding()
I would have expected, that each job has its own default encoding set to
“ascii” at start.
Maybe even other jobs running at the same time are influenced also? I didn’t
test it yet.
Maybe this behavior also is the reason for the first method working fine
sometimes …
Using the “reload(sys)” trick, I tested to use german characters for block,
testcase and
process names, for <log> to monitor and Job_User_Log. They all work, but print
from
<script> doesn’t. The reason is a little bug in the write method of
STAXPythonOutput.
If a character from the upper half of “latin-1” is written, a negative integer
value is provided
for write (sign-extension!)
The following patch fixes this by ignoring the upper bits of the integer value
(as specified in
Java-API, see
http://download.oracle.com/javase/6/docs/api/java/io/OutputStream.html)
--- services/stax/service/STAXPythonOutput.java 2011-06-28 19:21:02.000000000
+0200
+++ services/stax/service/STAXPythonOutput.java 2011-06-28 18:13:35.000000000
+0200
@@ -100,7 +100,7 @@ public class STAXPythonOutput extends Ou
*/
public void write(int b) throws IOException
{
- fData.append((char)b);
+ fData.append((char)(b & 0xff));
}
/**
BTW: It works fine for Latin-1 only (or probably other 8-bit codes also). But I
could not find a way to
make the full Unicode range work. I tried using U+12ca, but the Unicode string
in Python contains just
a ‘?’ instead.
Best regards
Bodo
From: Sharon Lucas [mailto:luc...@us.ibm.com]
Sent: Monday, June 20, 2011 7:03 PM
To: Strösser, Bodo; Strösser, Bodo
Cc: 'staf-users@lists.sourceforge.net'
Subject: Re: [staf-users] Print Unicode from STAX
STAX V3.5.0 uses Jython 2.5.2 (based on Python 2.5).
Try:
<script>
mystring = unicode('Störung.am.Netz', 'utf-8')
print mystring.encode('utf8')
</script>
<log message="True">mystring.encode('utf8')</log>
or:
<script>
import sys
reload(sys)
sys.setdefaultencoding( "latin-1" )
mystring = u'Störung.am.Netz'
print mystring
</script>
<log message="True">mystring</log>
Let me know if these suggestions worked for you.
See the following link for these suggestions for how to get around Python
UnicodeEncodeErr: 'ascii' codec can't encode character.
http://www.saltycrane.com/blog/2008/11/python-unicodeencodeerror-ascii-codec-cant-encode-character/
--------------------------------------------------------------
Sharon Lucas
IBM Austin, luc...@us.ibm.com
(512) 286-7313 or Tieline 363-7313
From: Strösser, Bodo <bodo.stroes...@ts.fujitsu.com>
To: "'staf-users@lists.sourceforge.net'"
<staf-users@lists.sourceforge.net>
Date: 06/20/2011 09:21 AM
Subject: [staf-users] Print Unicode from STAX
________________________________
Hi,
we are using STAX V3.5.0 Beta 1 and STAF 3.4.5 on a Linux x86_32.
Here is some more info from the server:
# echo $LANG
de_DE.UTF-8
# staf local VAR RESOLVE STRING {STAF/Config/CodePage}
Response
--------
UTF-8
#
The appended STAX-file written in UTF-8 defines a string containing a
German “Umlaut o”. When it tries to write this string to STAXMon or
Job_User_Log using Jython print or <log>, an error is thrown (Msg from the
Job_Log):
20110620-14:44:57 Error STAXPythonEvaluationError signal raised. Terminating
job.
===== XML Information =====
File: /home/STAF/emach/testit.xml, Machine: local://local
Line 6: Error in element type "script".
===== Python Error Information =====
com.ibm.staf.service.stax.STAXPythonEvaluationException:
Traceback (most recent call last):
File "<pyExec string>", line 5, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 4:
ordinal not in range(128)
===== Call Stack for STAX Thread 1 =====
[]
Then I inserted
# -*- coding: utf-8 -*-
as the first line of the first <script>. That results in an error when starting
the script (note: in this message the
“Umlaut o” is displayed correctly on the screen):
Error submitting request, RC: 4001
Additional info
---------------
Job ID : 50
Error Message: Caught com.ibm.staf.service.stax.STAXPythonCompileException:
File: /home/STAF/emach/testit.xml, Machine: local://local
Line 6: Error in element type "script".
Python code compile failed for:
# -*- coding: utf-8 -*-
print "Let's start the test\n"
mystring = u"Störung.am.Netz"
print "1 " + mystring + '\n'
SyntaxError: Illegal character in file '<string>' for encoding 'utf-8'
Is there a way to use UTF-8 in STAX consistently? Am I doing something wrong?
Thanx in advance
Bodo
[attachment "testit.xml" deleted by Sharon Lucas/Austin/IBM]
------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users
------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users