1 # -*- coding: iso-8859-1 -*- 2 """ 3 MoinMoin - MoinShare library 4 5 @copyright: 2011, 2012 by Paul Boddie <paul@boddie.org.uk> 6 @license: GNU GPL (v2 or later), see COPYING.txt for details. 7 """ 8 9 from MoinSupport import * 10 from MoinMoin import wikiutil 11 import re 12 13 escape = wikiutil.escape 14 15 __version__ = "0.1" 16 17 # More Moin 1.9 compatibility functions. 18 19 def has_member(request, groupname, username): 20 if hasattr(request.dicts, "has_member"): 21 return request.dicts.has_member(groupname, username) 22 else: 23 return username in request.dicts.get(groupname, []) 24 25 # Extraction of shared fragments. 26 27 marker_regexp_str = r"([{]{3,}|[}]{3,})" 28 marker_regexp = re.compile(marker_regexp_str, re.MULTILINE | re.DOTALL) # {{{... or }}}... 29 30 def getRegions(s): 31 32 "Parse the string 's', returning a list of shared regions." 33 34 regions = [] 35 marker = None 36 is_region = True 37 38 for match_text in marker_regexp.split(s): 39 40 # Capture section text. 41 42 if is_region and marker: 43 regions[-1] += match_text 44 45 # Handle section markers. 46 47 elif not is_region: 48 49 # Close any open sections, returning to exposed text regions. 50 51 if marker: 52 if match_text.startswith("}") and len(marker) == len(match_text): 53 marker = None 54 55 # Without a current marker, start a section if an appropriate marker 56 # is given. 57 58 elif match_text.startswith("{"): 59 marker = match_text 60 regions.append("") 61 62 # Markers and section text are added to the current region. 63 64 regions[-1] += match_text 65 66 # Exposed text is ignored. 67 68 # The match text alternates between text between markers and the markers 69 # themselves. 70 71 is_region = not is_region 72 73 return regions 74 75 # vim: tabstop=4 expandtab shiftwidth=4