Pythonic way of web-programming

Bengt Richter bokr at oz.net
Sun Apr 20 22:36:27 EDT 2003


On Sun, 20 Apr 2003 05:21:41 -0400, David Abrahams <dave at boost-consulting.com> wrote:
[...]
>
>I don't care much about XML programming (haven't had a use for it),
>but at PyConDC recently I got together with a couple of guys from the
>Twisted project who do care, and designed a nice little meta-language
>in Python for doing this sort of template processing.  Here's a little
>example of it in action:
>
Interesting ;-) Did you snip that from a working version? I didn't work one up,
but I'd guess the approach was to define classes or factory functions
for body, table, tr, td, etc. and have them return suitable objects with suitable
__getitem__ methods. So "body" seems like a predefined object, unlike the others?
Or are they all predefined instances with factory and normal __call__  methods?
Am I mistaken about the apparent extra ")" below?

>    template = body[
                body()[   # might be more consistent?
>        table(id="outer", width="100%", height="100%", border="0")[
>            tr(valign="bottom")[
>                td(id="output", width="75%", valign="top", model="latestOutput")[
>                    div(pattern="listItem", view="html")[
>                        "Foo"
>                    ]
>                ],
>                td(id="room-contents", valign="bottom")[
>                    strong[
>                        "Stuff you have"
>                    ],
>                    div(model="playerInventory", view="List")[
>
>                        # Note programmatic elements
>                        if_(not arg1)
>                        [    
>                            div(_class="item")["Nothing"]
>                        ].else_
>                        [
>                            for_each(arg1)
>                            [
>                                div(
>                                    style=["color: red", "color: blue", None]
>                                  , view="item"
>                                  , controller="look")[arg1]
                                   , controller="look" # or drop the ")" of the next line?
>                                )
                                 )[arg1]               # or drop the ")" of the previous line?
>                            ]
>
>                        ]
>                    ]
>                ]
>            ]
>        ] 
>    ]
>
>    # invoke the template with some data
>    template(['foo', 'bar', 'baz', 'another item'])
>
>which generates:
[ ... snip ...]
>I really loved this because it was the result of healthy
>cross-pollination between the cultures and techniques of two very
>different programming communities: Python and C++.
>
It's always nice to see people of different cultures able to
overcome xenophobia etc. and have a good time, but what did C++
per se actually have to do with the above? Was it done in C++ first?
;-)

Regards,
Bengt Richter




More information about the Python-list mailing list