# HG changeset patch # User Paul Boddie # Date 1381599464 -7200 # Node ID d18fd071e1f454162379cac3658e5c51556c933e # Parent d58ef5dbcbb1fc32b0e3a5e221754de1eced3adb# Parent bdc05cebca78e0025d1bfe3dd02086f4731b2120 Merged changes from the default branch. diff -r d58ef5dbcbb1 -r d18fd071e1f4 MoinSupport.py --- a/MoinSupport.py Sat Oct 12 18:52:10 2013 +0200 +++ b/MoinSupport.py Sat Oct 12 19:37:44 2013 +0200 @@ -509,6 +509,35 @@ return parameters +# Macro argument quoting. + +def quoteMacroArguments(args): + + """ + Quote the given 'args' - a collection of (name, value) tuples - returning a + string containing the comma-separated, quoted arguments. + """ + + quoted = [] + + for name, value in args: + quoted.append(quoteMacroArgument(name, value)) + + return ",".join(quoted) + +def quoteMacroArgument(name, value): + + """ + Quote the argument with the given 'name' (or None indicating an unnamed + argument) and 'value' so that it can be used with a macro. + """ + + value = unicode(value).replace('"', '""') + if name is None: + return '"%s"' % value + else: + return '"%s=%s"' % (name, value) + # Request-related classes and associated functions. class Form: @@ -945,7 +974,7 @@ "Encode the given 'text' in a verbatim representation." - return "<>" % text + return "<>" % quoteMacroArgument(None, text) def getPrettyTitle(title): diff -r d58ef5dbcbb1 -r d18fd071e1f4 README.txt --- a/README.txt Sat Oct 12 18:52:10 2013 +0200 +++ b/README.txt Sat Oct 12 19:37:44 2013 +0200 @@ -70,6 +70,8 @@ * Introduced an explicit error condition where pytz is not installed and an attempt is made to inspect Olson time zone information. * Fixed DateSupport to handle NonExistentTimeError. + * Added macro argument quoting functions. + * Fixed the quoting of text presented as an argument to the Verbatim macro. New in MoinSupport 0.4 (Changes since MoinSupport 0.3) ------------------------------------------------------