# HG changeset patch # User Paul Boddie # Date 1334704678 -7200 # Node ID 72dcf13893765134448eea5a49690940523b6970 # Parent 7d4112f58a8502bf309184e05bed227be9cb9076 Added section argument processing functions (from ImprovedTableParser). Added a current time function. Updated the release notes and version number. diff -r 7d4112f58a85 -r 72dcf1389376 DateSupport.py --- a/DateSupport.py Mon Apr 02 20:17:59 2012 +0200 +++ b/DateSupport.py Wed Apr 18 01:17:58 2012 +0200 @@ -910,14 +910,14 @@ def getCurrentDate(): - "Return the current date as a (year, month, day) tuple." + "Return the current date as a Date instance." today = datetime.date.today() return Date((today.year, today.month, today.day)) def getCurrentMonth(): - "Return the current month as a (year, month) tuple." + "Return the current month as a Month instance." today = datetime.date.today() return Month((today.year, today.month)) @@ -929,4 +929,11 @@ today = datetime.date.today() return today.year +def getCurrentTime(): + + "Return the current time as a DateTime instance." + + now = datetime.datetime.utcnow() + return DateTime((now.year, now.month, now.day, now.hour, now.minute, now.second, "UTC")) + # vim: tabstop=4 expandtab shiftwidth=4 diff -r 7d4112f58a85 -r 72dcf1389376 MoinSupport.py --- a/MoinSupport.py Mon Apr 02 20:17:59 2012 +0200 +++ b/MoinSupport.py Wed Apr 18 01:17:58 2012 +0200 @@ -11,10 +11,12 @@ from DateSupport import * from MoinMoin.Page import Page from MoinMoin import wikiutil +from StringIO import StringIO +from shlex import shlex import re import time -__version__ = "0.1" +__version__ = "0.2" # Content type parsing. @@ -47,6 +49,65 @@ else: return int(x) +def parseAttributes(s, escape=True): + + """ + Parse the section attributes string 's', returning a mapping of names to + values. If 'escape' is set to a true value, the attributes will be suitable + for use with the formatter API. If 'escape' is set to a false value, the + attributes will have any quoting removed. + """ + + attrs = {} + f = StringIO(s) + name = None + need_value = False + + for token in shlex(f): + + # Capture the name if needed. + + if name is None: + name = escape and wikiutil.escape(token) or strip_token(token) + + # Detect either an equals sign or another name. + + elif not need_value: + if token == "=": + need_value = True + else: + attrs[name.lower()] = escape and "true" or True + name = wikiutil.escape(token) + + # Otherwise, capture a value. + + else: + # Quoting of attributes done similarly to wikiutil.parseAttributes. + + if token: + if escape: + if token[0] in ("'", '"'): + token = wikiutil.escape(token) + else: + token = '"%s"' % wikiutil.escape(token, 1) + else: + token = strip_token(token) + + attrs[name.lower()] = token + name = None + need_value = False + + return attrs + +def strip_token(token): + + "Return the given 'token' stripped of quoting." + + if token[0] in ("'", '"') and token[-1] == token[0]: + return token[1:-1] + else: + return token + # Utility classes and associated functions. class Form: diff -r 7d4112f58a85 -r 72dcf1389376 PKG-INFO --- a/PKG-INFO Mon Apr 02 20:17:59 2012 +0200 +++ b/PKG-INFO Wed Apr 18 01:17:58 2012 +0200 @@ -1,12 +1,12 @@ Metadata-Version: 1.1 Name: MoinSupport -Version: 0.1 +Version: 0.2 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-1.tar.bz2 +Download-url: http://hgweb.boddie.org.uk/MoinSupport/archive/rel-0-2.tar.bz2 Summary: Support libraries for MoinMoin extensions License: GPL (version 2 or later) Description: The MoinSupport distribution provides libraries handling datetime diff -r 7d4112f58a85 -r 72dcf1389376 README.txt --- a/README.txt Mon Apr 02 20:17:59 2012 +0200 +++ b/README.txt Wed Apr 18 01:17:58 2012 +0200 @@ -62,6 +62,13 @@ 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.2 (Changes since MoinSupport 0.1) +------------------------------------------------------ + + * Added section argument processing functions from the ImprovedTableParser + distribution to MoinSupport. + * Added a getCurrentTime function to DateSupport. + Release Procedures ------------------ diff -r 7d4112f58a85 -r 72dcf1389376 setup.py --- a/setup.py Mon Apr 02 20:17:59 2012 +0200 +++ b/setup.py Wed Apr 18 01:17:58 2012 +0200 @@ -8,6 +8,6 @@ author = "Paul Boddie", author_email = "paul@boddie.org.uk", url = "http://hgweb.boddie.org.uk/MoinSupport", - version = "0.1", + version = "0.2", py_modules = ["DateSupport", "LocationSupport", "MoinDateSupport", "MoinSupport"] )