# HG changeset patch # User Paul Boddie # Date 1345314784 -7200 # Node ID 7389b1727dee3e229fdbb7fe6253ff349fe97f6b # Parent b5c5320def14f4f075517099bf9e78caa0b5f005 Introduced a header-writing convenience function to prevent continual duplication of this functionality in other projects. Moved colour-related functions from EventAggregatorSupport. diff -r b5c5320def14 -r 7389b1727dee MoinSupport.py --- a/MoinSupport.py Tue Jul 17 00:42:10 2012 +0200 +++ b/MoinSupport.py Sat Aug 18 20:33:04 2012 +0200 @@ -10,7 +10,7 @@ from DateSupport import * from MoinMoin.Page import Page -from MoinMoin import wikiutil +from MoinMoin import config, wikiutil from StringIO import StringIO from shlex import shlex import re @@ -241,6 +241,32 @@ else: return request.env.get((prefix and prefix + "_" or "") + header_name.upper()) +def writeHeaders(request, mimetype, metadata, status=None): + + """ + Using the 'request', write resource headers using the given 'mimetype', + based on the given 'metadata'. If the optional 'status' is specified, set + the status header to the given value. + """ + + send_headers = get_send_headers(request) + + # Define headers. + + headers = ["Content-Type: %s; charset=%s" % (mimetype, config.charset)] + + # Define the last modified time. + # NOTE: Consider using request.httpDate. + + latest_timestamp = metadata.get("last-modified") + if latest_timestamp: + headers.append("Last-Modified: %s" % latest_timestamp.as_HTTP_datetime_string()) + + if status: + headers.append("Status: %s" % status) + + send_headers(headers) + # Content/media type and preferences support. class MediaRange: diff -r b5c5320def14 -r 7389b1727dee README.txt --- a/README.txt Tue Jul 17 00:42:10 2012 +0200 +++ b/README.txt Sat Aug 18 20:33:04 2012 +0200 @@ -72,6 +72,8 @@ ImprovedTableParser to MoinSupport. * Added remote resource management from EventAggregator to MoinRemoteSupport. + * Added a header-writing function to MoinSupport. + * Added view-related functions from EventAggregator as ViewSupport. Release Procedures ------------------ diff -r b5c5320def14 -r 7389b1727dee ViewSupport.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ViewSupport.py Sat Aug 18 20:33:04 2012 +0200 @@ -0,0 +1,27 @@ +# -*- coding: iso-8859-1 -*- +""" + MoinMoin - ViewSupport library (derived from EventAggregatorSupport) + + @copyright: 2008, 2009, 2010, 2011, 2012 by Paul Boddie + @license: GNU GPL (v2 or later), see COPYING.txt for details. +""" + +# Colour-related functions. + +def getColour(s): + colour = [0, 0, 0] + digit = 0 + for c in s: + colour[digit] += ord(c) + colour[digit] = colour[digit] % 256 + digit += 1 + digit = digit % 3 + return tuple(colour) + +def getBlackOrWhite(colour): + if sum(colour) / 3.0 > 127: + return (0, 0, 0) + else: + return (255, 255, 255) + +# vim: tabstop=4 expandtab shiftwidth=4