473,569 Members | 2,731 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Jython 2.1 and Cheetah:Cyrilli c 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:

PythonInterpret er pyiInterp = new PythonInterpret er();
pyiInterp.set(" textTool", TextToolkit.get Instance());
String _body = readFile(strTem plateFile.repla ce('\\', '/'));

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

pyiInterp.set(" templBody", _pyBody);
ByteArrayOutput Stream bos = new ByteArrayOutput Stream();
PrintWriter pwOut = new PrintWriter(bos );
pyiInterp.setOu t(pwOut);
pyiInterp.exec( "from Cheetah.Templat e 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.Converte rs.getDefaultEn codingName() returns "Cp1251"
byte[] bytes = _body.getBytes( sun.io.Converte rs.getDefaultEn codingName());
isoScript = new String(bytes, "ISO-8859-1");
}
catch (Exception ex) {
System.out.prin tln("CONVERSION ERROR:" + ex);
}
PyString _pyBody = new PyString(isoScr ipt);
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.fill er(35, " ")}???????? ? ????
${textTool.fill er(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.setdefaulte ncoding('cp1251 ')

It didn't help but it caused compilation of the encodings\cp125 1.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 2397
mi****@abv.bg (Mike Grigorov) wrote in message news:<9d******* *************** ****@posting.go ogle.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.Strin g with their
recommended replacements and the problem seems to be solved. I also changed
references to StringBufferInp utStream with ByteArrayInputS tream 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
1949
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 "TypeError: update() takes exactly one argument (0 given)". The full output of the test suite is at (URL: http://www.cs.helsinki.fi/u/tjvirkka/out.txt )...
3
2181
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: http://groups.google.com/groups?sourceid=mozclient&ie=utf-8&oe=utf-8&q=super_reload I have been trying to come up with a solution that works for Jython, and so far nothing has worked. I was wondering if anyone has...
6
1513
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 this session management? is it just a cookie on the client side? thanks cheers
6
2156
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 (from jython). I prefer to do it file based ...something like pickle.dump(someObj, open("output.txt", "w"))
14
1602
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 there's nearly a complete separation between the presentation and the code. This is great when one person is designing the pages and another is writing...
1
4649
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) call gives results like Object.toString() of hello has being called. The example below shows this behaviour. Could somebody explain this?
2
1366
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 page we have to write two separate files ( py & tmpl). Is there any other better way of doing things.? Also if we want to have partial processing...
0
1188
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 is generated by cheetah and delivered to the site viewer. to explain it further: during the output processing by cheetah placeholders are...
1
3069
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 Laptop, running WinXP, Python 2.5 and the latest version of Cheetah. I have two questions: 1. How and where do you compile Cheetah templates in...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7673
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7970
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5513
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.