Skip to content

Instantly share code, notes, and snippets.

@Deepwalker
Created January 12, 2012 12:50
Show Gist options
  • Save Deepwalker/1600324 to your computer and use it in GitHub Desktop.
Save Deepwalker/1600324 to your computer and use it in GitHub Desktop.
import contract as c
import datetime
date_tuple = c.Dict(year=c.Int, month=c.Int, day=c.Int) >> (lambda d: datetime.datetime(**d))
task = c.Dict({
'key': c.String(),
c.Key('timestamp', optional=True): date_tuple,
})
try:
print task.check({'key': 'foo', 'timestamp': {'year': 2012, 'month': 1, 'day': 12}})
except c.ContractValidationError as e:
print e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment