473,699 Members | 2,385 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 2408
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
1951
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 ) I'd hate to spend hours debugging this thing, so I thought to ask here if someone has any ideas...
3
2186
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 attempted or succeeded in writing such a function for Jython. Thanks,
6
1516
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
2160
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
1614
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 the code to drive those pages. However, that's usually not the case for me. I'm usually doing both,
1
4655
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
1371
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 of the pages, i.e, the
0
1190
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 replaced with my text/html input. to edit/alter the page i have to extract my personal input out of the...
1
3078
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 Windows? The command in the docs is cheetah compile a, however, I believe that this
0
8685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8613
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9172
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9032
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8880
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4374
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3054
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
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.