1.1 --- a/MoinSupport.py Mon Nov 26 23:08:38 2012 +0100
1.2 +++ b/MoinSupport.py Thu Nov 29 00:48:56 2012 +0100
1.3 @@ -258,57 +258,73 @@
1.4
1.5 """
1.6 Return fragments from the given 'regions', each having the form
1.7 - (format, arguments, body text).
1.8 + (format, attributes, body text).
1.9 """
1.10
1.11 fragments = []
1.12
1.13 for region in regions:
1.14 - if region.startswith("{{{"):
1.15 + format, attributes, body, header, close = getFragmentFromRegion(region)
1.16 + fragments.append((format, attributes, body))
1.17
1.18 - body = region.lstrip("{").rstrip("}").lstrip()
1.19 + return fragments
1.20
1.21 - # Remove any prelude and process metadata.
1.22 +def getFragmentFromRegion(region):
1.23
1.24 - if body.startswith("#!"):
1.25 - body = body[2:]
1.26 + """
1.27 + Return a fragment for the given 'region' having the form (format,
1.28 + attributes, body text, header, close), where the 'header' is the original
1.29 + declaration of the 'region' or None if no explicit region is defined, and
1.30 + 'close' is the closing marker of the 'region' or None if no explicit region
1.31 + is defined.
1.32 + """
1.33
1.34 - try:
1.35 - arguments, body = body.split("\n", 1)
1.36 - except ValueError:
1.37 - arguments = body
1.38 - body = ""
1.39 + if region.startswith("{{{"):
1.40
1.41 - # Get any parser/format declaration.
1.42 + body = region.lstrip("{")
1.43 + level = len(region) - len(body)
1.44 + body = body.rstrip("}").lstrip()
1.45 +
1.46 + # Remove any prelude and process metadata.
1.47 +
1.48 + if body.startswith("#!"):
1.49
1.50 - if arguments and not arguments[0].isspace():
1.51 - details = arguments.split(None, 1)
1.52 - if len(details) == 2:
1.53 - format, arguments = details
1.54 - else:
1.55 - format = details[0]
1.56 - arguments = ""
1.57 - else:
1.58 - format = None
1.59 + try:
1.60 + declaration, body = body.split("\n", 1)
1.61 + except ValueError:
1.62 + declaration = body
1.63 + body = ""
1.64
1.65 - # Get the attributes/arguments for the region.
1.66 + arguments = declaration[2:]
1.67 +
1.68 + # Get any parser/format declaration.
1.69
1.70 - attributes = parseAttributes(arguments, False)
1.71 -
1.72 - # Add an entry for the format in the attribute dictionary.
1.73 + if arguments and not arguments[0].isspace():
1.74 + details = arguments.split(None, 1)
1.75 + if len(details) == 2:
1.76 + format, arguments = details
1.77 + else:
1.78 + format = details[0]
1.79 + arguments = ""
1.80 + else:
1.81 + format = None
1.82
1.83 - if format and not attributes.has_key(format):
1.84 - attributes[format] = True
1.85 + # Get the attributes/arguments for the region.
1.86 +
1.87 + attributes = parseAttributes(arguments, False)
1.88
1.89 - fragments.append((format, attributes, body))
1.90 + # Add an entry for the format in the attribute dictionary.
1.91
1.92 - else:
1.93 - fragments.append((None, {}, body))
1.94 + if format and not attributes.has_key(format):
1.95 + attributes[format] = True
1.96 +
1.97 + return format, attributes, body, level * "{" + declaration + "\n", level * "}"
1.98
1.99 else:
1.100 - fragments.append((None, {}, region))
1.101 + return None, {}, body, level * "{" + "\n", level * "}"
1.102
1.103 - return fragments
1.104 + else:
1.105 + return None, {}, region, None, None
1.106
1.107 def getFragments(s, include_non_regions=False):
1.108
1.109 @@ -432,6 +448,9 @@
1.110 def __getitem__(self, name):
1.111 return self.form.getlist(name)
1.112
1.113 + def items(self):
1.114 + return self.form.items(True)
1.115 +
1.116 class ActionSupport:
1.117
1.118 """