monkey patch html_quote (was: RE: [Zope] html_quote, quoting acce nts)
Tue, 6 May 2003 10:59:49 -0400

Ah, I was almost there, I traced it to DocumentTemplate, but didn't =
the seperate file ...

OK, now that all this makes sense ... I'm trying to overload/monkey =
the html_quote with some of my own code that quotes ALL html entities, =
just the cgi.escape() ones (& < >) ...

BUT, it's not working.  I noticed the the way DT_Var implements this in =
I'm not too sure I understand (coding beyond my current level of =
Something to do with modifiers, lambda, and mappings.

I'm guessing that the monkey patching isn't working because it's "too =
in the process, and the function has been "copied" or something like =

Anyways, could anyone point me in the right direction on how to do =
I've monkey patched other things before successfully, but this one =
cooperating :(

Any help would be greatly appreciated!

P.S. : Code is below, not optimized, just for testing.


The code in my product's

# Monkey patch that makes the html_quote actually quote ALL entities, =
just "&" "<" and ">", but NOT the octal coded ones, which would =
allready be
def my_html_quote(string, name=3D'(Unknown name)', md=3D{}):
        string =3D ustr(string)=20
        myentities =3D {}
        for (key, value) in entitydefs.items():=20
                if ( len(value) =3D=3D 1 ):
                        myentities[value] =3D key
        del myentities['&']=20
        # First do the ampersands
        if ( find(string,'&') > 0 ):=20
                string =3D replace(string,'&','&amp;')
        # Then everything else=20
        for char in myentities.keys():=20
                if ( char in string ):=20
                        string =3D
        return string=20
html_quote.html_quote =3D my_html_quote

-----Original Message-----
From: Troy Farrell []
Sent: Monday, May 05, 2003 12:09 PM
To:; zope
Subject: Re: [Zope] html_quote, quoting accents

Ok.  We're going to trace this to the root.  The html_quote you are=20
using is in Products.PythonScripts.standard.html_quote() or so, which=20
points to DocumentTemplate.DT_Var.html_quote() which points to=20
DocumentTemplate.html_quote.html_quote() which points to cgi.escape().

The cgi.escape() docs say this:

escape(s[, quote])
Convert the characters "&", "<" and ">" in string s to HTML-safe=20
sequences. Use this if you need to display text that might contain such =

characters in HTML. If the optional flag quote is true, the =
character (""") is also translated; this helps for inclusion in an HTML =

attribute value, as in <A HREF=3D"...">. If the value to be quoted =
include single- or double-quote characters, or both, consider using the =

quoteattr() function in the xml.sax.saxutils module instead.

All that being said, html_quote will not solve your problem.  One thing =

you might try is messing with the character coding used on your html=20
pages.  The only other option I can see is writing your own convertor.

Troy wrote:
> Troy,
> OK, well for the purpose of this example, and where I'm starting, is =
> CMF Metadata, such as the title.
> A user enters the metadata using their regular keyboards and so on, =
> means the accented characters are typed in in ISO-8859-1, and stored =
> I guess? (since technically this value isn't HTML, it should be =
stored in
> it's native character set)
> Now when I output the Title, it comes out in ISO-8859-1 properly, but =
> like to force it encoded as an HTML entity, so when a user enters the =
> "r=E9gion" in the Title, it'll be entered/saved that way, and by =
default be
> output that way, but ...
> My understanding was that uting html_quote would transform that into
> "r&eacute;gion" ... But it's not doing anything different for me.  =
> entity notation, &dtml-Title; doesn't do the html_quoting either.
> This is using the default metadata templates, or close enough that =
> have made shouldn't matter (I've extended the metadata, but not =
> existing DC setup).
> Am I misunderstanding the purpose of this command? Or is there =
> else I'm not getting?
> Thanks,
> J.F.
> -----Original Message-----
> From: Troy Farrell []
> Sent: Friday, May 02, 2003 5:15 PM
> To:
> Subject: Re: [Zope] html_quote, quoting accents
> Bonjour Jean-Fran=E7ois.
> We need more information before we can help you.  Where is your user=20
> typing these characters?  In what forms?  In what type of objects are =

> you storing this information?  We'll try to help you, but we need =
> information first.
> Troy
> wrote:
>>I have french content on my site, which means accents and other =
>>type characters.
>>For the first time a user actually ran into the problem of the =
>>coming out wrong on his screen, so now I have to fix it :P
>>I tried using html_quote without success, and also using the =
>>type syntax (Which apparently is auto-quoted) but in both cases my =
>>are still coming out in raw latin-1 instead of something like =
&eacute; ...
>>Of course in the case of the metadata, I don't want to html encode =
>>characters since technically it's not HTML just yet :)
>>Help ?
>>Jean-Fran=E7ois Doyon
>>Internet Service Development and Systems Support / Soutien de =
syst=E8mes et
>>developement de services Internet
>>GeoAccess Division / Division G=E9oAcc=E8s
>>Canada Center for Remote Sensing / Centre canadien de =
>>Natural Resources Canada /  Ressources naturelles Canada
>>Phone / T=E9l=E9phone: (613) 992-4902
>>Fax / T=E9l=E9copieur: (613) 947-2410
>>Zope maillist  -
>>**   No cross posts or HTML encoding!  **
>>(Related lists -=20
>> )
> _______________________________________________
> Zope maillist  -
> **   No cross posts or HTML encoding!  **
> (Related lists -=20
> )