Re: Overriding builtin getattr method
- From: Gabriel Genellina <gagsl-py@xxxxxxxxxxxx>
- Date: Tue, 03 Oct 2006 05:59:01 -0300
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 < > 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
.
- References:
- Overriding builtin getattr method
- From: Raja Raman Sundararajan
- Overriding builtin getattr method
- Prev by Date: Re: Python to use a non open source bug tracker?
- Next by Date: Howto pass Array/Hash into Function
- Previous by thread: Re: Overriding builtin getattr method
- Next by thread: Howto pass Array/Hash into Function
- Index(es):
Relevant Pages
|
Loading