[Checkins] SVN: zope.httpformdate/ Extracted the :date converter from zope.app.publisher.

Shane Hathaway shane at hathawaymix.org
Sat Feb 7 19:34:45 EST 2009


Log message for revision 96222:
  Extracted the :date converter from zope.app.publisher.
  

Changed:
  A   zope.httpformdate/
  A   zope.httpformdate/trunk/
  A   zope.httpformdate/trunk/.installed.cfg
  A   zope.httpformdate/trunk/CHANGES.txt
  A   zope.httpformdate/trunk/LICENSE.txt
  A   zope.httpformdate/trunk/README.txt
  A   zope.httpformdate/trunk/bootstrap.py
  A   zope.httpformdate/trunk/buildout.cfg
  A   zope.httpformdate/trunk/setup.py
  A   zope.httpformdate/trunk/src/
  A   zope.httpformdate/trunk/src/zope/
  A   zope.httpformdate/trunk/src/zope/__init__.py
  A   zope.httpformdate/trunk/src/zope/httpformdate/
  A   zope.httpformdate/trunk/src/zope/httpformdate/README.txt
  A   zope.httpformdate/trunk/src/zope/httpformdate/__init__.py
  A   zope.httpformdate/trunk/src/zope/httpformdate/tests.py

-=-
Added: zope.httpformdate/trunk/.installed.cfg
===================================================================
--- zope.httpformdate/trunk/.installed.cfg	                        (rev 0)
+++ zope.httpformdate/trunk/.installed.cfg	2009-02-08 00:34:44 UTC (rev 96222)
@@ -0,0 +1,71 @@
+[buildout]
+installed_develop_eggs = /home/shane/svn/zope.httpformdate/trunk/develop-eggs/zope.httpformdate.egg-link
+parts = coverage-test coverage-report test python
+
+[coverage-test]
+__buildout_installed__ = /home/shane/svn/zope.httpformdate/trunk/parts/coverage-test
+	/home/shane/svn/zope.httpformdate/trunk/bin/coverage-test
+__buildout_signature__ = zc.recipe.testrunner-1.1.0-py2.5.egg zc.recipe.egg-1.1.0-py2.5.egg setuptools-0.6c9-py2.5.egg zope.testing-3.7.1-py2.5.egg zc.buildout-1.1.1-py2.5.egg zc.buildout-1.1.1-py2.5.egg zope.interface-3.5.0-py2.5-linux-x86_64.egg
+_b = /home/shane/svn/zope.httpformdate/trunk/bin
+_d = /home/shane/svn/zope.httpformdate/trunk/develop-eggs
+_e = /home/shane/.buildout/eggs
+bin-directory = /home/shane/svn/zope.httpformdate/trunk/bin
+defaults = ['--coverage', '../../coverage']
+develop-eggs-directory = /home/shane/svn/zope.httpformdate/trunk/develop-eggs
+eggs = zope.httpform
+eggs-directory = /home/shane/.buildout/eggs
+executable = /usr/bin/python
+location = /home/shane/svn/zope.httpformdate/trunk/parts/coverage-test
+recipe = zc.recipe.testrunner
+script = /home/shane/svn/zope.httpformdate/trunk/bin/coverage-test
+
+[coverage-report]
+__buildout_installed__ = /home/shane/svn/zope.httpformdate/trunk/bin/coverage-report
+__buildout_signature__ = zc.recipe.egg-1.1.0-py2.5.egg setuptools-0.6c9-py2.5.egg zc.buildout-1.1.1-py2.5.egg
+_b = /home/shane/svn/zope.httpformdate/trunk/bin
+_d = /home/shane/svn/zope.httpformdate/trunk/develop-eggs
+_e = /home/shane/.buildout/eggs
+arguments = ('coverage', 'coverage/report')
+bin-directory = /home/shane/svn/zope.httpformdate/trunk/bin
+develop-eggs-directory = /home/shane/svn/zope.httpformdate/trunk/develop-eggs
+eggs = z3c.coverage
+eggs-directory = /home/shane/.buildout/eggs
+executable = /usr/bin/python
+recipe = zc.recipe.egg
+scripts = coverage=coverage-report
+
+[test]
+__buildout_installed__ = /home/shane/svn/zope.httpformdate/trunk/parts/test
+	/home/shane/svn/zope.httpformdate/trunk/bin/test
+__buildout_signature__ = zc.recipe.testrunner-1.1.0-py2.5.egg zc.recipe.egg-1.1.0-py2.5.egg setuptools-0.6c9-py2.5.egg zope.testing-3.7.1-py2.5.egg zc.buildout-1.1.1-py2.5.egg zc.buildout-1.1.1-py2.5.egg zope.interface-3.5.0-py2.5-linux-x86_64.egg
+_b = /home/shane/svn/zope.httpformdate/trunk/bin
+_d = /home/shane/svn/zope.httpformdate/trunk/develop-eggs
+_e = /home/shane/.buildout/eggs
+bin-directory = /home/shane/svn/zope.httpformdate/trunk/bin
+develop-eggs-directory = /home/shane/svn/zope.httpformdate/trunk/develop-eggs
+eggs = zope.httpformdate
+eggs-directory = /home/shane/.buildout/eggs
+executable = /usr/bin/python
+location = /home/shane/svn/zope.httpformdate/trunk/parts/test
+recipe = zc.recipe.testrunner
+script = /home/shane/svn/zope.httpformdate/trunk/bin/test
+
+[python]
+__buildout_installed__ = /home/shane/svn/zope.httpformdate/trunk/bin/python
+__buildout_signature__ = zc.recipe.egg-1.1.0-py2.5.egg setuptools-0.6c9-py2.5.egg zc.buildout-1.1.1-py2.5.egg
+_b = /home/shane/svn/zope.httpformdate/trunk/bin
+_d = /home/shane/svn/zope.httpformdate/trunk/develop-eggs
+_e = /home/shane/.buildout/eggs
+bin-directory = /home/shane/svn/zope.httpformdate/trunk/bin
+develop-eggs-directory = /home/shane/svn/zope.httpformdate/trunk/develop-eggs
+eggs = zope.httpformdate
+eggs-directory = /home/shane/.buildout/eggs
+executable = /usr/bin/python
+interpreter = python
+recipe = zc.recipe.egg
+
+[buildout]
+parts = coverage-report test python coverage-test
+
+[buildout]
+parts = test python coverage-test coverage-report

Added: zope.httpformdate/trunk/CHANGES.txt
===================================================================
--- zope.httpformdate/trunk/CHANGES.txt	                        (rev 0)
+++ zope.httpformdate/trunk/CHANGES.txt	2009-02-08 00:34:44 UTC (rev 96222)
@@ -0,0 +1,9 @@
+CHANGES
+=======
+
+Version 1.0.0 (unreleased)
+--------------------------
+
+- First release of zope.httpformdate.  Extracted from zope.app.publisher.
+
+- ...

Added: zope.httpformdate/trunk/LICENSE.txt
===================================================================
--- zope.httpformdate/trunk/LICENSE.txt	                        (rev 0)
+++ zope.httpformdate/trunk/LICENSE.txt	2009-02-08 00:34:44 UTC (rev 96222)
@@ -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.

Added: zope.httpformdate/trunk/README.txt
===================================================================
--- zope.httpformdate/trunk/README.txt	                        (rev 0)
+++ zope.httpformdate/trunk/README.txt	2009-02-08 00:34:44 UTC (rev 96222)
@@ -0,0 +1,5 @@
+
+This is a small library that extends the ``zope.httpform`` library to
+support date/time parsing.  It provides a ``:date`` converter that uses
+the ``zope.datetime`` library to convert a variety of date formats
+to a standard datetime object.

Added: zope.httpformdate/trunk/bootstrap.py
===================================================================
--- zope.httpformdate/trunk/bootstrap.py	                        (rev 0)
+++ zope.httpformdate/trunk/bootstrap.py	2009-02-08 00:34:44 UTC (rev 96222)
@@ -0,0 +1,54 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Corporation and Contributors.
+# 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.
+#
+##############################################################################
+"""Bootstrap a buildout-based project
+
+Simply run this script in a directory containing a buildout.cfg.
+The script accepts buildout command-line options, so you can
+use the -c option to specify an alternate configuration file.
+
+$Id: bootstrap.py,v 1.1 2009/01/10 15:13:39 shane Exp $
+"""
+
+import os, shutil, sys, tempfile, urllib2
+
+tmpeggs = tempfile.mkdtemp()
+
+ez = {}
+exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+                     ).read() in ez
+ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+
+# use pkg_resources from the package just downloaded.
+del sys.modules['pkg_resources']
+import pkg_resources
+
+cmd = 'from setuptools.command.easy_install import main; main()'
+if sys.platform == 'win32':
+    cmd = '"%s"' % cmd # work around spawn lamosity on windows
+
+ws = pkg_resources.working_set
+assert os.spawnle(
+    os.P_WAIT, sys.executable, sys.executable,
+    '-c', cmd, '-mqNxd', tmpeggs, 'zc.buildout',
+    dict(os.environ,
+         PYTHONPATH=
+         ws.find(pkg_resources.Requirement.parse('setuptools')).location
+         ),
+    ) == 0
+
+ws.add_entry(tmpeggs)
+ws.require('zc.buildout')
+import zc.buildout.buildout
+zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
+shutil.rmtree(tmpeggs)

Added: zope.httpformdate/trunk/buildout.cfg
===================================================================
--- zope.httpformdate/trunk/buildout.cfg	                        (rev 0)
+++ zope.httpformdate/trunk/buildout.cfg	2009-02-08 00:34:44 UTC (rev 96222)
@@ -0,0 +1,23 @@
+[buildout]
+develop = .
+parts = test python coverage-test coverage-report
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = zope.httpformdate
+
+[python]
+recipe = zc.recipe.egg
+eggs = zope.httpformdate
+interpreter = python
+
+[coverage-test]
+recipe = zc.recipe.testrunner
+eggs = zope.httpform
+defaults = ['--coverage', '../../coverage']
+
+[coverage-report]
+recipe = zc.recipe.egg
+eggs = z3c.coverage
+scripts = coverage=coverage-report
+arguments = ('coverage', 'coverage/report')

Added: zope.httpformdate/trunk/setup.py
===================================================================
--- zope.httpformdate/trunk/setup.py	                        (rev 0)
+++ zope.httpformdate/trunk/setup.py	2009-02-08 00:34:44 UTC (rev 96222)
@@ -0,0 +1,58 @@
+##############################################################################
+#
+# Copyright (c) 2009 Zope Corporation and Contributors.
+# 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.
+#
+##############################################################################
+"""zope.httpformdate setup
+
+$Id: $
+"""
+
+import os
+from setuptools import setup, find_packages
+
+def read(*rnames):
+    return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
+
+long_description = (read('README.txt') +
+                    '\n\n' +
+                    read('CHANGES.txt'))
+
+setup(
+    name='zope.httpformdate',
+    version='1.0.0dev',
+    url='http://pypi.python.org/pypi/zope.httpformdate',
+    license='ZPL 2.1',
+    author='Zope Corporation and Contributors',
+    author_email='zope-dev at zope.org',
+    description="Extension of zope.httpform for date support",
+    long_description=long_description,
+
+    # Get more from http://www.python.org/pypi?%3Aaction=list_classifiers
+    classifiers=[
+        "Development Status :: 4 - Beta",
+        "Intended Audience :: Developers",
+        'Programming Language :: Python',
+        'Environment :: Web Environment',
+        'Topic :: Internet :: WWW/HTTP :: WSGI :: Application',
+        'Framework :: Zope3',
+        ],
+
+    packages=find_packages('src'),
+    package_dir={'': 'src'},
+    namespace_packages=['zope'],
+    zip_safe=False,
+    install_requires=[
+        'setuptools',
+        'zope.httpform',
+        'zope.datetime',
+        ],
+    )

Added: zope.httpformdate/trunk/src/zope/__init__.py
===================================================================
--- zope.httpformdate/trunk/src/zope/__init__.py	                        (rev 0)
+++ zope.httpformdate/trunk/src/zope/__init__.py	2009-02-08 00:34:44 UTC (rev 96222)
@@ -0,0 +1,7 @@
+# this is a namespace package
+try:
+    import pkg_resources
+    pkg_resources.declare_namespace(__name__)
+except ImportError:
+    import pkgutil
+    __path__ = pkgutil.extend_path(__path__, __name__)

Added: zope.httpformdate/trunk/src/zope/httpformdate/README.txt
===================================================================
--- zope.httpformdate/trunk/src/zope/httpformdate/README.txt	                        (rev 0)
+++ zope.httpformdate/trunk/src/zope/httpformdate/README.txt	2009-02-08 00:34:44 UTC (rev 96222)
@@ -0,0 +1,29 @@
+
+Tests of zope.httpformdate
+==========================
+
+Register the ``:date`` converter.
+
+    >>> from zope.httpformdate import register
+    >>> register()
+
+Use it in a form.
+
+    >>> from pprint import pprint
+    >>> from zope.httpform import parse
+    >>> env = {'REQUEST_METHOD': 'GET', 'QUERY_STRING': 'x:date=2009-02-28'}
+    >>> pprint(parse(env))
+    {u'x': datetime.datetime(2009, 2, 28, 0, 0)}
+
+The parser supports English month and weekday names.
+
+    >>> env['QUERY_STRING'] = 'x:date=February+7,+2009'
+    >>> pprint(parse(env))
+    {u'x': datetime.datetime(2009, 2, 7, 0, 0)}
+
+The parser supports times.
+
+    >>> env['QUERY_STRING'] = 'x:date=February+7,+2009+4:30PM'
+    >>> pprint(parse(env))
+    {u'x': datetime.datetime(2009, 2, 7, 16, 30)}
+

Added: zope.httpformdate/trunk/src/zope/httpformdate/__init__.py
===================================================================
--- zope.httpformdate/trunk/src/zope/httpformdate/__init__.py	                        (rev 0)
+++ zope.httpformdate/trunk/src/zope/httpformdate/__init__.py	2009-02-08 00:34:44 UTC (rev 96222)
@@ -0,0 +1,57 @@
+##############################################################################
+#
+# Copyright (c) 2003 Zope Corporation and Contributors.
+# 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.
+#
+##############################################################################
+"""Date field converter.
+
+$Id: fieldconverters.py 67630 2006-04-27 00:54:03Z jim $
+"""
+from datetime import datetime
+
+from zope.httpform.typeconv import registerTypeConverter
+from zope.datetime import parse as parseDateTime
+
+def field2date_via_datetimeutils(v):
+    """Converter for request fields marshalled as ':date'.
+
+    o TODO: Uses the non-localized and non-tzinfo-aware 'parseDateTime'
+            utility from zope.datetime;  a better alternative
+            would be more I18N / L10N aware, perhaps even adapting to
+            the expressed preferences of the user.
+    """
+    if hasattr(v,'read'):
+        v = v.read()
+    else:
+        v = str(v)
+
+    # *Don't* force a timezone if not passed explicitly;  leave it as
+    # "naive" datetime.
+    year, month, day, hour, minute, second, tzname = parseDateTime(v, local=0)
+
+    # TODO:  look up a real tzinfo object using 'tzname'
+    #
+    # Option 1:  Use 'timezones' module as global registry::
+    #
+    #   from zope.app.timezones import getTimezoneInfo
+    #   tzinfo = getTimezoneInfo(tzname)
+    #
+    # Option 2:  Use a utility (or perhaps a view, for L10N).
+    #
+    #   tz_lookup = getUtility(ITimezoneLookup)
+    #   tzinfo = tz_lookup(tzname)
+    #
+    return datetime(year, month, day, hour, minute, second,
+                  # tzinfo=tzinfo
+                   )
+
+def register():
+    registerTypeConverter('date', field2date_via_datetimeutils)

Added: zope.httpformdate/trunk/src/zope/httpformdate/tests.py
===================================================================
--- zope.httpformdate/trunk/src/zope/httpformdate/tests.py	                        (rev 0)
+++ zope.httpformdate/trunk/src/zope/httpformdate/tests.py	2009-02-08 00:34:44 UTC (rev 96222)
@@ -0,0 +1,31 @@
+##############################################################################
+#
+# Copyright (c) 2009 Zope Corporation and Contributors.
+# 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.
+#
+##############################################################################
+"""Tests of the zope.httpformdate package.
+
+$Id: $
+"""
+
+import unittest
+from zope.testing import doctest
+
+
+def test_suite():
+    return unittest.TestSuite([
+        doctest.DocFileSuite(
+            'README.txt',
+            optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS),
+    ])
+
+if __name__ == '__main__':
+    unittest.main()



More information about the Checkins mailing list