# HG changeset patch # User Paul Boddie # Date 1362874610 -3600 # Node ID 99b3f4138cc2521d09bfbb2f5f81be8e45eafc4f # Parent eb1e9a4b7aa182f87ed81d54700523dafa9c7a46 Added macro argument parsing from MoinForms and a function to find parsers by content type. Changed the item storage API to use path tuples instead of strings when specifying directories. Introduced support for reverse iteration over stored items. Updated the release notes and version number. diff -r eb1e9a4b7aa1 -r 99b3f4138cc2 ItemSupport.py --- a/ItemSupport.py Mon Feb 18 18:50:02 2013 +0100 +++ b/ItemSupport.py Sun Mar 10 01:16:50 2013 +0100 @@ -149,20 +149,48 @@ "An iterator over items in a store." - def __init__(self, store): + def __init__(self, store, direction=1): self.store = store - self._next = -1 + self.direction = direction + self.reset() + + def reset(self): + if self.direction == 1: + self._next = 0 + self.final = len(self.store) + else: + self._next = len(self.store) - 1 + self.final = 0 + + def more(self): + if self.direction == 1: + return self._next < self.final + else: + return self._next >= self.final + + def get_next(self): + next = self._next + self._next += self.direction + return next def next(self): - final = len(self.store) - - while self._next < final: - self._next += 1 + while self.more(): try: - return self.store[self._next] + return self.store[self.get_next()] except IndexError: pass raise StopIteration + def reverse(self): + self.direction = -self.direction + self.reset() + + def reversed(self): + self.reverse() + return self + + def __iter__(self): + return self + # vim: tabstop=4 expandtab shiftwidth=4 diff -r eb1e9a4b7aa1 -r 99b3f4138cc2 MoinSupport.py --- a/MoinSupport.py Mon Feb 18 18:50:02 2013 +0100 +++ b/MoinSupport.py Sun Mar 10 01:16:50 2013 +0100 @@ -4,7 +4,10 @@ @copyright: 2008, 2009, 2010, 2011, 2012, 2013 by Paul Boddie @copyright: 2000-2004 Juergen Hermann , - 2005-2008 MoinMoin:ThomasWaldmann. + 2004 by Florian Festi, + 2006 by Mikko Virkkil, + 2005-2008 MoinMoin:ThomasWaldmann, + 2007 MoinMoin:ReimarBauer. @license: GNU GPL (v2 or later), see COPYING.txt for details. """ @@ -26,7 +29,7 @@ except ImportError: pass -__version__ = "0.2.1" +__version__ = "0.3" # Extraction of shared fragments. @@ -425,6 +428,33 @@ else: return token +# Macro argument parsing. + +def parseMacroArguments(args): + + """ + Interpret the arguments. To support commas in labels, the label argument + should be quoted. For example: + + "label=No, thanks!" + """ + + try: + parsed_args = args and wikiutil.parse_quoted_separated(args, name_value=False) or [] + except AttributeError: + parsed_args = args.split(",") + + pairs = [] + for arg in parsed_args: + if arg: + pair = arg.split("=", 1) + if len(pair) < 2: + pairs.append((None, arg)) + else: + pairs.append(tuple(pair)) + + return pairs + # Request-related classes and associated functions. class Form: @@ -758,6 +788,48 @@ buf.close() return text +# Finding components for content types. + +def getParsersForContentType(cfg, mimetype): + + """ + Find parsers that support the given 'mimetype', constructing a dictionary + mapping content types to lists of parsers that is then cached in the 'cfg' + object. A list of suitable parsers is returned for 'mimetype'. + """ + + if not hasattr(cfg.cache, "MIMETYPE_TO_PARSER"): + available = {} + + for name in wikiutil.getPlugins("parser", cfg): + + # Import each parser in order to inspect supported content types. + + try: + parser_cls = wikiutil.importPlugin(cfg, "parser", name, "Parser") + except wikiutil.PluginMissingError: + continue + + # Attempt to determine supported content types. + # NOTE: Extensions and /etc/mime.types (or equivalent) could also be + # NOTE: used. + + if hasattr(parser_cls, "input_mimetypes"): + for input_mimetype in parser_cls.input_mimetypes: + if not available.has_key(input_mimetype): + available[input_mimetype] = [] + available[input_mimetype].append(parser_cls) + + # Support some basic parsers. + + elif name == "text_moin_wiki": + available["text/moin-wiki"] = [parser_cls] + available["text/moin"] = [parser_cls] + + cfg.cache.MIMETYPE_TO_PARSER = available + + return cfg.cache.MIMETYPE_TO_PARSER.get(mimetype, []) + # Textual representations. def getSimpleWikiText(text): diff -r eb1e9a4b7aa1 -r 99b3f4138cc2 PKG-INFO --- a/PKG-INFO Mon Feb 18 18:50:02 2013 +0100 +++ b/PKG-INFO Sun Mar 10 01:16:50 2013 +0100 @@ -1,12 +1,12 @@ Metadata-Version: 1.1 Name: MoinSupport -Version: 0.2 +Version: 0.3 Author: Paul Boddie Author-email: paul at boddie org uk Maintainer: Paul Boddie Maintainer-email: paul at boddie org uk Home-page: http://hgweb.boddie.org.uk/MoinSupport -Download-url: http://hgweb.boddie.org.uk/MoinSupport/archive/rel-0-2.tar.bz2 +Download-url: http://hgweb.boddie.org.uk/MoinSupport/archive/rel-0-3.tar.bz2 Summary: Support libraries for MoinMoin extensions License: GPL (version 2 or later) Description: The MoinSupport distribution provides libraries handling datetime diff -r eb1e9a4b7aa1 -r 99b3f4138cc2 README.txt --- a/README.txt Mon Feb 18 18:50:02 2013 +0100 +++ b/README.txt Sun Mar 10 01:16:50 2013 +0100 @@ -64,6 +64,15 @@ If time zone handling is not required, pytz need not be installed. It is, however, highly recommended that pytz be installed. +New in MoinSupport 0.3 (Changes since MoinSupport 0.2) +------------------------------------------------------ + + * Added macro argument parsing from MoinForms and a function to find parsers + by content type. + * Changed the item storage API to use path tuples instead of strings when + specifying directories. + * Introduced support for reverse iteration over stored items. + New in MoinSupport 0.2 (Changes since MoinSupport 0.1) ------------------------------------------------------ diff -r eb1e9a4b7aa1 -r 99b3f4138cc2 setup.py --- a/setup.py Mon Feb 18 18:50:02 2013 +0100 +++ b/setup.py Sun Mar 10 01:16:50 2013 +0100 @@ -8,7 +8,7 @@ author = "Paul Boddie", author_email = "paul@boddie.org.uk", url = "http://hgweb.boddie.org.uk/MoinSupport", - version = "0.2", + version = "0.3", py_modules = ["ContentTypeSupport", "DateSupport", "GeneralSupport", "ItemSupport", "LocationSupport", "MoinDateSupport", "MoinRemoteSupport", "MoinSupport", "ViewSupport"]