# cwmx_ext.py # # Copyright © 2000, 2002 Carey Evans. # # Permission to use, copy, modify, and distribute this software and # its documentation for any purpose and without fee is hereby granted, # provided that the above copyright notice appear in all copies and # that both that copyright notice and this permission notice appear in # supporting documentation. """cwmx_ext.py XSLT extension functions for CWML. """ import cPickle from mx import DateTime from xml.dom import ext from xml.xpath import Conversions from xml.xslt import XsltElement from xml.xslt.AttributeValueTemplate import AttributeValueTemplate # Format for date and time strings. datefmt = '%a, %_d %B %Y' timefmt = datefmt + ' %_I:%M %p' # URI for CWML build extensions. CWMX_URI = 'http://home.clear.net.nz/pages/c.evans/xml/cwmx' def ext_isotime(context, date): s = Conversions.StringValue(date) if s[0] == 'D': s = s[1:] dt = DateTime.ISO.ParseDateTime(s) if 'T' in s: return dt.Format(timefmt) else: return dt.Format(datefmt) ExtFunctions = { (CWMX_URI, 'isotime'): ext_isotime, }