[Checkins] SVN: zope.generic/trunk/src/zope/generic/ add dedicated __repr__ to ConfigurationData

Dominik Huber dominik.huber at perse.ch
Thu May 18 11:31:28 EDT 2006


Log message for revision 68174:
  add dedicated __repr__ to ConfigurationData
  
  rename requiredInOrder to namesInOrder (sort the names)
  
  add field package for additional field implementations

Changed:
  U   zope.generic/trunk/src/zope/generic/configuration/api.py
  U   zope.generic/trunk/src/zope/generic/configuration/base.py
  U   zope.generic/trunk/src/zope/generic/configuration/helper.py
  A   zope.generic/trunk/src/zope/generic/field/
  A   zope.generic/trunk/src/zope/generic/field/DEPENDENCIES.cfg
  A   zope.generic/trunk/src/zope/generic/field/README.txt
  A   zope.generic/trunk/src/zope/generic/field/__init__.py
  A   zope.generic/trunk/src/zope/generic/field/_datetime.py
  A   zope.generic/trunk/src/zope/generic/field/api.py
  A   zope.generic/trunk/src/zope/generic/field/configure.zcml
  A   zope.generic/trunk/src/zope/generic/field/interfaces.py
  A   zope.generic/trunk/src/zope/generic/field/tests.py
  A   zope.generic/trunk/src/zope/generic/field/zope.generic.configuration-configure.zcml

-=-
Modified: zope.generic/trunk/src/zope/generic/configuration/api.py
===================================================================
--- zope.generic/trunk/src/zope/generic/configuration/api.py	2006-05-18 12:54:33 UTC (rev 68173)
+++ zope.generic/trunk/src/zope/generic/configuration/api.py	2006-05-18 15:31:27 UTC (rev 68174)
@@ -23,7 +23,7 @@
 from zope.generic.configuration.base import createConfiguration
 from zope.generic.configuration.helper import configuratonToDict
 from zope.generic.configuration.helper import provideConfigurationType
-from zope.generic.configuration.helper import requiredInOrder
+from zope.generic.configuration.helper import namesInOrder
 
 
 
@@ -128,7 +128,7 @@
         return pos[0]
 
     # pos and kws mixture
-    attribution = requiredInOrder(__keyface__)
+    attribution = namesInOrder(__keyface__)
     errors = []
     for i in range(len(pos)):
         key = attribution[i]

Modified: zope.generic/trunk/src/zope/generic/configuration/base.py
===================================================================
--- zope.generic/trunk/src/zope/generic/configuration/base.py	2006-05-18 12:54:33 UTC (rev 68173)
+++ zope.generic/trunk/src/zope/generic/configuration/base.py	2006-05-18 15:31:27 UTC (rev 68174)
@@ -31,12 +31,14 @@
 from zope.generic.face import IFace
 from zope.generic.face import IUndefinedContext
 from zope.generic.face.api import FaceForAttributeFaced
+from zope.generic.face.api import toDottedName
 
 from zope.generic.configuration import IConfigurationData
 from zope.generic.configuration import IConfigurations
 from zope.generic.configuration import IConfigurationType
 
 
+
 def createConfiguration(keyface, data):
     return ConfigurationData(keyface, data)
 
@@ -110,15 +112,18 @@
         >>> from zope.interface import Interface
         >>> from zope.schema import TextLine
         
-        >>> class IExampleConfiugrationSchema(Interface):
+        >>> class IExampleConfiugration(Interface):
         ...    foo = TextLine(title=u'Foo')
         ...    fuu = TextLine(title=u'Fuu', required=False)
         ...    fii = TextLine(title=u'Fii', required=False, readonly=True)
 
     Create a corresponding configuration data:
 
-        >>> config_data = ConfigurationData(IExampleConfiugrationSchema, {'foo': u'Foo!'})
-        >>> IExampleConfiugrationSchema.providedBy(config_data)
+        >>> config_data = ConfigurationData(IExampleConfiugration, {'foo': u'Foo!'})
+        >>> config_data
+        <Configuration zope.generic.configuration.base.IExampleConfiugration>
+
+        >>> IExampleConfiugration.providedBy(config_data)
         True
         >>> config_data.foo
         u'Foo!'
@@ -127,7 +132,7 @@
         >>> config_data.bar
         Traceback (most recent call last):
         ...
-        AttributeError: 'IExampleConfiugrationSchema' configuration has no attribute 'bar'.
+        AttributeError: 'IExampleConfiugration' configuration has no attribute 'bar'.
  
     The implementation provide an adapter to IFace by its __conform__ method:
 
@@ -135,7 +140,7 @@
         >>> IFace.providedBy(adapted)
         True
 
-        >>> adapted.keyface is IExampleConfiugrationSchema
+        >>> adapted.keyface is IExampleConfiugration
         True
 
     A configuration belong to the configuration context:
@@ -149,14 +154,14 @@
         >>> config_data.fii = u'Bla bla'
         Traceback (most recent call last):
         ...
-        ValueError: 'IExampleConfiugrationSchema' configuration's attribute 'fii' is readonly.
+        ValueError: 'IExampleConfiugration' configuration's attribute 'fii' is readonly.
 
     If a relevant key is missed within the data a key error is raised:
 
-        >>> config_data = ConfigurationData(IExampleConfiugrationSchema, {})
+        >>> config_data = ConfigurationData(IExampleConfiugration, {})
         Traceback (most recent call last):
         ...
-        TypeError: __init__ requires 'foo' of 'IExampleConfiugrationSchema'.
+        TypeError: __init__ requires 'foo' of 'IExampleConfiugration'.
 
     The schema should never contain methods:
 
@@ -184,6 +189,9 @@
         for key, value in prepareData(__keyface__, data).items():
             setattr(self, key, value)
 
+    def __repr__(self):
+        return '<Configuration %s>' % toDottedName(self.__keyface__)
+
     def __conform__(self, interface):
         if interface is IFace:
             return FaceForAttributeFaced(self)

Modified: zope.generic/trunk/src/zope/generic/configuration/helper.py
===================================================================
--- zope.generic/trunk/src/zope/generic/configuration/helper.py	2006-05-18 12:54:33 UTC (rev 68173)
+++ zope.generic/trunk/src/zope/generic/configuration/helper.py	2006-05-18 15:31:27 UTC (rev 68174)
@@ -89,7 +89,7 @@
 
 
 
-def requiredInOrder(configuration):
+def namesInOrder(configuration, required_only=True):
     """Evaluate the relevant order of positional arguments.
 
     The relevant order of positional arguments is evaluated by a configuration
@@ -104,9 +104,17 @@
         ...    c = TextLine(required=False, readonly=True, default=u'c bla')
         ...    d = TextLine()
 
-        >>> api.requiredInOrder(IAnyConfiguration)
+        >>> api.namesInOrder(IAnyConfiguration)
         ['a', 'd']
-    
+
+        >>> api.namesInOrder(IAnyConfiguration, False)
+        ['a', 'b', 'c', 'd']
     """
     
-    return [name for name in configuration if configuration[name].required is True]
+    if required_only:
+        names = [name for name in configuration if configuration[name].required is True]
+    else:
+        names = [name for name in configuration]
+
+    names.sort()
+    return names

Added: zope.generic/trunk/src/zope/generic/field/DEPENDENCIES.cfg
===================================================================
--- zope.generic/trunk/src/zope/generic/field/DEPENDENCIES.cfg	2006-05-18 12:54:33 UTC (rev 68173)
+++ zope.generic/trunk/src/zope/generic/field/DEPENDENCIES.cfg	2006-05-18 15:31:27 UTC (rev 68174)
@@ -0,0 +1,14 @@
+BTrees
+persistent
+zope.app.testing
+zope.component
+zope.event
+zope.generic.field
+zope.generic.directlyprovides
+zope.generic.face
+zope.generic.testing
+zope.interface
+zope.lifecycleevent
+zope.location
+zope.schema
+zope.testing
\ No newline at end of file


Property changes on: zope.generic/trunk/src/zope/generic/field/DEPENDENCIES.cfg
___________________________________________________________________
Name: svn:keywords
   + Id

Added: zope.generic/trunk/src/zope/generic/field/README.txt
===================================================================
--- zope.generic/trunk/src/zope/generic/field/README.txt	2006-05-18 12:54:33 UTC (rev 68173)
+++ zope.generic/trunk/src/zope/generic/field/README.txt	2006-05-18 15:31:27 UTC (rev 68174)
@@ -0,0 +1,5 @@
+=============
+Generic Field
+=============
+
+Provide a few more schema fields...


Property changes on: zope.generic/trunk/src/zope/generic/field/README.txt
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: zope.generic/trunk/src/zope/generic/field/__init__.py
===================================================================
--- zope.generic/trunk/src/zope/generic/field/__init__.py	2006-05-18 12:54:33 UTC (rev 68173)
+++ zope.generic/trunk/src/zope/generic/field/__init__.py	2006-05-18 15:31:27 UTC (rev 68174)
@@ -0,0 +1,19 @@
+##############################################################################
+#
+# Copyright (c) 2005, 2006 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.
+#
+##############################################################################
+
+"""
+$Id$
+"""
+
+from zope.generic.field.interfaces import *
\ No newline at end of file


Property changes on: zope.generic/trunk/src/zope/generic/field/__init__.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: zope.generic/trunk/src/zope/generic/field/_datetime.py
===================================================================
--- zope.generic/trunk/src/zope/generic/field/_datetime.py	2006-05-18 12:54:33 UTC (rev 68173)
+++ zope.generic/trunk/src/zope/generic/field/_datetime.py	2006-05-18 15:31:27 UTC (rev 68174)
@@ -0,0 +1,68 @@
+##############################################################################
+#
+# Copyright (c) 2005, 2006 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.
+#
+##############################################################################
+
+"""
+$Id$
+"""
+
+__docformat__ = 'restructuredtext'
+
+import time
+from datetime import date
+
+from zope.interface import implements
+from zope.schema import Date
+from zope.schema.interfaces import IFromUnicode
+
+from zope.generic.field import IToUnicode
+
+
+
+class EuroDate(Date):
+    """DD.MM.YYYY Date."""
+
+    implements(IFromUnicode, IToUnicode)
+
+    def fromUnicode(self, str):
+        """Retrieve a date from a unicode string.
+        
+        >>> field = EuroDate()
+        >>> field.fromUnicode('12.3.2006')
+        datetime.date(2006, 3, 12)
+        
+        >>> field.fromUnicode('12.33.2006')
+        Traceback (most recent call last):
+        ...
+        ValueError: time data did not match format:  data=12.33.2006  fmt=%d.%m.%Y
+
+        """
+        
+        timestamp = time.mktime(time.strptime(str, '%d.%m.%Y'))
+        d = date.fromtimestamp(timestamp)
+
+        self.validate(d)
+        return d
+
+    def toUnicode(self, value):
+        """Retrieve a date from a unicode string.
+        
+        >>> field = EuroDate()
+        >>> d = date(2006, 3, 12)
+        >>> field.toUnicode(d)
+        u'12.03.2006'
+
+        """
+
+        return unicode(value.strftime('%d.%m.%Y'))
+        
\ No newline at end of file


Property changes on: zope.generic/trunk/src/zope/generic/field/_datetime.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: zope.generic/trunk/src/zope/generic/field/api.py
===================================================================
--- zope.generic/trunk/src/zope/generic/field/api.py	2006-05-18 12:54:33 UTC (rev 68173)
+++ zope.generic/trunk/src/zope/generic/field/api.py	2006-05-18 15:31:27 UTC (rev 68174)
@@ -0,0 +1,21 @@
+##############################################################################
+#
+# Copyright (c) 2005, 2006 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.
+#
+##############################################################################
+
+"""
+$Id$
+"""
+
+__docformat__ = 'restructuredtext'
+
+from zope.generic.field._datetime import EuroDate


Property changes on: zope.generic/trunk/src/zope/generic/field/api.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: zope.generic/trunk/src/zope/generic/field/configure.zcml
===================================================================
--- zope.generic/trunk/src/zope/generic/field/configure.zcml	2006-05-18 12:54:33 UTC (rev 68173)
+++ zope.generic/trunk/src/zope/generic/field/configure.zcml	2006-05-18 15:31:27 UTC (rev 68174)
@@ -0,0 +1,16 @@
+<configure
+  xmlns="http://namespaces.zope.org/zope"
+  xmlns:apidoc="http://namespaces.zope.org/apidoc"
+  xmlns:generic="http://namespaces.zope.org/generic"
+  xmlns:zcml="http://namespaces.zope.org/zcml"
+  i18n_domain="zope">
+ 
+  <apidoc:bookchapter zcml:condition="have apidoc"
+      id="zope.generic.field.readme"
+      title="Field"
+      doc_path="README.txt"
+      parent="zope.generic"
+      />
+
+
+</configure>


Property changes on: zope.generic/trunk/src/zope/generic/field/configure.zcml
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: zope.generic/trunk/src/zope/generic/field/interfaces.py
===================================================================
--- zope.generic/trunk/src/zope/generic/field/interfaces.py	2006-05-18 12:54:33 UTC (rev 68173)
+++ zope.generic/trunk/src/zope/generic/field/interfaces.py	2006-05-18 15:31:27 UTC (rev 68174)
@@ -0,0 +1,27 @@
+##############################################################################
+#
+# Copyright (c) 2005, 2006 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.
+#
+##############################################################################
+
+"""
+$Id$
+"""
+
+__docformat__ = 'restructuredtext'
+
+from zope.interface import Interface
+
+class IToUnicode(Interface):
+    """Convert a value to a unicode string."""
+
+    def toUnicode(value):
+        """Convert a value to a unicode string."""


Property changes on: zope.generic/trunk/src/zope/generic/field/interfaces.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: zope.generic/trunk/src/zope/generic/field/tests.py
===================================================================
--- zope.generic/trunk/src/zope/generic/field/tests.py	2006-05-18 12:54:33 UTC (rev 68173)
+++ zope.generic/trunk/src/zope/generic/field/tests.py	2006-05-18 15:31:27 UTC (rev 68174)
@@ -0,0 +1,36 @@
+##############################################################################
+#
+# Copyright (c) 2005, 2006 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.
+#
+##############################################################################
+
+"""
+$Id$
+"""
+
+import unittest
+
+from zope.testing import doctest
+
+
+###############################################################################
+#
+# Unit tests  
+#
+###############################################################################
+
+
+def test_suite():
+    return unittest.TestSuite((
+        doctest.DocTestSuite('zope.generic.field._datetime'),
+        ))
+
+if __name__ == '__main__': unittest.main()


Property changes on: zope.generic/trunk/src/zope/generic/field/tests.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: zope.generic/trunk/src/zope/generic/field/zope.generic.configuration-configure.zcml
===================================================================
--- zope.generic/trunk/src/zope/generic/field/zope.generic.configuration-configure.zcml	2006-05-18 12:54:33 UTC (rev 68173)
+++ zope.generic/trunk/src/zope/generic/field/zope.generic.configuration-configure.zcml	2006-05-18 15:31:27 UTC (rev 68174)
@@ -0,0 +1,5 @@
+<configure xmlns="http://namespaces.zope.org/zope">
+
+  <include package="zope.generic.field" />
+
+</configure>


Property changes on: zope.generic/trunk/src/zope/generic/field/zope.generic.configuration-configure.zcml
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native



More information about the Checkins mailing list