[Checkins] SVN: z3c.form/trunk/src/z3c/form/ Added compatibility
layer for Zope 3.3 and thus Zope 2.10.
Stephan Richter
srichter at cosmos.phy.tufts.edu
Wed May 30 22:25:37 EDT 2007
Log message for revision 76030:
Added compatibility layer for Zope 3.3 and thus Zope 2.10.
Changed:
U z3c.form/trunk/src/z3c/form/__init__.py
A z3c.form/trunk/src/z3c/form/compatibility.py
-=-
Modified: z3c.form/trunk/src/z3c/form/__init__.py
===================================================================
--- z3c.form/trunk/src/z3c/form/__init__.py 2007-05-31 02:23:30 UTC (rev 76029)
+++ z3c.form/trunk/src/z3c/form/__init__.py 2007-05-31 02:25:37 UTC (rev 76030)
@@ -1 +1,6 @@
# Make a package.
+
+# Apply compatibility layer
+from z3c.form import compatibility
+compatibility.apply()
+del compatibility
Added: z3c.form/trunk/src/z3c/form/compatibility.py
===================================================================
--- z3c.form/trunk/src/z3c/form/compatibility.py (rev 0)
+++ z3c.form/trunk/src/z3c/form/compatibility.py 2007-05-31 02:25:37 UTC (rev 76030)
@@ -0,0 +1,85 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Foundation 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.
+#
+##############################################################################
+"""Form and Widget Framework Interfaces
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+import datetime
+import decimal
+import zope.interface
+
+def addTimeField():
+ """Add ITime interface and Time field to zope.schema.
+
+ Target: Zope 3.3
+ """
+ from zope.schema import interfaces
+ if hasattr(interfaces, 'ITime'):
+ return
+
+ class ITime(interfaces.IMinMax, interfaces.IField):
+ u"""Field containing a time."""
+ interfaces.ITime = ITime
+
+ class Time(zope.schema.Orderable, zope.schema.Field):
+ __doc__ = ITime.__doc__
+ zope.interface.implements(ITime)
+ _type = datetime.time
+ zope.schema.Time = Time
+
+
+def addDecimalField():
+ """Add IDecimal interface and Decimal field to zope.schema.
+
+ Target: Zope 3.3
+ """
+ from zope.schema import interfaces
+ if hasattr(interfaces, 'IDecimal'):
+ return
+
+ class IDecimal(interfaces.IMinMax, interfaces.IField):
+ u"""Field containing a Decimal."""
+ interfaces.IDecimal = IDecimal
+
+ class Decimal(zope.schema.Orderable, zope.schema.Field):
+ __doc__ = IDecimal.__doc__
+ zope.interface.implements(IDecimal, interfaces.IFromUnicode)
+ _type = decimal.Decimal
+
+ def __init__(self, *args, **kw):
+ super(Decimal, self).__init__(*args, **kw)
+
+ def fromUnicode(self, u):
+ """
+ >>> f = Decimal()
+ >>> f.fromUnicode("1.25")
+ Decimal("1.25")
+ >>> f.fromUnicode("1.25.6")
+ Traceback (most recent call last):
+ ...
+ ValueError: invalid literal for Decimal(): 1.25.6
+ """
+ try:
+ v = decimal.Decimal(u)
+ except decimal.InvalidOperation:
+ raise ValueError('invalid literal for Decimal(): %s' % u)
+ self.validate(v)
+ return v
+ zope.schema.Decimal = Decimal
+
+
+def apply():
+ addTimeField()
+ addDecimalField()
Property changes on: z3c.form/trunk/src/z3c/form/compatibility.py
___________________________________________________________________
Name: svn:keywords
+ Id
More information about the Checkins
mailing list