1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/MoinShare.py Sat Apr 14 00:42:16 2012 +0200
1.3 @@ -0,0 +1,75 @@
1.4 +# -*- coding: iso-8859-1 -*-
1.5 +"""
1.6 + MoinMoin - MoinShare library
1.7 +
1.8 + @copyright: 2011, 2012 by Paul Boddie <paul@boddie.org.uk>
1.9 + @license: GNU GPL (v2 or later), see COPYING.txt for details.
1.10 +"""
1.11 +
1.12 +from MoinSupport import *
1.13 +from MoinMoin import wikiutil
1.14 +import re
1.15 +
1.16 +escape = wikiutil.escape
1.17 +
1.18 +__version__ = "0.1"
1.19 +
1.20 +# More Moin 1.9 compatibility functions.
1.21 +
1.22 +def has_member(request, groupname, username):
1.23 + if hasattr(request.dicts, "has_member"):
1.24 + return request.dicts.has_member(groupname, username)
1.25 + else:
1.26 + return username in request.dicts.get(groupname, [])
1.27 +
1.28 +# Extraction of shared fragments.
1.29 +
1.30 +marker_regexp_str = r"([{]{3,}|[}]{3,})"
1.31 +marker_regexp = re.compile(marker_regexp_str, re.MULTILINE | re.DOTALL) # {{{... or }}}...
1.32 +
1.33 +def getRegions(s):
1.34 +
1.35 + "Parse the string 's', returning a list of shared regions."
1.36 +
1.37 + regions = []
1.38 + marker = None
1.39 + is_region = True
1.40 +
1.41 + for match_text in marker_regexp.split(s):
1.42 +
1.43 + # Capture section text.
1.44 +
1.45 + if is_region and marker:
1.46 + regions[-1] += match_text
1.47 +
1.48 + # Handle section markers.
1.49 +
1.50 + elif not is_region:
1.51 +
1.52 + # Close any open sections, returning to exposed text regions.
1.53 +
1.54 + if marker:
1.55 + if match_text.startswith("}") and len(marker) == len(match_text):
1.56 + marker = None
1.57 +
1.58 + # Without a current marker, start a section if an appropriate marker
1.59 + # is given.
1.60 +
1.61 + elif match_text.startswith("{"):
1.62 + marker = match_text
1.63 + regions.append("")
1.64 +
1.65 + # Markers and section text are added to the current region.
1.66 +
1.67 + regions[-1] += match_text
1.68 +
1.69 + # Exposed text is ignored.
1.70 +
1.71 + # The match text alternates between text between markers and the markers
1.72 + # themselves.
1.73 +
1.74 + is_region = not is_region
1.75 +
1.76 + return regions
1.77 +
1.78 +# vim: tabstop=4 expandtab shiftwidth=4