[mod_python] Problem with html quoted/unquoted

Deron Meranda deron.meranda at gmail.com
Wed May 17 11:06:47 EDT 2006


On 5/17/06, Deron Meranda <deron.meranda at gmail.com> wrote:
> def encodechar( c ):
>     codepoint = ord(c)
>     if codepoint >= 128 or codepoint < 32:
>         return '&#%d;' % codepoint
>     else:
>         return c

Oops, in my first encodechar() function, the else clause should read:

   else:
      import cgi
      return cgi.escape( c, True )

Or some equivalent, in order to insure that &, <, and > get encoded.

My second example which uses htmlentitdefs doesn't need that
since those characters are already in the htmlentitydefs.
-- 
Deron Meranda



More information about the Mod_python mailing list