1.1 --- a/ImprovedTableParser.py Mon Apr 02 20:08:41 2012 +0200
1.2 +++ b/ImprovedTableParser.py Wed Apr 18 01:20:51 2012 +0200
1.3 @@ -8,11 +8,12 @@
1.4 """
1.5
1.6 from MoinMoin import wikiutil
1.7 -from shlex import shlex
1.8 from StringIO import StringIO
1.9 from MoinSupport import *
1.10 import re
1.11
1.12 +__version__ = "0.2"
1.13 +
1.14 # Regular expressions.
1.15
1.16 syntax = {
1.17 @@ -268,65 +269,6 @@
1.18 table_attrs[name] = value
1.19 del attrs[name]
1.20
1.21 -def parseAttributes(s, escape=True):
1.22 -
1.23 - """
1.24 - Parse the table attributes string 's', returning a mapping of names to
1.25 - values. If 'escape' is set to a true value, the attributes will be suitable
1.26 - for use with the formatter API. If 'escape' is set to a false value, the
1.27 - attributes will have any quoting removed.
1.28 - """
1.29 -
1.30 - attrs = {}
1.31 - f = StringIO(s)
1.32 - name = None
1.33 - need_value = False
1.34 -
1.35 - for token in shlex(f):
1.36 -
1.37 - # Capture the name if needed.
1.38 -
1.39 - if name is None:
1.40 - name = escape and wikiutil.escape(token) or strip_token(token)
1.41 -
1.42 - # Detect either an equals sign or another name.
1.43 -
1.44 - elif not need_value:
1.45 - if token == "=":
1.46 - need_value = True
1.47 - else:
1.48 - attrs[name.lower()] = escape and "true" or True
1.49 - name = wikiutil.escape(token)
1.50 -
1.51 - # Otherwise, capture a value.
1.52 -
1.53 - else:
1.54 - # Quoting of attributes done similarly to wikiutil.parseAttributes.
1.55 -
1.56 - if token:
1.57 - if escape:
1.58 - if token[0] in ("'", '"'):
1.59 - token = wikiutil.escape(token)
1.60 - else:
1.61 - token = '"%s"' % wikiutil.escape(token, 1)
1.62 - else:
1.63 - token = strip_token(token)
1.64 -
1.65 - attrs[name.lower()] = token
1.66 - name = None
1.67 - need_value = False
1.68 -
1.69 - return attrs
1.70 -
1.71 -def strip_token(token):
1.72 -
1.73 - "Return the given 'token' stripped of quoting."
1.74 -
1.75 - if token[0] in ("'", '"') and token[-1] == token[0]:
1.76 - return token[1:-1]
1.77 - else:
1.78 - return token
1.79 -
1.80 # Formatting of embedded content.
1.81 # NOTE: Borrowed from EventAggregator.
1.82