1.1 --- a/MoinShare.py Wed Jul 11 00:52:41 2012 +0200
1.2 +++ b/MoinShare.py Sun Jul 15 21:33:24 2012 +0200
1.3 @@ -7,7 +7,8 @@
1.4 """
1.5
1.6 from MoinSupport import *
1.7 -from MoinMoin import wikiutil
1.8 +from MoinMoin import config, wikiutil
1.9 +from DateSupport import getCurrentTime
1.10 import re
1.11
1.12 escape = wikiutil.escape
1.13 @@ -125,4 +126,72 @@
1.14
1.15 return getFragmentsFromRegions(getRegions(s))
1.16
1.17 +def getOutputTypes(request, format):
1.18 +
1.19 + """
1.20 + Using the 'request' and the 'format' of a fragment, return the media types
1.21 + available for the fragment.
1.22 + """
1.23 +
1.24 + # This uses an extended parser API method if available.
1.25 +
1.26 + parser = getParserClass(request, format)
1.27 + if hasattr(parser, "getOutputTypes"):
1.28 + return parser.getOutputTypes()
1.29 + else:
1.30 + return ["text/html"]
1.31 +
1.32 +def getPreferredOutputTypes(request, mimetypes):
1.33 +
1.34 + """
1.35 + Using the 'request', perform content negotiation, obtaining mimetypes common
1.36 + to the fragment (given by 'mimetypes') and the client (found in the Accept
1.37 + header).
1.38 + """
1.39 +
1.40 + accept = getHeader(request, "Accept", "HTTP")
1.41 + prefs = getContentPreferences(accept)
1.42 + return prefs.get_preferred_types(mimetypes)
1.43 +
1.44 +def writeHeaders(request, mimetype, metadata, status=None):
1.45 +
1.46 + """
1.47 + Using the 'request', write resource headers using the given 'mimetype',
1.48 + based on the given 'metadata'. If the optional 'status' is specified, set
1.49 + the status header to the given value.
1.50 + """
1.51 +
1.52 + send_headers = get_send_headers(request)
1.53 +
1.54 + # Define headers.
1.55 +
1.56 + headers = ["Content-Type: %s; charset=%s" % (mimetype, config.charset)]
1.57 +
1.58 + # Define the last modified time.
1.59 + # NOTE: Consider using request.httpDate.
1.60 +
1.61 + latest_timestamp = metadata.get("last-modified")
1.62 + if latest_timestamp:
1.63 + headers.append("Last-Modified: %s" % latest_timestamp.as_HTTP_datetime_string())
1.64 +
1.65 + if status:
1.66 + headers.append("Status: %s" % status)
1.67 +
1.68 + send_headers(headers)
1.69 +
1.70 +def getUpdatedTime(metadata):
1.71 +
1.72 + """
1.73 + Return the last updated time based on the given 'metadata', using the
1.74 + current time if no explicit last modified time is specified.
1.75 + """
1.76 +
1.77 + # NOTE: We could attempt to get the last edit time of a fragment.
1.78 +
1.79 + latest_timestamp = metadata.get("last-modified")
1.80 + if latest_timestamp:
1.81 + return latest_timestamp.as_ISO8601_datetime_string()
1.82 + else:
1.83 + return getCurrentTime().as_ISO8601_datetime_string()
1.84 +
1.85 # vim: tabstop=4 expandtab shiftwidth=4