[Twisted-Python] Woven unicode
Hi! I'm working on the final phases of a Open Source software for collaborative text edition in real time (LeoN) (alpha or beta release will be anounced in this list too). The code is develloped using python + twisted (PB and Woven). One of the features is that the actual contents of the text nodes can be seen via web. My problem is that I cannot show accent in woven. I have tryed different things but non seems to work. Please help ! Actually I have a simple data model interface that has a method that return some text def wmfactory_text(self, request): return self.original.get_text() So for test purpose I had changed the method by def wmfactory_text(self, request): return u"eló" What I have to do to get the string looking good on the web browser? I have tryed using a meta tag to indicate iso-8859-1 coding and replaced u"eló" by u"eló".encode("iso-8859-1"); but that does not work too. I have a presentation in two days more and this is the only ugly point. Thanks in advance. RodrigoB.
On Monday, Oct 6, 2003, at 19:29 America/New_York, Rita Díaz y/o Rodrigo Benenson wrote:
def wmfactory_text(self, request): return u"eló"
What I have to do to get the string looking good on the web browser?
I have tryed using a meta tag to indicate iso-8859-1 coding and replaced u"eló" by u"eló".encode("iso-8859-1"); but that does not work too.
u"eló".encode('ascii', 'xmlcharrefreplace') It's not the most elegant solution in the world, but it should work. -bob
On Mon, 06 Oct 2003 19:29:55 -0400 Rita Díaz y/o Rodrigo Benenson <rdrb@123.cl> wrote:
def wmfactory_text(self, request): return u"eló"
(This is not legal Python unless you're using 2.3 and have specifically said your source code is iso-8859-1. It can break on other people's computers if they have other default encodings than yours. \u escapes will always work, of course. Not related to your problem though.) Make sure you specify the encoding in your HTML document! I'm pretty sure that microdom (and thus woven) are semi-hardcoded to UTF8, so try saying that in your html page, and just returning unicode. -- Itamar Shtull-Trauring http://itamarst.org/ Available for Python & Twisted consulting
On Mon, 2003-10-06 at 20:07, Itamar Shtull-Trauring wrote:
On Mon, 06 Oct 2003 19:29:55 -0400 Rita Díaz y/o Rodrigo Benenson <rdrb@123.cl> wrote:
def wmfactory_text(self, request): return u"eló"
(This is not legal Python unless you're using 2.3 and have specifically said your source code is iso-8859-1. It can break on other people's computers if they have other default encodings than yours. \u escapes will always work, of course. Not related to your problem though.)
Make sure you specify the encoding in your HTML document! I'm pretty sure that microdom (and thus woven) are semi-hardcoded to UTF8, so try saying that in your html page, and just returning unicode.
Part of the problem is that the XML declaration that Woven (possibly Microdom?) spits out does not include the encoding.
On Oct 6, 2003, at 7:29 PM, Rita Díaz y/o Rodrigo Benenson wrote:
I have tryed using a meta tag to indicate iso-8859-1 coding and replaced u"eló" by u"eló".encode("iso-8859-1"); but that does not work too.
I just happen to be working on this at the moment so you may be in luck. The technique that worked for me was to encode the unicode string as utf8: u"eló".encode("utf8") Then override render in your Page subclass, so you can set the Content-type header: class MyPage(page.Page): def render(self, request): request.setHeader("Content-type", "text/html; charset=utf8") return page.Page.render(self, request) It worked for me, anyway. Hope it works for you! dp
I sometimes encounter the problem that when a connection (producer) has been lost, the consumer still try to call resumeProducing() to the producer, so that a non-valid fileno is added to the select loop, and generate endless error messages. I'm almost sure that this is b/c I didn't do unregisterProducer() at the correct time. Even though, I feel like endless error messages are not very pleasant. Could anyone help to fix this? My temp solution is that I modified the abstract.py and tcp.py to set a flag indicate whether the fileno is deleted or not, and won't let resumeProducing to add a invalid reader into the reactor. Any better suggestions? To play with this bug, you may want to modify socks.py, add these into SOCKSv4Outgoing.connectionMade() self.socks.transport.registerProducer(self.transport, 0) self.transport.registerProducer(self.socks.transport, 0) Yun
participants (6)
-
Alexander Winston
-
Bob Ippolito
-
Donovan Preston
-
Itamar Shtull-Trauring
-
Rita Díaz y/o Rodrigo Benenson
-
Yun Mao