Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added default_to validation function.

  • Loading branch information...
commit 26ebd204ceb6207a6f6a28b4761e100a23cf085b 1 parent 5fda2ed
@decbis decbis authored committed
Showing with 14 additions and 0 deletions.
  1. +14 −0 voluptuous.py
View
14 voluptuous.py
@@ -765,6 +765,20 @@ def title(v):
return str(v).title()
+def default_to(default_value, msg=None):
+ """Sets a value to default_value if none provided.
+
+ >>> s = Schema(default_to(42))
+ >>> s(None)
+ 42
+ """
+ def f(v):
+ if v is None:
+ v = default_value
+ return v
+ return f
+
+
if __name__ == '__main__':
import doctest
doctest.testmod()
Please sign in to comment.
Something went wrong with that request. Please try again.