[Checkins] SVN: zc.metarecipe/trunk/src/zc/metarecipe/ When setting option values, unicode and int values will be converted

jim cvs-admin at zope.org
Mon Sep 24 16:57:40 UTC 2012


Log message for revision 127881:
  When setting option values, unicode and int values will be converted
  to strings.  Other non-string values are rejected.  Previously, it
  was easy to get errors from buildout when setting options with
  values read from ZooKeeper trees, which are unicode due to the use
  of JSON.
  

Changed:
  U   zc.metarecipe/trunk/src/zc/metarecipe/README.txt
  U   zc.metarecipe/trunk/src/zc/metarecipe/__init__.py
  U   zc.metarecipe/trunk/src/zc/metarecipe/tests.py

-=-
Modified: zc.metarecipe/trunk/src/zc/metarecipe/README.txt
===================================================================
--- zc.metarecipe/trunk/src/zc/metarecipe/README.txt	2012-09-24 16:07:41 UTC (rev 127880)
+++ zc.metarecipe/trunk/src/zc/metarecipe/README.txt	2012-09-24 16:57:36 UTC (rev 127881)
@@ -62,7 +62,7 @@
   [main]
   recipe = zc.zodbrecipes:server
   deployment = deployment
-  address = :8100
+  address = 8100
   path = /var/databases/ample/main.fs
   zeo.conf =
      <zeo>
@@ -124,7 +124,7 @@
           self['main'] = dict(
               recipe = 'zc.zodbrecipes:server',
               deployment = 'deployment',
-              address = ':8100',
+              address = 8100,
               path = options['path'],
               **{
                 'zeo.conf': '''
@@ -172,6 +172,10 @@
 referenced parts must be defined first.  This is why, for example, the
 ``pack`` part is added after the ``main`` part.
 
+Note that the meta recipe supplied an integer for one of the
+options. In addition to strings, it's legal to supply integer and
+unicode values.
+
 Testing
 =======
 
@@ -188,7 +192,7 @@
     recipe = zc.recipe.deployment
     user = zope
     [main]
-    address = :8100
+    address = 8100
     deployment = deployment
     path = /var/databases/ample/main.fs
     recipe = zc.zodbrecipes:server
@@ -223,14 +227,20 @@
 Changes
 =======
 
-0.1.1 (2012-09-24)
+0.2.0 (2012-09-24)
 ------------------
 
-Fixed: When using the meta-recipe parse method, the order that
-       resulting sections were added was not=deterministic, due to the
-       way ConfigParser works.  Not sections are added to a buildout
-       in sortd order, by section name.
+- When setting option values, unicode and int values will be converted
+  to strings.  Other non-string values are rejected.  Previously, it
+  was easy to get errors from buildout when setting options with
+  values read from ZooKeeper trees, which are unicode due to the use
+  of JSON.
 
+- Fixed: When using the meta-recipe parse method, the order that
+  resulting sections were added was non-deterministic, due to the
+  way ConfigParser works.  Not sections are added to a buildout
+  in sortd order, by section name.
+
 0.1.0 (2012-05-31)
 ------------------
 

Modified: zc.metarecipe/trunk/src/zc/metarecipe/__init__.py
===================================================================
--- zc.metarecipe/trunk/src/zc/metarecipe/__init__.py	2012-09-24 16:07:41 UTC (rev 127880)
+++ zc.metarecipe/trunk/src/zc/metarecipe/__init__.py	2012-09-24 16:57:36 UTC (rev 127881)
@@ -13,6 +13,7 @@
     update = install
 
     def __setitem__(self, name, data):
+        data = dict(stringify(name, i) for i in data.items())
         self.buildout._raw[name] = data
         self.buildout[name]
 
@@ -22,3 +23,14 @@
 
         for section in sorted(parser.sections()):
             self[section] = dict(parser.items(section))
+
+validtypes = unicode, int
+
+def stringify(section, (key, value)):
+    if not isinstance(value, str):
+        if isinstance(value, validtypes):
+            value = str(value)
+        else:
+            raise TypeError("Invalid type: %s for %s:%s, %r" %
+                            (type(value), section, key, value))
+    return key, value

Modified: zc.metarecipe/trunk/src/zc/metarecipe/tests.py
===================================================================
--- zc.metarecipe/trunk/src/zc/metarecipe/tests.py	2012-09-24 16:07:41 UTC (rev 127880)
+++ zc.metarecipe/trunk/src/zc/metarecipe/tests.py	2012-09-24 16:57:36 UTC (rev 127881)
@@ -12,11 +12,34 @@
 #
 ##############################################################################
 from zope.testing import setupstack
+import doctest
 import manuel.capture
 import manuel.doctest
 import manuel.testing
 import unittest
 
+def test_funky_option_types():
+    """
+    We can supply unicode and int option values and they're stringified:
+
+    >>> import zc.metarecipe.testing
+    >>> buildout = zc.metarecipe.testing.Buildout()
+    >>> recipe = zc.metarecipe.Recipe(buildout, '', {})
+    >>> recipe['s'] = dict(o1=1, o2=u'foo', o3='bar')
+    [s]
+    o1 = 1
+    o2 = foo
+    o3 = bar
+
+    Other types are not OK:
+
+    >>> recipe['x'] = dict(o1=1.0)
+    Traceback (most recent call last):
+    ...
+    TypeError: Invalid type: <type 'float'> for x:o1, 1.0
+
+    """
+
 def test_suite():
     return unittest.TestSuite((
         manuel.testing.TestSuite(
@@ -24,5 +47,6 @@
             'README.txt',
             setUp=setupstack.setUpDirectory, tearDown=setupstack.tearDown,
             ),
+        doctest.DocTestSuite(),
         ))
 



More information about the checkins mailing list