1.1 --- a/ItemSupport.py Mon Feb 18 18:50:02 2013 +0100
1.2 +++ b/ItemSupport.py Sun Mar 10 01:16:50 2013 +0100
1.3 @@ -149,20 +149,48 @@
1.4
1.5 "An iterator over items in a store."
1.6
1.7 - def __init__(self, store):
1.8 + def __init__(self, store, direction=1):
1.9 self.store = store
1.10 - self._next = -1
1.11 + self.direction = direction
1.12 + self.reset()
1.13 +
1.14 + def reset(self):
1.15 + if self.direction == 1:
1.16 + self._next = 0
1.17 + self.final = len(self.store)
1.18 + else:
1.19 + self._next = len(self.store) - 1
1.20 + self.final = 0
1.21 +
1.22 + def more(self):
1.23 + if self.direction == 1:
1.24 + return self._next < self.final
1.25 + else:
1.26 + return self._next >= self.final
1.27 +
1.28 + def get_next(self):
1.29 + next = self._next
1.30 + self._next += self.direction
1.31 + return next
1.32
1.33 def next(self):
1.34 - final = len(self.store)
1.35 -
1.36 - while self._next < final:
1.37 - self._next += 1
1.38 + while self.more():
1.39 try:
1.40 - return self.store[self._next]
1.41 + return self.store[self.get_next()]
1.42 except IndexError:
1.43 pass
1.44
1.45 raise StopIteration
1.46
1.47 + def reverse(self):
1.48 + self.direction = -self.direction
1.49 + self.reset()
1.50 +
1.51 + def reversed(self):
1.52 + self.reverse()
1.53 + return self
1.54 +
1.55 + def __iter__(self):
1.56 + return self
1.57 +
1.58 # vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/MoinSupport.py Mon Feb 18 18:50:02 2013 +0100
2.2 +++ b/MoinSupport.py Sun Mar 10 01:16:50 2013 +0100
2.3 @@ -4,7 +4,10 @@
2.4
2.5 @copyright: 2008, 2009, 2010, 2011, 2012, 2013 by Paul Boddie <paul@boddie.org.uk>
2.6 @copyright: 2000-2004 Juergen Hermann <jh@web.de>,
2.7 - 2005-2008 MoinMoin:ThomasWaldmann.
2.8 + 2004 by Florian Festi,
2.9 + 2006 by Mikko Virkkil,
2.10 + 2005-2008 MoinMoin:ThomasWaldmann,
2.11 + 2007 MoinMoin:ReimarBauer.
2.12 @license: GNU GPL (v2 or later), see COPYING.txt for details.
2.13 """
2.14
2.15 @@ -26,7 +29,7 @@
2.16 except ImportError:
2.17 pass
2.18
2.19 -__version__ = "0.2.1"
2.20 +__version__ = "0.3"
2.21
2.22 # Extraction of shared fragments.
2.23
2.24 @@ -425,6 +428,33 @@
2.25 else:
2.26 return token
2.27
2.28 +# Macro argument parsing.
2.29 +
2.30 +def parseMacroArguments(args):
2.31 +
2.32 + """
2.33 + Interpret the arguments. To support commas in labels, the label argument
2.34 + should be quoted. For example:
2.35 +
2.36 + "label=No, thanks!"
2.37 + """
2.38 +
2.39 + try:
2.40 + parsed_args = args and wikiutil.parse_quoted_separated(args, name_value=False) or []
2.41 + except AttributeError:
2.42 + parsed_args = args.split(",")
2.43 +
2.44 + pairs = []
2.45 + for arg in parsed_args:
2.46 + if arg:
2.47 + pair = arg.split("=", 1)
2.48 + if len(pair) < 2:
2.49 + pairs.append((None, arg))
2.50 + else:
2.51 + pairs.append(tuple(pair))
2.52 +
2.53 + return pairs
2.54 +
2.55 # Request-related classes and associated functions.
2.56
2.57 class Form:
2.58 @@ -758,6 +788,48 @@
2.59 buf.close()
2.60 return text
2.61
2.62 +# Finding components for content types.
2.63 +
2.64 +def getParsersForContentType(cfg, mimetype):
2.65 +
2.66 + """
2.67 + Find parsers that support the given 'mimetype', constructing a dictionary
2.68 + mapping content types to lists of parsers that is then cached in the 'cfg'
2.69 + object. A list of suitable parsers is returned for 'mimetype'.
2.70 + """
2.71 +
2.72 + if not hasattr(cfg.cache, "MIMETYPE_TO_PARSER"):
2.73 + available = {}
2.74 +
2.75 + for name in wikiutil.getPlugins("parser", cfg):
2.76 +
2.77 + # Import each parser in order to inspect supported content types.
2.78 +
2.79 + try:
2.80 + parser_cls = wikiutil.importPlugin(cfg, "parser", name, "Parser")
2.81 + except wikiutil.PluginMissingError:
2.82 + continue
2.83 +
2.84 + # Attempt to determine supported content types.
2.85 + # NOTE: Extensions and /etc/mime.types (or equivalent) could also be
2.86 + # NOTE: used.
2.87 +
2.88 + if hasattr(parser_cls, "input_mimetypes"):
2.89 + for input_mimetype in parser_cls.input_mimetypes:
2.90 + if not available.has_key(input_mimetype):
2.91 + available[input_mimetype] = []
2.92 + available[input_mimetype].append(parser_cls)
2.93 +
2.94 + # Support some basic parsers.
2.95 +
2.96 + elif name == "text_moin_wiki":
2.97 + available["text/moin-wiki"] = [parser_cls]
2.98 + available["text/moin"] = [parser_cls]
2.99 +
2.100 + cfg.cache.MIMETYPE_TO_PARSER = available
2.101 +
2.102 + return cfg.cache.MIMETYPE_TO_PARSER.get(mimetype, [])
2.103 +
2.104 # Textual representations.
2.105
2.106 def getSimpleWikiText(text):
3.1 --- a/PKG-INFO Mon Feb 18 18:50:02 2013 +0100
3.2 +++ b/PKG-INFO Sun Mar 10 01:16:50 2013 +0100
3.3 @@ -1,12 +1,12 @@
3.4 Metadata-Version: 1.1
3.5 Name: MoinSupport
3.6 -Version: 0.2
3.7 +Version: 0.3
3.8 Author: Paul Boddie
3.9 Author-email: paul at boddie org uk
3.10 Maintainer: Paul Boddie
3.11 Maintainer-email: paul at boddie org uk
3.12 Home-page: http://hgweb.boddie.org.uk/MoinSupport
3.13 -Download-url: http://hgweb.boddie.org.uk/MoinSupport/archive/rel-0-2.tar.bz2
3.14 +Download-url: http://hgweb.boddie.org.uk/MoinSupport/archive/rel-0-3.tar.bz2
3.15 Summary: Support libraries for MoinMoin extensions
3.16 License: GPL (version 2 or later)
3.17 Description: The MoinSupport distribution provides libraries handling datetime
4.1 --- a/README.txt Mon Feb 18 18:50:02 2013 +0100
4.2 +++ b/README.txt Sun Mar 10 01:16:50 2013 +0100
4.3 @@ -64,6 +64,15 @@
4.4 If time zone handling is not required, pytz need not be installed. It is,
4.5 however, highly recommended that pytz be installed.
4.6
4.7 +New in MoinSupport 0.3 (Changes since MoinSupport 0.2)
4.8 +------------------------------------------------------
4.9 +
4.10 + * Added macro argument parsing from MoinForms and a function to find parsers
4.11 + by content type.
4.12 + * Changed the item storage API to use path tuples instead of strings when
4.13 + specifying directories.
4.14 + * Introduced support for reverse iteration over stored items.
4.15 +
4.16 New in MoinSupport 0.2 (Changes since MoinSupport 0.1)
4.17 ------------------------------------------------------
4.18
5.1 --- a/setup.py Mon Feb 18 18:50:02 2013 +0100
5.2 +++ b/setup.py Sun Mar 10 01:16:50 2013 +0100
5.3 @@ -8,7 +8,7 @@
5.4 author = "Paul Boddie",
5.5 author_email = "paul@boddie.org.uk",
5.6 url = "http://hgweb.boddie.org.uk/MoinSupport",
5.7 - version = "0.2",
5.8 + version = "0.3",
5.9 py_modules = ["ContentTypeSupport", "DateSupport", "GeneralSupport",
5.10 "ItemSupport", "LocationSupport", "MoinDateSupport",
5.11 "MoinRemoteSupport", "MoinSupport", "ViewSupport"]