[Twisted-Python] interface for Last-Modified

Glyph Lefkowitz glyph at twistedmatrix.com
Wed Sep 25 02:07:00 EDT 2002

On 24 Sep 2002 20:50:18 -0700, Kevin Turner <kevin.m.turner at pobox.com> wrote:
> itamar has led me to what looks to be a much more elegant solution. 
> Since the only resources that worry about receiving conditional requests
> are those that set cache validation headers (such as "Last-Modified"),
> the check to see if you're dealing with a conditional request can go in
> the L{http.Request.setLastModified} method.  setLastModified's return
> value can then let the caller know if they date they gave was older than
> the one in the conditional request, so they don't have to render the
> body of the request.  And this works, because Last-Modified being a
> header and all, you're having to set it before you write the request
> body anyway.

Wow!  This is not a solution I would have thought of, but I agree that it's
very clean.  If you've got this implemented, you're probably 99% of the way

> and I was all ready to check it in, until I tried to apply it in my
> actual use-case, using it in a superclass::

Your use-case is pretty much complete except for one thing:
(widgets.Widget, mvc.View):
>         def display(self, request):
>             if request.setLastModified(self.lastModified) is http.CACHED:
>                 # Body should be empty.
>                 return ''
>             else:
>                 # Body is rendered by subclass.
>                 return ''

Since this is a new superclass, we can redefine the interface of its subclasses
and change them not to be regular widgets.  Since .display() is rather
higher-level than .render() it might even make sense to do this at the
top-level render() rather than in a subclass...  Though twisted.web.widgets is
hopefully going away once woven is well-documented and provides replacements
for everything...  For an initial release, though, something like this:

                  return self.displayBody(request)

Worst case, if in the future this API is later supported at a lower level in
Widget itself, setLastModified will be called twice with the same argument.

>     class RssChannel(AbstractCommitList):
>         def display(self, request):
and this would, of course, be

          def displayBody(self, request):
>             s = AbstractCommitList.display(self, request)
>             # Now how do I know if I'm supposed to render the body or not?

Probably for the initial implementation, the only class to support this in the
base should be static.File.

 |    <`'>    |  Glyph Lefkowitz: Traveling Sorcerer   |
 |   < _/ >   |  Lead Developer,  the Twisted project  |
 |  < ___/ >  |      http://www.twistedmatrix.com      |
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20020925/938f8aec/attachment.pgp 

More information about the Twisted-Python mailing list