Giuseppe Lavagetto has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/347356 )

Change subject: Add a free-form 'any' type
......................................................................


Add a free-form 'any' type

Bug: T156924
Change-Id: I03da20db6f6b263606ca6c600f9f7eefa4d93a60
---
M conftool/tests/unit/test_types.py
M conftool/types.py
M debian/changelog
M setup.py
4 files changed, 32 insertions(+), 2 deletions(-)

Approvals:
  Giuseppe Lavagetto: Looks good to me, approved
  jenkins-bot: Verified
  Volans: Looks good to me, but someone else must approve



diff --git a/conftool/tests/unit/test_types.py 
b/conftool/tests/unit/test_types.py
index b3aa2c3..e358405 100644
--- a/conftool/tests/unit/test_types.py
+++ b/conftool/tests/unit/test_types.py
@@ -36,3 +36,14 @@
         validator = types.get_validator("enum:a|b|c")
         self.assertEqual('c', validator('c'))
         self.assertRaises(ValueError, validator, 'd')
+
+    def test_any_validator(self):
+        validator = types.get_validator("any")
+        self.assertEqual("a string", validator("a string"))
+        self.assertEqual(['a', 'list'], validator(['a', 'list']))
+        self.assertEqual({'a': 'dict'}, validator({'a': 'dict'}))
+
+        class Foo(object):
+            pass
+
+        self.assertRaises(ValueError, validator, Foo())
diff --git a/conftool/types.py b/conftool/types.py
index 8da7f4a..ed40b3f 100644
--- a/conftool/types.py
+++ b/conftool/types.py
@@ -1,3 +1,6 @@
+import json
+
+
 def choice(arg):
     args = arg.split('|')
 
@@ -20,6 +23,15 @@
     return data
 
 
+def any_validator(data):
+    """Any value that can be translated to json is ok."""
+    try:
+        json.dumps(data)
+        return data
+    except TypeError:
+        raise ValueError('values need to be json-serializable')
+
+
 validators = {
     'int': int,
     'list': lambda x: x if isinstance(x, list) else [],
@@ -27,6 +39,7 @@
     'bool': bool_validator,
     'enum': choice,
     'dict': dict_validator,
+    'any': any_validator,
 }
 
 
diff --git a/debian/changelog b/debian/changelog
index 8131e34..99b8b9a 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,4 +1,10 @@
-python-conftool (0.4.0) UNRELEASED; urgency=medium
+python-conftool (0.4.1) UNRELEASED; urgency=medium
+
+  * Add a raw 'any' type to the schema
+
+ -- Giuseppe Lavagetto <[email protected]>  Mon, 10 Apr 2017 13:42:04 
+0200
+
+python-conftool (0.4.0) jessie-wikimedia; urgency=medium
 
   * Allow defining any object type via a schema file
   * Refactoring of the syncer system
diff --git a/setup.py b/setup.py
index 44fe7bd..004b498 100755
--- a/setup.py
+++ b/setup.py
@@ -4,7 +4,7 @@
 
 setup(
     name='conftool',
-    version='0.4.0',
+    version='0.4.1',
     description='Tools to interoperate with distributed k/v stores',
     author='Joe',
     author_email='[email protected]',

-- 
To view, visit https://gerrit.wikimedia.org/r/347356
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I03da20db6f6b263606ca6c600f9f7eefa4d93a60
Gerrit-PatchSet: 1
Gerrit-Project: operations/software/conftool
Gerrit-Branch: master
Gerrit-Owner: Giuseppe Lavagetto <[email protected]>
Gerrit-Reviewer: Giuseppe Lavagetto <[email protected]>
Gerrit-Reviewer: Volans <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to