alecthomas/voluptuous — pull request #5 by decbis (2012-07-26 04:13:20+00:00)
Title: Added default_to validation mutating function.

Added `default_to` validation mutating function to set a value to a default one if none provided. Intended use case would be make sure the validated data has some sensible defaults if no value was supplied, thus simplifying subsequent logic.

A couple simple examples:

* 1: file creation API

```python
import voluptuous as v

file_permissions_schema = v.Schema({v.required('permissions'): v.default_to(['read', 'write'])})

user_supplied_file_permissions = {'permissions': None}
file_permissions = file_permissions_schema(user_supplied_file_permissions)
# no need to worry about missing permissions below this point
```

* 2: paged results query API

```python
import voluptuous as v

results_query_schema = v.Schema({v.required('per_page'): v.default_to(100)})

user_supplied_results_query = {'per_page': None}
results_query = results_query_schema(user_supplied_results_query )
# we have a sensible default for per_page after this point
```