durusmail: quixote-users: PTL for SQL (was Re: [Quixote-users] New syntax for PTL templates?)
New syntax for PTL templates?
2002-10-08
2002-10-08
2002-10-08
2002-10-08
2002-10-09
2002-10-09
2002-10-09
2002-10-09
2002-10-10
PTL for SQL (was Re: [Quixote-users] New syntax for PTL templates?)
2002-10-10
python 2.2 required for widgets
2002-10-28
2002-10-28
2002-10-28
2002-10-28
quote keyword on widget constructors
2002-10-29
2002-10-29
2002-10-29
2002-10-28
2002-10-28
2002-10-29
2002-10-29
2002-10-29
2002-10-10
PTL for SQL (was Re: [Quixote-users] New syntax for PTL templates?)
Greg Ward
2002-10-10
On 10 October 2002, Joel Shprentz said:
> I hope that plain and html are class names, not keywords.  Then we would
> not be limited to three types of functions.  For example, one could imagine
> an sql class that converts strings to the appropriate form for SQL queries.
>
>     def bar [sql] (lastName):
>         "SELECT * FROM staff\n"
>         "WHERE last = "
>         lastName
>
> Calling bar ("O'Henry") produces:
>
>     SELECT * FROM staff
>     WHERE last = 'O''Henry'

Interesting idea.  We have zero interest in SQL, so you're on your own
in coding this one.

> The PTL documentation says, "the value is converted to a string using str()
> and appended to the template's return value. There's a single exception to
> this rule: None is the only value that's ever ignored, adding nothing to
> the output."
>
> I haven't looked under the hood to see where this is implemented.  Is it
> specific to the current string output, or is it generic to all PTL template
> processing?

Look in TemplateIO.py, specifically the __iadd__() method.  If I'm
understanding ptl_compile.py correctly, PTL works by converting every
expression

   foo

to

  __output += foo

where __output is a TemplateIO instance, created at the top of the
function (err, template) and returned by it.  See the
TemplateTransformer class in ptl_compile.py.

Of course this stuff will probably change when Neil checks in his
pending patch.  Watch the CVS tree.  Subscribe to quixote-checkins if
you're really interested.

So you would have to 1) create an SQL-specific subclass of TemplateIO,
and 2) persuade TemplateTransformer to use it.  It looks to me like some
module-level globals in ptl_compile.py should become class attributes to
make this a bit cleaner.  Play around, let us know if you come up with
something.  Patches welcome!

        Greg
--
Greg Ward - software developer                gward@mems-exchange.org
MEMS Exchange                            http://www.mems-exchange.org


reply