1.1 --- a/MoinShare.py Tue May 07 23:44:34 2013 +0200
1.2 +++ b/MoinShare.py Sat May 11 00:35:03 2013 +0200
1.3 @@ -12,6 +12,11 @@
1.4 from MoinMoin import wikiutil
1.5 import re
1.6
1.7 +try:
1.8 + from cStringIO import StringIO
1.9 +except ImportError:
1.10 + from StringIO import StringIO
1.11 +
1.12 escape = wikiutil.escape
1.13 _getFragments = getFragments
1.14
1.15 @@ -30,6 +35,9 @@
1.16 fragment_attribute = "moinshare"
1.17
1.18 def getFragments(s):
1.19 +
1.20 + "Return all fragments in 's' having the MoinShare fragment attribute."
1.21 +
1.22 fragments = []
1.23 for format, attributes, body in _getFragments(s):
1.24 if attributes.has_key(fragment_attribute):
1.25 @@ -81,4 +89,72 @@
1.26 else:
1.27 return getCurrentTime().as_ISO8601_datetime_string()
1.28
1.29 +def getUpdateSources(request, sources_page):
1.30 +
1.31 + """
1.32 + Using the 'request', return the update sources defined on the given
1.33 + 'sources_page'.
1.34 + """
1.35 +
1.36 + # Remote sources are accessed via dictionary page definitions.
1.37 +
1.38 + return getWikiDict(sources_page, request)
1.39 +
1.40 +def getUpdateFragmentsFromPage(page, request):
1.41 +
1.42 + """
1.43 + Get update fragments from the given 'page' using the 'request'. A list of
1.44 + update descriptions is returned, each being a tuple of the form...
1.45 +
1.46 + (fragment identifer, summary text, preferred mimetypes, textual content,
1.47 + updated datetime)
1.48 + """
1.49 +
1.50 + updates = []
1.51 +
1.52 + # NOTE: Use the updated datetime from the page for updates.
1.53 + # NOTE: The published and updated details would need to be deduced from
1.54 + # NOTE: the page history instead of being taken from the page as a whole.
1.55 +
1.56 + metadata = getMetadata(page)
1.57 + updated = getUpdatedTime(metadata)
1.58 +
1.59 + # Get the fragment regions for the page.
1.60 +
1.61 + for n, (format, attributes, body) in enumerate(getFragments(page.get_raw_body())):
1.62 +
1.63 + # Produce a fragment identifier.
1.64 + # NOTE: Choose a more robust identifier where none is explicitly given.
1.65 +
1.66 + fragment = attributes.get("fragment", str(n))
1.67 + summary = attributes.get("summary", "Update #%d" % n)
1.68 +
1.69 + # Get the preferred content types available for the fragment.
1.70 +
1.71 + preferred = getPreferredOutputTypes(request, getOutputTypes(request, format))
1.72 +
1.73 + # Try and obtain some suitable content for the entry.
1.74 + # NOTE: Could potentially get a summary for the fragment.
1.75 +
1.76 + content = None
1.77 +
1.78 + if "text/html" in preferred:
1.79 + parser_cls = getParserClass(request, format)
1.80 + parser = parser_cls(body, request)
1.81 +
1.82 + if format == "html":
1.83 + content = body
1.84 + elif hasattr(parser, "formatForOutputType"):
1.85 + s = StringIO()
1.86 + parser.formatForOutputType("text/html", write=s.write)
1.87 + content = s.getvalue()
1.88 + else:
1.89 + fmt = request.html_formatter
1.90 + fmt.setPage(page)
1.91 + content = formatText(body, request, fmt, parser_cls)
1.92 +
1.93 + updates.append((fragment, summary, preferred, content, updated))
1.94 +
1.95 + return updates
1.96 +
1.97 # vim: tabstop=4 expandtab shiftwidth=4