Looking for a nice CGI-related string representation module

Mike McGavin jester at NOSPAM.mcsnospam.vuw.netNOSPAM.nz
Mon Feb 3 02:15:14 CET 2003

Hi everyone.

I'm writing some CGI scripts that deal with user input and databases, 
and I was wondering if anyone could recommend any good string handling 
modules designed for use with CGI applications.  I'm looking for 
something that can efficiently translate between the different 
representations of the same string.

Examples of different representations might include what the user typed 
in verses the escaped version for a SQL string, verses a differently 
escaped version for output as part of an HTML page, verses an integer 
representation if possible, and so on. Being able to naturally add 
representation modes would be a bonus. Maybe the user types in a 
wiki-like representation, such as using *'s for bulleted lists, and the 
module can translate it to an HTML format or SQL format on the fly, and 
so on.

I'd like to be able to create some type of string object that would act 
similar to a python string, but also contain internal information about 
the sort of string it is so the conversions can be idempotent. eg. If I 
ask for an HTML-escaped version of something that already knows it's 
HTML-escaped, I want it to just return itself rather than something 
doubly-escaped... unless I told it that I wanted it doubly-escaped for 
some reason. I'm not sure how it would act for things like appending 
different representations of strings together, but hopefully it'd do 
something intelligent. :)

I guess I'm looking for something that handles strings in the same way 
that mxDateTime handles dates and timezones and so on. :)

I'd also like it to be able to run input through filters to do basic 
things like checking for HTML tags, maybe allowing some through and 
blocking others, and so on.

I've written my own very primitive module that does some of this in a 
not-too-tidy way, and I could improve what I have as I need to.  On the 
other hand if there's already a well established module out there, I'd 
prefer to use it instead. Having searched around a bit though, I can't 
seem to find anything.

If anyone can point me to any modules that can do this sort of string 
manipulation and filtering, I'd very much appreciate it.

Thanks for any help.

More information about the Python-list mailing list