An html decorator that wraps the return value of its function in HTML tags, including a <TITLE> tag in the HTML <HEAD>.

A needsLogin decorator that checks whether a user is logged in before providing "private" content.

I originally implemented this using cherrypy.lib.aspect, but I ran into some limitations of that class:

You get precisely one _before and _after method for each Aspect-derived class, so you can't easily mix-and-match multiple aspects.

If your _before handler returns STOP, your _after handler never gets called. This means that if you're trying to implement header and footer aspects, your header aspect has to do the same work as the footer aspect if it halts processing.

The handlers don't get access to either the self object or the arguments of the method to be called.

I started implementing a version of Aspect that corrected these problems, but I soon realized I was re-implementing decorators, so I switched to a decorator-based implementation.

Attachments

check.py (2.9 kB) -I have modified the file to use without decorators (Python 2.3), added by py@topmusic.ch on 03/18/07 01:09:49.