# HG changeset patch # User Paul Boddie # Date 1369958873 -7200 # Node ID 965d1f6ff37ae7611b78092ec527e85674ba3259 # Parent 301f91b05129731fc0737fabb049901681d33719 Added a common wikidict entry parsing function. diff -r 301f91b05129 -r 965d1f6ff37a MoinSupport.py --- a/MoinSupport.py Fri May 17 20:22:39 2013 +0200 +++ b/MoinSupport.py Fri May 31 02:07:53 2013 +0200 @@ -456,6 +456,47 @@ return pairs +def parseDictEntry(entry, unqualified=None): + + """ + Return the parameters specified by the given dict 'entry' string. The + optional 'unqualified' parameter can be used to indicate parameters that + need not be specified together with a keyword and can therefore be populated + in the given order as such unqualified parameters are encountered. + + NOTE: This is similar to parseMacroArguments but employs space as a + NOTE: separator and attempts to assign unqualified parameters. + """ + + parameters = {} + unqualified = unqualified or () + + try: + parsed_args = entry and wikiutil.parse_quoted_separated(entry, separator=None, name_value=False) or [] + except AttributeError: + parsed_args = entry.split() + + for arg in parsed_args: + try: + argname, argvalue = arg.split("=", 1) + + # Detect unlikely parameter names. + + if not argname.isalpha(): + raise ValueError + + parameters[argname] = argvalue + + # Unqualified parameters are assumed to be one of a recognised set. + + except ValueError: + for argname in unqualified: + if not parameters.has_key(argname): + parameters[argname] = arg + break + + return parameters + # Request-related classes and associated functions. class Form: diff -r 301f91b05129 -r 965d1f6ff37a README.txt --- a/README.txt Fri May 17 20:22:39 2013 +0200 +++ b/README.txt Fri May 31 02:07:53 2013 +0200 @@ -73,6 +73,7 @@ datetime parsing support. * Fixed the time zone information associated with page revisions. * Added RFC 2822 datetime parsing with help from the email.utils module. + * Added a common wikidict entry parsing function. New in MoinSupport 0.3 (Changes since MoinSupport 0.2) ------------------------------------------------------