Performance impact of using decorators

Diez B. Roggisch deets at nospam.web.de
Fri Mar 10 11:53:43 EST 2006


> @expose -> cherrypy decorator
> @startTransactrionAndBuildPage -> starts a db transaction, populates
> the user in the session.

I guess that is ok - transaction handling is a "classic" for decorator-like
concepts. After all, you don't want

begin()
try:
  pass
  commit()
finally:
  if not comitted():
    rollback()

all over the place.

> Does some error handling. Adds header, footer 
> and error messages to the page.

That sounds like something for the templating engine, and _certainly_ not
for a decorator that otherwise deals with transactions.

> @partOfTabUi -> besides the top level navigation, I have tab level
> (with actions) for navigation on individual pages

Template I guess.

> @convert -> this converts boolean like 'True' or '0' to python True,
> '231' -> int

Looks ok to me.

> @cache -> (not implemented, but will ad it).
> 
> I would love to hear other people's experience with using decorators
> for web application building.

I used them in turbogears (which builds on cherrypy) - and I found them
useful for some aspects.

Diez



More information about the Python-list mailing list