At Tuesday 3/10/2006 05:24, Raja Raman Sundararajan wrote:

Hello guys,
    I have data stored in the database which has special characters
like <, > etc.
Case 1: Whenever I wanted to present the output to a browser
      I need to escape these special characters into the browser
equivalent like &lt;  &gt; etc.( for example by using the cgi module)
Case 2: Whenever I wanted to present the output to some client other
than a browser, I wanted to present the data as it is stored in the
database.

For doing this I thought of overriding the __builtin__.__getattr__
method.

Not very reasonable on the source object itself. Escaping <&> is a *presentation* requirement and should be managed at that level. For example, in a PageTemplate, using tal:content or tal:attribute does the right escaping.

I am wondering if there is any other way of achieving this. I have
loads of files that get the attribute values of objects stored in the
database and I do not want to manually change the way of DB access in
those files. I rather prefer a centralized way to achieve this.

If your data contains a '<', that's OK, it's the real contents and should remain that way.
If you have to build an HTML page, escape those characters at *that* stage.
If you have to write a CSV file, perhaps a '<' is irrelevant but a ',' is problematic.
For some Windows text controls you have to escape '&' characters.
None of these operations should make you to change your data, or the way you access your data. You invoke them at the presentation stage, depending on the final target.



Gabriel Genellina
Softlab SRL

        

        
                
__________________________________________________ Preguntá. Respondé. Descubrí. Todo lo que querías saber, y lo que ni imaginabas, está en Yahoo! Respuestas (Beta). ¡Probalo ya! http://www.yahoo.com.ar/respuestas
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to