473,408 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Jython 2.1 and Cheetah:Cyrillic templates output mixed encoding

I am using cheetah with jython 2.1 and I have problem generating templates
that contain cyrillic text. Some texts are printed OK and others are not.

I searched Jython and cheetah projects mailing lists on sourceforge.net as
well as these groups and tried some other fixes proposed but without success.

I call the template like this:

PythonInterpreter pyiInterp = new PythonInterpreter();
pyiInterp.set("textTool", TextToolkit.getInstance());
String _body = readFile(strTemplateFile.replace('\\', '/'));

//----Encoding:
PyString _pyBody = new PyString(_body);
//----

pyiInterp.set("templBody", _pyBody);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
PrintWriter pwOut = new PrintWriter(bos);
pyiInterp.setOut(pwOut);
pyiInterp.exec("from Cheetah.Template import Template");
pyiInterp.exec("t = Template(source=templBody)");
pyiInterp.exec("t.textTool = textTool");
pyiInterp.exec("print t");

I tried replacing the section marked as //---Encoding:
String isoScript = _body;
try {
//The call to sun.io.Converters.getDefaultEncodingName() returns "Cp1251"
byte[] bytes = _body.getBytes(sun.io.Converters.getDefaultEncodin gName());
isoScript = new String(bytes, "ISO-8859-1");
}
catch (Exception ex) {
System.out.println("CONVERSION ERROR:" + ex);
}
PyString _pyBody = new PyString(isoScript);
This resulted in the problem inverted - the 'good' text became 'bad' and vice versa.

Here are sample lines one of which prints good text and the second - not
good(depending on its position in the template) /I guess text will be garbled
here/ :

${textTool.filler(35, " ")}????????? ????
${textTool.filler(35, " ")}???????????? ?? ??????????

textTool is a java object and this call produces 35 spaces

The encoding of the lines is the same(I checked the int values for the
letters).
I tried:

import sys
sys.setdefaultencoding('cp1251')

It didn't help but it caused compilation of the encodings\cp1251.py module ->
cp1251$py.class so I guess it was taken into account

Please guide me to papers that can help solving this or propose ideas what
might be causing this behaviour.

Thanks for your cooperation
Mike
Jul 18 '05 #1
1 2384
mi****@abv.bg (Mike Grigorov) wrote in message news:<9d**************************@posting.google. com>...
I am using cheetah with jython 2.1 and I have problem generating templates
that contain cyrillic text. Some texts are printed OK and others are not.


The fact is that cheetah had nothing to do with the problem. I studied Jython
code and changed PyString and PyFile classes in the org.python.core package. I
changed all calls to deprecated methods of java.lang.String with their
recommended replacements and the problem seems to be solved. I also changed
references to StringBufferInputStream with ByteArrayInputStream in the "Py" and
"parser" classes of the same package but haven't studied if this helped to solve
the problem.
Thanks for your time
Mike
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Timo Virkkala | last post by:
I tried to install Cheetah (0.9.15) and ran into trouble. When running the test suite, I get 61 failures and 57 errors. Most of the errors are "ImportError: No module named temp", with some...
3
by: Dave Benjamin | last post by:
There have been several discussions here about how to write a reload() function that works for classes as well as modules: ...
6
by: Ajay | last post by:
hi! i am looking for a framework to create a fast dynamic website. between using Cheetah and HTMLTemplate which would you recommend? also quixote offers a session management API? how secure is...
6
by: py | last post by:
I want to serialize an object in jython and then be able to read it in using python, and vice versa. Any suggestions on how to do this? pickle doesnt work, nor does using ObjectOutputStream...
14
by: projecktzero | last post by:
For some of the web programming I've done in Python, I've used htmltmpl. I had some experience with it in Perl, and found a Python version. http://htmltmpl.sourceforge.net/ I like that...
1
by: ivansh | last post by:
Hello, For one java class (Hello) i use another (HelloPrinter) to build the string representation of the first one. When i've tried to use this from within jython, HelloPrinter.toString(hello)...
2
by: Sai Krishna M | last post by:
Hi, I have been working for some time developing web pages using python, modpython, cheetah. I find that this method has come inherent difficulties in it like if we want to generate a single...
0
by: manuel.reil | last post by:
Hello, currently i am developing a very small cms using python and cheetah. very early i have noticed that i was lacking the method to extract/recover the contents (html,text) from the html that...
1
by: brianrpsgt1 | last post by:
Newbie here.... I have been able to successful pull info from a MySQL DB, get the results and output them in an HTML format using Cheetah to the screen using IDLE. I am doing this on a Windows...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.