[Checkins] SVN: van.timeformat/ Initial import

Brian Sutherland jinty at web.de
Thu Nov 20 18:50:43 EST 2008


Log message for revision 93200:
  Initial import

Changed:
  A   van.timeformat/
  A   van.timeformat/trunk/
  A   van.timeformat/trunk/CHANGES.txt
  A   van.timeformat/trunk/ZopePublicLicense.txt
  A   van.timeformat/trunk/buildout.cfg
  A   van.timeformat/trunk/setup.py
  A   van.timeformat/trunk/van/
  A   van.timeformat/trunk/van/__init__.py
  A   van.timeformat/trunk/van/timeformat/
  A   van.timeformat/trunk/van/timeformat/README.txt
  A   van.timeformat/trunk/van/timeformat/__init__.py
  A   van.timeformat/trunk/van/timeformat/configure.zcml
  A   van.timeformat/trunk/van/timeformat/ftesting.zcml
  A   van.timeformat/trunk/van/timeformat/interfaces.py
  A   van.timeformat/trunk/van/timeformat/meta.zcml
  A   van.timeformat/trunk/van/timeformat/tales.py
  A   van.timeformat/trunk/van/timeformat/tests.py
  A   van.timeformat/trunk/van/timeformat/zcml.py
  A   van.timeformat/trunk/van/timeformat/zpt.txt

-=-
Added: van.timeformat/trunk/CHANGES.txt
===================================================================
--- van.timeformat/trunk/CHANGES.txt	                        (rev 0)
+++ van.timeformat/trunk/CHANGES.txt	2008-11-20 23:50:42 UTC (rev 93200)
@@ -0,0 +1,7 @@
+Changes
+=======
+
+1.0.0 (Unreleased)
+------------------
+
+- Initial Release


Property changes on: van.timeformat/trunk/CHANGES.txt
___________________________________________________________________
Added: svn:eol-style
   + native

Added: van.timeformat/trunk/ZopePublicLicense.txt
===================================================================
--- van.timeformat/trunk/ZopePublicLicense.txt	                        (rev 0)
+++ van.timeformat/trunk/ZopePublicLicense.txt	2008-11-20 23:50:42 UTC (rev 93200)
@@ -0,0 +1,54 @@
+Zope Public License (ZPL) Version 2.1
+-------------------------------------
+
+A copyright notice accompanies this license document that
+identifies the copyright holders.
+
+This license has been certified as open source. It has also
+been designated as GPL compatible by the Free Software
+Foundation (FSF).
+
+Redistribution and use in source and binary forms, with or
+without modification, are permitted provided that the
+following conditions are met:
+
+1. Redistributions in source code must retain the
+   accompanying copyright notice, this list of conditions,
+   and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the accompanying
+   copyright notice, this list of conditions, and the
+   following disclaimer in the documentation and/or other
+   materials provided with the distribution.
+
+3. Names of the copyright holders must not be used to
+   endorse or promote products derived from this software
+   without prior written permission from the copyright
+   holders.
+
+4. The right to distribute this software or to use it for
+   any purpose does not give you the right to use
+   Servicemarks (sm) or Trademarks (tm) of the copyright
+   holders. Use of them is covered by separate agreement
+   with the copyright holders.
+
+5. If any files are modified, you must cause the modified
+   files to carry prominent notices stating that you changed
+   the files and the date of any change.
+
+Disclaimer
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS''
+  AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+  NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+  AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
+  NO EVENT SHALL THE COPYRIGHT HOLDERS BE
+  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+  DAMAGE.


Property changes on: van.timeformat/trunk/ZopePublicLicense.txt
___________________________________________________________________
Added: svn:eol-style
   + native

Added: van.timeformat/trunk/buildout.cfg
===================================================================
--- van.timeformat/trunk/buildout.cfg	                        (rev 0)
+++ van.timeformat/trunk/buildout.cfg	2008-11-20 23:50:42 UTC (rev 93200)
@@ -0,0 +1,9 @@
+[buildout]
+parts = test
+develop = .
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = van.timeformat
+       zope.app.pagetemplate [test]
+defaults = ['-m', 'van.timeformat']

Added: van.timeformat/trunk/setup.py
===================================================================
--- van.timeformat/trunk/setup.py	                        (rev 0)
+++ van.timeformat/trunk/setup.py	2008-11-20 23:50:42 UTC (rev 93200)
@@ -0,0 +1,52 @@
+##############################################################################
+#
+# Copyright (c) 2008 Vanguardistas LLC.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+
+import os
+from setuptools import setup, find_packages
+
+long_description = (
+    '.. contents::\n\n'
+    + open(os.path.join('van', 'timeformat', 'README.txt')).read()
+    + '\n\n'
+    + open(os.path.join('van', 'timeformat', 'zpt.txt')).read()
+    + '\n\n'
+    + open(os.path.join('CHANGES.txt')).read()
+    )
+
+setup(name="van.timeformat",
+      version='1.0.0dev',
+      license='ZPL 2.1',
+      url='http://pypi.python.org/pypi/van.timeformat',
+      packages=find_packages(),
+      author="Vanguardistas LLC",
+      description="Convienience functions for formatting dates/times using zope.i18n and TAL",
+      namespace_packages=["van"],
+      install_requires = [
+          'setuptools',
+          'van.testing',
+          'zope.i18n',
+          ],
+    classifiers=[
+        'Environment :: Web Environment',
+        'Intended Audience :: Developers',
+        'License :: OSI Approved :: Zope Public License',
+        'Programming Language :: Python',
+        'Topic :: Internet :: WWW/HTTP',
+        'Framework :: Zope3',
+        'Development Status :: 5 - Production/Stable',
+        ],
+      long_description=long_description,
+      include_package_data = True,
+      zip_safe = False,
+      )


Property changes on: van.timeformat/trunk/setup.py
___________________________________________________________________
Added: svn:eol-style
   + native

Added: van.timeformat/trunk/van/__init__.py
===================================================================
--- van.timeformat/trunk/van/__init__.py	                        (rev 0)
+++ van.timeformat/trunk/van/__init__.py	2008-11-20 23:50:42 UTC (rev 93200)
@@ -0,0 +1,3 @@
+# this is a namespace package
+import pkg_resources
+pkg_resources.declare_namespace(__name__)


Property changes on: van.timeformat/trunk/van/__init__.py
___________________________________________________________________
Added: svn:eol-style
   + native

Added: van.timeformat/trunk/van/timeformat/README.txt
===================================================================
--- van.timeformat/trunk/van/timeformat/README.txt	                        (rev 0)
+++ van.timeformat/trunk/van/timeformat/README.txt	2008-11-20 23:50:42 UTC (rev 93200)
@@ -0,0 +1,141 @@
+Python Format Functions
+=======================
+
+The van.timefmt module is a support module for date/time specific operations.
+
+    >>> from datetime import date, datetime
+    >>> mydate = date(1975, 12, 17)
+    >>> mydatetime = datetime(1975, 12, 17, 5, 24, 36)
+
+It provides a "timefmt" function which can take either a date or datetime object:
+
+    >>> from van.timeformat import ltimefmt, timefmt
+
+Fixed formatting
+----------------
+
+Fixed formats are locale independant. They are useful in 2 situations:
+
+* Computer parsable dates
+* Projects with no localization requirement
+
+default formatting
+++++++++++++++++++
+
+If no format argument is specified, dates and datetimes are formatted using .isoformat(" "):
+
+    >>> print timefmt(mydatetime)
+    1975-12-17 05:24:36
+
+    >>> print timefmt(mydate)
+    1975-12-17
+
+The 'iso' format also triggers this:
+    
+    >>> print timefmt(mydatetime, format='iso')
+    1975-12-17 05:24:36
+
+rfc2822
++++++++
+
+The date in compliance with the RFC 2822 Internet email standard.
+
+    >>> print timefmt(mydate, 'rfc2822')
+    Wed, 17 Dec 1975 00:00:00 +0000
+
+    >>> print timefmt(mydatetime, 'rfc2822')
+    Wed, 17 Dec 1975 05:24:36 +0000
+
+
+Extending formats
++++++++++++++++++
+
+If we want to extend the list of formats available, we can use the
+"time_format" zcml command defined in this module's meta.zcml.
+
+An example of use is in configure.zcml where the rfc2822 format is defined.
+
+Note: it's probably a good idea to use namespaces for registrations. The
+van.timeformat module promises to not use "." in any of it's default
+registrations.
+
+Unicode
++++++++
+
+The return type is a unicode string:
+
+    >>> timefmt(mydatetime)
+    u'1975-12-17 05:24:36'
+
+And we can have unicode in the formats:
+
+    >>> timefmt(mydatetime, format='unicode_test')
+    u'1975-17-12 Extended Arabic-Indic Digit Seven: \u06f7:'
+
+Locale dependant translations
+-----------------------------
+
+    >>> from zope.i18n.locales import locales
+    >>> german = locales.getLocale('de', 'de')
+    >>> us = locales.getLocale('en', 'us')
+    >>> britain = locales.getLocale('en', 'gb')
+
+Returns unicode:
+
+    >>> ltimefmt(mydate, us)
+    u'Dec 17, 1975'
+
+Defaults correctly chosen for date and datetime:
+
+    >>> print ltimefmt(mydate, us)
+    Dec 17, 1975
+    >>> print ltimefmt(mydatetime, us)
+    Dec 17, 1975 5:24:36 AM
+
+But we can force format one as the other:
+
+    >>> print ltimefmt(mydate, us, category="dateTime")
+    Dec 17, 1975 12:00:00 AM
+    >>> print ltimefmt(mydatetime, us, category="date")
+    Dec 17, 1975
+
+Localized:
+
+    >>> print ltimefmt(mydate, britain, category="date", length="long")
+    17 December 1975
+    >>> print ltimefmt(mydate, german, category="date", length="long")
+    17. Dezember 1975
+
+
+Localized formatting examples
++++++++++++++++++++++++++++++
+
+Short dates:
+
+    >>> print ltimefmt(mydate, us, category="date", length="short")
+    12/17/75
+
+Medium Dates:
+
+    >>> print ltimefmt(mydate, us, category="date", length="medium")
+    Dec 17, 1975
+
+Long Dates:
+
+    >>> print ltimefmt(mydate, us, category="date", length="long")
+    December 17, 1975
+
+Short Datetimes:
+
+    >>> print ltimefmt(mydatetime, us, category="dateTime", length="short")
+    12/17/75 5:24 AM
+
+Medium Datetimes:
+
+    >>> print ltimefmt(mydatetime, us, category="dateTime", length="medium")
+    Dec 17, 1975 5:24:36 AM
+
+Long Datetimes:
+
+    >>> print ltimefmt(mydatetime, us, category="dateTime", length="long")
+    December 17, 1975 5:24:36 AM +000


Property changes on: van.timeformat/trunk/van/timeformat/README.txt
___________________________________________________________________
Added: svn:eol-style
   + native

Added: van.timeformat/trunk/van/timeformat/__init__.py
===================================================================
--- van.timeformat/trunk/van/timeformat/__init__.py	                        (rev 0)
+++ van.timeformat/trunk/van/timeformat/__init__.py	2008-11-20 23:50:42 UTC (rev 93200)
@@ -0,0 +1,39 @@
+##############################################################################
+#
+# Copyright (c) 2008 Vanguardistas LLC.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+from datetime import datetime, date
+from zope.component import getUtility
+
+from van.timeformat.interfaces import ITimeFormat
+
+def timefmt(obj, format='iso'):
+    assert isinstance(obj, date), "format only accepts date or datetime objects"
+    if format == 'iso':
+        if isinstance(obj, datetime):
+            s = obj.isoformat(sep=" ")
+        else:
+            s = obj.isoformat()
+    else:
+        format = getUtility(ITimeFormat, name=format).format
+        format = format.encode('utf-8')
+        s = obj.strftime(format).decode('utf-8')
+    return unicode(s)
+
+def ltimefmt(obj, locale, category=None, length=None):
+    if category is None:
+        if isinstance(obj, datetime):
+            category = 'dateTime'
+        elif isinstance(obj, date):
+            category = 'date'
+    formatter = locale.dates.getFormatter(category, length=length)
+    return formatter.format(obj)


Property changes on: van.timeformat/trunk/van/timeformat/__init__.py
___________________________________________________________________
Added: svn:eol-style
   + native

Added: van.timeformat/trunk/van/timeformat/configure.zcml
===================================================================
--- van.timeformat/trunk/van/timeformat/configure.zcml	                        (rev 0)
+++ van.timeformat/trunk/van/timeformat/configure.zcml	2008-11-20 23:50:42 UTC (rev 93200)
@@ -0,0 +1,28 @@
+<configure
+    xmlns="http://namespaces.zope.org/zope"
+    xmlns:zcml="http://namespaces.zope.org/zcml"
+    xmlns:tales="http://namespaces.zope.org/tales"
+    xmlns:v="http://namespaces.vanguardistas.net/vanguardistas"
+    >
+
+  <configure zcml:condition="installed zope.app.pagetemplate">
+
+    <tales:expressiontype
+        name="timefmt"
+        handler=".tales.TimeFormatExpr"
+        />
+
+    <tales:expressiontype
+        name="ltimefmt"
+        handler=".tales.LocalTimeFormatExpr"
+        />
+
+  </configure>
+
+  <v:time_format
+      name='rfc2822'
+      format="%a, %d %b %Y %H:%M:%S +0000"
+      />
+
+</configure>
+


Property changes on: van.timeformat/trunk/van/timeformat/configure.zcml
___________________________________________________________________
Added: svn:eol-style
   + native

Added: van.timeformat/trunk/van/timeformat/ftesting.zcml
===================================================================
--- van.timeformat/trunk/van/timeformat/ftesting.zcml	                        (rev 0)
+++ van.timeformat/trunk/van/timeformat/ftesting.zcml	2008-11-20 23:50:42 UTC (rev 93200)
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configure
+    xmlns="http://namespaces.zope.org/zope"
+    xmlns:zcml="http://namespaces.zope.org/zcml"
+    xmlns:v="http://namespaces.vanguardistas.net/vanguardistas"
+    >
+
+  <include zcml:condition="installed zope.app.pagetemplate"
+      package="zope.app.pagetemplate"
+      file="ftesting.zcml"/>
+
+  <include package="van.timeformat" file="meta.zcml"/>
+  <include package="van.timeformat"/>
+  
+  <v:time_format
+      name='unicode_test'
+      format="%Y-%d-%m Extended Arabic-Indic Digit Seven: Û·:"
+      />
+
+
+</configure>


Property changes on: van.timeformat/trunk/van/timeformat/ftesting.zcml
___________________________________________________________________
Added: svn:eol-style
   + native

Added: van.timeformat/trunk/van/timeformat/interfaces.py
===================================================================
--- van.timeformat/trunk/van/timeformat/interfaces.py	                        (rev 0)
+++ van.timeformat/trunk/van/timeformat/interfaces.py	2008-11-20 23:50:42 UTC (rev 93200)
@@ -0,0 +1,19 @@
+##############################################################################
+#
+# Copyright (c) 2008 Vanguardistas LLC.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+from zope.interface import Interface
+from zope.schema import TextLine
+
+class ITimeFormat(Interface):
+
+    format = TextLine(title=u"A format string suitable for strftime")


Property changes on: van.timeformat/trunk/van/timeformat/interfaces.py
___________________________________________________________________
Added: svn:eol-style
   + native

Added: van.timeformat/trunk/van/timeformat/meta.zcml
===================================================================
--- van.timeformat/trunk/van/timeformat/meta.zcml	                        (rev 0)
+++ van.timeformat/trunk/van/timeformat/meta.zcml	2008-11-20 23:50:42 UTC (rev 93200)
@@ -0,0 +1,11 @@
+<configure
+    xmlns="http://namespaces.zope.org/zope"
+    xmlns:meta="http://namespaces.zope.org/meta">
+
+  <meta:directive
+      name="time_format"
+      namespace="http://namespaces.vanguardistas.net/vanguardistas"
+      schema=".zcml.ITimeFormatDirective"
+      handler=".zcml.time_format"/>
+
+</configure>


Property changes on: van.timeformat/trunk/van/timeformat/meta.zcml
___________________________________________________________________
Added: svn:eol-style
   + native

Added: van.timeformat/trunk/van/timeformat/tales.py
===================================================================
--- van.timeformat/trunk/van/timeformat/tales.py	                        (rev 0)
+++ van.timeformat/trunk/van/timeformat/tales.py	2008-11-20 23:50:42 UTC (rev 93200)
@@ -0,0 +1,60 @@
+##############################################################################
+#
+# Copyright (c) 2008 Vanguardistas LLC.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""ZPT integration for time formatting"""
+
+from van.timeformat import timefmt, ltimefmt
+
+from zope.tales.expressions import PathExpr
+
+class LocalTimeFormatExpr(object):
+
+    def __init__(self, name, expr, engine):
+        self._name = name
+        self._s = expr
+        cat, length = expr.split(':')[:2]
+        self._category = cat.strip()
+        self._length = length.strip()
+        var_expr = ':'.join(expr.split(':')[2:])
+        self._var_expr = engine.compile(var_expr)
+
+    def __call__(self, econtext):
+        locale = econtext.vars['request'].locale
+        ob = self._var_expr(econtext)
+        return ltimefmt(ob, locale=locale, category=self._category, length=self._length)
+
+    def __str__(self):
+        return '%s expression (%s)' % (self._name, self._s)
+
+    def __repr__(self):
+        return '<LocaliTimeFormatExpr %s:%s>' % (self._name, self._s)
+
+
+class TimeFormatExpr(object):
+
+    def __init__(self, name, expr, engine):
+        self._name = name
+        self._s = expr
+        self._format = expr.split(':')[0].strip()
+        var_expr = ':'.join(expr.split(':')[1:])
+        self._var_expr = engine.compile(var_expr)
+
+    def __call__(self, econtext):
+        ob = self._var_expr(econtext)
+        return timefmt(ob, format=self._format)
+
+    def __str__(self):
+        return '%s expression (%s)' % (self._name, self._s)
+
+    def __repr__(self):
+        return '<TimeFormatExpr %s:%s>' % (self._name, self._s)


Property changes on: van.timeformat/trunk/van/timeformat/tales.py
___________________________________________________________________
Added: svn:eol-style
   + native

Added: van.timeformat/trunk/van/timeformat/tests.py
===================================================================
--- van.timeformat/trunk/van/timeformat/tests.py	                        (rev 0)
+++ van.timeformat/trunk/van/timeformat/tests.py	2008-11-20 23:50:42 UTC (rev 93200)
@@ -0,0 +1,41 @@
+##############################################################################
+#
+# Copyright (c) 2008 Vanguardistas LLC.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+import os
+import unittest
+from doctest import DocFileSuite
+
+from van.testing.layer import zcml_layer
+
+class ZCMLLayer:
+    zcml = os.path.join(os.path.dirname(__file__), 'ftesting.zcml')
+zcml_layer(ZCMLLayer)
+
+have_zpt = True
+try:
+    import zope.app.pagetemplate
+except ImportError:
+    have_zpt = False
+
+def test_suite():
+    suite = unittest.TestSuite()
+    test = DocFileSuite('README.txt')
+    test.layer = ZCMLLayer
+    suite.addTest(test)
+    if have_zpt:
+        zpt_test = DocFileSuite('zpt.txt')
+        zpt_test.layer = ZCMLLayer
+        suite.addTest(zpt_test)
+    return suite
+
+


Property changes on: van.timeformat/trunk/van/timeformat/tests.py
___________________________________________________________________
Added: svn:eol-style
   + native

Added: van.timeformat/trunk/van/timeformat/zcml.py
===================================================================
--- van.timeformat/trunk/van/timeformat/zcml.py	                        (rev 0)
+++ van.timeformat/trunk/van/timeformat/zcml.py	2008-11-20 23:50:42 UTC (rev 93200)
@@ -0,0 +1,33 @@
+##############################################################################
+#
+# Copyright (c) 2008 Vanguardistas LLC.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+from zope.interface import implements
+from zope.component.zcml import utility
+from zope.schema import TextLine
+
+from van.timeformat.interfaces import ITimeFormat
+
+class TimeFormat:
+
+    implements(ITimeFormat)
+
+    def __init__(self, format):
+        self.format = format
+
+class ITimeFormatDirective(ITimeFormat):
+
+    name = TextLine(title=u"The name of the time format")
+
+def time_format(context, name, format):
+    format = TimeFormat(format)
+    utility(context, component=format, name=name, provides=ITimeFormat)


Property changes on: van.timeformat/trunk/van/timeformat/zcml.py
___________________________________________________________________
Added: svn:eol-style
   + native

Added: van.timeformat/trunk/van/timeformat/zpt.txt
===================================================================
--- van.timeformat/trunk/van/timeformat/zpt.txt	                        (rev 0)
+++ van.timeformat/trunk/van/timeformat/zpt.txt	2008-11-20 23:50:42 UTC (rev 93200)
@@ -0,0 +1,67 @@
+Integration with ZPT
+====================
+
+If the zope.app.pagetemplate module is available, the timeformat module will integrate itself with it:
+
+    >>> import os
+    >>> import tempfile
+    >>> from zope.publisher.browser import TestRequest
+
+    >>> temp_file = tempfile.mkstemp()[1]
+    >>> open(temp_file, 'w').write("""
+    ... <html>
+    ...   <body tal:define="mydatetime python:modules['datetime'].datetime(1975, 12, 17, 5, 24, 36)">
+    ...       RFC 2822 date         : <span tal:replace="timefmt:rfc2822:mydatetime" />
+    ...       Medium Date           : <span tal:replace="ltimefmt:date:medium:mydatetime" />
+    ...       Medium DateTime       : <span tal:replace="ltimefmt:dateTime:medium:mydatetime" />
+    ...       Python Expr (ltimefmt): <span tal:replace="ltimefmt:dateTime:long:python:modules['datetime'].date(1975, 12, 17)" />
+    ...       Python Expr (timefmt) : <span tal:replace="timefmt:rfc2822:python:modules['datetime'].date(1975, 12, 17)" />
+    ...   </body>
+    ... </html>
+    ... """)
+
+    >>> from zope.app.pagetemplate.simpleviewclass import SimpleViewClass
+    >>> Page = SimpleViewClass(temp_file, name='main.html')
+    >>> request = TestRequest()
+    >>> print Page(None, request)().strip() # doctest: +NORMALIZE_WHITESPACE
+    <html>
+      <body>
+          RFC 2822 date         : Wed, 17 Dec 1975 05:24:36 +0000
+          Medium Date           : 1975 12 17
+          Medium DateTime       : 1975 12 17  05:24:36
+          Python Expr (ltimefmt): 1975 12 17  00:00:00 +000
+          Python Expr (timefmt) : Wed, 17 Dec 1975 00:00:00 +0000
+      </body>
+    </html>
+
+
+Let's see if it works with spaces after the colon (at various places):
+
+    >>> open(temp_file, 'w').write("""
+    ... <html>
+    ...   <body tal:define="mydatetime python:modules['datetime'].datetime(1975, 12, 17, 5, 24, 36)">
+    ...       RFC 2822 date         : <span tal:replace="timefmt: rfc2822:mydatetime" />
+    ...       Medium Date           : <span tal:replace="ltimefmt: date: medium:mydatetime" />
+    ...       Medium DateTime       : <span tal:replace="ltimefmt: dateTime:medium: mydatetime" />
+    ...       Python Expr (ltimefmt): <span tal:replace="ltimefmt: dateTime:long: python:modules['datetime'].date(1975, 12, 17)" />
+    ...       Python Expr (timefmt) : <span tal:replace="timefmt: rfc2822: python:modules['datetime'].date(1975, 12, 17)" />
+    ...   </body>
+    ... </html>
+    ... """)
+
+    >>> Page = SimpleViewClass(temp_file, name='main_with_spaces.html')
+    >>> request = TestRequest()
+    >>> print Page(None, request)().strip() # doctest: +NORMALIZE_WHITESPACE
+    <html>
+      <body>
+          RFC 2822 date         : Wed, 17 Dec 1975 05:24:36 +0000
+          Medium Date           : 1975 12 17
+          Medium DateTime       : 1975 12 17  05:24:36
+          Python Expr (ltimefmt): 1975 12 17  00:00:00 +000
+          Python Expr (timefmt) : Wed, 17 Dec 1975 00:00:00 +0000
+      </body>
+    </html>
+
+CleanUp:
+
+    >>> os.remove(temp_file)


Property changes on: van.timeformat/trunk/van/timeformat/zpt.txt
___________________________________________________________________
Added: svn:eol-style
   + native



More information about the Checkins mailing list