Re: Overriding builtin getattr method



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

.



Relevant Pages

  • Overriding builtin getattr method
    ... I have data stored in the database which has special characters ... Whenever I wanted to present the output to a browser ... database and I do not want to manually change the way of DB access in ...
    (comp.lang.python)
  • Re: Overriding builtin getattr method
    ... Raja Raman Sundararajan skrev: ... I have data stored in the database which has special characters ... Whenever I wanted to present the output to a browser ...
    (comp.lang.python)
  • Re: Overriding builtin getattr method
    ... Whenever I wanted to present the output to a browser ... I need to escape these special characters into the browser ... database and I do not want to manually change the way of DB access in ... So the better approach is to gather the data as it is, and when you transform it to something that requires escaping, do it there. ...
    (comp.lang.python)
  • Re: Tables - Cells - Preview Mode
    ... That is where a database driven web site comes into play, ... Thomas A. Rowe (Microsoft MVP - FrontPage) ... > peices when previewed anywhere....in the browser or in ... distributing cells around and ect. ...
    (microsoft.public.frontpage.client)
  • Re: Replication problems
    ... An error occurred while accessing the DHCP database. ... DHCP server event log for more information on this error. ... browser for the domain on transport NetBT_Tcpip_{99B638B5-2C0B. ... master browser is stopping or an election is being forced. ...
    (microsoft.public.windows.server.active_directory)

Loading