On Sat, Mar 24, 2012 at 6:32 PM, Phil Charlesworth <[email protected]> wrote: > On 24/03/12 13:25, lkcl luke wrote: >> On Sat, Mar 24, 2012 at 12:39 PM, Phil Charlesworth >> <[email protected]> wrote: >> >>> On 23/03/12 17:14, lkcl luke wrote: >>> >>>> On Fri, Mar 23, 2012 at 4:32 PM, Phil Charlesworth >>>> <[email protected]> wrote: >>>> >>>> >>>>> On 23/03/12 10:03, Peter Bittner wrote: >>>>> >>>>> >>>>>> Phil, >>>>>> >>>>>> thanks for the testing. >>>>>> >>>>>> What I have noticed is that the logging module works with Pyjamas >>>>>> Desktop, unfortunately it doesn't work quite that well with pyjs. I >>>>>> hope I'll have some time in the evenings this weekend to look into >>>>>> this more closely. >>>>>> >>>>>> 2012/3/22 Phil Charlesworth<[email protected]>: >>>>>> >>>>>> >>>>>> >>>>>>> I've done a bit of very rudimentary testing of the various handlers >>>>>>> under pyjd on Windows >>>>>>> (just AlertLogger, AppendLogger and PrintLogger and everything seemed to >>>>>>> work. Just one comment. AlertLogger and PrintLogger (and, no doubt, >>>>>>> ConsoleLogger all work with text but AppendLogger is treating the >>>>>>> message as HTML. So, if the record is something like >>>>>>> <Sink.SinkInfo instance at 0x04C5CD28> it doesn't come out. Maybe >>>>>>> AppendHandler needs to call an escape function to turn things that are >>>>>>> special characters to HTML into their equivalent HTML entities. >>>>>>> >>>>>>> >>>>>>> >>>>>> That's strange: The message itself is not modified much, just that >>>>>> line feeds are replaced by br tags: >>>>>> >>>>>> (pyjamas/library/pyjamas/logging/handlers.py, class AppendHandler) >>>>>> def emit(self, record): >>>>>> msg = self.format(record) >>>>>> msg = msg.replace("\n", "<br/>\n") + "<br/>\n" >>>>>> self.output += msg >>>>>> self.__addLogElement() >>>>>> DOM.setInnerHTML(self.div, self.output) >>>>>> >>>>>> Peter >>>>>> >>>>>> >>>>> Peter, >>>>> Just to clarify what I said about AppendHandler, the whole >>>>> message is rendered as HTML, so if you have, say,<Sink.SinkInfo >>>>> instance at 0x04C5CD28>, it looks like an HTML tag but the renderer >>>>> can't make sense of it so it leaves it out. I have made my version work >>>>> by adding the two lines >>>>> msg = msg.replace("<","<") >>>>> msg = msg.replace(">",">") >>>>> >>>>> >>>> err.... those are i believe in cgi.escape, already. or something like >>>> it. >>>> >>>> >>>> >>>>> before the line where you replace "\n" by "<br/>\n". >>>>> However, all those replace calls and any other ones deemed necessary, or >>>>> desirable, could be put into one escape routine, so that you had: >>>>> msg = format(record) >>>>> self.output += escape(msg) >>>>> >>>>> Another way would be to have a dictionary with keys being characters to >>>>> be replaced and values being the replacement character. Then something >>>>> like: >>>>> def escape(text): >>>>> return "".join(escape_dict.get(c,c) for c in text) >>>>> will work in cPython. (not sure if it works in pyjs - would have to check) >>>>> >>>>> >>>> should do. if not, that's a bug in pyjs, and the above code-snippet >>>> should go into libtest. >>>> >>>> l. >>>> >>> L, >>> Yes, cgi.escape(s, quote = None) replaces& with&,< with<, >>> > with> and, optionally, " with". >>> Also there is xml.saxutils.escape(data, entities = {}), which does >>> exactly the same for&,< and> but will also replace any keys in >>> entities with their values. >>> >>> Presumably something like one of these functions should be added to some >>> existing pyjamas module but which one? DOM? >>> >> no, they're already there, in pyjs/src/pyjs/lib. if they're not >> there, they should be added. >> >> l. >> Ah, yes, in cgi.py, so that's the one to use. I don't see a libtest for it. >> I'll do a simple one. P
you should be able to rip the one from python, it's usually installed in the test subdirectory

