# HG changeset patch # User Paul Boddie # Date 1381597822 -7200 # Node ID 8d385ce66bd045580f48232bcca6f2ff4469ea2b # Parent c054b733d0466b18001c7047dfc12f7a37a72041 Added macro argument quoting functions. diff -r c054b733d046 -r 8d385ce66bd0 MoinSupport.py --- a/MoinSupport.py Fri Oct 11 08:29:45 2013 +0200 +++ b/MoinSupport.py Sat Oct 12 19:10:22 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: diff -r c054b733d046 -r 8d385ce66bd0 README.txt --- a/README.txt Fri Oct 11 08:29:45 2013 +0200 +++ b/README.txt Sat Oct 12 19:10:22 2013 +0200 @@ -70,6 +70,7 @@ * 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. New in MoinSupport 0.4 (Changes since MoinSupport 0.3) ------------------------------------------------------