1.1 --- a/MoinSupport.py Tue Jul 17 00:42:10 2012 +0200
1.2 +++ b/MoinSupport.py Sat Aug 18 20:33:04 2012 +0200
1.3 @@ -10,7 +10,7 @@
1.4
1.5 from DateSupport import *
1.6 from MoinMoin.Page import Page
1.7 -from MoinMoin import wikiutil
1.8 +from MoinMoin import config, wikiutil
1.9 from StringIO import StringIO
1.10 from shlex import shlex
1.11 import re
1.12 @@ -241,6 +241,32 @@
1.13 else:
1.14 return request.env.get((prefix and prefix + "_" or "") + header_name.upper())
1.15
1.16 +def writeHeaders(request, mimetype, metadata, status=None):
1.17 +
1.18 + """
1.19 + Using the 'request', write resource headers using the given 'mimetype',
1.20 + based on the given 'metadata'. If the optional 'status' is specified, set
1.21 + the status header to the given value.
1.22 + """
1.23 +
1.24 + send_headers = get_send_headers(request)
1.25 +
1.26 + # Define headers.
1.27 +
1.28 + headers = ["Content-Type: %s; charset=%s" % (mimetype, config.charset)]
1.29 +
1.30 + # Define the last modified time.
1.31 + # NOTE: Consider using request.httpDate.
1.32 +
1.33 + latest_timestamp = metadata.get("last-modified")
1.34 + if latest_timestamp:
1.35 + headers.append("Last-Modified: %s" % latest_timestamp.as_HTTP_datetime_string())
1.36 +
1.37 + if status:
1.38 + headers.append("Status: %s" % status)
1.39 +
1.40 + send_headers(headers)
1.41 +
1.42 # Content/media type and preferences support.
1.43
1.44 class MediaRange:
2.1 --- a/README.txt Tue Jul 17 00:42:10 2012 +0200
2.2 +++ b/README.txt Sat Aug 18 20:33:04 2012 +0200
2.3 @@ -72,6 +72,8 @@
2.4 ImprovedTableParser to MoinSupport.
2.5 * Added remote resource management from EventAggregator to
2.6 MoinRemoteSupport.
2.7 + * Added a header-writing function to MoinSupport.
2.8 + * Added view-related functions from EventAggregator as ViewSupport.
2.9
2.10 Release Procedures
2.11 ------------------
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/ViewSupport.py Sat Aug 18 20:33:04 2012 +0200
3.3 @@ -0,0 +1,27 @@
3.4 +# -*- coding: iso-8859-1 -*-
3.5 +"""
3.6 + MoinMoin - ViewSupport library (derived from EventAggregatorSupport)
3.7 +
3.8 + @copyright: 2008, 2009, 2010, 2011, 2012 by Paul Boddie <paul@boddie.org.uk>
3.9 + @license: GNU GPL (v2 or later), see COPYING.txt for details.
3.10 +"""
3.11 +
3.12 +# Colour-related functions.
3.13 +
3.14 +def getColour(s):
3.15 + colour = [0, 0, 0]
3.16 + digit = 0
3.17 + for c in s:
3.18 + colour[digit] += ord(c)
3.19 + colour[digit] = colour[digit] % 256
3.20 + digit += 1
3.21 + digit = digit % 3
3.22 + return tuple(colour)
3.23 +
3.24 +def getBlackOrWhite(colour):
3.25 + if sum(colour) / 3.0 > 127:
3.26 + return (0, 0, 0)
3.27 + else:
3.28 + return (255, 255, 255)
3.29 +
3.30 +# vim: tabstop=4 expandtab shiftwidth=4