alecthomas/voluptuous — pull request #82 by sirfz (2014-08-07 11:59:45+00:00)
Title: Add Remove marker and option for extra keys to be excluded from output

This is a feature lacking in almost all schema validators out there but could be very useful to a lot of people who wish to "sanitize" received data. This feature introduces a new marker `Remove` which allows us to defined keys to be removed from the generated output. For Example:
```python
from voluptuous import Schema, Remove

schema = Schema({
"id": int,
"price": float,
"available": int,
Remove(str): str # remove all string keys with string values
})
print schema({"id": 1, "title": "unneeded title", "subtitle": "misc", "price": 100.0, "available": 1})
"""output would be something like this:
{"id": 1,
"price": 100.0,
"available": 1}
"""
```
In addition, we can have a similar behavior by passing the `REMOVE_EXTRA` constant to `Schema`'s `extra` parameter:
```python
from voluptuous import Schema, REMOVE_EXTRA
schema = Schema({
"id": int,
"price": float,
"available": int,
}, extra=REMOVE_EXTRA)
print schema({"id": 1, "title": "unneeded title", "subtitle": "misc", "price": 100.0, "available": 1})
```
available `extra` options are:
```python
PREVENT_EXTRA = 0 # any extra key not in schema will raise an error
ALLOW_EXTRA = 1 # extra keys not in schema will be included in output
REMOVE_EXTRA = 2 # extra keys not in schema will be excluded from output
```